Skip to content

Commit

Permalink
feat: Add ProductTitle Molecule
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Andrade <arthurfelandrade@gmail.com>
  • Loading branch information
ArthurTriis1 committed Jul 25, 2022
1 parent 4cba5f2 commit f2bf75c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/styles/src/molecules/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
@import './radio-group.css';
@import './search-input.css';
@import './table.css';
@import './product-title.css';
23 changes: 23 additions & 0 deletions packages/styles/src/molecules/product-title.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[data-fs-product-title] {
width: fit-content;
background-color: #cecece;
padding: 8px;
border-radius: 5px;
}
[data-fs-product-title] [data-fs-product-title-header] {
display: flex;
column-gap: .75rem;
justify-content: space-between;
}
[data-fs-product-title] [data-fs-product-title-header]:first-child {
font-size: var(--fs-product-title-text-size);
font-weight: 400;
line-height: 1.12;
}
[data-fs-product-title] [data-fs-product-title-header] [data-store-badge] {
white-space: nowrap;
}
[data-fs-product-title] [data-fs-product-title-addendum] {
margin-top: 1rem;
color: #5d666f;
}
3 changes: 3 additions & 0 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export { default as Incentive } from './atoms/Incentive'
export type { IncentiveProps } from './atoms/Incentive'

// Molecules
export { default as ProductTitle } from './molecules/ProductTitle'
export type { ProductTitleProps } from './molecules/ProductTitle'

export { default as AggregateRating } from './molecules/AggregateRating'
export type { AggregateRatingProps } from './molecules/AggregateRating'

Expand Down
44 changes: 44 additions & 0 deletions packages/ui/src/molecules/ProductTitle/ProductTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { HTMLAttributes } from 'react'
import type { ReactNode } from 'react'

export type ProductTitleProps = Omit<HTMLAttributes<HTMLElement>, 'title'> & {
/**
* A react component to be used as the product title, e.g. a `h1`
*/
title: ReactNode
/**
* A react component to be used as the product label, e.g. a `DiscountBadge`
*/
label?: ReactNode
/**
* Label for reference.
*/
refTag?: string
/**
* A text to be used below the title and the label, such as the product's reference number.
*/
refNumber?: string
/**
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
*/
testId?: string
}

function ProductTitle({ title, label, refTag= "Ref.: ",refNumber, testId= 'store-product-title', ...otherProps }: ProductTitleProps) {
return (
<header data-fs-product-title data-testid={testId} {...otherProps}>
<div data-fs-product-title-header>
{title}
{!!label && label}
</div>

{refNumber && (
<p data-fs-product-title-addendum>
{refTag}{refNumber}
</p>
)}
</header>
)
}

export default ProductTitle
2 changes: 2 additions & 0 deletions packages/ui/src/molecules/ProductTitle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './ProductTitle'
export type { ProductTitleProps } from './ProductTitle'
20 changes: 20 additions & 0 deletions packages/ui/src/molecules/ProductTitle/stories/ProductTitle.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'

import ProductTitle from '../ProductTitle'

# ProductTitle

<Canvas>
<Story id="molecules-producttitle--product-title" />
</Canvas>

## Props

<ArgsTable of={ ProductTitle } />

## CSS Selectors

```css
[data-store-product-title] {
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Story, Meta } from '@storybook/react'
import React from 'react'

import type { ProductTitleProps } from '../ProductTitle'
import Component from '../ProductTitle'
import mdx from './ProductTitle.mdx'
import Badge from '../../../atoms/Badge'

const ProductTitleTemplate: Story<ProductTitleProps> = () => (
<Component
title={<h1>Apple Magic Mouse</h1>}
refNumber='99995945'
label={<Badge>90%</Badge>}
/>
)

export const ProductTitle = ProductTitleTemplate.bind({})
ProductTitle.storyName = 'ProductTitle'

export default {
title: 'Molecules/ProductTitle',
parameters: {
docs: {
page: mdx,
},
},
} as Meta

0 comments on commit f2bf75c

Please sign in to comment.