@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
@@ -0,0 +1,177 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-webpack5';
2
+ import { userEvent } from 'storybook/test';
3
+ import { useState } from 'react';
4
+
5
+ import { withVariantConfig } from '../../.storybook/helpers';
6
+ import Chips, { type ChipValue } from './Chips';
7
+
8
+ export default {
9
+ component: Chips,
10
+ title: 'Actions/Chips/Tests',
11
+ tags: ['!autodocs', '!manifest'],
12
+ } satisfies Meta<typeof Chips>;
13
+
14
+ type Story = StoryObj<typeof Chips>;
15
+
16
+ const wait = async (ms: number) =>
17
+ new Promise<void>((resolve) => {
18
+ setTimeout(resolve, ms);
19
+ });
20
+
21
+ const filterChips = [
22
+ { value: 'all', label: 'All' },
23
+ { value: 'accounting', label: 'Accounting' },
24
+ { value: 'payroll', label: 'Payroll' },
25
+ { value: 'payments', label: 'Payments' },
26
+ ];
27
+
28
+ const choiceChips = [
29
+ { value: 100, label: '100 GBP' },
30
+ { value: 200, label: '200 GBP' },
31
+ { value: 300, label: '300 GBP' },
32
+ { value: 500, label: '500 GBP+' },
33
+ ];
34
+
35
+ /** Filter and choice chips across all themes. */
36
+ export const Variants: Story = {
37
+ render: function Render() {
38
+ const [filterSelected, setFilterSelected] = useState<readonly ChipValue[]>([
39
+ 'accounting',
40
+ 'payments',
41
+ ]);
42
+ const [choiceSelected, setChoiceSelected] = useState<ChipValue>(300);
43
+
44
+ return (
45
+ <div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
46
+ <Chips
47
+ chips={filterChips}
48
+ multiple
49
+ selected={filterSelected}
50
+ aria-label="Category filter"
51
+ onChange={({ selectedValue, isEnabled }) => {
52
+ setFilterSelected((prev) =>
53
+ isEnabled ? [...prev, selectedValue] : prev.filter((v) => v !== selectedValue),
54
+ );
55
+ }}
56
+ />
57
+ <Chips
58
+ chips={choiceChips}
59
+ selected={choiceSelected}
60
+ aria-label="Transfer amount"
61
+ onChange={({ selectedValue }) => setChoiceSelected(selectedValue)}
62
+ />
63
+ </div>
64
+ );
65
+ },
66
+ ...withVariantConfig(['default', 'dark', 'bright-green', 'forest-green']),
67
+ };
68
+
69
+ /**
70
+ * Tab moves between chips. Enter or Space toggles selection.
71
+ */
72
+ export const ChoiceKeyboardInteraction: Story = {
73
+ render: function Render() {
74
+ const [selected, setSelected] = useState<ChipValue>(300);
75
+ return (
76
+ <Chips
77
+ chips={choiceChips}
78
+ selected={selected}
79
+ aria-label="Transfer amount"
80
+ onChange={({ selectedValue }) => setSelected(selectedValue)}
81
+ />
82
+ );
83
+ },
84
+ play: async () => {
85
+ await userEvent.tab();
86
+ await wait(400);
87
+ await userEvent.tab();
88
+ await wait(400);
89
+ await userEvent.keyboard('{Enter}');
90
+ },
91
+ };
92
+
93
+ /**
94
+ * Tab moves between chips. Enter or Space toggles selection.
95
+ */
96
+ export const FilterKeyboardInteraction: Story = {
97
+ render: function Render() {
98
+ const [selected, setSelected] = useState<readonly ChipValue[]>(['accounting']);
99
+ return (
100
+ <Chips
101
+ chips={filterChips}
102
+ multiple
103
+ selected={selected}
104
+ aria-label="Category filter"
105
+ onChange={({ selectedValue, isEnabled }) => {
106
+ setSelected((prev) =>
107
+ isEnabled ? [...prev, selectedValue] : prev.filter((v) => v !== selectedValue),
108
+ );
109
+ }}
110
+ />
111
+ );
112
+ },
113
+ play: async () => {
114
+ await userEvent.tab();
115
+ await wait(400);
116
+ await userEvent.tab();
117
+ await wait(400);
118
+ await userEvent.tab();
119
+ await wait(400);
120
+ await userEvent.keyboard('{Enter}');
121
+ },
122
+ };
123
+
124
+ /** Filter and choice chips in right-to-left layout. */
125
+ export const RTL: Story = {
126
+ render: function Render() {
127
+ const [filterSelected, setFilterSelected] = useState<readonly ChipValue[]>([
128
+ 'accounting',
129
+ 'payments',
130
+ ]);
131
+ const [choiceSelected, setChoiceSelected] = useState<ChipValue>(300);
132
+
133
+ return (
134
+ <div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
135
+ <Chips
136
+ chips={filterChips}
137
+ multiple
138
+ selected={filterSelected}
139
+ aria-label="Category filter"
140
+ onChange={({ selectedValue, isEnabled }) => {
141
+ setFilterSelected((prev) =>
142
+ isEnabled ? [...prev, selectedValue] : prev.filter((v) => v !== selectedValue),
143
+ );
144
+ }}
145
+ />
146
+ <Chips
147
+ chips={choiceChips}
148
+ selected={choiceSelected}
149
+ aria-label="Transfer amount"
150
+ onChange={({ selectedValue }) => setChoiceSelected(selectedValue)}
151
+ />
152
+ </div>
153
+ );
154
+ },
155
+ ...withVariantConfig(['rtl']),
156
+ };
157
+
158
+ /** Filter chips at 400% zoom for accessibility testing. */
159
+ export const Zoom400: Story = {
160
+ render: function Render() {
161
+ const [selected, setSelected] = useState<readonly ChipValue[]>(['accounting']);
162
+ return (
163
+ <Chips
164
+ chips={filterChips}
165
+ multiple
166
+ selected={selected}
167
+ aria-label="Category filter"
168
+ onChange={({ selectedValue, isEnabled }) => {
169
+ setSelected((prev) =>
170
+ isEnabled ? [...prev, selectedValue] : prev.filter((v) => v !== selectedValue),
171
+ );
172
+ }}
173
+ />
174
+ );
175
+ },
176
+ ...withVariantConfig(['400%']),
177
+ };
@@ -27,7 +27,7 @@ export type ChipsProps = CommonProps &
27
27
  }) => void;
