@faststore/ui 1.3.36 → 1.3.40

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 (42) 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/Link/Link.d.ts +19 -0
  5. package/dist/atoms/Link/index.d.ts +2 -0
  6. package/dist/atoms/Price/stories/Price.stories.d.ts +1 -1
  7. package/dist/index.d.ts +4 -0
  8. package/dist/molecules/Banner/BannerContent.d.ts +1 -1
  9. package/dist/organisms/Card/Card.d.ts +10 -0
  10. package/dist/organisms/Card/CardActions.d.ts +10 -0
  11. package/dist/organisms/Card/CardContent.d.ts +14 -0
  12. package/dist/organisms/Card/CardImage.d.ts +10 -0
  13. package/dist/organisms/Card/index.d.ts +8 -0
  14. package/dist/organisms/Card/stories/Card.stories.d.ts +4 -0
  15. package/dist/typings/PolymorphicGenerics.d.ts +1 -0
  16. package/dist/typings/index.d.ts +1 -1
  17. package/dist/ui.cjs.development.js +79 -8
  18. package/dist/ui.cjs.development.js.map +1 -1
  19. package/dist/ui.cjs.production.min.js +1 -1
  20. package/dist/ui.cjs.production.min.js.map +1 -1
  21. package/dist/ui.esm.js +75 -9
  22. package/dist/ui.esm.js.map +1 -1
  23. package/package.json +3 -3
  24. package/src/atoms/Badge/Badge.tsx +4 -4
  25. package/src/atoms/Link/Link.test.tsx +53 -0
  26. package/src/atoms/Link/Link.tsx +47 -0
  27. package/src/atoms/Link/index.tsx +2 -0
  28. package/src/atoms/Link/stories/Link.mdx +35 -0
  29. package/src/atoms/Link/stories/Link.stories.tsx +30 -0
  30. package/src/index.ts +15 -0
  31. package/src/molecules/Banner/BannerContent.tsx +1 -3
  32. package/src/molecules/SearchInput/SearchInput.tsx +2 -1
  33. package/src/organisms/Card/Card.test.tsx +68 -0
  34. package/src/organisms/Card/Card.tsx +22 -0
  35. package/src/organisms/Card/CardActions.tsx +29 -0
  36. package/src/organisms/Card/CardContent.tsx +40 -0
  37. package/src/organisms/Card/CardImage.tsx +22 -0
  38. package/src/organisms/Card/index.tsx +11 -0
  39. package/src/organisms/Card/stories/Card.mdx +54 -0
  40. package/src/organisms/Card/stories/Card.stories.tsx +62 -0
  41. package/src/typings/PolymorphicGenerics.ts +5 -0
  42. package/src/typings/index.ts +1 -0
@@ -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
  )
