-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ProductTitle Molecule (#1418)
Co-authored-by: Filipe W. Lima <filipe.lima@vtex.com.br> Co-authored-by: Fanny Chien <fannychienn@gmail.com>
- Loading branch information
1 parent
9fb3648
commit 184d0b9
Showing
7 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 20px; | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './ProductTitle' | ||
export type { ProductTitleProps } from './ProductTitle' |
26 changes: 26 additions & 0 deletions
26
packages/ui/src/molecules/ProductTitle/stories/ProductTitle.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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-fs-product-title] { | ||
} | ||
|
||
[data-fs-product-title-header] { | ||
} | ||
|
||
[data-fs-product-title-addendum] { | ||
} | ||
``` |
27 changes: 27 additions & 0 deletions
27
packages/ui/src/molecules/ProductTitle/stories/ProductTitle.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
184d0b9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
faststore – ./
faststore-docs.vercel.app
faststore-git-main-faststore.vercel.app
faststore.dev
faststore-faststore.vercel.app
www.faststore.dev