@transferwise/components 46.133.0 → 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.
Files changed (46) hide show
  1. package/build/chips/Chips.js.map +1 -1
  2. package/build/chips/Chips.mjs.map +1 -1
  3. package/build/label/Label.js +1 -1
  4. package/build/label/Label.js.map +1 -1
  5. package/build/label/Label.mjs +1 -1
  6. package/build/label/Label.mjs.map +1 -1
  7. package/build/logo/Logo.js +6 -0
  8. package/build/logo/Logo.js.map +1 -1
  9. package/build/logo/Logo.mjs +6 -0
  10. package/build/logo/Logo.mjs.map +1 -1
  11. package/build/main.css +4 -4
  12. package/build/styles/listItem/ListItem.css +4 -4
  13. package/build/styles/listItem/ListItem.grid.css +3 -3
  14. package/build/styles/main.css +4 -4
  15. package/build/types/chips/Chips.d.ts +1 -1
  16. package/build/types/chips/Chips.d.ts.map +1 -1
  17. package/build/types/common/commonProps.d.ts +0 -6
  18. package/build/types/common/commonProps.d.ts.map +1 -1
  19. package/build/types/label/Label.d.ts.map +1 -1
  20. package/build/types/logo/Logo.d.ts +10 -1
  21. package/build/types/logo/Logo.d.ts.map +1 -1
  22. package/package.json +3 -3
  23. package/src/button/_stories/Button.story.tsx +15 -5
  24. package/src/checkboxButton/CheckboxButton.story.tsx +125 -44
  25. package/src/checkboxButton/CheckboxButton.test.story.tsx +236 -0
  26. package/src/chips/Chips.story.tsx +141 -102
  27. package/src/chips/Chips.test.story.tsx +177 -0
  28. package/src/chips/Chips.tsx +1 -1
  29. package/src/circularButton/CircularButton.story.tsx +261 -49
  30. package/src/circularButton/CircularButton.test.story.tsx +192 -2
  31. package/src/common/commonProps.ts +0 -6
  32. package/src/iconButton/IconButton.story.tsx +315 -110
  33. package/src/iconButton/IconButton.test.story.tsx +217 -44
  34. package/src/label/Label.tsx +1 -2
  35. package/src/listItem/ListItem.css +4 -4
  36. package/src/listItem/ListItem.grid.css +3 -3
  37. package/src/listItem/ListItem.grid.less +5 -3
  38. package/src/listItem/ListItem.less +1 -1
  39. package/src/listItem/ListItem.vars.less +2 -2
  40. package/src/listItem/_stories/ListItem.layout.test.story.tsx +55 -0
  41. package/src/logo/Logo.story.tsx +181 -21
  42. package/src/logo/Logo.test.story.tsx +40 -7
  43. package/src/logo/Logo.tsx +10 -1
  44. package/src/main.css +4 -4
  45. package/src/switch/Switch.story.tsx +64 -42
  46. package/src/switch/Switch.test.story.tsx +123 -0
@@ -1,67 +1,148 @@
1
- import { action } from 'storybook/actions';
1
+ import { useState, useEffect } from 'react';
2
+ import { fn } from 'storybook/test';
2
3
  import { Meta, StoryObj } from '@storybook/react-webpack5';
3
- import { useState } from 'react';
4
4
 
5
- import CheckboxButton from './CheckboxButton';
5
+ import { storySourceWithoutNoise } from '../../.storybook/helpers';
6
+ import CheckboxButton, { type CheckboxButtonProps } from './CheckboxButton';
7
+ import { Label } from '../label/Label';
6
8
 
