@faststore/ui 1.8.32 → 1.8.35
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 +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/organisms/OutOfStock/OutOfStock.d.ts +21 -0
- package/dist/organisms/OutOfStock/OutOfStockMessage.d.ts +9 -0
- package/dist/organisms/OutOfStock/OutOfStockTitle.d.ts +9 -0
- package/dist/organisms/OutOfStock/index.d.ts +6 -0
- package/dist/organisms/OutOfStock/stories/OutOfStock.stories.d.ts +10 -0
- package/dist/ui.cjs.development.js +39 -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 +37 -1
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +10 -0
- package/src/organisms/OutOfStock/OutOfStock.test.tsx +122 -0
- package/src/organisms/OutOfStock/OutOfStock.tsx +39 -0
- package/src/organisms/OutOfStock/OutOfStockMessage.tsx +22 -0
- package/src/organisms/OutOfStock/OutOfStockTitle.tsx +22 -0
- package/src/organisms/OutOfStock/index.tsx +6 -0
- package/src/organisms/OutOfStock/stories/OutOfStock.mdx +37 -0
- package/src/organisms/OutOfStock/stories/OutOfStock.stories.tsx +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.35",
|
|
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.8.
|
|
79
|
+
"@vtex/theme-b2c-tailwind": "^1.8.35",
|
|
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": "2fd108e719fd2450c755e622af0cde78d640a9b2"
|
|
93
93
|
}
|
package/src/index.ts
CHANGED
|
@@ -176,6 +176,16 @@ export type {
|
|
|
176
176
|
} from './molecules/Dropdown'
|
|
177
177
|
|
|
178
178
|
// Organisms
|
|
179
|
+
export {
|
|
180
|
+
default as OutOfStock,
|
|
181
|
+
OutOfStockTitle,
|
|
182
|
+
OutOfStockMessage,
|
|
183
|
+
} from './organisms/OutOfStock'
|
|
184
|
+
export type {
|
|
185
|
+
OutOfStockProps,
|
|
186
|
+
OutOfStockMessageProps,
|
|
187
|
+
OutOfStockTitleProps,
|
|
188
|
+
} from './organisms/OutOfStock'
|
|
179
189
|
|
|
180
190
|
// Hooks
|
|
181
191
|
export { default as useSlider } from './hooks/useSlider'
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import userEvent from '@testing-library/user-event'
|
|
3
|
+
import { axe } from 'jest-axe'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
import { OutOfStockMessage, OutOfStockTitle } from '.'
|
|
7
|
+
import Button from '../../atoms/Button'
|
|
8
|
+
import Input from '../../atoms/Input'
|
|
9
|
+
import Label from '../../atoms/Label'
|
|
10
|
+
import OutOfStock from './OutOfStock'
|
|
11
|
+
|
|
12
|
+
const SimpleOutOfStock = () => (
|
|
13
|
+
<OutOfStock>
|
|
14
|
+
<OutOfStockTitle>
|
|
15
|
+
Text <span>icon</span>
|
|
16
|
+
</OutOfStockTitle>
|
|
17
|
+
<OutOfStockMessage>Notify me when available</OutOfStockMessage>
|
|
18
|
+
<Label>
|
|
19
|
+
Email
|
|
20
|
+
<Input />
|
|
21
|
+
</Label>
|
|
22
|
+
<Button>Notify me</Button>
|
|
23
|
+
</OutOfStock>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
describe('OutOfStock', () => {
|
|
27
|
+
it('`Out Of Stock` components should have corrects attributes', () => {
|
|
28
|
+
render(<SimpleOutOfStock />)
|
|
29
|
+
|
|
30
|
+
const outOfStock = screen.getByTestId('store-out-of-stock')
|
|
31
|
+
const outOfStockTitle = screen.getByTestId('store-out-of-stock-title')
|
|
32
|
+
const outOfStockMessage = screen.getByTestId('store-out-of-stock-message')
|
|
33
|
+
const outOfStockForm = screen.getByTestId('store-out-of-stock-form')
|
|
34
|
+
|
|
35
|
+
expect(outOfStock).toHaveAttribute('data-store-out-of-stock')
|
|
36
|
+
expect(outOfStockForm).toHaveAttribute('data-out-of-stock-form')
|
|
37
|
+
expect(outOfStockTitle).toHaveAttribute('data-out-of-stock-title')
|
|
38
|
+
expect(outOfStockMessage).toHaveAttribute('data-out-of-stock-message')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('Should emit event', () => {
|
|
42
|
+
const onSubmitMock = jest.fn((e) => e.preventDefault())
|
|
43
|
+
|
|
44
|
+
render(
|
|
45
|
+
<OutOfStock onSubmit={onSubmitMock}>
|
|
46
|
+
<OutOfStockTitle>Out of Stock</OutOfStockTitle>
|
|
47
|
+
<Input name="email" />
|
|
48
|
+
<Button type="submit">Notify me</Button>
|
|
49
|
+
</OutOfStock>
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const outOfStockEventButton = screen.getByTestId('store-button')
|
|
53
|
+
|
|
54
|
+
userEvent.click(outOfStockEventButton)
|
|
55
|
+
|
|
56
|
+
expect(onSubmitMock).toHaveBeenCalledTimes(1)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('Should not render message', () => {
|
|
60
|
+
render(
|
|
61
|
+
<OutOfStock>
|
|
62
|
+
<OutOfStockTitle>Out of Stock</OutOfStockTitle>
|
|
63
|
+
<Input name="email" />
|
|
64
|
+
<Button type="submit">Notify me</Button>
|
|
65
|
+
</OutOfStock>
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const message = screen.queryByTestId('store-out-of-stock-message')
|
|
69
|
+
|
|
70
|
+
expect(message).not.toBeInTheDocument()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('Accessibility', () => {
|
|
75
|
+
it('should not have violations or incompletes', async () => {
|
|
76
|
+
const { container } = render(<SimpleOutOfStock />)
|
|
77
|
+
|
|
78
|
+
expect(await axe(container)).toHaveNoViolations()
|
|
79
|
+
expect(await axe(container)).toHaveNoIncompletes()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('Out of Stock component should be a `section`', () => {
|
|
83
|
+
render(<SimpleOutOfStock />)
|
|
84
|
+
const outOfStock = screen.getByTestId('store-out-of-stock')
|
|
85
|
+
|
|
86
|
+
expect(outOfStock.tagName).toEqual('SECTION')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('Out of Stock `title` component should be a `heading 2` as default', () => {
|
|
90
|
+
render(<SimpleOutOfStock />)
|
|
91
|
+
const outOfStockTitle = screen.getByTestId('store-out-of-stock-title')
|
|
92
|
+
|
|
93
|
+
expect(outOfStockTitle.tagName).toEqual('H2')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('Out of Stock `message` should be a `paragraph` as default', () => {
|
|
97
|
+
render(<SimpleOutOfStock />)
|
|
98
|
+
const outOfStockMessage = screen.getByTestId('store-out-of-stock-message')
|
|
99
|
+
|
|
100
|
+
expect(outOfStockMessage.tagName).toEqual('P')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('Out of Stock should render `title` as heading 1 and `message` as span', () => {
|
|
104
|
+
render(
|
|
105
|
+
<OutOfStock>
|
|
106
|
+
<OutOfStockTitle as="h1">Head Out Os Stock</OutOfStockTitle>
|
|
107
|
+
<OutOfStockMessage as="span">Head Out Os Stock</OutOfStockMessage>
|
|
108
|
+
<Label>
|
|
109
|
+
Email
|
|
110
|
+
<Input />
|
|
111
|
+
</Label>
|
|
112
|
+
<Button>Notify me</Button>
|
|
113
|
+
</OutOfStock>
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const outOfStockMessage = screen.getByTestId('store-out-of-stock-message')
|
|
117
|
+
const outOfStockTitle = screen.getByTestId('store-out-of-stock-title')
|
|
118
|
+
|
|
119
|
+
expect(outOfStockTitle.tagName).toEqual('H1')
|
|
120
|
+
expect(outOfStockMessage.tagName).toEqual('SPAN')
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { ReactNode, FormHTMLAttributes } from 'react'
|
|
3
|
+
|
|
4
|
+
import Form from '../../molecules/Form'
|
|
5
|
+
|
|
6
|
+
export type OutOfStockBaseProps = {
|
|
7
|
+
/**
|
|
8
|
+
* ID to find this component in testing tools (e.g.: cypress,
|
|
9
|
+
* testing-library, and jest).
|
|
10
|
+
*/
|
|
11
|
+
testId?: string
|
|
12
|
+
/**
|
|
13
|
+
* Children for Out of Stock components.
|
|
14
|
+
*/
|
|
15
|
+
children: string | ReactNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type OutOfStockProps = OutOfStockBaseProps & {
|
|
19
|
+
/**
|
|
20
|
+
* Event emitted when form is submitted.
|
|
21
|
+
*/
|
|
22
|
+
onSubmit?: (event: React.FormEvent<HTMLFormElement>) => void
|
|
23
|
+
} & FormHTMLAttributes<HTMLFormElement>
|
|
24
|
+
|
|
25
|
+
const OutOfStock = ({
|
|
26
|
+
testId = 'store-out-of-stock',
|
|
27
|
+
children,
|
|
28
|
+
...otherProps
|
|
29
|
+
}: OutOfStockProps) => {
|
|
30
|
+
return (
|
|
31
|
+
<section data-store-out-of-stock data-testid={testId}>
|
|
32
|
+
<Form data-out-of-stock-form testId={`${testId}-form`} {...otherProps}>
|
|
33
|
+
{children}
|
|
34
|
+
</Form>
|
|
35
|
+
</section>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default OutOfStock
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import type { OutOfStockBaseProps } from './OutOfStock'
|
|
4
|
+
|
|
5
|
+
export type OutOfStockMessageProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Attribute used for polymorphic component.
|
|
8
|
+
*/
|
|
9
|
+
as?: 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'div' | 'span'
|
|
10
|
+
} & OutOfStockBaseProps
|
|
11
|
+
|
|
12
|
+
export const OutOfStockMessage = ({
|
|
13
|
+
as: MessageComponent = 'p',
|
|
14
|
+
testId = 'store-out-of-stock-message',
|
|
15
|
+
children,
|
|
16
|
+
}: OutOfStockMessageProps) => {
|
|
17
|
+
return (
|
|
18
|
+
<MessageComponent data-out-of-stock-message data-testid={testId}>
|
|
19
|
+
{children}
|
|
20
|
+
</MessageComponent>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import type { OutOfStockBaseProps } from './OutOfStock'
|
|
4
|
+
|
|
5
|
+
export type OutOfStockTitleProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Attribute used for polymorphic component.
|
|
8
|
+
*/
|
|
9
|
+
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'
|
|
10
|
+
} & OutOfStockBaseProps
|
|
11
|
+
|
|
12
|
+
export const OutOfStockTitle = ({
|
|
13
|
+
as: TitleComponent = 'h2',
|
|
14
|
+
testId = 'store-out-of-stock-title',
|
|
15
|
+
children,
|
|
16
|
+
}: OutOfStockTitleProps) => {
|
|
17
|
+
return (
|
|
18
|
+
<TitleComponent data-out-of-stock-title data-testid={testId}>
|
|
19
|
+
{children}
|
|
20
|
+
</TitleComponent>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default } from './OutOfStock'
|
|
2
|
+
export { OutOfStockMessage } from './OutOfStockMessage'
|
|
3
|
+
export { OutOfStockTitle } from './OutOfStockTitle'
|
|
4
|
+
export type { OutOfStockProps } from './OutOfStock'
|
|
5
|
+
export type { OutOfStockMessageProps } from './OutOfStockMessage'
|
|
6
|
+
export type { OutOfStockTitleProps } from './OutOfStockTitle'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import OutOfStock from '../OutOfStock'
|
|
4
|
+
|
|
5
|
+
# OutOfStock
|
|
6
|
+
|
|
7
|
+
<Canvas>
|
|
8
|
+
<Story id="organisms-outofstock--out-of-stock" />
|
|
9
|
+
</Canvas>
|
|
10
|
+
|
|
11
|
+
The `OutOfStock` uses the [Compound Component](https://kentcdodds.com/blog/compound-components-with-react-hooks) pattern, its components are:
|
|
12
|
+
|
|
13
|
+
- `OutOfStock`: the form wrapper of the out of stock component with title and message;
|
|
14
|
+
- `OutOfStockTitle`: the main title component for out of stock component;
|
|
15
|
+
- `OutOfStockMessage`: the message component for out of stock component;
|
|
16
|
+
|
|
17
|
+
## Props
|
|
18
|
+
|
|
19
|
+
### `OutOfStock`
|
|
20
|
+
|
|
21
|
+
<ArgsTable of={ OutOfStock } />
|
|
22
|
+
|
|
23
|
+
## CSS Selectors
|
|
24
|
+
|
|
25
|
+
```css
|
|
26
|
+
[data-store-out-of-stock] {
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[data-out-of-stock-form] {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[data-out-of-stock-title] {
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[data-out-of-stock-message] {
|
|
36
|
+
}
|
|
37
|
+
```
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Story, Meta } from '@storybook/react'
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
OutOfStockMessageProps,
|
|
6
|
+
OutOfStockTitleProps,
|
|
7
|
+
OutOfStockProps,
|
|
8
|
+
} from '..'
|
|
9
|
+
import Component, { OutOfStockTitle, OutOfStockMessage } from '..'
|
|
10
|
+
import Button from '../../../atoms/Button'
|
|
11
|
+
import Input from '../../../atoms/Input'
|
|
12
|
+
import mdx from './OutOfStock.mdx'
|
|
13
|
+
|
|
14
|
+
type OutOfStockTemplateProps = {
|
|
15
|
+
title: string
|
|
16
|
+
message: string
|
|
17
|
+
titleAs: OutOfStockTitleProps['as']
|
|
18
|
+
messageAs: OutOfStockMessageProps['as']
|
|
19
|
+
} & OutOfStockProps
|
|
20
|
+
|
|
21
|
+
const OutOfStockTemplate: Story<OutOfStockTemplateProps> = ({
|
|
22
|
+
title,
|
|
23
|
+
message,
|
|
24
|
+
titleAs,
|
|
25
|
+
messageAs,
|
|
26
|
+
...props
|
|
27
|
+
}) => {
|
|
28
|
+
const [value, setValue] = useState('')
|
|
29
|
+
|
|
30
|
+
const handlerSubmitForm = (e: React.FormEvent<HTMLFormElement>) => {
|
|
31
|
+
e.preventDefault()
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line no-alert
|
|
34
|
+
alert(value)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Component onSubmit={handlerSubmitForm} {...props}>
|
|
39
|
+
<OutOfStockTitle as={titleAs}>{title}</OutOfStockTitle>
|
|
40
|
+
<OutOfStockMessage as={messageAs}>{message}</OutOfStockMessage>
|
|
41
|
+
<Input value={value} onChange={(e) => setValue(e.target.value)} />
|
|
42
|
+
<Button>Notify me</Button>
|
|
43
|
+
</Component>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const OutOfStock = OutOfStockTemplate.bind({})
|
|
48
|
+
OutOfStock.storyName = 'OutOfStock'
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
title: 'Organisms/OutOfStock',
|
|
52
|
+
parameters: {
|
|
53
|
+
docs: {
|
|
54
|
+
page: mdx,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
args: {
|
|
58
|
+
title: 'Notify me',
|
|
59
|
+
message: 'Notify me when available',
|
|
60
|
+
},
|
|
61
|
+
argTypes: {
|
|
62
|
+
titleAs: {
|
|
63
|
+
defaultValue: 'h2',
|
|
64
|
+
options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'],
|
|
65
|
+
control: { type: 'select' },
|
|
66
|
+
},
|
|
67
|
+
messageAs: {
|
|
68
|
+
defaultValue: 'p',
|
|
69
|
+
options: ['h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'span'],
|
|
70
|
+
control: { type: 'select' },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
} as Meta
|