@faststore/ui 1.3.26 → 1.3.30
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 +35 -0
- package/dist/atoms/List/List.d.ts +9 -14
- package/dist/atoms/List/stories/List.stories.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/ui.cjs.development.js +50 -19
- 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 +48 -20
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/atoms/List/List.test.tsx +37 -0
- package/src/atoms/List/List.tsx +18 -51
- package/src/atoms/List/stories/List.mdx +2 -2
- package/src/atoms/List/stories/List.stories.tsx +2 -2
- package/src/index.ts +12 -2
|
@@ -84,6 +84,43 @@ describe('List', () => {
|
|
|
84
84
|
expect(getByTestId('store-list')).toBeInstanceOf(HTMLDListElement)
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
+
it('should respect the HTML tag passed as "as" prop', () => {
|
|
88
|
+
const { getByTestId, rerender } = render(
|
|
89
|
+
<List variant="unordered" as="div">
|
|
90
|
+
{optionsArray.map((value) => {
|
|
91
|
+
return <li key={value}>{value}</li>
|
|
92
|
+
})}
|
|
93
|
+
</List>
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
expect(getByTestId('store-list')).toBeInstanceOf(HTMLDivElement)
|
|
97
|
+
|
|
98
|
+
rerender(
|
|
99
|
+
<List variant="ordered" as="div">
|
|
100
|
+
{optionsArray.map((value) => {
|
|
101
|
+
return <li key={value}>{value}</li>
|
|
102
|
+
})}
|
|
103
|
+
</List>
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
expect(getByTestId('store-list')).toBeInstanceOf(HTMLDivElement)
|
|
107
|
+
|
|
108
|
+
rerender(
|
|
109
|
+
<List variant="description" as="div">
|
|
110
|
+
{optionsArray.map((value, index) => {
|
|
111
|
+
return (
|
|
112
|
+
<Fragment key={index}>
|
|
113
|
+
<dt key={`${index}--term`}>{value}</dt>
|
|
114
|
+
<dd key={`${index}--details`}>option</dd>
|
|
115
|
+
</Fragment>
|
|
116
|
+
)
|
|
117
|
+
})}
|
|
118
|
+
</List>
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
expect(getByTestId('store-list')).toBeInstanceOf(HTMLDivElement)
|
|
122
|
+
})
|
|
123
|
+
|
|
87
124
|
describe('Accessibility', () => {
|
|
88
125
|
it('should have no violations when rendering the default variant', async () => {
|
|
89
126
|
const { getByTestId } = render(
|
package/src/atoms/List/List.tsx
CHANGED
|
@@ -1,55 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ElementType,
|
|
3
|
-
ComponentPropsWithRef,
|
|
4
|
-
ReactElement,
|
|
5
|
-
FC,
|
|
6
|
-
} from 'react'
|
|
7
1
|
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { ElementType, HTMLAttributes } from 'react'
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const variantToType = (variant: ListVariant) => {
|
|
14
|
-
switch (variant) {
|
|
15
|
-
case 'description':
|
|
16
|
-
return 'dl'
|
|
17
|
-
|
|
18
|
-
case 'unordered':
|
|
19
|
-
return 'ul'
|
|
20
|
-
|
|
21
|
-
case 'ordered':
|
|
22
|
-
return 'ol'
|
|
23
|
-
|
|
24
|
-
default:
|
|
25
|
-
return 'ul'
|
|
26
|
-
}
|
|
4
|
+
const variantToElement = {
|
|
5
|
+
description: 'dl',
|
|
6
|
+
unordered: 'ul',
|
|
7
|
+
ordered: 'ol',
|
|
27
8
|
}
|
|
28
9
|
|
|
29
|
-
interface
|
|
10
|
+
export interface ListProps<T = HTMLElement> extends HTMLAttributes<T> {
|
|
11
|
+
/**
|
|
12
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
13
|
+
*/
|
|
30
14
|
testId?: string
|
|
31
|
-
variant?:
|
|
15
|
+
variant?: 'description' | 'ordered' | 'unordered'
|
|
16
|
+
as?: ElementType
|
|
32
17
|
}
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
C,
|
|
36
|
-
Props
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
type ListComponent = <C extends ElementType = 'ul'>(
|
|
40
|
-
props: ListProps<C>
|
|
41
|
-
) => ReactElement | null
|
|
42
|
-
|
|
43
|
-
const List: ListComponent = forwardRef(function List<
|
|
44
|
-
C extends ElementType = 'ul'
|
|
45
|
-
>(
|
|
19
|
+
const List = forwardRef<HTMLUListElement, ListProps>(function List(
|
|
46
20
|
{
|
|
47
21
|
testId = 'store-list',
|
|
48
22
|
variant = 'unordered',
|
|
49
|
-
as,
|
|
50
|
-
...
|
|
51
|
-
}
|
|
52
|
-
ref
|
|
23
|
+
as: MaybeComponent,
|
|
24
|
+
...otherProps
|
|
25
|
+
},
|
|
26
|
+
ref
|
|
53
27
|
) {
|
|
54
28
|
const dataAttributes = {
|
|
55
29
|
'data-testid': testId,
|
|
@@ -57,16 +31,9 @@ const List: ListComponent = forwardRef(function List<
|
|
|
57
31
|
[`data-${variant}`]: true,
|
|
58
32
|
}
|
|
59
33
|
|
|
60
|
-
const Component =
|
|
34
|
+
const Component = MaybeComponent ?? variantToElement[variant] ?? 'ul'
|
|
61
35
|
|
|
62
|
-
return <Component ref={ref} {...dataAttributes} {...
|
|
36
|
+
return <Component ref={ref} {...dataAttributes} {...otherProps} />
|
|
63
37
|
})
|
|
64
38
|
|
|
65
|
-
/**
|
|
66
|
-
* This is only being exported to make it easier to use in Storybook.
|
|
67
|
-
* **DON'T** import this directly to use this component, use the default export
|
|
68
|
-
* instead.
|
|
69
|
-
*/
|
|
70
|
-
export const StorybookList = List as FC<Props>
|
|
71
|
-
|
|
72
39
|
export default List
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
-
import
|
|
2
|
+
import List from '../List'
|
|
3
3
|
|
|
4
4
|
# List
|
|
5
5
|
|
|
@@ -23,7 +23,7 @@ import { StorybookList } from '../List'
|
|
|
23
23
|
|
|
24
24
|
## Props
|
|
25
25
|
|
|
26
|
-
<ArgsTable of={
|
|
26
|
+
<ArgsTable of={List} />
|
|
27
27
|
|
|
28
28
|
## CSS Selectors
|
|
29
29
|
|
|
@@ -6,8 +6,8 @@ import type { ListProps } from '../List'
|
|
|
6
6
|
import Component from '../List'
|
|
7
7
|
import mdx from './List.mdx'
|
|
8
8
|
|
|
9
|
-
type ListStoryProps = ListProps
|
|
10
|
-
type DescriptionListStoryProps = ListProps
|
|
9
|
+
type ListStoryProps = ListProps & { options: string[] }
|
|
10
|
+
type DescriptionListStoryProps = ListProps & { options: string[][] }
|
|
11
11
|
|
|
12
12
|
const ListTemplate: Story<ListStoryProps> = ({ options, ...props }) => {
|
|
13
13
|
return (
|
package/src/index.ts
CHANGED
|
@@ -63,8 +63,18 @@ export type { IconButtonProps } from './molecules/IconButton'
|
|
|
63
63
|
export { default as Modal } from './molecules/Modal'
|
|
64
64
|
export type { ModalProps } from './molecules/Modal'
|
|
65
65
|
|
|
66
|
-
export {
|
|
67
|
-
|
|
66
|
+
export {
|
|
67
|
+
default as Banner,
|
|
68
|
+
BannerContent,
|
|
69
|
+
BannerImage,
|
|
70
|
+
BannerLink,
|
|
71
|
+
} from './molecules/Banner'
|
|
72
|
+
export type {
|
|
73
|
+
BannerProps,
|
|
74
|
+
BannerContentProps,
|
|
75
|
+
BannerImageProps,
|
|
76
|
+
BannerLinkProps,
|
|
77
|
+
} from './molecules/Banner'
|
|
68
78
|
|
|
69
79
|
export { default as PaymentMethods } from './molecules/PaymentMethods'
|
|
70
80
|
export type { PaymentMethodsProps } from './molecules/PaymentMethods'
|