@faststore/ui 1.3.39 → 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.
- package/CHANGELOG.md +11 -0
- package/dist/atoms/Link/Link.d.ts +19 -0
- package/dist/atoms/Link/index.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/typings/PolymorphicGenerics.d.ts +1 -0
- package/dist/typings/index.d.ts +1 -1
- package/dist/ui.cjs.development.js +15 -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 +15 -1
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- 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 +3 -0
- 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.40",
|
|
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.40",
|
|
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": "528decacbe8c799b9560c7620e315df6bd7fa4f8"
|
|
93
93
|
}
|
|
@@ -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
|
@@ -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']
|