9
+ /**
10
+ * Use <a href="?path=/docs/forms-checkbox--docs">Checkbox</a> component instead when pairing with a label. Only use CheckboxButton when you need a standalone checkbox (e.g. settings matrix) and provide an `aria-label`.
11
+ *
12
+ * **Design guidance**: <a href="https://wise.design/components/checkbox" target="_blank">wise.design/components/checkbox</a>
13
+ */
7
14
  export default {
8
15
  component: CheckboxButton,
9
16
  title: 'Actions/CheckboxButton',
10
17
  args: {
18
+ 'aria-label': 'Toggle checkbox',
19
+ checked: true,
11
20
  disabled: false,
12
- onBlur: action('blur'),
13
- onClick: action('click'),
14
- onFocus: action('focus'),
21
+ indeterminate: false,
22
+ onBlur: fn(),
23
+ onChange: fn(),
24
+ onClick: fn(),
25
+ onFocus: fn(),
26
+ },
27
+ argTypes: {
28
+ 'aria-label': {
29
+ description: 'Provides the accessible name when the control has no visible text label.',
30
+ },
31
+ checked: {
32
+ description: 'Controls whether the checkbox is checked.',
33
+ },
34
+ disabled: {
35
+ description: 'Toggles the disabled state.',
36
+ },
37
+ name: {
38
+ description: 'Name submitted with the form when the checkbox is checked.',
39
+ },
40
+ value: {
41
+ description: 'Value submitted with the form when the checkbox is checked.',
42
+ },
43
+ onChange: {
44
+ description: 'Called when the checked state changes.',
45
+ },
46
+ indeterminate: {
47
+ description:
48
+ 'Sets the native mixed state — used when some (not all) child items are selected. Clicking resolves to checked; clear `indeterminate` in `onChange` to reflect the transition.',
49
+ },
50
+ defaultChecked: { table: { category: 'Common' } },
51
+ id: { table: { category: 'Common' } },
52
+ className: { table: { category: 'Common' } },
53
+ onBlur: { table: { category: 'Common' } },
54
+ onClick: { table: { category: 'Common' } },
55
+ onFocus: { table: { category: 'Common' } },
56
+ },
57
+ parameters: {
58
+ docs: { toc: true },
15
59
  },
16
60
  } satisfies Meta<typeof CheckboxButton>;
17
61
 
18
62
  type Story = StoryObj<typeof CheckboxButton>;
19
63
 
