@faststore/ui 1.3.19 → 1.3.23
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 +38 -0
- package/README.md +1 -44
- package/dist/index.d.ts +10 -0
- package/dist/molecules/Banner/Banner.d.ts +13 -0
- package/dist/molecules/Banner/BannerContent.d.ts +10 -0
- package/dist/molecules/Banner/BannerImage.d.ts +10 -0
- package/dist/molecules/Banner/BannerLink.d.ts +10 -0
- package/dist/molecules/Banner/index.d.ts +8 -0
- package/dist/molecules/Banner/stories/Banner.stories.d.ts +4 -0
- package/dist/molecules/RadioGroup/index.d.ts +4 -4
- package/dist/ui.cjs.development.js +199 -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 +195 -2
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +15 -0
- package/src/molecules/Banner/Banner.test.tsx +63 -0
- package/src/molecules/Banner/Banner.tsx +26 -0
- package/src/molecules/Banner/BannerContent.tsx +31 -0
- package/src/molecules/Banner/BannerImage.tsx +29 -0
- package/src/molecules/Banner/BannerLink.tsx +29 -0
- package/src/molecules/Banner/index.ts +11 -0
- package/src/molecules/Banner/stories/Banner.mdx +63 -0
- package/src/molecules/Banner/stories/Banner.stories.tsx +66 -0
- package/src/molecules/RadioGroup/RadioGroup.test.tsx +3 -1
- package/src/molecules/RadioGroup/index.tsx +4 -10
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import { axe } from 'jest-axe'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import Banner from './Banner'
|
|
6
|
+
import BannerImage from './BannerImage'
|
|
7
|
+
import BannerContent from './BannerContent'
|
|
8
|
+
import BannerLink from './BannerLink'
|
|
9
|
+
|
|
10
|
+
const BannerTest = () => {
|
|
11
|
+
return (
|
|
12
|
+
<Banner>
|
|
13
|
+
<BannerImage>
|
|
14
|
+
<img
|
|
15
|
+
alt="A person with hands on the pocket, carrying a round straw bag"
|
|
16
|
+
src="https://storecomponents.vtex.app/assets/fit-in/1280x613/center/middle/https%3A%2F%2Fstorecomponents.vtexassets.com%2Fassets%2Fvtex.file-manager-graphql%2Fimages%2Fedce348c-068c-4fb9-91f2-7d235d596e0f___b2822f893b14f87337d08f07f0e520ab.jpg"
|
|
17
|
+
/>
|
|
18
|
+
</BannerImage>
|
|
19
|
+
<BannerContent>
|
|
20
|
+
<div>
|
|
21
|
+
<h3>Get yo know our next release</h3>
|
|
22
|
+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
|
|
23
|
+
</div>
|
|
24
|
+
<BannerLink>Shop now</BannerLink>
|
|
25
|
+
</BannerContent>
|
|
26
|
+
</Banner>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('Banner', () => {
|
|
31
|
+
describe('Data attributes', () => {
|
|
32
|
+
const { getByTestId } = render(<BannerTest />)
|
|
33
|
+
|
|
34
|
+
const banner = getByTestId('store-banner')
|
|
35
|
+
const bannerImage = getByTestId('store-banner-image')
|
|
36
|
+
const bannerContent = getByTestId('store-banner-content')
|
|
37
|
+
const bannerLink = getByTestId('store-banner-link')
|
|
38
|
+
|
|
39
|
+
it('`Banner` component should have `data-store-banner` attribute', () => {
|
|
40
|
+
expect(banner).toHaveAttribute('data-store-banner')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('`BannerImage` component should have `data-store-banner-image` attribute', () => {
|
|
44
|
+
expect(bannerImage).toHaveAttribute('data-store-banner-image')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('`BannerContent` component should have `data-store-banner-content` attribute', () => {
|
|
48
|
+
expect(bannerContent).toHaveAttribute('data-store-banner-content')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('`BannerLink` component should have `data-store-banner-link` attribute', () => {
|
|
52
|
+
expect(bannerLink).toHaveAttribute('data-store-banner-link')
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('Accessibility', () => {
|
|
57
|
+
it('should have no violations', async () => {
|
|
58
|
+
const { getByTestId } = render(<BannerTest />)
|
|
59
|
+
|
|
60
|
+
expect(await axe(getByTestId('store-banner'))).toHaveNoViolations()
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
type BannerDirectionVariant = 'vertical' | 'horizontal'
|
|
4
|
+
export interface BannerProps {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress,
|
|
7
|
+
* testing-library, and jest).
|
|
8
|
+
*/
|
|
9
|
+
testId?: string
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
variant?: BannerDirectionVariant
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Banner = ({
|
|
15
|
+
testId = 'store-banner',
|
|
16
|
+
children,
|
|
17
|
+
variant = 'vertical',
|
|
18
|
+
}: BannerProps) => {
|
|
19
|
+
return (
|
|
20
|
+
<article data-store-banner={variant} data-testid={testId}>
|
|
21
|
+
{children}
|
|
22
|
+
</article>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default Banner
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface BannerContentProps
|
|
5
|
+
extends Omit<HTMLAttributes<HTMLDivElement>, 'role'> {
|
|
6
|
+
/**
|
|
7
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
8
|
+
*/
|
|
9
|
+
testId?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const BannerContent = forwardRef<HTMLDivElement, BannerContentProps>(
|
|
13
|
+
function BannerContent(
|
|
14
|
+
{ testId = 'store-banner-content', children, ...otherProps },
|
|
15
|
+
ref
|
|
16
|
+
) {
|
|
17
|
+
return (
|
|
18
|
+
<div
|
|
19
|
+
ref={ref}
|
|
20
|
+
role="region"
|
|
21
|
+
data-store-banner-content
|
|
22
|
+
data-testid={testId}
|
|
23
|
+
{...otherProps}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
export default BannerContent
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface BannerImageProps 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 BannerImage = forwardRef<HTMLDivElement, BannerImageProps>(
|
|
12
|
+
function BannerImage(
|
|
13
|
+
{ testId = 'store-banner-image', children, ...otherProps },
|
|
14
|
+
ref
|
|
15
|
+
) {
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
ref={ref}
|
|
19
|
+
data-store-banner-image
|
|
20
|
+
data-testid={testId}
|
|
21
|
+
{...otherProps}
|
|
22
|
+
>
|
|
23
|
+
{children}
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export default BannerImage
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface BannerLinkProps 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 BannerLink = forwardRef<HTMLDivElement, BannerLinkProps>(
|
|
12
|
+
function BannerLink(
|
|
13
|
+
{ testId = 'store-banner-link', children, ...otherProps },
|
|
14
|
+
ref
|
|
15
|
+
) {
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
ref={ref}
|
|
19
|
+
data-store-banner-link
|
|
20
|
+
data-testid={testId}
|
|
21
|
+
{...otherProps}
|
|
22
|
+
>
|
|
23
|
+
{children}
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export default BannerLink
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default } from './Banner'
|
|
2
|
+
export type { BannerProps } from './Banner'
|
|
3
|
+
|
|
4
|
+
export { default as BannerImage } from './BannerImage'
|
|
5
|
+
export type { BannerImageProps } from './BannerImage'
|
|
6
|
+
|
|
7
|
+
export { default as BannerContent } from './BannerContent'
|
|
8
|
+
export type { BannerContentProps } from './BannerContent'
|
|
9
|
+
|
|
10
|
+
export { default as BannerLink } from './BannerLink'
|
|
11
|
+
export type { BannerLinkProps } from './BannerLink'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import Banner from '../Banner'
|
|
4
|
+
import BannerImage from '../BannerImage'
|
|
5
|
+
import BannerContent from '../BannerContent'
|
|
6
|
+
import BannerLink from '../BannerLink'
|
|
7
|
+
|
|
8
|
+
# Banner
|
|
9
|
+
|
|
10
|
+
<Canvas>
|
|
11
|
+
<Story id="molecules-banner--banner" />
|
|
12
|
+
</Canvas>
|
|
13
|
+
|
|
14
|
+
## Components
|
|
15
|
+
|
|
16
|
+
The `Banner` uses the [Compound Component](https://kentcdodds.com/blog/compound-components-with-react-hooks) pattern, its components are:
|
|
17
|
+
|
|
18
|
+
- `Banner`: the wrapper component, it can receive a `variant` prop to set its direction, supports `"vertical"` and `"horizontal"` values.
|
|
19
|
+
- `BannerImage`: the component that wraps the image displayed in the component.
|
|
20
|
+
- `BannerContent`: the component that can receive a title, description, and a `BannerLink`.
|
|
21
|
+
- `BannerLink`: the banner's call-to-action link.
|
|
22
|
+
|
|
23
|
+
## Props
|
|
24
|
+
|
|
25
|
+
All banner-related components support all attributes also supported by the `<div>` tag.
|
|
26
|
+
|
|
27
|
+
Besides those attributes, the following props are also supported:
|
|
28
|
+
|
|
29
|
+
### `Banner`
|
|
30
|
+
|
|
31
|
+
<ArgsTable of={Banner} />
|
|
32
|
+
|
|
33
|
+
### `BannerImage`
|
|
34
|
+
|
|
35
|
+
<ArgsTable of={BannerImage} />
|
|
36
|
+
|
|
37
|
+
### `BannerContent`
|
|
38
|
+
|
|
39
|
+
<ArgsTable of={BannerContent} />
|
|
40
|
+
|
|
41
|
+
### `BannerLink`
|
|
42
|
+
|
|
43
|
+
<ArgsTable of={BannerLink} />
|
|
44
|
+
|
|
45
|
+
## Guidelines
|
|
46
|
+
|
|
47
|
+
- Don’t hide important information in an image. If there is some important information, add it as text instead. For more information, see [Images Concepts • Images • WAI Web Accessibility Tutorials](https://www.w3.org/WAI/tutorials/images/)
|
|
48
|
+
- Use understandable links (avoid generic meaning, i.e., click here). For more information, see [Link Purpose](https://www.w3.org/WAI/WCAG21/Understanding/link-purpose-in-context.html)
|
|
49
|
+
|
|
50
|
+
## CSS Selectors
|
|
51
|
+
|
|
52
|
+
```css
|
|
53
|
+
[data-store-banner] {
|
|
54
|
+
}
|
|
55
|
+
[data-store-banner=('vertical'|'horizontal')] {
|
|
56
|
+
}
|
|
57
|
+
[data-store-banner-image] {
|
|
58
|
+
}
|
|
59
|
+
[data-store-banner-content] {
|
|
60
|
+
}
|
|
61
|
+
[data-store-banner-link] {
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Story, Meta } from '@storybook/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import BannerComponent from '../Banner'
|
|
5
|
+
import BannerImage from '../BannerImage'
|
|
6
|
+
import BannerContent from '../BannerContent'
|
|
7
|
+
import BannerLink from '../BannerLink'
|
|
8
|
+
import type { BannerProps } from '../Banner'
|
|
9
|
+
import { Icon } from '../../..'
|
|
10
|
+
import mdx from './Banner.mdx'
|
|
11
|
+
|
|
12
|
+
const RightArrow = () => (
|
|
13
|
+
<svg
|
|
14
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
15
|
+
width="18"
|
|
16
|
+
height="18"
|
|
17
|
+
viewBox="0 0 18 18"
|
|
18
|
+
>
|
|
19
|
+
<path
|
|
20
|
+
d="M10.6553 3.40717C10.3624 3.11428 9.88756 3.11428 9.59467 3.40717C9.30178 3.70006 9.30178 4.17494 9.59467 4.46783L13.3768 8.25H2.8125C2.39829 8.25 2.0625 8.58579 2.0625 9C2.0625 9.41421 2.39829 9.75 2.8125 9.75H13.3768L9.59467 13.5322C9.30178 13.8251 9.30178 14.2999 9.59467 14.5928C9.88756 14.8857 10.3624 14.8857 10.6553 14.5928L15.7178 9.53033C15.8643 9.38388 15.9375 9.19194 15.9375 9C15.9375 8.89831 15.9173 8.80134 15.8806 8.71291C15.844 8.62445 15.7897 8.54158 15.7178 8.46967L10.6553 3.40717Z"
|
|
21
|
+
fill="currentColor"
|
|
22
|
+
/>
|
|
23
|
+
</svg>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const BannerTemplate: Story<BannerProps> = ({ testId, variant }) => (
|
|
27
|
+
<BannerComponent testId={testId} variant={variant}>
|
|
28
|
+
<BannerImage>
|
|
29
|
+
<img
|
|
30
|
+
alt="A person with hands on the pocket, carrying a round straw bag"
|
|
31
|
+
src="https://storecomponents.vtex.app/assets/fit-in/1280x613/center/middle/https%3A%2F%2Fstorecomponents.vtexassets.com%2Fassets%2Fvtex.file-manager-graphql%2Fimages%2Fedce348c-068c-4fb9-91f2-7d235d596e0f___b2822f893b14f87337d08f07f0e520ab.jpg"
|
|
32
|
+
/>
|
|
33
|
+
</BannerImage>
|
|
34
|
+
<BannerContent>
|
|
35
|
+
<div>
|
|
36
|
+
<h3>Get to know our new release</h3>
|
|
37
|
+
<p>Your one-stop shop for making this summer season the best of all.</p>
|
|
38
|
+
</div>
|
|
39
|
+
<BannerLink>
|
|
40
|
+
<a href="/">
|
|
41
|
+
Shop now <Icon component={<RightArrow />} />
|
|
42
|
+
</a>
|
|
43
|
+
</BannerLink>
|
|
44
|
+
</BannerContent>
|
|
45
|
+
</BannerComponent>
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
export const Banner = BannerTemplate.bind({})
|
|
49
|
+
Banner.storyName = 'Banner'
|
|
50
|
+
|
|
51
|
+
const argTypes = {
|
|
52
|
+
variant: {
|
|
53
|
+
options: ['vertical', 'horizontal'],
|
|
54
|
+
control: { type: 'select' },
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
title: 'Molecules/Banner',
|
|
60
|
+
argTypes,
|
|
61
|
+
parameters: {
|
|
62
|
+
docs: {
|
|
63
|
+
page: mdx,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
} as Meta
|
|
@@ -4,7 +4,9 @@ import userEvent from '@testing-library/user-event'
|
|
|
4
4
|
import type { ReactNode } from 'react'
|
|
5
5
|
import React from 'react'
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import RadioGroup from './RadioGroup'
|
|
8
|
+
import RadioOption from './RadioOption'
|
|
9
|
+
import { useRadioGroup } from './useRadioGroup'
|
|
8
10
|
|
|
9
11
|
describe('RadioGroup', () => {
|
|
10
12
|
it('Should render radio group with radio option', () => {
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useRadioGroup } from './useRadioGroup'
|
|
1
|
+
export { default } from './RadioGroup'
|
|
2
|
+
export type { RadioGroupProps } from './RadioGroup'
|
|
4
3
|
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
RadioOption,
|
|
8
|
-
useRadioGroup,
|
|
9
|
-
RadioGroupProps,
|
|
10
|
-
RadioOptionProps,
|
|
11
|
-
}
|
|
4
|
+
export { default as RadioOption } from './RadioOption'
|
|
5
|
+
export type { RadioOptionProps } from './RadioOption'
|