@faststore/ui 1.3.33 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/ui",
3
- "version": "1.3.33",
3
+ "version": "1.3.37",
4
4
  "description": "A lightweight, framework agnostic component library for React",
5
5
  "author": "emersonlaurentino",
6
6
  "license": "MIT",
@@ -72,12 +72,15 @@
72
72
  "@testing-library/react": "^11.2.6",
73
73
  "@testing-library/react-hooks": "^7.0.2",
74
74
  "@testing-library/user-event": "^13.1.8",
75
+ "@types/axe-core": "^2.0.7",
75
76
  "@types/jest-axe": "^3.5.3",
76
77
  "@types/tabbable": "^3.1.1",
77
78
  "@types/testing-library__jest-dom": "^5.9.5",
78
- "@vtex/theme-b2c-tailwind": "^1.3.33",
79
+ "@vtex/theme-b2c-tailwind": "^1.3.37",
79
80
  "@vtex/tsconfig": "^0.5.0",
81
+ "chalk": "^5.0.0",
80
82
  "jest-axe": "^5.0.1",
83
+ "jest-matcher-utils": "^27.4.2",
81
84
  "react": "^17.0.2",
82
85
  "react-docgen-typescript-loader": "^3.7.2",
83
86
  "react-dom": "^17.0.2",
@@ -86,5 +89,5 @@
86
89
  "tsdx": "^0.14.1",
87
90
  "typescript": "^4.2.4"
88
91
  },
89
- "gitHead": "41e345c1c5ae90a7c8b21c3f3c378169d36b7d35"
92
+ "gitHead": "45ea1ebe1bdd2bea6c3c5fa05432be8cdb7c9a02"
90
93
  }
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'
@@ -76,6 +76,14 @@ describe('Modal WAI-ARIA Specifications', () => {
76
76
  )
77
77
 
78
78
  expect(await axe(document.body)).toHaveNoViolations()
79
+ // This is disabled because the useTrapFocus use sentinel div elements
80
+ // with tabindex and aria-hidden true. This is intentionally, because
81
+ // these divs shouldn't be considered to accessibility API.
82
+ expect(
83
+ await axe(document.body, {
84
+ rules: { 'aria-hidden-focus': { enabled: false } },
85
+ })
86
+ ).toHaveNoIncompletes()
79
87
  })
80
88
 
81
89
  it('Focus first element', () => {
@@ -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
package/src/setupTests.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import '@testing-library/jest-dom/extend-expect'
2
2
  import { toHaveNoViolations } from 'jest-axe'
3
3
 
4
+ import { toHaveNoIncompletes } from './utils/toHaveNoIncomplete'
5
+
4
6
  expect.extend(toHaveNoViolations)
7
+ expect.extend(toHaveNoIncompletes)
@@ -0,0 +1,76 @@
1
+ import type { AxeResults } from 'axe-core'
2
+ import { printReceived, matcherHint } from 'jest-matcher-utils'
3
+ import chalk from 'chalk'
4
+
5
+ // This code is based on jest-axe library.
6
+ // https://github.com/nickcolley/jest-axe
7
+ export const toHaveNoIncompletes = {
8
+ toHaveNoIncompletes: (results: AxeResults) => {
9
+ if (typeof results.incomplete === 'undefined') {
10
+ throw new Error('No incompletes found in aXe results object')
11
+ }
12
+
13
+ const reporter = (incompletes: AxeResults['incomplete']) => {
14
+ if (incompletes.length === 0) {
15
+ return []
16
+ }
17
+
18
+ const lineBreak = '\n\n'
19
+ const horizontalLine = '\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500'
20
+
21
+ return incompletes
22
+ .map((incomplete) => {
23
+ const errorBody = incomplete.nodes
24
+ .map((node) => {
25
+ const selector = node.target.join(', ')
26
+ const expectedText = `Expected the HTML found at $('${selector}') to have no incompletes:${lineBreak}`
27
+
28
+ return `${
29
+ expectedText + chalk.grey(node.html) + lineBreak
30
+ }Received:${lineBreak}${printReceived(
31
+ `${incomplete.help} (${incomplete.id})`
32
+ )}${lineBreak}${chalk.yellow(node.failureSummary)}${lineBreak}${
33
+ incomplete.helpUrl
34
+ ? `You can find more information on this issue here: \n${chalk.blue(
35
+ incomplete.helpUrl
36
+ )}`
37
+ : ''
38
+ }`
39
+ })
40
+ .join(lineBreak)
41
+
42
+ return errorBody
43
+ })
44
+ .join(lineBreak + horizontalLine + lineBreak)
45
+ }
46
+
47
+ const { incomplete: incompletes } = results
48
+ const formatedIncompletes = reporter(incompletes)
49
+ const pass = formatedIncompletes.length === 0
50
+
51
+ const message = () => {
52
+ if (pass) {
53
+ return ''
54
+ }
55
+
56
+ return (
57
+ `${matcherHint('.toHaveNoIncompletes')}\n\n` + `${formatedIncompletes}`
58
+ )
59
+ }
60
+
61
+ return { actual: incompletes, message, pass }
62
+ },
63
+ }
64
+
65
+ declare global {
66
+ // eslint-disable-next-line
67
+ namespace jest {
68
+ interface Matchers<R> {
69
+ toHaveNoIncompletes(): R
70
+ }
71
+ }
72
+
73
+ // axe-core depends on a global Node
74
+ // eslint-disable-next-line
75
+ interface Node {}
76
+ }