@faststore/ui 1.3.36 → 1.3.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/organisms/Card/Card.d.ts +10 -0
- package/dist/organisms/Card/CardActions.d.ts +10 -0
- package/dist/organisms/Card/CardContent.d.ts +14 -0
- package/dist/organisms/Card/CardImage.d.ts +10 -0
- package/dist/organisms/Card/index.d.ts +8 -0
- package/dist/organisms/Card/stories/Card.stories.d.ts +4 -0
- package/dist/ui.cjs.development.js +55 -0
- package/dist/ui.cjs.development.js.map +1 -1
- package/dist/ui.cjs.production.min.js +1 -1
- package/dist/ui.cjs.production.min.js.map +1 -1
- package/dist/ui.esm.js +52 -1
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +12 -0
- package/src/organisms/Card/Card.test.tsx +68 -0
- package/src/organisms/Card/Card.tsx +22 -0
- package/src/organisms/Card/CardActions.tsx +29 -0
- package/src/organisms/Card/CardContent.tsx +40 -0
- package/src/organisms/Card/CardImage.tsx +22 -0
- package/src/organisms/Card/index.tsx +11 -0
- package/src/organisms/Card/stories/Card.mdx +54 -0
- package/src/organisms/Card/stories/Card.stories.tsx +62 -0
package/src/index.ts
CHANGED
|
@@ -128,6 +128,18 @@ export { default as Alert } from './molecules/Alert'
|
|
|
128
128
|
export type { AlertProps } from './molecules/Alert'
|
|
129
129
|
|
|
130
130
|
// Organisms
|
|
131
|
+
export {
|
|
132
|
+
default as Card,
|
|
133
|
+
CardImage,
|
|
134
|
+
CardContent,
|
|
135
|
+
CardActions,
|
|
136
|
+
} from './organisms/Card'
|
|
137
|
+
export type {
|
|
138
|
+
CardProps,
|
|
139
|
+
CardImageProps,
|
|
140
|
+
CardContentProps,
|
|
141
|
+
CardActionsProps,
|
|
142
|
+
} from './organisms/Card'
|
|
131
143
|
|
|
132
144
|
// Hooks
|
|
133
145
|
export { default as useSlider } from './hooks/useSlider'
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import { axe } from 'jest-axe'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import Card from './Card'
|
|
6
|
+
import CardImage from './CardImage'
|
|
7
|
+
import CardContent from './CardContent'
|
|
8
|
+
import CardActions from './CardActions'
|
|
9
|
+
|
|
10
|
+
const TestCard = () => {
|
|
11
|
+
return (
|
|
12
|
+
<Card>
|
|
13
|
+
<CardImage>
|
|
14
|
+
<div>An image</div>
|
|
15
|
+
</CardImage>
|
|
16
|
+
<CardContent>
|
|
17
|
+
<h3>A title</h3>
|
|
18
|
+
<p>89.90</p>
|
|
19
|
+
<div>A tag</div>
|
|
20
|
+
</CardContent>
|
|
21
|
+
<CardActions>
|
|
22
|
+
<button>A button</button>
|
|
23
|
+
</CardActions>
|
|
24
|
+
</Card>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('Card', () => {
|
|
29
|
+
let card: HTMLElement
|
|
30
|
+
let cardImage: HTMLElement
|
|
31
|
+
let cardContent: HTMLElement
|
|
32
|
+
let cardActions: HTMLElement
|
|
33
|
+
let cardContainer: HTMLElement
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
const { getByTestId, container } = render(<TestCard />)
|
|
37
|
+
|
|
38
|
+
cardContainer = container
|
|
39
|
+
card = getByTestId('store-card')
|
|
40
|
+
cardImage = getByTestId('store-card-image')
|
|
41
|
+
cardContent = getByTestId('store-card-content')
|
|
42
|
+
cardActions = getByTestId('store-card-actions')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('Data attributes', () => {
|
|
46
|
+
it('`Card` component should have `data-store-card` attribute', () => {
|
|
47
|
+
expect(card).toHaveAttribute('data-store-card')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('`CardContent` component should have `data-store-card-content` attribute', () => {
|
|
51
|
+
expect(cardContent).toHaveAttribute('data-store-card-content')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('`CardImage` component should have `data-store-card-image` attribute', () => {
|
|
55
|
+
expect(cardImage).toHaveAttribute('data-store-card-image')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('`CardActions` component should have `data-store-card-actions` attribute', () => {
|
|
59
|
+
expect(cardActions).toHaveAttribute('data-store-card-actions')
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('Accessibility', () => {
|
|
64
|
+
it('should not have violations', async () => {
|
|
65
|
+
expect(await axe(cardContainer)).toHaveNoViolations()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { HTMLAttributes } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
7
|
+
*/
|
|
8
|
+
testId?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Card = forwardRef<HTMLDivElement, CardProps>(function Card(
|
|
12
|
+
{ testId = 'store-card', children, ...otherProps },
|
|
13
|
+
ref
|
|
14
|
+
) {
|
|
15
|
+
return (
|
|
16
|
+
<article ref={ref} data-store-card data-testid={testId} {...otherProps}>
|
|
17
|
+
{children}
|
|
18
|
+
</article>
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export default Card
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { HTMLAttributes } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface CardActionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
7
|
+
*/
|
|
8
|
+
testId?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const CardActions = forwardRef<HTMLDivElement, CardActionsProps>(
|
|
12
|
+
function CardActions(
|
|
13
|
+
{ testId = 'store-card-actions', children, ...otherProps },
|
|
14
|
+
ref
|
|
15
|
+
) {
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
ref={ref}
|
|
19
|
+
data-store-card-actions
|
|
20
|
+
data-testid={testId}
|
|
21
|
+
{...otherProps}
|
|
22
|
+
>
|
|
23
|
+
{children}
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export default CardActions
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { HTMLAttributes, AriaAttributes } from 'react'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface CardContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
7
|
+
*/
|
|
8
|
+
testId?: string
|
|
9
|
+
/**
|
|
10
|
+
* Defines a string value that labels the current element.
|
|
11
|
+
*/
|
|
12
|
+
'aria-label'?: AriaAttributes['aria-label']
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CardContent = forwardRef<HTMLDivElement, CardContentProps>(
|
|
16
|
+
function CardContent(
|
|
17
|
+
{
|
|
18
|
+
testId = 'store-card-content',
|
|
19
|
+
'aria-label': ariaLabel = 'Card content',
|
|
20
|
+
children,
|
|
21
|
+
...otherProps
|
|
22
|
+
},
|
|
23
|
+
ref
|
|
24
|
+
) {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
ref={ref}
|
|
28
|
+
role="region"
|
|
29
|
+
aria-label={ariaLabel}
|
|
30
|
+
data-store-card-content
|
|
31
|
+
data-testid={testId}
|
|
32
|
+
{...otherProps}
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export default CardContent
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface CardImageProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
7
|
+
*/
|
|
8
|
+
testId?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const CardImage = forwardRef<HTMLDivElement, CardImageProps>(function CardImage(
|
|
12
|
+
{ testId = 'store-card-image', children, ...otherProps },
|
|
13
|
+
ref
|
|
14
|
+
) {
|
|
15
|
+
return (
|
|
16
|
+
<div ref={ref} data-store-card-image data-testid={testId} {...otherProps}>
|
|
17
|
+
{children}
|
|
18
|
+
</div>
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export default CardImage
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default } from './Card'
|
|
2
|
+
export type { CardProps } from './Card'
|
|
3
|
+
|
|
4
|
+
export { default as CardImage } from './CardImage'
|
|
5
|
+
export type { CardImageProps } from './CardImage'
|
|
6
|
+
|
|
7
|
+
export { default as CardContent } from './CardContent'
|
|
8
|
+
export type { CardContentProps } from './CardContent'
|
|
9
|
+
|
|
10
|
+
export { default as CardActions } from './CardActions'
|
|
11
|
+
export type { CardActionsProps } from './CardActions'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import Card from '../Card'
|
|
4
|
+
import CardImage from '../CardImage'
|
|
5
|
+
import CardContent from '../CardContent'
|
|
6
|
+
import CardActions from '../CardActions'
|
|
7
|
+
|
|
8
|
+
# Card
|
|
9
|
+
|
|
10
|
+
<Canvas>
|
|
11
|
+
<Story id="organisms-card--card" />
|
|
12
|
+
</Canvas>
|
|
13
|
+
|
|
14
|
+
## Components
|
|
15
|
+
|
|
16
|
+
The `Card` uses the [Compound Component](https://kentcdodds.com/blog/compound-components-with-react-hooks) pattern, its components are:
|
|
17
|
+
|
|
18
|
+
- `Card`: the wrapper component;
|
|
19
|
+
- `CardImage`: the wrapper component for the content's image;
|
|
20
|
+
- `CardContent`: the wrapper component for the content's details;
|
|
21
|
+
- `CardActions`: the wrapper component for the content's CTAs (call-to-action);
|
|
22
|
+
|
|
23
|
+
## Props
|
|
24
|
+
|
|
25
|
+
All Card-related components support all attributes also supported by the `<div>` tag.
|
|
26
|
+
|
|
27
|
+
### `Card`
|
|
28
|
+
|
|
29
|
+
<ArgsTable of={Card} />
|
|
30
|
+
|
|
31
|
+
### `CardImage`
|
|
32
|
+
|
|
33
|
+
<ArgsTable of={CardImage} />
|
|
34
|
+
|
|
35
|
+
### `CardContent`
|
|
36
|
+
|
|
37
|
+
<ArgsTable of={CardContent} />
|
|
38
|
+
|
|
39
|
+
### `CardActions`
|
|
40
|
+
|
|
41
|
+
<ArgsTable of={CardActions} />
|
|
42
|
+
|
|
43
|
+
## CSS Selectors
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
[data-store-card] {
|
|
47
|
+
}
|
|
48
|
+
[data-store-card-image] {
|
|
49
|
+
}
|
|
50
|
+
[data-store-card-content] {
|
|
51
|
+
}
|
|
52
|
+
[data-store-card-actions] {
|
|
53
|
+
}
|
|
54
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Story, Meta } from '@storybook/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
// Atoms
|
|
5
|
+
import Price from '../../../atoms/Price'
|
|
6
|
+
import Badge from '../../../atoms/Badge'
|
|
7
|
+
import Button from '../../../atoms/Button'
|
|
8
|
+
// Card components
|
|
9
|
+
import CardComponent from '../Card'
|
|
10
|
+
import CardImage from '../CardImage'
|
|
11
|
+
import CardContent from '../CardContent'
|
|
12
|
+
import CardActions from '../CardActions'
|
|
13
|
+
import type { CardProps } from '../Card'
|
|
14
|
+
import mdx from './Card.mdx'
|
|
15
|
+
|
|
16
|
+
const CardTemplate: Story<CardProps> = ({ testId }) => {
|
|
17
|
+
return (
|
|
18
|
+
<CardComponent testId={testId}>
|
|
19
|
+
<CardImage>
|
|
20
|
+
<img
|
|
21
|
+
alt="A vintage camera"
|
|
22
|
+
src="https://storecomponents.vtex.app/assets/fit-in/480x480/center/middle/https%3A%2F%2Fstorecomponents.vtexassets.com%2Farquivos%2Fids%2F155481%2FFrame-3.jpg%3Fv%3D636793814536230000"
|
|
23
|
+
/>
|
|
24
|
+
</CardImage>
|
|
25
|
+
<CardContent>
|
|
26
|
+
<h3>Vintage Top Camera</h3>
|
|
27
|
+
<div>
|
|
28
|
+
<Price
|
|
29
|
+
value={89.9}
|
|
30
|
+
variant="selling"
|
|
31
|
+
formatter={formatter}
|
|
32
|
+
style={{ textDecoration: 'line-through' }}
|
|
33
|
+
/>
|
|
34
|
+
<Price value={68.9} variant="selling" formatter={formatter} />
|
|
35
|
+
</div>
|
|
36
|
+
<Badge>15% OFF</Badge>
|
|
37
|
+
</CardContent>
|
|
38
|
+
<CardActions>
|
|
39
|
+
<Button onClick={() => null}>Add to Cart</Button>
|
|
40
|
+
</CardActions>
|
|
41
|
+
</CardComponent>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function formatter(price: number) {
|
|
46
|
+
return new Intl.NumberFormat('en-US', {
|
|
47
|
+
style: 'currency',
|
|
48
|
+
currency: 'USD',
|
|
49
|
+
}).format(price)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const Card = CardTemplate.bind({})
|
|
53
|
+
Card.storyName = 'Card'
|
|
54
|
+
|
|
55
|
+
export default {
|
|
56
|
+
title: 'Organisms/Card',
|
|
57
|
+
parameters: {
|
|
58
|
+
docs: {
|
|
59
|
+
page: mdx,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
} as Meta
|