28
28
  /** Used to manage which chips are selected */
29
29
  selected: ChipValue | readonly ChipValue[];
30
- /** Used to activate multi-selection */
30
+ /** True turns on Filter-mode, False is Choice */
31
31
  multiple?: boolean;
32
32
  };
33
33
 
@@ -1,18 +1,26 @@
1
1
  import * as Icons from '@transferwise/icons';
2
2
 
3
- import { ControlType, Priority } from '../common';
4
-
5
3
  import { Meta, StoryObj } from '@storybook/react-webpack5';
6
- import CircularButton from './CircularButton';
4
+ import { fn } from 'storybook/test';
5
+ import CircularButton, { CircularButtonProps } from './CircularButton';
7
6
  import Title from '../title';
8
- import Body from '../body';
7
+ import SentimentSurface from '../sentimentSurface';
9
8
 
9
+ /**
10
+ * An <a href="?path=/docs/actions-iconbutton--docs">IconButton</a> with a text label below it.
11
+ *
12
+ * **Design guidance**: <a href="https://wise.design/components/circular-button" target="_blank">wise.design/components/circular-button</a>
13
+ */
10
14
  export default {
11
15
  component: CircularButton,
12
16
  title: 'Actions/CircularButton',
13
17
  args: {
14
18
  children: 'Button text',
15
19
  icon: <Icons.Freeze />,
20
+ onClick: fn(),
21
+ priority: 'primary',
22
+ type: 'default',
23
+ disabled: false,
16
24
  },
17
25
  argTypes: {
18
26
  icon: {
@@ -21,66 +29,270 @@ export default {
21
29
  Object.entries(Icons).map(([name, Icon]) => [name, <Icon key={name} />]),
22
30
  ),
23
31
  },
32
+ className: { table: { category: 'Common' } },
33
+ onClick: { table: { category: 'Common', type: { summary: 'function' } } },
34
+ },
35
+ parameters: {
36
+ docs: { toc: true },
24
37
  },
25
38
  } satisfies Meta<typeof CircularButton>;
26
39
 
27
40
  type Story = StoryObj<typeof CircularButton>;
28
41
 