20
- export const Basic: Story = {
21
- args: {
22
- 'aria-label': 'Toggle email updates',
23
- },
24
- render: (args) => {
25
- const [checked, setChecked] = useState(true);
64
+ const withColumnLayout = (Story: () => JSX.Element) => (
65
+ <div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
66
+ <Story />
67
+ </div>
68
+ );
26
69
 
27
- return <CheckboxButton {...args} checked={checked} onChange={() => setChecked(!checked)} />;
28
- },
29
- };
70
+ /** Interactive single checkbox use the Controls panel to toggle `disabled` and `indeterminate`. */
71
+ export const Playground: Story = storySourceWithoutNoise({
72
+ render: function Render(args: CheckboxButtonProps) {
73
+ const [checked, setChecked] = useState(args.checked ?? true);
30
74
 
31
- /**
32
- * The `indeterminate` state is predominantly visual and should match the [native HTML checkbox
33
- * implementation](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/indeterminate).
34
- * It is used to indicate a mixed state, where some but not all items are selected, but does not
35
- * change the `checked` state of the input itself – it remains either checked or unchecked.
36
- *
37
- * In the example below the 1st checkbox is unchecked and the 2nd checkbox is checked.
38
- */
39
- export const Indeterminate: Story = {
40
- args: {
41
- indeterminate: true,
42
- },
43
- render: (args) => {
44
- const [checked1, setChecked1] = useState<boolean | undefined>(false);
45
- const [checked2, setChecked2] = useState<boolean | undefined>(true);
75
+ useEffect(() => {
76
+ setChecked(args.checked ?? true);
77
+ }, [args.checked]);
46
78
 
47
79
  return (
48
- <>
80
+ <CheckboxButton
81
+ {...args}
82
+ checked={checked}
83
+ onChange={(e) => {
84
+ setChecked(e.currentTarget.checked);
85
+ args.onChange?.(e);
86
+ }}
87
+ />
88
+ );
89
+ },
90
+ });
91
+
92
+ /** Disabled state — checked and unchecked. */
93
+ export const Disabled: Story = {
94
+ decorators: [withColumnLayout],
95
+ render: (args) => (
96
+ <>
97
+ <div>
98
+ <Label htmlFor="disabled-unchecked">Disabled unchecked</Label>
99
+ <CheckboxButton
100
+ id="disabled-unchecked"
101
+ aria-label="Disabled unchecked"
102
+ checked={false}
103
+ disabled
104
+ onChange={() => {}}
105
+ />
106
+ </div>
107
+ <div>
108
+ <Label htmlFor="disabled-checked">Disabled checked</Label>
49
109
  <CheckboxButton
50
- {...args}
51
- checked={checked1}
52
- indeterminate={args.indeterminate}
53
- aria-label="Initially disabled checkbox with indeterminate state"
54
- onChange={() => setChecked1((current) => !current)}
110
+ id="disabled-checked"
111
+ aria-label="Disabled checked"
112
+ checked
113
+ disabled
114
+ onChange={() => {}}
55
115
  />
116
+ </div>
117
+ </>
118
+ ),
119
+ };
56
120
 
121
+ /** Indeterminate state — checked and unchecked. */
122
+ export const Indeterminate: Story = {
123
+ decorators: [withColumnLayout],
124
+ render: (args) => (
125
+ <>
126
+ <div>
127
+ <Label htmlFor="indeterminate-unchecked">Indeterminate (unchecked)</Label>
57
128
  <CheckboxButton
58
- {...args}
59
- checked={checked2}
60
- indeterminate={args.indeterminate}
61
- aria-label="Initially enabled checkbox with indeterminate state"
62
- onChange={() => setChecked2((current) => !current)}
129
+ id="indeterminate-unchecked"
130
+ aria-label="Indeterminate unchecked"
131
+ checked={false}
132
+ indeterminate
133
+ onChange={() => {}}
63
134
  />
64
- </>
65
- );
66
- },
135
+ </div>
136
+ <div>
137
+ <Label htmlFor="indeterminate-checked">Indeterminate (checked)</Label>
138
+ <CheckboxButton
139
+ id="indeterminate-checked"
140
+ aria-label="Indeterminate checked"
141
+ checked
142
+ indeterminate
143
+ onChange={() => {}}
144
+ />
145
+ </div>
146
+ </>
147
+ ),
67
148
  };