@@ -0,0 +1,53 @@
1
+ import { render } from '@testing-library/react'
2
+ import { axe } from 'jest-axe'
3
+ import React from 'react'
4
+
5
+ import type { LinkProps } from '.'
6
+ import LinkComponent from '.'
7
+
8
+ const TestLink = ({ href = '/', testId }: LinkProps<'a'>) => {
9
+ return (
10
+ <LinkComponent testId={testId} href={href}>
11
+ Link
12
+ </LinkComponent>
13
+ )
14
+ }
15
+
16
+ describe('Link', () => {
17
+ it('should receive a custom component', () => {
18
+ const { getByTestId } = render(
19
+ <LinkComponent
20
+ href="/"
21
+ as={(props: { href: string }) => {
22
+ return (
23
+ <div {...props}>
24
+ <a data-testid="custom-anchor" href={props.href}>
25
+ Link
26
+ </a>
27
+ </div>
28
+ )
29
+ }}
30
+ />
31
+ )
32
+
33
+ expect(getByTestId('custom-anchor')).toHaveAttribute('href', '/')
34
+ expect(getByTestId('store-link')).toHaveAttribute('data-store-link')
35
+ })
36
+
37
+ describe('Data Attributes', () => {
38
+ it('should have `data-store-link` attribute', () => {
39
+ const { getByTestId } = render(<TestLink />)
40
+
41
+ expect(getByTestId('store-link')).toHaveAttribute('data-store-link')
42
+ })
43
+ })
44
+
45
+ describe('Accessibility', () => {
46
+ it('should have no violations', async () => {
47
+ const { getByTestId } = render(<TestLink />)
48
+
49
+ expect(await axe(getByTestId('store-link'))).toHaveNoViolations()
50
+ expect(await axe(getByTestId('store-link'))).toHaveNoIncompletes()
51
+ })
52
+ })
53
+ })
@@ -0,0 +1,47 @@
1
+ import React, { forwardRef } from 'react'
2
+ import type { FC, ElementType, ReactElement } from 'react'
3
+
4
+ import type {
5
+ PolymorphicRef,
6
+ PolymorphicComponentPropsWithRef,
7
+ } from '../../typings'
8
+
9
+ interface Props {
10
+ /**
11
+ * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
12
+ */
13
+ testId?: string
14
+ }
15
+
16
+ export type LinkProps<C extends ElementType> = PolymorphicComponentPropsWithRef<
17
+ C,
18
+ Props
19
+ >
20
+
21
+ type LinkComponent = <C extends ElementType = 'a'>(
22
+ props: LinkProps<C>
23
+ ) => ReactElement | null
24
+
25
+ const Link: LinkComponent = forwardRef(function Link<
26
+ C extends ElementType = 'a'
27
+ >(
28
+ { as, children, testId = 'store-link', ...otherProps }: LinkProps<C>,
29
+ ref?: PolymorphicRef<C>
30
+ ) {
31
+ const Component = as ?? 'a'
32
+
33
+ return (
34
+ <Component ref={ref} data-store-link data-testid={testId} {...otherProps}>
35
+ {children}
36
+ </Component>
37
+ )
38
+ })
39
+
40
+ /**
41
+ * This is only being exported to make it easier to use in Storybook.
42
+ * **DON'T** import this directly to use this component, use the default export
43
+ * instead.
44
+ */
45
+ export const StorybookLink = Link as FC<Props>
46
+
47
+ export default Link
@@ -0,0 +1,2 @@
1
+ export { default } from './Link'
2
+ export type { LinkProps } from './Link'
@@ -0,0 +1,35 @@
1
+ import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
2
+ import { StorybookLink } from '../Link'
3
+
4
+ # Link
5
+
6
+ `Link` component performs the same behavior of a regular anchor tag (`<a>`), but can be used as any HTML tag.
7
+
8
+ ## Default
9
+
10
+ <Canvas>
11
+ <Story id="atoms-link--default" />
12
+ </Canvas>
13
+
14
+ ## As Div
15
+
16
+ <Canvas>
17
+ <Story id="atoms-link--as-div" />
18
+ </Canvas>
19
+
20
+ ## Props
21
+
22
+ The component supports all attributes also supported by the choosen tag (through the prop `as`).
23
+
24
+ For example, in cases it is wanted to be used as a wrapper for any external link component (i.e., Next.js Link or Gatsby Link), the component can be used with the prop `as="div"`.
25
+
26
+ Besides those attributes, the following props are also supported:
27
+
28
+ <ArgsTable of={StorybookLink} />
29
+
30
+ ## CSS Selectors
31
+
32
+ ```css
33
+ [data-store-link] {
34
+ }
35
+ ```
@@ -0,0 +1,30 @@
1
+ import type { Story, Meta } from '@storybook/react'
2
+ import React from 'react'
3
+
4
+ import type { LinkProps } from '../Link'
5
+ import LinkComponent from '../Link'
6
+ import mdx from './Link.mdx'
7
+
8
+ const LinkDefaultTemplate: Story<LinkProps<'a'>> = () => (
9
+ <LinkComponent href="/">A default link</LinkComponent>
10
+ )
11
+
12
+ export const Default = LinkDefaultTemplate.bind({})
13
+
14
+ const LinkAsDivTemplate: Story<LinkProps<'div'>> = () => (
15
+ <LinkComponent as="div">
16
+ <span>A span inside the Link component</span>
17
+ <a href="/">A link inside the Link component</a>
18
+ </LinkComponent>
19
+ )
20
+
21
+ export const AsDiv = LinkAsDivTemplate.bind({})
22
+
23
+ export default {
24
+ title: 'Atoms/Link',
25
+ parameters: {
26
+ docs: {
27
+ page: mdx,
28
+ },
29
+ },
30
+ } as Meta
package/src/index.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  // Atoms
2
+ export { default as Link } from './atoms/Link'
3
+ export type { LinkProps } from './atoms/Link'
4
+
2
5
  export { default as Button } from './atoms/Button'
3
6
  export type { ButtonProps } from './atoms/Button'
4
7
 
@@ -128,6 +131,18 @@ export { default as Alert } from './molecules/Alert'
128
131
  export type { AlertProps } from './molecules/Alert'
129
132
 
130
133
  // Organisms
134
+ export {
135
+ default as Card,
136
+ CardImage,
137
+ CardContent,
138
+ CardActions,
139
+ } from './organisms/Card'
140
+ export type {
141
+ CardProps,
142
+ CardImageProps,
143
+ CardContentProps,
144
+ CardActionsProps,
145
+ } from './organisms/Card'
131
146
 
132
147
  // Hooks
133
148
  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
@@ -44,3 +44,8 @@ export type PolymorphicComponentPropsWithRef<
44
44
  C extends ElementType,
45
45
  P = Record<string, never>
46
46
  > = PolymorphicComponentProps<C, P> & { ref?: ComponentPropsWithRef<C>['ref'] }
47
+
48
+ // Extract the `ref` prop from a polymorphic component
49
+ export type PolymorphicRef<
50
+ C extends ElementType
51
+ > = PolymorphicComponentPropsWithRef<C>['ref']
@@ -1,4 +1,5 @@
1
1
  export type {
2
2
  PolymorphicComponentProps,
3
3
  PolymorphicComponentPropsWithRef,
4
+ PolymorphicRef,
4
5
  } from './PolymorphicGenerics'