@faststore/ui 1.3.42 → 1.3.46
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/index.d.ts +2 -0
- package/dist/molecules/QuantitySelector/QuantitySelector.d.ts +30 -0
- package/dist/molecules/QuantitySelector/index.d.ts +2 -0
- package/dist/molecules/QuantitySelector/stories/QuantitySelector.stories.d.ts +5 -0
- package/dist/molecules/QuantitySelector/stories/assets/Icons.d.ts +7 -0
- package/dist/organisms/Card/CardContent.d.ts +3 -7
- package/dist/ui.cjs.development.js +30 -4
- 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 +30 -5
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/molecules/QuantitySelector/QuantitySelector.test.tsx +93 -0
- package/src/molecules/QuantitySelector/QuantitySelector.tsx +82 -0
- package/src/molecules/QuantitySelector/index.ts +2 -0
- package/src/molecules/QuantitySelector/stories/QuantitySelector.mdx +26 -0
- package/src/molecules/QuantitySelector/stories/QuantitySelector.stories.tsx +77 -0
- package/src/molecules/QuantitySelector/stories/assets/Icons.tsx +52 -0
- package/src/organisms/Card/CardContent.tsx +6 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.46",
|
|
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.46",
|
|
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": "ce15da21f404a4dd19d6d0d9a03b709a26a452cc"
|
|
93
93
|
}
|
package/src/index.ts
CHANGED
|
@@ -133,6 +133,9 @@ export type { FormProps } from './molecules/Form'
|
|
|
133
133
|
export { default as Alert } from './molecules/Alert'
|
|
134
134
|
export type { AlertProps } from './molecules/Alert'
|
|
135
135
|
|
|
136
|
+
export { default as QuantitySelector } from './molecules/QuantitySelector'
|
|
137
|
+
export type { QuantitySelectorProps } from './molecules/QuantitySelector'
|
|
138
|
+
|
|
136
139
|
// Organisms
|
|
137
140
|
export {
|
|
138
141
|
default as Card,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
import { axe } from 'jest-axe'
|
|
5
|
+
|
|
6
|
+
import QuantitySelector from '.'
|
|
7
|
+
|
|
8
|
+
describe('QuantitySelector', () => {
|
|
9
|
+
it('should render', () => {
|
|
10
|
+
const { getByTestId } = render(
|
|
11
|
+
<QuantitySelector
|
|
12
|
+
name="quantity-selector"
|
|
13
|
+
quantity={1}
|
|
14
|
+
leftButtonProps={{ icon: <span>-</span> }}
|
|
15
|
+
rightButtonProps={{ icon: <span>+</span> }}
|
|
16
|
+
inputProps={{ readOnly: true }}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
expect(getByTestId('store-quantity-selector')).toBeInTheDocument()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should render with the correct quantity', () => {
|
|
24
|
+
const { getByLabelText } = render(
|
|
25
|
+
<QuantitySelector
|
|
26
|
+
name="quantity-selector"
|
|
27
|
+
quantity={123}
|
|
28
|
+
leftButtonProps={{ icon: <span>-</span> }}
|
|
29
|
+
rightButtonProps={{ icon: <span>+</span> }}
|
|
30
|
+
inputProps={{ readOnly: true }}
|
|
31
|
+
/>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
expect(getByLabelText('Quantity')).toHaveValue('123')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should update correctly according to event changes', () => {
|
|
38
|
+
const QuantitySelectorTest = () => {
|
|
39
|
+
const [quantity, setQuantity] = useState(1)
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<QuantitySelector
|
|
43
|
+
name="quantity-selector"
|
|
44
|
+
quantity={quantity}
|
|
45
|
+
leftButtonProps={{
|
|
46
|
+
icon: <span>-</span>,
|
|
47
|
+
onClick: () => {
|
|
48
|
+
setQuantity((curr) => curr - 1)
|
|
49
|
+
},
|
|
50
|
+
}}
|
|
51
|
+
rightButtonProps={{
|
|
52
|
+
icon: <span>+</span>,
|
|
53
|
+
onClick: () => {
|
|
54
|
+
setQuantity((curr) => curr + 1)
|
|
55
|
+
},
|
|
56
|
+
}}
|
|
57
|
+
inputProps={{ readOnly: true }}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { getByLabelText } = render(<QuantitySelectorTest />)
|
|
63
|
+
|
|
64
|
+
expect(getByLabelText('Quantity')).toHaveValue('1')
|
|
65
|
+
|
|
66
|
+
const rightButton = getByLabelText('Increment Quantity')
|
|
67
|
+
const leftButton = getByLabelText('Decrement Quantity')
|
|
68
|
+
|
|
69
|
+
userEvent.click(rightButton)
|
|
70
|
+
expect(getByLabelText('Quantity')).toHaveValue('2')
|
|
71
|
+
userEvent.click(leftButton)
|
|
72
|
+
expect(getByLabelText('Quantity')).toHaveValue('1')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('QuantitySelector Accessibility', () => {
|
|
76
|
+
it('should pass the AXE tests', async () => {
|
|
77
|
+
render(
|
|
78
|
+
<main>
|
|
79
|
+
<QuantitySelector
|
|
80
|
+
name="quantity-selector"
|
|
81
|
+
quantity={1}
|
|
82
|
+
leftButtonProps={{ icon: <span>-</span> }}
|
|
83
|
+
rightButtonProps={{ icon: <span>+</span> }}
|
|
84
|
+
inputProps={{ readOnly: true }}
|
|
85
|
+
/>
|
|
86
|
+
</main>
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
expect(await axe(document.body)).toHaveNoViolations()
|
|
90
|
+
expect(await axe(document.body)).toHaveNoIncompletes()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { InputHTMLAttributes } from 'react'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
|
|
4
|
+
import type { InputProps } from '../../atoms/Input'
|
|
5
|
+
import Input from '../../atoms/Input'
|
|
6
|
+
import type { IconButtonProps } from '../IconButton'
|
|
7
|
+
import IconButton from '../IconButton'
|
|
8
|
+
|
|
9
|
+
export interface QuantitySelectorProps
|
|
10
|
+
extends InputHTMLAttributes<HTMLDivElement> {
|
|
11
|
+
/**
|
|
12
|
+
* Sets the current value that should be displayed on the input at the center of the quantity selector.
|
|
13
|
+
*/
|
|
14
|
+
quantity: number | string
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Object with properties that will be passed forward the inner IconButton atom at the left of the input.
|
|
18
|
+
*/
|
|
19
|
+
leftButtonProps: IconButtonProps
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Object with properties that will be passed forward the inner Input atom between the two buttons.
|
|
23
|
+
*/
|
|
24
|
+
inputProps: InputProps
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Object with properties that will be passed forward the inner IconButton atom at the right of the input.
|
|
28
|
+
*/
|
|
29
|
+
rightButtonProps: IconButtonProps
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
33
|
+
*
|
|
34
|
+
* @default 'store-quantity-selector'
|
|
35
|
+
*/
|
|
36
|
+
testId?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const QuantitySelector = forwardRef<HTMLDivElement, QuantitySelectorProps>(
|
|
40
|
+
function QuantitySelector(
|
|
41
|
+
{
|
|
42
|
+
quantity,
|
|
43
|
+
testId = 'store-quantity-selector',
|
|
44
|
+
leftButtonProps,
|
|
45
|
+
inputProps,
|
|
46
|
+
rightButtonProps,
|
|
47
|
+
...otherProps
|
|
48
|
+
}: QuantitySelectorProps,
|
|
49
|
+
ref
|
|
50
|
+
) {
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
data-store-quantity-selector
|
|
54
|
+
data-testid={testId}
|
|
55
|
+
ref={ref}
|
|
56
|
+
{...otherProps}
|
|
57
|
+
>
|
|
58
|
+
<IconButton
|
|
59
|
+
aria-controls="quantity-selector-input"
|
|
60
|
+
aria-label="Decrement Quantity"
|
|
61
|
+
data-quantity-selector-button="left"
|
|
62
|
+
{...leftButtonProps}
|
|
63
|
+
/>
|
|
64
|
+
<Input
|
|
65
|
+
aria-label="Quantity"
|
|
66
|
+
data-quantity-selector-input
|
|
67
|
+
id="quantity-selector-input"
|
|
68
|
+
value={quantity}
|
|
69
|
+
{...inputProps}
|
|
70
|
+
/>
|
|
71
|
+
<IconButton
|
|
72
|
+
aria-controls="quantity-selector-input"
|
|
73
|
+
aria-label="Increment Quantity"
|
|
74
|
+
data-quantity-selector-button="right"
|
|
75
|
+
{...rightButtonProps}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
export default QuantitySelector
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import QuantitySelector from '../QuantitySelector'
|
|
4
|
+
|
|
5
|
+
# QuantitySelector
|
|
6
|
+
|
|
7
|
+
## Default Style
|
|
8
|
+
|
|
9
|
+
<Canvas>
|
|
10
|
+
<Story id="molecules-quantityselector--default-style" />
|
|
11
|
+
</Canvas>
|
|
12
|
+
|
|
13
|
+
# Props
|
|
14
|
+
|
|
15
|
+
<ArgsTable of={QuantitySelector} />
|
|
16
|
+
|
|
17
|
+
# CSS Selectors
|
|
18
|
+
|
|
19
|
+
```css
|
|
20
|
+
[data-store-quantity-selector] {
|
|
21
|
+
}
|
|
22
|
+
[data-quantity-selector-input] {
|
|
23
|
+
}
|
|
24
|
+
[data-quantity-selector-button='(left|right)'] {
|
|
25
|
+
}
|
|
26
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Meta, Story } from '@storybook/react'
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import type { QuantitySelectorProps } from '../QuantitySelector'
|
|
5
|
+
import Component from '../QuantitySelector'
|
|
6
|
+
import { PlusIcon, MinusIcon } from './assets/Icons'
|
|
7
|
+
import mdx from './QuantitySelector.mdx'
|
|
8
|
+
|
|
9
|
+
const MAX_QUANTITY = 10
|
|
10
|
+
const MIN_QUANTITY = 1
|
|
11
|
+
|
|
12
|
+
export const QuantitySelector: Story<QuantitySelectorProps> = () => {
|
|
13
|
+
const [quantity, setQuantity] = useState(MIN_QUANTITY)
|
|
14
|
+
|
|
15
|
+
function increase() {
|
|
16
|
+
setQuantity((currentQuantity) =>
|
|
17
|
+
validateQuantityBounds(currentQuantity + 1)
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function decrease() {
|
|
22
|
+
setQuantity((currentQuantity) =>
|
|
23
|
+
validateQuantityBounds(currentQuantity - 1)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isLeftDisabled(): boolean {
|
|
28
|
+
return quantity === MIN_QUANTITY
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isRightDisabled(): boolean {
|
|
32
|
+
return quantity === MAX_QUANTITY
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function validateQuantityBounds(n: number): number {
|
|
36
|
+
return Math.min(Math.max(n, MIN_QUANTITY), MAX_QUANTITY)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function validateInput(e: React.FormEvent<HTMLInputElement>) {
|
|
40
|
+
const val = e.currentTarget.value
|
|
41
|
+
|
|
42
|
+
if (!Number.isNaN(Number(val))) {
|
|
43
|
+
setQuantity(validateQuantityBounds(Number(val)))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Component
|
|
49
|
+
quantity={quantity}
|
|
50
|
+
leftButtonProps={{
|
|
51
|
+
onClick: decrease,
|
|
52
|
+
disabled: isLeftDisabled(),
|
|
53
|
+
icon: <MinusIcon color={isLeftDisabled() ? '#898F9E' : '#2953B2'} />,
|
|
54
|
+
}}
|
|
55
|
+
rightButtonProps={{
|
|
56
|
+
onClick: increase,
|
|
57
|
+
disabled: isRightDisabled(),
|
|
58
|
+
icon: <PlusIcon color={isRightDisabled() ? '#898F9E' : '#2953B2'} />,
|
|
59
|
+
}}
|
|
60
|
+
inputProps={{
|
|
61
|
+
onChange: validateInput,
|
|
62
|
+
readOnly: false,
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
QuantitySelector.storyName = 'QuantitySelector'
|
|
69
|
+
|
|
70
|
+
export default {
|
|
71
|
+
title: 'Molecules/QuantitySelector',
|
|
72
|
+
parameters: {
|
|
73
|
+
docs: {
|
|
74
|
+
page: mdx,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
} as Meta
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
type QuantitySelectorIconProps = {
|
|
4
|
+
color: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function PlusIcon(props: QuantitySelectorIconProps) {
|
|
8
|
+
return (
|
|
9
|
+
<svg
|
|
10
|
+
width="32"
|
|
11
|
+
height="32"
|
|
12
|
+
viewBox="0 0 32 32"
|
|
13
|
+
fill="none"
|
|
14
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
15
|
+
>
|
|
16
|
+
<path
|
|
17
|
+
d="M11 16H21"
|
|
18
|
+
stroke={props.color}
|
|
19
|
+
strokeWidth="1.5"
|
|
20
|
+
strokeLinecap="round"
|
|
21
|
+
strokeLinejoin="round"
|
|
22
|
+
/>
|
|
23
|
+
<path
|
|
24
|
+
d="M16 11V21"
|
|
25
|
+
stroke={props.color}
|
|
26
|
+
strokeWidth="1.5"
|
|
27
|
+
strokeLinecap="round"
|
|
28
|
+
strokeLinejoin="round"
|
|
29
|
+
/>
|
|
30
|
+
</svg>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function MinusIcon(props: QuantitySelectorIconProps) {
|
|
35
|
+
return (
|
|
36
|
+
<svg
|
|
37
|
+
width="32"
|
|
38
|
+
height="32"
|
|
39
|
+
viewBox="0 0 32 32"
|
|
40
|
+
fill="none"
|
|
41
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
42
|
+
>
|
|
43
|
+
<path
|
|
44
|
+
d="M11 16H21"
|
|
45
|
+
stroke={props.color}
|
|
46
|
+
strokeWidth="1.5"
|
|
47
|
+
strokeLinecap="round"
|
|
48
|
+
strokeLinejoin="round"
|
|
49
|
+
/>
|
|
50
|
+
</svg>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -1,38 +1,27 @@
|
|
|
1
|
-
import type { HTMLAttributes
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
2
|
import React, { forwardRef } from 'react'
|
|
3
3
|
|
|
4
|
-
export interface CardContentProps extends HTMLAttributes<
|
|
4
|
+
export interface CardContentProps extends HTMLAttributes<HTMLElement> {
|
|
5
5
|
/**
|
|
6
6
|
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
7
7
|
*/
|
|
8
8
|
testId?: string
|
|
9
|
-
/**
|
|
10
|
-
* Defines a string value that labels the current element.
|
|
11
|
-
*/
|
|
12
|
-
'aria-label'?: AriaAttributes['aria-label']
|
|
13
9
|
}
|
|
14
10
|
|
|
15
|
-
const CardContent = forwardRef<
|
|
11
|
+
const CardContent = forwardRef<HTMLElement, CardContentProps>(
|
|
16
12
|
function CardContent(
|
|
17
|
-
{
|
|
18
|
-
testId = 'store-card-content',
|
|
19
|
-
'aria-label': ariaLabel = 'Card content',
|
|
20
|
-
children,
|
|
21
|
-
...otherProps
|
|
22
|
-
},
|
|
13
|
+
{ testId = 'store-card-content', children, ...otherProps },
|
|
23
14
|
ref
|
|
24
15
|
) {
|
|
25
16
|
return (
|
|
26
|
-
<
|
|
17
|
+
<section
|
|
27
18
|
ref={ref}
|
|
28
|
-
role="region"
|
|
29
|
-
aria-label={ariaLabel}
|
|
30
19
|
data-store-card-content
|
|
31
20
|
data-testid={testId}
|
|
32
21
|
{...otherProps}
|
|
33
22
|
>
|
|
34
23
|
{children}
|
|
35
|
-
</
|
|
24
|
+
</section>
|
|
36
25
|
)
|
|
37
26
|
}
|
|
38
27
|
)
|