@@ -0,0 +1,236 @@
1
+ import React, { useState } from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react-webpack5';
3
+ import { expect, userEvent, within } from 'storybook/test';
4
+
5
+ import { withVariantConfig } from '../../.storybook/helpers';
6
+ import CheckboxButton from './CheckboxButton';
7
+
8
+ export default {
9
+ component: CheckboxButton,
10
+ title: 'Actions/CheckboxButton/Tests',
11
+ tags: ['!autodocs', '!manifest'],
12
+ } satisfies Meta<typeof CheckboxButton>;
13
+
14
+ type Story = StoryObj<typeof CheckboxButton>;
15
+
16
+ /** All checkbox states across all themes. */
17
+ export const Variants: Story = {
18
+ render: function Render() {
19
+ const [unchecked, setUnchecked] = useState(false);
20
+ const [checked, setChecked] = useState(true);
21
+ const [indeterminate, setIndeterminate] = useState(false);
22
+ return (
23
+ <div style={{ display: 'flex', gap: '16px', alignItems: 'center', padding: '16px' }}>
24
+ <CheckboxButton
25
+ aria-label="Unchecked"
26
+ checked={unchecked}
27
+ onChange={() => setUnchecked((v) => !v)}
28
+ />
29
+ <CheckboxButton
30
+ aria-label="Checked"
31
+ checked={checked}
32
+ onChange={() => setChecked((v) => !v)}
33
+ />
34
+ <CheckboxButton
35
+ aria-label="Indeterminate"
36
+ checked={indeterminate}
37
+ indeterminate
38
+ onChange={() => setIndeterminate((v) => !v)}
39
+ />
40
+ <CheckboxButton
41
+ aria-label="Disabled unchecked"
42
+ checked={false}
43
+ disabled
44
+ onChange={() => {}}
45
+ />
46
+ <CheckboxButton aria-label="Disabled checked" checked disabled onChange={() => {}} />
47
+ </div>
48
+ );
49
+ },
50
+ ...withVariantConfig(['default', 'dark', 'bright-green', 'forest-green']),
51
+ };
52
+
53
+ /**
54
+ * `Space` toggles when focused (requires `onChange`). Tab skips disabled checkboxes.
55
+ * Indeterminate resolves to checked on first `Space`, then toggles normally.
56
+ */
57
+ export const KeyboardInteraction: Story = {
58
+ render: function Render() {
59
+ const [unchecked, setUnchecked] = useState(false);
60
+ const [checked, setChecked] = useState(true);
61
+ const [indeterminate, setIndeterminate] = useState(false);
62
+ const [disabledUnchecked] = useState(false);
63
+ const [disabledChecked] = useState(true);
64
+
65
+ const row: React.CSSProperties = {
66
+ display: 'flex',
67
+ alignItems: 'center',
68
+ gap: '8px',
69
+ };
70
+
71
+ const label: React.CSSProperties = {
72
+ fontSize: '14px',
73
+ color: '#4a5568',
74
+ width: '140px',
75
+ };
76
+
77
+ return (
78
+ <div style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
79
+ <div style={row}>
80
+ <CheckboxButton
81
+ aria-label="Unchecked"
82
+ checked={unchecked}
83
+ onChange={() => setUnchecked((v: boolean) => !v)}
84
+ />
85
+ <span style={label}>Unchecked</span>
86
+ </div>
87
+ <div style={row}>
88
+ <CheckboxButton
89
+ aria-label="Checked"
90
+ checked={checked}
91
+ onChange={() => setChecked((v: boolean) => !v)}
92
+ />
93
+ <span style={label}>Checked</span>
94
+ </div>
95
+ <div style={row}>
96
+ <CheckboxButton
97
+ aria-label="Indeterminate"
98
+ checked={indeterminate}
99
+ indeterminate
100
+ onChange={() => setIndeterminate((v: boolean) => !v)}
101
+ />
102
+ <span style={label}>Indeterminate</span>
103
+ </div>
104
+ <div style={row}>
105
+ <CheckboxButton
106
+ aria-label="Disabled unchecked"
107
+ checked={disabledUnchecked}
108
+ disabled
109
+ onChange={() => {}}
110
+ />
111
+ <span style={label}>Disabled unchecked</span>
112
+ </div>
113
+ <div style={row}>
114
+ <CheckboxButton
115
+ aria-label="Disabled checked"
116
+ checked={disabledChecked}
117
+ disabled
118
+ onChange={() => {}}
119
+ />
120
+ <span style={label}>Disabled checked</span>
121
+ </div>
122
+ </div>
123
+ );
124
+ },
125
+ play: async ({ canvasElement, step }) => {
126
+ const wait = async (ms: number) =>
127
+ new Promise<void>((resolve) => {
128
+ setTimeout(resolve, ms);
129
+ });
130
+ const canvas = within(canvasElement);
131
+
132
+ await step('tab to Unchecked and toggle on then off', async () => {
133
+ await userEvent.tab();
134
+ const cb = canvas.getByRole('checkbox', { name: /^unchecked$/i });
135
+ await expect(cb).toHaveFocus();
136
+ await wait(400);
137
+ await userEvent.keyboard(' ');
138
+ await expect(cb).toBeChecked();
139
+ await wait(400);
140
+ await userEvent.keyboard(' ');
141
+ await expect(cb).not.toBeChecked();
142
+ });
143
+
144
+ await wait(400);
145
+
146
+ await step('tab to Checked and toggle off then on', async () => {
147
+ await userEvent.tab();
148
+ const cb = canvas.getByRole('checkbox', { name: /^checked$/i });
149
+ await expect(cb).toHaveFocus();
150
+ await wait(400);
151
+ await userEvent.keyboard(' ');
152
+ await expect(cb).not.toBeChecked();
153
+ await wait(400);
154
+ await userEvent.keyboard(' ');
155
+ await expect(cb).toBeChecked();
156
+ });
157
+
158
+ await wait(400);
159
+
160
+ await step('tab to Indeterminate and toggle on then off', async () => {
161
+ await userEvent.tab();
162
+ const cb = canvas.getByRole('checkbox', { name: /^indeterminate$/i });
163
+ await expect(cb).toHaveFocus();
164
+ await wait(400);
165
+ await userEvent.keyboard(' ');
166
+ await expect(cb).toBeChecked();
167
+ await wait(400);
168
+ await userEvent.keyboard(' ');
169
+ await expect(cb).not.toBeChecked();
170
+ });
171
+
172
+ await wait(400);
173
+
174
+ await step('tab skips both disabled checkboxes — focus leaves the component', async () => {
175
+ await userEvent.tab();
176
+ const disabledUnchecked = canvas.getByRole('checkbox', { name: /disabled unchecked/i });
177
+ const disabledChecked = canvas.getByRole('checkbox', { name: /disabled checked/i });
178
+ await expect(disabledUnchecked).not.toHaveFocus();
179
+ await expect(disabledChecked).not.toHaveFocus();
180
+ });
181
+ },
182
+ };
183
+
184
+ /** Base checkbox states in right-to-left layout. */
185
+ export const RTL: Story = {
186
+ render: function Render() {
187
+ const [unchecked, setUnchecked] = useState(false);
188
+ const [checked, setChecked] = useState(true);
189
+ const [indeterminate, setIndeterminate] = useState(false);
190
+ return (
191
+ <div style={{ display: 'flex', gap: '16px', alignItems: 'center', padding: '16px' }}>
192
+ <CheckboxButton
193
+ aria-label="Unchecked"
194
+ checked={unchecked}
195
+ onChange={() => setUnchecked((v) => !v)}
196
+ />
197
+ <CheckboxButton
198
+ aria-label="Checked"
199
+ checked={checked}
200
+ onChange={() => setChecked((v) => !v)}
201
+ />
202
+ <CheckboxButton
203
+ aria-label="Indeterminate"
204
+ checked={indeterminate}
205
+ indeterminate
206
+ onChange={() => setIndeterminate((v) => !v)}
207
+ />
208
+ <CheckboxButton
209
+ aria-label="Disabled unchecked"
210
+ checked={false}
211
+ disabled
212
+ onChange={() => {}}
213
+ />
214
+ <CheckboxButton aria-label="Disabled checked" checked disabled onChange={() => {}} />
215
+ </div>
216
+ );
217
+ },
218
+ ...withVariantConfig(['rtl']),
219
+ };
220
+
221
+ /** Checkbox states at 400% zoom for accessibility testing. */
222
+ export const Zoom400: Story = {
223
+ render: () => (
224
+ <div style={{ display: 'flex', gap: '16px', alignItems: 'center', padding: '16px' }}>
225
+ <CheckboxButton aria-label="Unchecked" checked={false} onChange={() => {}} />
226
+ <CheckboxButton aria-label="Checked" checked onChange={() => {}} />
227
+ <CheckboxButton
228
+ aria-label="Indeterminate"
229
+ checked={false}
230
+ indeterminate
231
+ onChange={() => {}}
232
+ />
233
+ </div>
234
+ ),
235
+ ...withVariantConfig(['400%']),
236
+ };
@@ -1,112 +1,151 @@
1
- import { StoryFn, Meta } from '@storybook/react-webpack5';
1
+ import type { Meta, StoryObj } from '@storybook/react-webpack5';
2
+ import { fn } from 'storybook/test';
2
3
  import { useState } from 'react';
