@faststore/ui 1.11.8 → 1.11.20
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 +27 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/molecules/CartItem/CartItem.d.ts +10 -0
- package/dist/molecules/CartItem/CartItem.js +6 -0
- package/dist/molecules/CartItem/CartItem.js.map +1 -0
- package/dist/molecules/CartItem/CartItemActions.d.ts +10 -0
- package/dist/molecules/CartItem/CartItemActions.js +6 -0
- package/dist/molecules/CartItem/CartItemActions.js.map +1 -0
- package/dist/molecules/CartItem/CartItemContent.d.ts +10 -0
- package/dist/molecules/CartItem/CartItemContent.js +6 -0
- package/dist/molecules/CartItem/CartItemContent.js.map +1 -0
- package/dist/molecules/CartItem/CartItemImage.d.ts +10 -0
- package/dist/molecules/CartItem/CartItemImage.js +6 -0
- package/dist/molecules/CartItem/CartItemImage.js.map +1 -0
- package/dist/molecules/CartItem/CartItemPrices.d.ts +10 -0
- package/dist/molecules/CartItem/CartItemPrices.js +6 -0
- package/dist/molecules/CartItem/CartItemPrices.js.map +1 -0
- package/dist/molecules/CartItem/CartItemSummary.d.ts +10 -0
- package/dist/molecules/CartItem/CartItemSummary.js +6 -0
- package/dist/molecules/CartItem/CartItemSummary.js.map +1 -0
- package/dist/molecules/CartItem/CartItemTitle.d.ts +10 -0
- package/dist/molecules/CartItem/CartItemTitle.js +6 -0
- package/dist/molecules/CartItem/CartItemTitle.js.map +1 -0
- package/dist/molecules/CartItem/index.d.ts +14 -0
- package/dist/molecules/CartItem/index.js +8 -0
- package/dist/molecules/CartItem/index.js.map +1 -0
- package/dist/molecules/OrderSummary/OrderSummary.d.ts +35 -0
- package/dist/molecules/OrderSummary/OrderSummary.js +16 -0
- package/dist/molecules/OrderSummary/OrderSummary.js.map +1 -0
- package/dist/molecules/OrderSummary/index.d.ts +2 -0
- package/dist/molecules/OrderSummary/index.js +2 -0
- package/dist/molecules/OrderSummary/index.js.map +1 -0
- package/dist/molecules/SkuSelector/SkuSelector.d.ts +58 -0
- package/dist/molecules/SkuSelector/SkuSelector.js +15 -0
- package/dist/molecules/SkuSelector/SkuSelector.js.map +1 -0
- package/dist/molecules/SkuSelector/index.d.ts +2 -0
- package/dist/molecules/SkuSelector/index.js +2 -0
- package/dist/molecules/SkuSelector/index.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +25 -0
- package/src/molecules/CartItem/CartItem.test.tsx +79 -0
- package/src/molecules/CartItem/CartItem.tsx +22 -0
- package/src/molecules/CartItem/CartItemActions.tsx +24 -0
- package/src/molecules/CartItem/CartItemContent.tsx +24 -0
- package/src/molecules/CartItem/CartItemImage.tsx +22 -0
- package/src/molecules/CartItem/CartItemPrices.tsx +24 -0
- package/src/molecules/CartItem/CartItemSummary.tsx +24 -0
- package/src/molecules/CartItem/CartItemTitle.tsx +22 -0
- package/src/molecules/CartItem/index.tsx +20 -0
- package/src/molecules/CartItem/stories/CartItem.mdx +79 -0
- package/src/molecules/CartItem/stories/CartItem.stories.tsx +70 -0
- package/src/molecules/OrderSummary/OrderSummary.test.tsx +103 -0
- package/src/molecules/OrderSummary/OrderSummary.tsx +109 -0
- package/src/molecules/OrderSummary/index.tsx +2 -0
- package/src/molecules/OrderSummary/stories/OrderSummary.mdx +29 -0
- package/src/molecules/OrderSummary/stories/OrderSummary.stories.tsx +29 -0
- package/src/molecules/QuantitySelector/stories/QuantitySelector.mdx +1 -1
- package/src/molecules/SkuSelector/SkuSelector.test.tsx +42 -0
- package/src/molecules/SkuSelector/SkuSelector.tsx +106 -0
- package/src/molecules/SkuSelector/index.tsx +2 -0
- package/src/molecules/SkuSelector/stories/SkuSelector.mdx +24 -0
- package/src/molecules/SkuSelector/stories/SkuSelector.stories.tsx +52 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { HTMLAttributes, ChangeEventHandler } from 'react'
|
|
3
|
+
import { Label, RadioGroup } from '../..'
|
|
4
|
+
|
|
5
|
+
interface SkuProps {
|
|
6
|
+
/**
|
|
7
|
+
* Alternative text description of the image.
|
|
8
|
+
*/
|
|
9
|
+
alt?: string
|
|
10
|
+
/**
|
|
11
|
+
* Image URL.
|
|
12
|
+
*/
|
|
13
|
+
src?: string
|
|
14
|
+
/**
|
|
15
|
+
* Label to describe the option when selected.
|
|
16
|
+
*/
|
|
17
|
+
label: string
|
|
18
|
+
/**
|
|
19
|
+
* Current value for this option.
|
|
20
|
+
*/
|
|
21
|
+
value: string
|
|
22
|
+
/**
|
|
23
|
+
* Specifies that this option should be disabled.
|
|
24
|
+
*/
|
|
25
|
+
disabled?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// TODO: Add the 'color' variant back once the store supports naturally handling color SKUs.
|
|
29
|
+
type Variant = 'label' | 'image'
|
|
30
|
+
|
|
31
|
+
export interface SkuSelectorProps extends HTMLAttributes<HTMLDivElement> {
|
|
32
|
+
/**
|
|
33
|
+
* ID to find this component in testing tools (e.g.: cypress,
|
|
34
|
+
* testing-library, and jest).
|
|
35
|
+
*/
|
|
36
|
+
testId?: string
|
|
37
|
+
/**
|
|
38
|
+
* ID of the current instance of the component.
|
|
39
|
+
*/
|
|
40
|
+
id?: string
|
|
41
|
+
/**
|
|
42
|
+
* Specify which variant the component should handle.
|
|
43
|
+
*/
|
|
44
|
+
variant: Variant
|
|
45
|
+
/**
|
|
46
|
+
* SKU options that should be rendered.
|
|
47
|
+
*/
|
|
48
|
+
options: SkuProps[]
|
|
49
|
+
/**
|
|
50
|
+
* Section label for the SKU selector.
|
|
51
|
+
*/
|
|
52
|
+
label?: string
|
|
53
|
+
/**
|
|
54
|
+
* Currently active variation's value.
|
|
55
|
+
*/
|
|
56
|
+
activeValue: string
|
|
57
|
+
/**
|
|
58
|
+
* Function to be triggered when SKU option change.
|
|
59
|
+
*/
|
|
60
|
+
onChange?: ChangeEventHandler<HTMLInputElement>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const SkuSelector = forwardRef<HTMLDivElement, SkuSelectorProps>(
|
|
64
|
+
function SkuSelector(
|
|
65
|
+
{
|
|
66
|
+
id,
|
|
67
|
+
label,
|
|
68
|
+
variant,
|
|
69
|
+
onChange,
|
|
70
|
+
testId = 'store-sku-selector',
|
|
71
|
+
activeValue,
|
|
72
|
+
children,
|
|
73
|
+
...otherProps
|
|
74
|
+
},
|
|
75
|
+
ref
|
|
76
|
+
) {
|
|
77
|
+
const radioGroupId = id ? `-${id}` : ''
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
ref={ref}
|
|
82
|
+
data-fs-sku-selector
|
|
83
|
+
data-testid={testId}
|
|
84
|
+
data-fs-sku-selector-variant={variant}
|
|
85
|
+
{...otherProps}
|
|
86
|
+
>
|
|
87
|
+
{label && (
|
|
88
|
+
<Label data-fs-sku-selector-title>
|
|
89
|
+
{label}: <strong>{activeValue}</strong>
|
|
90
|
+
</Label>
|
|
91
|
+
)}
|
|
92
|
+
<RadioGroup
|
|
93
|
+
selectedValue={activeValue}
|
|
94
|
+
name={`sku-selector-${variant}${radioGroupId}`}
|
|
95
|
+
onChange={(e) => {
|
|
96
|
+
onChange?.(e)
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{children}
|
|
100
|
+
</RadioGroup>
|
|
101
|
+
</div>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
export default SkuSelector
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import SkuSelector from '../SkuSelector'
|
|
4
|
+
|
|
5
|
+
# SkuSelector
|
|
6
|
+
|
|
7
|
+
<Canvas>
|
|
8
|
+
<Story id="molecules-skuselector--sku-selector" />
|
|
9
|
+
</Canvas>
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
<ArgsTable of={ SkuSelector } />
|
|
14
|
+
|
|
15
|
+
## CSS Selectors
|
|
16
|
+
|
|
17
|
+
```css
|
|
18
|
+
[data-fs-sku-selector] {
|
|
19
|
+
}
|
|
20
|
+
[data-fs-sku-selector-variant='(label|image)'] {
|
|
21
|
+
}
|
|
22
|
+
[data-fs-sku-selector-title] {
|
|
23
|
+
}
|
|
24
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Story, Meta } from '@storybook/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { RadioOption } from '../../..'
|
|
4
|
+
|
|
5
|
+
import type { SkuSelectorProps } from '../SkuSelector'
|
|
6
|
+
import Component from '../SkuSelector'
|
|
7
|
+
import mdx from './SkuSelector.mdx'
|
|
8
|
+
|
|
9
|
+
const SkuSelectorTemplate: Story<SkuSelectorProps> = ({ testId }) => {
|
|
10
|
+
const activeValue = 'Pink'
|
|
11
|
+
const options = [
|
|
12
|
+
{ label: 'Color Pink', value: 'Pink' },
|
|
13
|
+
{ label: 'Color White', value: 'White' },
|
|
14
|
+
]
|
|
15
|
+
const variant = 'label'
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Component
|
|
19
|
+
testId={testId}
|
|
20
|
+
variant={variant}
|
|
21
|
+
options={options}
|
|
22
|
+
activeValue={activeValue}
|
|
23
|
+
label='Color'
|
|
24
|
+
>
|
|
25
|
+
{options.map((option, index) => {
|
|
26
|
+
return (
|
|
27
|
+
<RadioOption
|
|
28
|
+
data-fs-sku-selector-option
|
|
29
|
+
key={String(index)}
|
|
30
|
+
label={option.label}
|
|
31
|
+
value={option.value}
|
|
32
|
+
checked={option.value === activeValue}
|
|
33
|
+
>
|
|
34
|
+
<span>{option.value}</span>
|
|
35
|
+
</RadioOption>
|
|
36
|
+
)
|
|
37
|
+
})}
|
|
38
|
+
</Component>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const SkuSelector = SkuSelectorTemplate.bind({})
|
|
43
|
+
SkuSelector.storyName = 'SkuSelector'
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
title: 'Molecules/SkuSelector',
|
|
47
|
+
parameters: {
|
|
48
|
+
docs: {
|
|
49
|
+
page: mdx,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
} as Meta
|