@faststore/ui 1.3.37 → 1.3.41
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/dist/atoms/Badge/Badge.d.ts +2 -2
- package/dist/atoms/Icon/stories/Icon.stories.d.ts +1 -1
- package/dist/atoms/Incentive/Incentive.d.ts +11 -0
- package/dist/atoms/Incentive/index.d.ts +2 -0
- package/dist/atoms/Incentive/stories/Incentive.stories.d.ts +4 -0
- package/dist/atoms/Incentive/stories/assets/Icons.d.ts +2 -0
- package/dist/atoms/Link/Link.d.ts +19 -0
- package/dist/atoms/Link/index.d.ts +2 -0
- package/dist/atoms/Price/stories/Price.stories.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/molecules/Banner/BannerContent.d.ts +1 -1
- package/dist/typings/PolymorphicGenerics.d.ts +1 -0
- package/dist/typings/index.d.ts +1 -1
- package/dist/ui.cjs.development.js +37 -8
- 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 +36 -9
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/atoms/Badge/Badge.tsx +4 -4
- package/src/atoms/Incentive/Incentive.test.tsx +36 -0
- package/src/atoms/Incentive/Incentive.tsx +23 -0
- package/src/atoms/Incentive/index.tsx +2 -0
- package/src/atoms/Incentive/stories/Incentive.mdx +24 -0
- package/src/atoms/Incentive/stories/Incentive.stories.tsx +26 -0
- package/src/atoms/Incentive/stories/assets/Icons.tsx +14 -0
- package/src/atoms/Link/Link.test.tsx +53 -0
- package/src/atoms/Link/Link.tsx +47 -0
- package/src/atoms/Link/index.tsx +2 -0
- package/src/atoms/Link/stories/Link.mdx +35 -0
- package/src/atoms/Link/stories/Link.stories.tsx +30 -0
- package/src/index.ts +6 -0
- package/src/molecules/Banner/BannerContent.tsx +1 -3
- package/src/molecules/SearchInput/SearchInput.tsx +2 -1
- package/src/typings/PolymorphicGenerics.ts +5 -0
- package/src/typings/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.41",
|
|
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.
|
|
79
|
+
"@vtex/theme-b2c-tailwind": "^1.3.41",
|
|
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": "
|
|
92
|
+
"gitHead": "bb41f6f6a342bab2c79b17562f8007fd245860d6"
|
|
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}
|
|
17
|
+
<div ref={ref} data-store-badge data-testid={testId} {...otherProps}>
|
|
18
18
|
{children}
|
|
19
19
|
</div>
|
|
20
20
|
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import { axe } from 'jest-axe'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import Incentive from './Incentive'
|
|
6
|
+
|
|
7
|
+
const TestIncentive = () => {
|
|
8
|
+
return (
|
|
9
|
+
<Incentive>
|
|
10
|
+
<span>Item title</span>
|
|
11
|
+
<span>Item description</span>
|
|
12
|
+
</Incentive>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('Incentive', () => {
|
|
17
|
+
let incentive: HTMLElement
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
const { getByTestId } = render(<TestIncentive />)
|
|
21
|
+
|
|
22
|
+
incentive = getByTestId('store-incentive')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('Data attributes', () => {
|
|
26
|
+
it('should have `data-store-incentive` attribute', () => {
|
|
27
|
+
expect(incentive).toHaveAttribute('data-store-incentive')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('Accessibility', () => {
|
|
32
|
+
it('should have no violations', async () => {
|
|
33
|
+
expect(await axe(incentive)).toHaveNoViolations()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { HTMLAttributes } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface IncentiveProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress,
|
|
7
|
+
* testing-library, and jest).
|
|
8
|
+
*/
|
|
9
|
+
testId?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Incentive = forwardRef<HTMLDivElement, IncentiveProps>(function Incentive(
|
|
13
|
+
{ testId = 'store-incentive', children, ...otherProps },
|
|
14
|
+
ref
|
|
15
|
+
) {
|
|
16
|
+
return (
|
|
17
|
+
<div ref={ref} data-store-incentive data-testid={testId} {...otherProps}>
|
|
18
|
+
{children}
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export default Incentive
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import Incentive from '../Incentive'
|
|
4
|
+
|
|
5
|
+
# Incentive
|
|
6
|
+
|
|
7
|
+
<Canvas>
|
|
8
|
+
<Story id="atoms-incentive--incentive" />
|
|
9
|
+
</Canvas>
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
`Incentive` component support all attributes also supported by the `<div>` tag.
|
|
14
|
+
|
|
15
|
+
Besides those attributes, the following props are also supported:
|
|
16
|
+
|
|
17
|
+
<ArgsTable of={Incentive} />
|
|
18
|
+
|
|
19
|
+
## CSS Selectors
|
|
20
|
+
|
|
21
|
+
```css
|
|
22
|
+
[data-store-incentive] {
|
|
23
|
+
}
|
|
24
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Story, Meta } from '@storybook/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { SafetyIcon } from './assets/Icons'
|
|
5
|
+
import type { IncentiveProps } from '../Incentive'
|
|
6
|
+
import Component from '../Incentive'
|
|
7
|
+
import mdx from './Incentive.mdx'
|
|
8
|
+
|
|
9
|
+
const IncentiveTemplate: Story<IncentiveProps> = ({ testId }) => (
|
|
10
|
+
<Component testId={testId}>
|
|
11
|
+
<SafetyIcon />
|
|
12
|
+
<span>Trusted by SafeCompany</span>
|
|
13
|
+
</Component>
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
export const Incentive = IncentiveTemplate.bind({})
|
|
17
|
+
Incentive.storyName = 'Incentive'
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
title: 'Atoms/Incentive',
|
|
21
|
+
parameters: {
|
|
22
|
+
docs: {
|
|
23
|
+
page: mdx,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
} as Meta
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export function SafetyIcon() {
|
|
4
|
+
return (
|
|
5
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="35" height="35" fill="none">
|
|
6
|
+
<path
|
|
7
|
+
fillRule="evenodd"
|
|
8
|
+
clipRule="evenodd"
|
|
9
|
+
d="M6 7h20v7c0 10-8 14-10 14S6 24 6 14V7Zm0-2a2 2 0 0 0-2 2v7c0 11 10 15 11 16h2c1-1 11-5 11-16V7a2 2 0 0 0-2-2H6Zm16 9a1 1 0 0 0-1-2l-7 7-3-3a1 1 0 0 0-1 1l4 4h1l7-7Z"
|
|
10
|
+
fill="#323845"
|
|
11
|
+
/>
|
|
12
|
+
</svg>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -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,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
|
|
|
@@ -47,6 +50,9 @@ export type { SpinnerProps } from './atoms/Spinner'
|
|
|
47
50
|
export { default as Label } from './atoms/Label'
|
|
48
51
|
export type { LabelProps } from './atoms/Label'
|
|
49
52
|
|
|
53
|
+
export { default as Incentive } from './atoms/Incentive'
|
|
54
|
+
export type { IncentiveProps } from './atoms/Incentive'
|
|
55
|
+
|
|
50
56
|
// Molecules
|
|
51
57
|
export { default as Bullets } from './molecules/Bullets'
|
|
52
58
|
export type { BulletsProps } from './molecules/Bullets'
|
|
@@ -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=
|
|
83
|
+
<Button type="submit" aria-label="Submit Search">
|
|
83
84
|
<Icon component={icon ?? <SearchIcon />} />
|
|
84
85
|
</Button>
|
|
85
86
|
</Form>
|
|
@@ -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']
|