3
4
 
4
- import Chips, { ChipsProps, ChipValue } from './Chips';
5
+ import Chips, { type ChipValue, type ChipsProps } from './Chips';
6
+ import { storySourceWithoutNoise } from '../../.storybook/helpers';
5
7
 
6
- const meta: Meta<typeof Chips> = {
7
- title: 'Actions/Chips',
8
+ /**
9
+ * Can be used for making a <a href="?path=/story/actions-chips--choice">choice</a>, or as a <a href="?path=/story/actions-chips--filter">filter</a> with multiple options.
10
+ *
11
+ * **Design guidance**: <a href="https://wise.design/components/chip" target="_blank">wise.design/components/chip</a>
12
+ */
13
+ export default {
8
14
  component: Chips,
9
- };
10
- export default meta;
15
+ title: 'Actions/Chips',
16
+ args: {
17
+ multiple: false,
18
+ onChange: fn(),
19
+ 'aria-label': 'Category filter',
20
+ },
21
+ argTypes: {
22
+ 'aria-label': {
23
+ control: 'text',
24
+ description: 'Provides the accessible name for the chip group.',
25
+ },
26
+ className: { table: { category: 'Common' } },
27
+ },
28
+ parameters: {
29
+ docs: { toc: true },
30
+ },
31
+ } satisfies Meta<typeof Chips>;
11
32
 