29
- export const Basic: Story = {
42
+ /** Explore all props via the controls panel. */
43
+ export const Playground: Story = {};
44
+
45
+ /**
46
+ * Priorities set a visual hierarchy amongst the buttons displayed on the
47
+ * screen to help more important buttons to take precedence over others. <br />
48
+ * [Design documentation](https://wise.design/components/circular-button#priority)
49
+ */
50
+ export const Priority: Story = {
30
51
  args: {
31
- priority: 'primary',
32
52
  type: 'default',
33
- disabled: false,
34
53
  },
54
+ argTypes: {
55
+ type: {
56
+ control: 'radio',
57
+ options: ['default', 'negative'],
58
+ },
59
+ priority: { table: { disable: true } },
60
+ disabled: { table: { disable: true } },
61
+ icon: { table: { disable: true } },
62
+ children: { table: { disable: true } },
63
+ onClick: { table: { disable: true } },
64
+ },
65
+ decorators: [
66
+ (Story) => (
67
+ <div style={{ display: 'flex', gap: '24px' }}>
68
+ <Story />
69
+ </div>
70
+ ),
71
+ ],
72
+ render: (args: CircularButtonProps) => (
73
+ <>
74
+ <CircularButton priority="primary" type={args.type} icon={<Icons.Send />} onClick={fn()}>
75
+ Primary
76
+ </CircularButton>
77
+ <CircularButton priority="secondary" type={args.type} icon={<Icons.Plus />} onClick={fn()}>
78
+ Secondary
79
+ </CircularButton>
80
+ </>
81
+ ),
35
82
  };
36
83
 
37
- export const All: Story = {
84
+ /**
85
+ * There are two different types of button – default and negative – designed to emphasise the nature of the action. <br />
86
+ * [Design documentation](https://wise.design/components/circular-button#types)
87
+ */
88
+ export const Type: Story = {
38
89
  args: {
39
- className: 'm-r-2',
90
+ priority: 'primary',
40
91
  },
41
- render: (props) => {
42
- return (
43
- <>
44
- <Title type="title-subsection" className="m-y-2">
45
- Default (Primary and secondary)
46
- </Title>
47
- <Body>
48
- <CircularButton {...props} priority="primary" type="default" />
49
- <CircularButton {...props} priority="secondary" type="default" />
50
- <CircularButton {...props} priority="primary" type="default" disabled />
51
- <CircularButton {...props} priority="secondary" type="default" disabled />
52
- </Body>
92
+ argTypes: {
93
+ priority: {
94
+ control: 'radio',
95
+ options: ['primary', 'secondary'],
96
+ },
97
+ type: { table: { disable: true } },
98
+ disabled: { table: { disable: true } },
99
+ icon: { table: { disable: true } },
100
+ children: { table: { disable: true } },
101
+ onClick: { table: { disable: true } },
102
+ },
103
+ decorators: [
104
+ (Story) => (
105
+ <div style={{ display: 'flex', gap: '24px' }}>
106
+ <Story />
107
+ </div>
108
+ ),
109
+ ],
110
+ render: (args: CircularButtonProps) => (
111
+ <>
112
+ <CircularButton priority={args.priority} type="default" icon={<Icons.Send />} onClick={fn()}>
113
+ Default
114
+ </CircularButton>
115
+ <CircularButton
116
+ priority={args.priority}
117
+ type="negative"
118
+ icon={<Icons.Cross />}
119
+ onClick={fn()}
120
+ >
121
+ Negative
122
+ </CircularButton>
123
+ </>
124
+ ),
125
+ };
53
126
 
54
- <Title type="title-subsection" className="m-y-2">
55
- Negative (Primary and secondary)
56
- </Title>
57
- <Body>
58
- <CircularButton {...props} priority="primary" type="negative" />
59
- <CircularButton {...props} priority="secondary" type="negative" />
60
- <CircularButton {...props} priority="primary" type="negative" disabled />
61
- <CircularButton {...props} priority="secondary" type="negative" disabled />
62
- </Body>
127
+ /**
128
+ * Disabled buttons cannot be interacted with and are visually distinct.
129
+ */
130
+ export const Disabled: Story = {
131
+ args: {
132
+ priority: 'primary',
133
+ type: 'default',
134
+ },
135
+ argTypes: {
136
+ priority: {
137
+ control: 'radio',
138
+ options: ['primary', 'secondary'],
139
+ },
140
+ type: {
141
+ control: 'radio',
142
+ options: ['default', 'negative'],
143
+ },
144
+ disabled: { table: { disable: true } },
145
+ icon: { table: { disable: true } },
146
+ children: { table: { disable: true } },
147
+ onClick: { table: { disable: true } },
148
+ },
149
+ decorators: [
150
+ (Story) => (
151
+ <div style={{ display: 'flex', justifyContent: 'center' }}>
152
+ <Story />
153
+ </div>
154
+ ),
155
+ ],
156
+ render: (args: CircularButtonProps) => (
157
+ <CircularButton disabled priority={args.priority} type={args.type} icon={<Icons.Card />}>
158
+ Disabled
159
+ </CircularButton>
160
+ ),
161
+ };
63
162
 
64
- <Title type="title-body" className="m-y-2">
65
- Accent (Deprecated)
66
- </Title>
67
- <Body>
68
- <CircularButton {...props} priority="primary" type="accent" />
69
- <CircularButton {...props} priority="secondary" type="accent" />
70
- <CircularButton {...props} priority="primary" type="accent" disabled />
71
- <CircularButton {...props} priority="secondary" type="accent" disabled />
72
- </Body>
163
+ /**
164
+ * `CircularButton` is sentiment-aware and will automatically adjust its colours if wrapped inside
165
+ * the <a href="?path=/docs/foundations-sentimentsurface--docs">SentimentSurface</a> component. <br />
166
+ * [Design documentation](https://wise.design/components/circular-button)
167
+ */
168
+ export const SentimentAwareness: Story = {
169
+ render: () => {
170
+ const buttons = [
171
+ {
172
+ priority: 'primary',
173
+ type: 'default',
174
+ icon: <Icons.Send />,
175
+ label: 'primary',
176
+ disabled: false,
177
+ },
178
+ {
179
+ priority: 'secondary',
180
+ type: 'default',
181
+ icon: <Icons.Plus />,
182
+ label: 'secondary',
183
+ disabled: false,
184
+ },
185
+ {
186
+ priority: 'primary',
187
+ type: 'negative',
188
+ icon: <Icons.Cross />,
189
+ label: 'neg primary',
190
+ disabled: false,
191
+ },
192
+ {
193
+ priority: 'secondary',
194
+ type: 'negative',
195
+ icon: <Icons.Edit />,
196
+ label: 'neg secondary',
197
+ disabled: false,
198
+ },
199
+ {
200
+ priority: 'primary',
201
+ type: 'default',
202
+ icon: <Icons.Card />,
203
+ label: 'disabled',
204
+ disabled: true,
205
+ },
206
+ ] as const;
207
+ const sentiments = ['success', 'warning', 'negative', 'neutral', 'proposition'] as const;
73
208
 
74
- <Title type="title-body" className="m-y-2">
75
- Positive (Deprecated)
76
- </Title>
77
- <Body>
78
- <CircularButton {...props} priority="primary" type="positive" />
79
- <CircularButton {...props} priority="secondary" type="positive" />
80
- <CircularButton {...props} priority="primary" type="positive" disabled />
81
- <CircularButton {...props} priority="secondary" type="positive" disabled />
82
- </Body>
83
- </>
209
+ return (
210
+ <div style={{ display: 'flex', flexDirection: 'column' }}>
211
+ {/* Rows for each sentiment with base and elevated emphasis */}
212
+ {sentiments.flatMap((sentiment) => [
213
+ <SentimentSurface
214
+ key={`${sentiment}-base`}
215
+ sentiment={sentiment}
216
+ emphasis="base"
217
+ style={{ display: 'flex', alignItems: 'center', padding: '8px 0', gap: '8px' }}
218
+ >
219
+ <div
220
+ style={{
221
+ width: '120px',
222
+ fontSize: '11px',
223
+ fontWeight: 'bold',
224
+ textAlign: 'left',
225
+ paddingLeft: '8px',
226
+ }}
227
+ >
228
+ {sentiment} (base)
229
+ </div>
230
+ {buttons.map((button) => (
231
+ <div
232
+ key={button.label}
233
+ style={{
234
+ width: '100px',
235
+ display: 'flex',
236
+ justifyContent: 'center',
237
+ }}
238
+ >
239
+ <CircularButton
240
+ priority={button.priority}
241
+ type={button.type}
242
+ icon={button.icon}
243
+ disabled={button.disabled}
244
+ onClick={fn()}
245
+ >
246
+ {button.label}
247
+ </CircularButton>
248
+ </div>
249
+ ))}
250
+ </SentimentSurface>,
251
+ <SentimentSurface
252
+ key={`${sentiment}-elevated`}
253
+ sentiment={sentiment}
254
+ emphasis="elevated"
255
+ style={{ display: 'flex', alignItems: 'center', padding: '8px 0', gap: '8px' }}
256
+ >
257
+ <div
258
+ style={{
259
+ width: '120px',
260
+ fontSize: '11px',
261
+ fontWeight: 'bold',
262
+ textAlign: 'left',
263
+ paddingLeft: '8px',
264
+ }}
265
+ >
266
+ {sentiment} (elevated)
267
+ </div>
268
+ {buttons.map((button) => (
269
+ <div
270
+ key={button.label}
271
+ style={{
272
+ width: '100px',
273
+ display: 'flex',
274
+ justifyContent: 'center',
275
+ }}
276
+ >
277
+ <CircularButton
278
+ priority={button.priority}
279
+ type={button.type}
280
+ icon={button.icon}
281
+ disabled={button.disabled}
282
+ onClick={fn()}
283
+ >
284
+ {button.label}
285
+ </CircularButton>
286
+ </div>
287
+ ))}
288
+ </SentimentSurface>,
289
+ ])}
290
+ </div>
84
291
  );
85
292
  },
293
+ parameters: {
294
+ docs: {
295
+ canvas: { sourceState: 'hidden' },
296
+ },
297
+ },
86
298
  };