@faststore/ui 1.3.35 → 1.3.39

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/atoms/Badge/Badge.d.ts +2 -2
  3. package/dist/atoms/Icon/stories/Icon.stories.d.ts +1 -1
  4. package/dist/atoms/Price/stories/Price.stories.d.ts +1 -1
  5. package/dist/index.d.ts +2 -0
  6. package/dist/molecules/Banner/BannerContent.d.ts +1 -1
  7. package/dist/organisms/Card/Card.d.ts +10 -0
  8. package/dist/organisms/Card/CardActions.d.ts +10 -0
  9. package/dist/organisms/Card/CardContent.d.ts +14 -0
  10. package/dist/organisms/Card/CardImage.d.ts +10 -0
  11. package/dist/organisms/Card/index.d.ts +8 -0
  12. package/dist/organisms/Card/stories/Card.stories.d.ts +4 -0
  13. package/dist/ui.cjs.development.js +64 -8
  14. package/dist/ui.cjs.development.js.map +1 -1
  15. package/dist/ui.cjs.production.min.js +1 -1
  16. package/dist/ui.cjs.production.min.js.map +1 -1
  17. package/dist/ui.esm.js +61 -9
  18. package/dist/ui.esm.js.map +1 -1
  19. package/dist/utils/toHaveNoIncomplete.d.ts +1 -1
  20. package/package.json +3 -3
  21. package/src/atoms/Badge/Badge.tsx +4 -4
  22. package/src/index.ts +12 -0
  23. package/src/molecules/Banner/BannerContent.tsx +1 -3
  24. package/src/molecules/SearchInput/SearchInput.tsx +2 -1
  25. package/src/organisms/Card/Card.test.tsx +68 -0
  26. package/src/organisms/Card/Card.tsx +22 -0
  27. package/src/organisms/Card/CardActions.tsx +29 -0
  28. package/src/organisms/Card/CardContent.tsx +40 -0
  29. package/src/organisms/Card/CardImage.tsx +22 -0
  30. package/src/organisms/Card/index.tsx +11 -0
  31. package/src/organisms/Card/stories/Card.mdx +54 -0
  32. package/src/organisms/Card/stories/Card.stories.tsx +62 -0
  33. package/src/utils/toHaveNoIncomplete.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/ui",
3
- "version": "1.3.35",
3
+ "version": "1.3.39",
4
4
  "description": "A lightweight, framework agnostic component library for React",
5
5
  "author": "emersonlaurentino",
6
6
  "license": "MIT",
@@ -76,7 +76,7 @@
76
76
  "@types/jest-axe": "^3.5.3",
77
77
  "@types/tabbable": "^3.1.1",
78
78
  "@types/testing-library__jest-dom": "^5.9.5",
79
- "@vtex/theme-b2c-tailwind": "^1.3.35",
79
+ "@vtex/theme-b2c-tailwind": "^1.3.39",
80
80
  "@vtex/tsconfig": "^0.5.0",
81
81
  "chalk": "^5.0.0",
82
82
  "jest-axe": "^5.0.1",
@@ -89,5 +89,5 @@
89
89
  "tsdx": "^0.14.1",
90
90
  "typescript": "^4.2.4"
91
91
  },
92
- "gitHead": "2180e37bd61f31e0ded50f56e4834d89879fce9a"
92
+ "gitHead": "cb7ddf3c761d6fd57b11c81c6fec4424ec8b26ef"
93
93
  }
@@ -1,7 +1,7 @@
1
- import type { ReactNode } from 'react'
1
+ import type { ReactNode, HTMLAttributes } from 'react'
2
2
  import React, { forwardRef } from 'react'
3
3
 
4
- export interface BadgeProps {
4
+ export interface BadgeProps extends HTMLAttributes<HTMLDivElement> {
5
5
  /**
6
6
  * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
7
7
  */
@@ -10,11 +10,11 @@ export interface BadgeProps {
10
10
  }
11
11
 
12
12
  const Badge = forwardRef<HTMLDivElement, BadgeProps>(function Badge(
13
- { testId = 'store-badge', children }: BadgeProps,
13
+ { testId = 'store-badge', children, ...otherProps }: BadgeProps,
14
14
  ref
15
15
  ) {
16
16
  return (
17
- <div ref={ref} data-testid={testId} data-store-badge>
17
+ <div ref={ref} data-store-badge data-testid={testId} {...otherProps}>
18
18
  {children}
19
19
  </div>
20
20
  )
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'
@@ -1,8 +1,7 @@
1
1
  import type { HTMLAttributes } from 'react'
2
2
  import React, { forwardRef } from 'react'
3
3
 
4
- export interface BannerContentProps
5
- extends Omit<HTMLAttributes<HTMLDivElement>, 'role'> {
4
+ export interface BannerContentProps extends HTMLAttributes<HTMLDivElement> {
6
5
  /**
7
6
  * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
8
7
  */
@@ -17,7 +16,6 @@ const BannerContent = forwardRef<HTMLDivElement, BannerContentProps>(
17
16
  return (
18
17
  <div
19
18
  ref={ref}
20
- role="region"
21
19
  data-store-banner-content
22
20
  data-testid={testId}
23
21
  {...otherProps}
@@ -77,9 +77,10 @@ const SearchInput = forwardRef<HTMLFormElement, SearchInputProps>(
77
77
  data-store-search-input
78
78
  data-testid={testId}
79
79
  onSubmit={handleSubmit}
80
+ role="search"
80
81
  >
81
82
  <Input ref={valueRef} aria-label={ariaLabel} {...otherProps} />
82
- <Button type="submit" aria-label={`button-${ariaLabel}`}>
83
+ <Button type="submit" aria-label="Submit Search">
83
84
  <Icon component={icon ?? <SearchIcon />} />
84
85
  </Button>
85
86
  </Form>
@@ -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
@@ -65,7 +65,7 @@ export const toHaveNoIncompletes = {
65
65
  declare global {
66
66
  // eslint-disable-next-line
67
67
  namespace jest {
68
- interface Matchers<R, T> {
68
+ interface Matchers<R> {
69
69
  toHaveNoIncompletes(): R
70
70
  }
71
71
  }