12
- type Story = StoryFn<ChipsProps>;
33
+ type Story = StoryObj<typeof Chips>;
13
34
 
14
- const FilterTemplate: Story = (args: ChipsProps) => {
15
- const [selected, setSelected] = useState<readonly ChipValue[]>(
16
- args.selected == null || Array.isArray(args.selected) ? args.selected : [args.selected],
17
- );
18
- return (
19
- <Chips
20
- {...args}
21
- selected={selected}
22
- multiple
23
- onChange={({ selectedValue, isEnabled }) => {
24
- if (isEnabled) {
25
- setSelected([...selected, selectedValue]);
26
- } else {
27
- const updatedSelected = selected.filter((value) => selectedValue !== value);
28
- setSelected(updatedSelected);
29
- }
30
- }}
31
- />
32
- );
33
- };
35
+ const categoryChips = [
36
+ { value: 'all', label: 'All' },
37
+ { value: 'accounting', label: 'Accounting' },
38
+ { value: 'payroll', label: 'Payroll' },
39
+ { value: 'reporting', label: 'Reporting' },
40
+ { value: 'payments', label: 'Payments' },
41
+ ];
34
42
 
35
- const ChoiceTemplate: Story = (args: ChipsProps) => {
36
- const [selected, setSelected] = useState<ChipValue>(args.selected as ChipValue);
37
- return (
38
- <Chips
39
- {...args}
40
- selected={selected}
41
- onChange={({ selectedValue }) => setSelected(selectedValue)}
42
- />
43
- );
44
- };
43
+ const amountChips = [
44
+ { value: 100, label: '100 GBP' },
45
+ { value: 200, label: '200 GBP' },
46
+ { value: 300, label: '300 GBP' },
47
+ { value: 500, label: '500 GBP+' },
48
+ ];
45
49
 
