@transferwise/components 46.132.1 → 46.133.1
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/build/chips/Chips.js.map +1 -1
- package/build/chips/Chips.mjs.map +1 -1
- package/build/inputs/InputGroup.js +10 -1
- package/build/inputs/InputGroup.js.map +1 -1
- package/build/inputs/InputGroup.mjs +10 -1
- package/build/inputs/InputGroup.mjs.map +1 -1
- package/build/label/Label.js +1 -1
- package/build/label/Label.js.map +1 -1
- package/build/label/Label.mjs +1 -1
- package/build/label/Label.mjs.map +1 -1
- package/build/logo/Logo.js +6 -0
- package/build/logo/Logo.js.map +1 -1
- package/build/logo/Logo.mjs +6 -0
- package/build/logo/Logo.mjs.map +1 -1
- package/build/main.css +22 -6
- package/build/phoneNumberInput/PhoneNumberInput.js +6 -1
- package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.mjs +6 -1
- package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
- package/build/styles/inputs/InputGroup.css +10 -2
- package/build/styles/listItem/ListItem.css +4 -4
- package/build/styles/listItem/ListItem.grid.css +3 -3
- package/build/styles/main.css +22 -6
- package/build/styles/phoneNumberInput/PhoneNumberInput.css +5 -0
- package/build/types/chips/Chips.d.ts +1 -1
- package/build/types/chips/Chips.d.ts.map +1 -1
- package/build/types/common/commonProps.d.ts +0 -6
- package/build/types/common/commonProps.d.ts.map +1 -1
- package/build/types/label/Label.d.ts.map +1 -1
- package/build/types/logo/Logo.d.ts +10 -1
- package/build/types/logo/Logo.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/button/_stories/Button.accessibility.docs.mdx +10 -6
- package/src/button/_stories/Button.story.tsx +15 -7
- package/src/checkboxButton/CheckboxButton.story.tsx +125 -44
- package/src/checkboxButton/CheckboxButton.test.story.tsx +236 -0
- package/src/chips/Chips.story.tsx +141 -102
- package/src/chips/Chips.test.story.tsx +177 -0
- package/src/chips/Chips.tsx +1 -1
- package/src/circularButton/CircularButton.story.tsx +261 -49
- package/src/circularButton/CircularButton.test.story.tsx +192 -2
- package/src/common/bottomSheet/BottomSheet.story.tsx +11 -9
- package/src/common/bottomSheet/BottomSheet.test.story.tsx +28 -15
- package/src/common/commonProps.ts +0 -6
- package/src/divider/Divider.accessibility.docs.mdx +1 -10
- package/src/divider/Divider.story.tsx +0 -1
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.story.tsx +1 -2
- package/src/header/Header.accessibility.docs.mdx +9 -5
- package/src/iconButton/IconButton.story.tsx +315 -110
- package/src/iconButton/IconButton.test.story.tsx +217 -44
- package/src/inputs/InputGroup.css +10 -2
- package/src/inputs/InputGroup.less +12 -2
- package/src/inputs/InputGroup.story.tsx +27 -0
- package/src/inputs/InputGroup.tsx +10 -0
- package/src/inputs/SelectInput/_stories/SelectInput.story.tsx +0 -1
- package/src/label/Label.tsx +1 -2
- package/src/legacylistItem/LegacyListItem.test.story.tsx +1 -1
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.story.tsx +0 -1
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.story.tsx +0 -1
- package/src/listItem/AvatarView/ListItemAvatarView.story.tsx +0 -1
- package/src/listItem/Button/ListItemButton.story.tsx +0 -1
- package/src/listItem/Checkbox/ListItemCheckbox.story.tsx +0 -1
- package/src/listItem/IconButton/ListItemIconButton.story.tsx +0 -1
- package/src/listItem/ListItem.css +4 -4
- package/src/listItem/ListItem.grid.css +3 -3
- package/src/listItem/ListItem.grid.less +5 -3
- package/src/listItem/ListItem.less +1 -1
- package/src/listItem/ListItem.vars.less +2 -2
- package/src/listItem/Navigation/ListItemNavigation.story.tsx +0 -1
- package/src/listItem/Prompt/ListItemPrompt.story.tsx +0 -1
- package/src/listItem/Radio/ListItemRadio.story.tsx +0 -1
- package/src/listItem/Switch/ListItemSwitch.story.tsx +0 -1
- package/src/listItem/_stories/ListItem.layout.test.story.tsx +55 -0
- package/src/listItem/_stories/ListItem.story.tsx +1 -0
- package/src/logo/Logo.story.tsx +181 -21
- package/src/logo/Logo.test.story.tsx +40 -7
- package/src/logo/Logo.tsx +10 -1
- package/src/main.css +22 -6
- package/src/phoneNumberInput/PhoneNumberInput.css +5 -0
- package/src/phoneNumberInput/PhoneNumberInput.less +7 -0
- package/src/phoneNumberInput/PhoneNumberInput.tsx +10 -1
- package/src/prompt/InlinePrompt/InlinePrompt.story.tsx +0 -1
- package/src/section/Section.story.tsx +12 -7
- package/src/sentimentSurface/SentimentSurface.story.tsx +1 -1
- package/src/snackbar/Snackbar.test.story.tsx +16 -104
- package/src/summary/Summary.test.story.tsx +1 -1
- package/src/switch/Switch.story.tsx +64 -42
- package/src/switch/Switch.test.story.tsx +123 -0
- package/src/switchOption/SwitchOption.story.tsx +0 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { userEvent, within } from 'storybook/test';
|
|
1
|
+
import { userEvent, within, expect } from 'storybook/test';
|
|
2
2
|
import { action } from 'storybook/actions';
|
|
3
|
-
import {
|
|
3
|
+
import { withVariantConfig } from '../../.storybook/helpers';
|
|
4
|
+
import { lorem20 } from '../test-utils';
|
|
5
|
+
import { wait } from '../test-utils/wait';
|
|
6
|
+
import Button from '../button';
|
|
4
7
|
import { Snackbar, type SnackbarProps } from './Snackbar';
|
|
5
8
|
import { SnackbarConsumer } from './SnackbarContext';
|
|
6
9
|
import SnackbarProvider from './SnackbarProvider';
|
|
7
|
-
import Button from '../button';
|
|
8
|
-
import CheckboxOption from '../checkboxOption';
|
|
9
|
-
import { wait } from '../test-utils/wait';
|
|
10
|
-
import { withVariantConfig } from '../../.storybook/helpers';
|
|
11
10
|
|
|
12
11
|
export default {
|
|
13
12
|
title: 'Dialogs/Snackbar/Tests',
|
|
@@ -43,6 +42,7 @@ const Default = {
|
|
|
43
42
|
{({ createSnackbar }) => (
|
|
44
43
|
<>
|
|
45
44
|
<Button
|
|
45
|
+
v2
|
|
46
46
|
block
|
|
47
47
|
onClick={() => {
|
|
48
48
|
createSnackbar({
|
|
@@ -69,36 +69,6 @@ export const Basic = {
|
|
|
69
69
|
...Default,
|
|
70
70
|
args: {
|
|
71
71
|
...Default.args,
|
|
72
|
-
extraContext: (
|
|
73
|
-
<div className="p-t-3">
|
|
74
|
-
<CheckboxOption
|
|
75
|
-
title="In light mode, snackbar has drop shadow"
|
|
76
|
-
content={
|
|
77
|
-
<a
|
|
78
|
-
href="https://transferwise.atlassian.net/browse/DS-4477"
|
|
79
|
-
target="_blank"
|
|
80
|
-
rel="noreferrer"
|
|
81
|
-
>
|
|
82
|
-
Bug DS-4477
|
|
83
|
-
</a>
|
|
84
|
-
}
|
|
85
|
-
media={<Bulb />}
|
|
86
|
-
/>
|
|
87
|
-
<CheckboxOption
|
|
88
|
-
title="Font size is 14 px, not 16px"
|
|
89
|
-
content={
|
|
90
|
-
<a
|
|
91
|
-
href="https://transferwise.atlassian.net/browse/DS-3716"
|
|
92
|
-
target="_blank"
|
|
93
|
-
rel="noreferrer"
|
|
94
|
-
>
|
|
95
|
-
Bug DS-3716
|
|
96
|
-
</a>
|
|
97
|
-
}
|
|
98
|
-
media={<Info size="16" />}
|
|
99
|
-
/>
|
|
100
|
-
</div>
|
|
101
|
-
) as React.ReactNode,
|
|
102
72
|
},
|
|
103
73
|
};
|
|
104
74
|
|
|
@@ -106,14 +76,6 @@ export const Mobile = {
|
|
|
106
76
|
...Default,
|
|
107
77
|
args: {
|
|
108
78
|
...Default.args,
|
|
109
|
-
extraContext: (
|
|
110
|
-
<div className="p-t-3">
|
|
111
|
-
<CheckboxOption
|
|
112
|
-
title="In mobile view, snackbar is full-width, not centered"
|
|
113
|
-
media={<MobileIcon />}
|
|
114
|
-
/>
|
|
115
|
-
</div>
|
|
116
|
-
) as React.ReactNode,
|
|
117
79
|
},
|
|
118
80
|
...withVariantConfig(['mobile'], Default),
|
|
119
81
|
};
|
|
@@ -136,15 +98,6 @@ export const DarkMode = {
|
|
|
136
98
|
...Default,
|
|
137
99
|
args: {
|
|
138
100
|
...Default.args,
|
|
139
|
-
extraContext: (
|
|
140
|
-
<div className="p-t-3">
|
|
141
|
-
<CheckboxOption title="In dark mode, snackbar has no drop shadow" media={<Theme />} />
|
|
142
|
-
<CheckboxOption
|
|
143
|
-
title="In dark mode, snackbar is inverted and has light background"
|
|
144
|
-
media={<Theme />}
|
|
145
|
-
/>
|
|
146
|
-
</div>
|
|
147
|
-
) as React.ReactNode,
|
|
148
101
|
},
|
|
149
102
|
play: switchToDarkMode,
|
|
150
103
|
...withVariantConfig(['dark'], Default),
|
|
@@ -167,36 +120,6 @@ export const RTL = {
|
|
|
167
120
|
...Default,
|
|
168
121
|
args: {
|
|
169
122
|
...Default.args,
|
|
170
|
-
extraContext: (
|
|
171
|
-
<div className="p-t-3">
|
|
172
|
-
<CheckboxOption
|
|
173
|
-
title="In RTL, snackbar is not left aligned"
|
|
174
|
-
content={
|
|
175
|
-
<a
|
|
176
|
-
href="https://transferwise.atlassian.net/browse/DS-4642"
|
|
177
|
-
target="_blank"
|
|
178
|
-
rel="noreferrer"
|
|
179
|
-
>
|
|
180
|
-
Bug DS-4642
|
|
181
|
-
</a>
|
|
182
|
-
}
|
|
183
|
-
media={<Switch />}
|
|
184
|
-
/>
|
|
185
|
-
<CheckboxOption
|
|
186
|
-
title="In RTL, snackbar has proper padding on left and right of button"
|
|
187
|
-
content={
|
|
188
|
-
<a
|
|
189
|
-
href="https://transferwise.atlassian.net/browse/DS-4643"
|
|
190
|
-
target="_blank"
|
|
191
|
-
rel="noreferrer"
|
|
192
|
-
>
|
|
193
|
-
Bug DS-4643
|
|
194
|
-
</a>
|
|
195
|
-
}
|
|
196
|
-
media={<Switch />}
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
) as React.ReactNode,
|
|
200
123
|
},
|
|
201
124
|
play: switchToRTL,
|
|
202
125
|
...withVariantConfig(['rtl'], Default),
|
|
@@ -217,42 +140,31 @@ export const Zoom400 = {
|
|
|
217
140
|
...Default.args,
|
|
218
141
|
extraContext: (
|
|
219
142
|
<div className="p-t-3">
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
target="_blank"
|
|
226
|
-
rel="noreferrer"
|
|
227
|
-
>
|
|
228
|
-
Bug DS-3716
|
|
229
|
-
</a>
|
|
230
|
-
}
|
|
231
|
-
media={<Coins />}
|
|
232
|
-
/>
|
|
143
|
+
Snackbar isn't transparent (I'm going to make this text very long so that it will
|
|
144
|
+
fill up the entire page and go behind the snackbar. This way, when you look at it you will
|
|
145
|
+
easily be able to tell if the snackbar is transparent and recognize the bug because we
|
|
146
|
+
don't want it to be transparent. Transparent is bad. When we first did rebrand we had a
|
|
147
|
+
lot of problems with transparencies. {lorem20}
|
|
233
148
|
</div>
|
|
234
149
|
),
|
|
235
150
|
},
|
|
236
151
|
...withVariantConfig(['400%'], Default),
|
|
237
152
|
};
|
|
238
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Snackbar is only shown once even if trigger is clicked many times
|
|
156
|
+
*/
|
|
239
157
|
export const MultipleClicks = {
|
|
240
158
|
...Default,
|
|
241
159
|
args: {
|
|
242
160
|
...Default.args,
|
|
243
|
-
extraContext: (
|
|
244
|
-
<div className="p-t-3">
|
|
245
|
-
<CheckboxOption
|
|
246
|
-
title="Snackbar is only shown once even if clicked many times"
|
|
247
|
-
media={<Team />}
|
|
248
|
-
/>
|
|
249
|
-
</div>
|
|
250
|
-
),
|
|
251
161
|
},
|
|
252
162
|
play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
|
|
253
163
|
const canvas = within(canvasElement);
|
|
254
164
|
for (let i = 0; i < 8; i += 1) {
|
|
255
165
|
await userEvent.click(canvas.getByRole('button'));
|
|
256
166
|
}
|
|
167
|
+
|
|
168
|
+
await expect(within(document.body).getAllByRole('alert')).toHaveLength(1);
|
|
257
169
|
},
|
|
258
170
|
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
2
|
import { fn } from 'storybook/test';
|
|
3
3
|
|
|
4
|
+
import { storySourceWithoutNoise } from '../../.storybook/helpers';
|
|
4
5
|
import Switch, { SwitchProps } from './Switch';
|
|
5
6
|
import { Field } from '../field/Field';
|
|
6
7
|
import { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
7
8
|
import { Label } from '../label';
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* **Design guidance**: <a href="https://wise.design/components/switch" target="_blank">wise.design/components/switch</a>
|
|
12
|
+
*/
|
|
9
13
|
const meta: Meta<typeof Switch> = {
|
|
10
14
|
component: Switch,
|
|
11
15
|
title: 'Actions/Switch',
|
|
@@ -15,59 +19,84 @@ const meta: Meta<typeof Switch> = {
|
|
|
15
19
|
id: 'switchId',
|
|
16
20
|
className: 'switchClassName',
|
|
17
21
|
'aria-labelledby': undefined,
|
|
18
|
-
'aria-label':
|
|
22
|
+
'aria-label': 'Toggle switch',
|
|
19
23
|
onClick: fn(),
|
|
20
24
|
},
|
|
25
|
+
argTypes: {
|
|
26
|
+
id: { description: '', table: { category: 'Common' } },
|
|
27
|
+
className: { description: '', table: { category: 'Common' } },
|
|
28
|
+
onClick: { description: '', table: { category: 'Common', type: { summary: 'function' } } },
|
|
29
|
+
},
|
|
30
|
+
parameters: {
|
|
31
|
+
docs: { toc: true },
|
|
32
|
+
},
|
|
21
33
|
} satisfies Meta<typeof Switch>;
|
|
22
34
|
|
|
23
35
|
export default meta;
|
|
24
36
|
type Story = StoryObj<typeof Switch>;
|
|
25
37
|
|
|
26
|
-
export const
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
export const Playground: Story = storySourceWithoutNoise({
|
|
39
|
+
render: function Render(args: SwitchProps) {
|
|
40
|
+
const [checked, setChecked] = useState(args.checked ?? false);
|
|
29
41
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
setChecked(args.checked ?? false);
|
|
44
|
+
}, [args.checked]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Field id="playground-field" label="Switch label">
|
|
48
|
+
<Switch
|
|
49
|
+
{...args}
|
|
50
|
+
checked={checked}
|
|
51
|
+
onClick={() => setChecked((value: boolean) => !value)}
|
|
52
|
+
/>
|
|
53
|
+
</Field>
|
|
54
|
+
);
|
|
34
55
|
},
|
|
35
|
-
};
|
|
56
|
+
});
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Three labelling patterns: <a href="?path=/docs/forms-label--docs">Label</a>, `aria-labelledby`, and <a href="?path=/docs/forms-field--docs">Field</a>. <br />
|
|
60
|
+
* Use Label for simple label-input pairs. Use `aria-labelledby` to reference existing text as the accessible name. Use Field for form layouts with labels, descriptions, and validation.
|
|
61
|
+
*/
|
|
62
|
+
export const LabelPatterns: Story = {
|
|
38
63
|
render: function Render({ disabled }: SwitchProps) {
|
|
39
|
-
const [checked1, setCheck1] = useState(
|
|
40
|
-
const [checked2, setCheck2] = useState(
|
|
41
|
-
const [checked3, setCheck3] = useState(
|
|
64
|
+
const [checked1, setCheck1] = useState(true);
|
|
65
|
+
const [checked2, setCheck2] = useState(false);
|
|
66
|
+
const [checked3, setCheck3] = useState(true);
|
|
42
67
|
|
|
43
68
|
return (
|
|
44
|
-
|
|
45
|
-
<Field id="fieldId" label="Using Field component">
|
|
46
|
-
<Switch checked={checked1} disabled={disabled} onClick={() => setCheck1(!checked1)} />
|
|
47
|
-
</Field>
|
|
48
|
-
|
|
69
|
+
<div className="d-flex flex-column" style={{ gap: '1rem' }}>
|
|
49
70
|
<div>
|
|
50
|
-
<Label htmlFor="labelId">
|
|
71
|
+
<Label htmlFor="labelId">Enable two-factor authentication</Label>
|
|
51
72
|
<Switch
|
|
52
73
|
id="labelId"
|
|
53
|
-
checked={
|
|
74
|
+
checked={checked1}
|
|
54
75
|
disabled={disabled}
|
|
55
|
-
onClick={() =>
|
|
76
|
+
onClick={() => setCheck1(!checked1)}
|
|
56
77
|
/>
|
|
57
78
|
</div>
|
|
58
79
|
|
|
59
80
|
<div>
|
|
60
81
|
<strong id="ariaId" className="d-block">
|
|
61
|
-
|
|
82
|
+
Marketing emails
|
|
62
83
|
</strong>
|
|
63
84
|
<Switch
|
|
64
85
|
aria-labelledby="ariaId"
|
|
65
|
-
checked={
|
|
86
|
+
checked={checked2}
|
|
66
87
|
disabled={disabled}
|
|
67
|
-
onClick={() =>
|
|
88
|
+
onClick={() => setCheck2(!checked2)}
|
|
68
89
|
/>
|
|
69
90
|
</div>
|
|
70
|
-
|
|
91
|
+
|
|
92
|
+
<Field
|
|
93
|
+
id="fieldId"
|
|
94
|
+
label="Enable notifications"
|
|
95
|
+
description="Get alerts when transfers complete"
|
|
96
|
+
>
|
|
97
|
+
<Switch checked={checked3} disabled={disabled} onClick={() => setCheck3(!checked3)} />
|
|
98
|
+
</Field>
|
|
99
|
+
</div>
|
|
71
100
|
);
|
|
72
101
|
},
|
|
73
102
|
parameters: {
|
|
@@ -78,7 +107,7 @@ function Render() {
|
|
|
78
107
|
const [checked1, setCheck1] = useState(false);
|
|
79
108
|
const [checked2, setCheck2] = useState(true);
|
|
80
109
|
const [checked3, setCheck3] = useState(false);
|
|
81
|
-
|
|
110
|
+
|
|
82
111
|
return (
|
|
83
112
|
<>
|
|
84
113
|
<Field id="fieldId" label="Using Field component">
|
|
@@ -87,7 +116,7 @@ function Render() {
|
|
|
87
116
|
onClick={() => setCheck1(!checked1)}
|
|
88
117
|
/>
|
|
89
118
|
</Field>
|
|
90
|
-
|
|
119
|
+
|
|
91
120
|
<div>
|
|
92
121
|
<Label htmlFor="labelId">Using standalone Label component</Label>
|
|
93
122
|
<Switch
|
|
@@ -96,7 +125,7 @@ function Render() {
|
|
|
96
125
|
onClick={() => setCheck2(!checked2)}
|
|
97
126
|
/>
|
|
98
127
|
</div>
|
|
99
|
-
|
|
128
|
+
|
|
100
129
|
<div>
|
|
101
130
|
<strong id="ariaId" className="d-block">Using \`aria-labelledby\`</strong>
|
|
102
131
|
<Switch
|
|
@@ -111,13 +140,6 @@ function Render() {
|
|
|
111
140
|
},
|
|
112
141
|
},
|
|
113
142
|
},
|
|
114
|
-
decorators: [
|
|
115
|
-
(Story: any) => (
|
|
116
|
-
<div className="d-flex flex-column" style={{ gap: '1rem' }}>
|
|
117
|
-
<Story />
|
|
118
|
-
</div>
|
|
119
|
-
),
|
|
120
|
-
],
|
|
121
143
|
args: {},
|
|
122
144
|
argTypes: {
|
|
123
145
|
checked: { table: { disable: true } },
|
|
@@ -126,17 +148,17 @@ function Render() {
|
|
|
126
148
|
};
|
|
127
149
|
|
|
128
150
|
export const Disabled: Story = {
|
|
129
|
-
render: function Render(
|
|
151
|
+
render: function Render() {
|
|
130
152
|
const [checked1, setCheck1] = useState(false);
|
|
131
153
|
const [checked2, setCheck2] = useState(true);
|
|
132
154
|
|
|
133
155
|
return (
|
|
134
156
|
<>
|
|
135
|
-
<Field label="
|
|
157
|
+
<Field label="Disabled unchecked">
|
|
136
158
|
<Switch checked={checked1} disabled onClick={() => setCheck1(!checked1)} />
|
|
137
159
|
</Field>
|
|
138
160
|
|
|
139
|
-
<Field label="
|
|
161
|
+
<Field label="Disabled checked">
|
|
140
162
|
<Switch checked={checked2} disabled onClick={() => setCheck2(!checked2)} />
|
|
141
163
|
</Field>
|
|
142
164
|
</>
|
|
@@ -152,14 +174,14 @@ function Render() {
|
|
|
152
174
|
|
|
153
175
|
return (
|
|
154
176
|
<>
|
|
155
|
-
<Field label="
|
|
177
|
+
<Field label="Disabled unchecked">
|
|
156
178
|
<Switch
|
|
157
179
|
checked={checked1}
|
|
158
180
|
disabled
|
|
159
181
|
onClick={() => setCheck1(!checked1)}
|
|
160
182
|
/>
|
|
161
|
-
</
|
|
162
|
-
<Field label="
|
|
183
|
+
</Field>
|
|
184
|
+
<Field label="Disabled checked">
|
|
163
185
|
<Switch
|
|
164
186
|
checked={checked2}
|
|
165
187
|
disabled
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
2
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { withVariantConfig } from '../../.storybook/helpers';
|
|
6
|
+
import { Field } from '../field/Field';
|
|
7
|
+
import Switch from './Switch';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
component: Switch,
|
|
11
|
+
title: 'Actions/Switch/Tests',
|
|
12
|
+
tags: ['!autodocs', '!manifest'],
|
|
13
|
+
} satisfies Meta<typeof Switch>;
|
|
14
|
+
|
|
15
|
+
type Story = StoryObj<typeof Switch>;
|
|
16
|
+
|
|
17
|
+
/** All switch states across all themes. */
|
|
18
|
+
export const Variants: Story = {
|
|
19
|
+
render: function Render() {
|
|
20
|
+
const [unchecked, setUnchecked] = useState(false);
|
|
21
|
+
const [checked, setChecked] = useState(true);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px', padding: '16px' }}>
|
|
25
|
+
<Field label="Unchecked">
|
|
26
|
+
<Switch checked={unchecked} onClick={() => setUnchecked((v) => !v)} />
|
|
27
|
+
</Field>
|
|
28
|
+
<Field label="Checked">
|
|
29
|
+
<Switch checked={checked} onClick={() => setChecked((v) => !v)} />
|
|
30
|
+
</Field>
|
|
31
|
+
<Field label="Disabled (off)">
|
|
32
|
+
<Switch checked={false} disabled onClick={() => {}} />
|
|
33
|
+
</Field>
|
|
34
|
+
<Field label="Disabled (on)">
|
|
35
|
+
<Switch checked disabled onClick={() => {}} />
|
|
36
|
+
</Field>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
...withVariantConfig(['default', 'dark', 'bright-green', 'forest-green']),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Tests keyboard navigation and interaction:
|
|
45
|
+
* - Tab focuses the switch
|
|
46
|
+
* - Space toggles the switch on and off
|
|
47
|
+
*/
|
|
48
|
+
export const KeyboardInteraction: Story = {
|
|
49
|
+
render: function Render() {
|
|
50
|
+
const [checked, setChecked] = useState(false);
|
|
51
|
+
return (
|
|
52
|
+
<Field id="notif-field" label="Email notifications">
|
|
53
|
+
<Switch checked={checked} onClick={() => setChecked((v) => !v)} />
|
|
54
|
+
</Field>
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
play: async ({ canvasElement, step }) => {
|
|
58
|
+
const wait = async (ms: number) =>
|
|
59
|
+
new Promise<void>((resolve) => {
|
|
60
|
+
setTimeout(resolve, ms);
|
|
61
|
+
});
|
|
62
|
+
const canvas = within(canvasElement);
|
|
63
|
+
const switchEl = canvas.getByRole('switch');
|
|
64
|
+
|
|
65
|
+
await step('tab focuses the switch', async () => {
|
|
66
|
+
await userEvent.tab();
|
|
67
|
+
await expect(switchEl).toHaveFocus();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await wait(400);
|
|
71
|
+
|
|
72
|
+
await step('space toggles the switch on', async () => {
|
|
73
|
+
await userEvent.keyboard(' ');
|
|
74
|
+
await expect(switchEl).toHaveAttribute('aria-checked', 'true');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await wait(400);
|
|
78
|
+
|
|
79
|
+
await step('space toggles the switch off', async () => {
|
|
80
|
+
await userEvent.keyboard(' ');
|
|
81
|
+
await expect(switchEl).toHaveAttribute('aria-checked', 'false');
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Switch rendered in RTL mode. */
|
|
87
|
+
export const RTL: Story = {
|
|
88
|
+
render: function Render() {
|
|
89
|
+
const [unchecked, setUnchecked] = useState(false);
|
|
90
|
+
const [checked, setChecked] = useState(true);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px', padding: '16px' }}>
|
|
94
|
+
<Field label="Unchecked">
|
|
95
|
+
<Switch checked={unchecked} onClick={() => setUnchecked((v) => !v)} />
|
|
96
|
+
</Field>
|
|
97
|
+
<Field label="Checked">
|
|
98
|
+
<Switch checked={checked} onClick={() => setChecked((v) => !v)} />
|
|
99
|
+
</Field>
|
|
100
|
+
<Field label="Disabled (off)">
|
|
101
|
+
<Switch checked={false} disabled onClick={() => {}} />
|
|
102
|
+
</Field>
|
|
103
|
+
<Field label="Disabled (on)">
|
|
104
|
+
<Switch checked disabled onClick={() => {}} />
|
|
105
|
+
</Field>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
...withVariantConfig(['rtl']),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Switch at 400% zoom for accessibility testing. */
|
|
113
|
+
export const Zoom400: Story = {
|
|
114
|
+
render: function Render() {
|
|
115
|
+
const [checked, setChecked] = useState(false);
|
|
116
|
+
return (
|
|
117
|
+
<Field label="Email notifications">
|
|
118
|
+
<Switch checked={checked} onClick={() => setChecked((v) => !v)} />
|
|
119
|
+
</Field>
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
...withVariantConfig(['400%']),
|
|
123
|
+
};
|