46
- export const FilterChips: typeof FilterTemplate = FilterTemplate.bind({});
47
- FilterChips.args = {
48
- chips: [
49
- {
50
- value: 'accounting',
51
- label: 'Accounting',
52
- },
53
- {
54
- value: 'payroll',
55
- label: 'Payroll',
56
- },
57
- {
58
- value: 'reporting',
59
- label: 'Reporting',
60
- },
61
- {
62
- value: 'payments',
63
- label: 'Payments',
64
- },
65
- ],
66
- };
50
+ /**
51
+ * Toggle `multiple` in the controls panel to switch between filter (multi-select)
52
+ * and choice (single-select) modes.
53
+ */
54
+ export const Playground: Story = storySourceWithoutNoise<typeof Chips>({
55
+ args: {
56
+ chips: categoryChips,
57
+ multiple: true,
58
+ },
59
+ render: function Render(args: ChipsProps) {
60
+ const [selectedMulti, setSelectedMulti] = useState<readonly ChipValue[]>(['accounting']);
61
+ const [selectedSingle, setSelectedSingle] = useState<ChipValue>('accounting');
67
62
 
68
- export const PreSelectedFilterChips: typeof FilterTemplate = FilterTemplate.bind({});
69
- PreSelectedFilterChips.args = {
70
- chips: [
71
- {
72
- value: 'accounting',
73
- label: 'Accounting',
74
- },
75
- {
76
- value: 'payroll',
77
- label: 'Payroll',
78
- },
79
- {
80
- value: 'reporting',
81
- label: 'Reporting',
82
- },
83
- {
84
- value: 'payments',
85
- label: 'Payments',
86
- },
87
- ],
88
- selected: ['accounting', 'payments'],
89
- };
63
+ if (args.multiple) {
64
+ return (
65
+ <Chips
66
+ chips={args.chips}
67
+ multiple
68
+ selected={selectedMulti}
69
+ aria-label={args['aria-label']}
70
+ onChange={({ selectedValue, isEnabled }) => {
71
+ setSelectedMulti((prev) =>
72
+ isEnabled ? [...prev, selectedValue] : prev.filter((v) => v !== selectedValue),
73
+ );
74
+ args.onChange({ selectedValue, isEnabled });
75
+ }}
76
+ />
77
+ );
78
+ }
90
79
 
91
- export const ChoiceChips: typeof ChoiceTemplate = ChoiceTemplate.bind({});
92
- ChoiceChips.args = {
93
- chips: [
94
- {
95
- value: 1,
96
- label: '100 GBP',
97
- },
98
- {
99
- value: 2,
100
- label: '200 GBP',
101
- },
102
- {
103
- value: 3,
104
- label: '300 GBP',
105
- },
106
- {
107
- value: 4,
108
- label: '400 GBP+',
109
- },
110
- ],
111
- selected: 3,
112
- };
80
+ return (
81
+ <Chips
82
+ chips={args.chips}
83
+ selected={selectedSingle}
84
+ aria-label={args['aria-label']}
85
+ onChange={({ selectedValue, isEnabled }) => {
86
+ setSelectedSingle(selectedValue);
87
+ args.onChange({ selectedValue, isEnabled });
88
+ }}
89
+ />
90
+ );
91
+ },
92
+ });
93
+
94
+ /**
95
+ * The user can select any number of chips with the selected prop as an array (`multiple` prop set to `true`). <br />
96
+ * <a href="https://wise.design/components/chip#filter-chips" target="_blank">Design documentation</a>
97
+ */
98
+ export const Filter: Story = storySourceWithoutNoise<typeof Chips>({
99
+ args: {
100
+ chips: categoryChips,
101
+ },
102
+ argTypes: {
103
+ multiple: { table: { disable: true } },
104
+ },
105
+ render: function Render(args: ChipsProps) {
106
+ const [selected, setSelected] = useState<readonly ChipValue[]>(['accounting', 'payments']);
107
+
108
+ return (
109
+ <Chips
110
+ chips={args.chips}
111
+ selected={selected}
112
+ multiple
113
+ aria-label="Category filter"
114
+ onChange={({ selectedValue, isEnabled }) => {
115
+ setSelected((prev) =>
116
+ isEnabled ? [...prev, selectedValue] : prev.filter((v) => v !== selectedValue),
117
+ );
118
+ args.onChange({ selectedValue, isEnabled });
119
+ }}
120
+ />
121
+ );
122
+ },
123
+ });
124
+
125
+ /**
126
+ * The user can only select one chip with the selected prop as a single value (`multiple` prop set to `false`). <br />
127
+ * <a href="https://wise.design/components/chip#choice-chips" target="_blank">Design documentation</a>
128
+ */
129
+ export const Choice: Story = storySourceWithoutNoise<typeof Chips>({
130
+ args: {
131
+ chips: amountChips,
132
+ },
133
+ argTypes: {
134
+ multiple: { table: { disable: true } },
135
+ },
136
+ render: function Render(args: ChipsProps) {
137
+ const [selected, setSelected] = useState<ChipValue>(300);
138
+
139
+ return (
140
+ <Chips
141
+ chips={args.chips}
142
+ selected={selected}
143
+ aria-label="Transfer amount"
144
+ onChange={({ selectedValue, isEnabled }) => {
145
+ setSelected(selectedValue);
146
+ args.onChange({ selectedValue, isEnabled });
147
+ }}
148
+ />
149
+ );
150
+ },
151
+ });