@transferwise/components 46.133.0 → 46.134.0
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/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 +47 -9
- package/build/moneyInput/MoneyInput.js +28 -12
- package/build/moneyInput/MoneyInput.js.map +1 -1
- package/build/moneyInput/MoneyInput.mjs +30 -14
- package/build/moneyInput/MoneyInput.mjs.map +1 -1
- package/build/moneyInput/currencyFormatting.js +8 -2
- package/build/moneyInput/currencyFormatting.js.map +1 -1
- package/build/moneyInput/currencyFormatting.mjs +5 -4
- package/build/moneyInput/currencyFormatting.mjs.map +1 -1
- package/build/statusIcon/StatusIcon.js +1 -12
- package/build/statusIcon/StatusIcon.js.map +1 -1
- package/build/statusIcon/StatusIcon.mjs +1 -12
- package/build/statusIcon/StatusIcon.mjs.map +1 -1
- package/build/styles/listItem/ListItem.css +4 -4
- package/build/styles/listItem/ListItem.grid.css +3 -3
- package/build/styles/main.css +47 -9
- package/build/styles/sentimentSurface/SentimentSurface.css +1 -1
- package/build/styles/statusIcon/StatusIcon.css +35 -4
- 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/moneyInput/MoneyInput.d.ts +6 -0
- package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
- package/build/types/moneyInput/currencyFormatting.d.ts +4 -3
- package/build/types/moneyInput/currencyFormatting.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/button/_stories/Button.story.tsx +15 -5
- 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/commonProps.ts +0 -6
- package/src/iconButton/IconButton.story.tsx +315 -110
- package/src/iconButton/IconButton.test.story.tsx +217 -44
- package/src/label/Label.tsx +1 -2
- 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/_stories/ListItem.layout.test.story.tsx +55 -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 +47 -9
- package/src/moneyInput/MoneyInput.story.tsx +10 -1
- package/src/moneyInput/MoneyInput.test.story.tsx +141 -1
- package/src/moneyInput/MoneyInput.test.tsx +45 -0
- package/src/moneyInput/MoneyInput.tsx +27 -3
- package/src/moneyInput/currencyFormatting.ts +11 -5
- package/src/sentimentSurface/SentimentSurface.css +1 -1
- package/src/sentimentSurface/SentimentSurface.less +1 -1
- package/src/statusIcon/StatusIcon.css +35 -4
- package/src/statusIcon/StatusIcon.less +35 -4
- package/src/statusIcon/StatusIcon.story.tsx +119 -79
- package/src/statusIcon/StatusIcon.test.story.tsx +125 -0
- package/src/statusIcon/StatusIcon.test.tsx +16 -23
- package/src/statusIcon/StatusIcon.tsx +2 -16
- package/src/switch/Switch.story.tsx +64 -42
- package/src/switch/Switch.test.story.tsx +123 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Info, Alert, Cross, Check, ClockBorderless } from '@transferwise/icons';
|
|
2
2
|
import { clsx } from 'clsx';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
|
-
import { PropsWithChildren } from 'react';
|
|
5
4
|
|
|
6
|
-
import SentimentSurface from '../sentimentSurface';
|
|
7
5
|
import { SizeSmall, SizeMedium, SizeLarge, Sentiment, Size, Breakpoint, Status } from '../common';
|
|
8
6
|
import Circle, { CircleProps } from '../common/circle';
|
|
9
7
|
import { useMedia } from '../common/hooks/useMedia';
|
|
@@ -88,30 +86,18 @@ const StatusIcon = ({
|
|
|
88
86
|
};
|
|
89
87
|
const { Icon, defaultIconLabel } = iconMetaBySentiment[sentiment];
|
|
90
88
|
|
|
91
|
-
const iconColor = sentiment === 'warning' || sentiment === 'pending' ? 'dark' : 'light';
|
|
92
89
|
const isTinyViewport = useMedia(`(max-width: ${Breakpoint.ZOOM_400}px)`);
|
|
93
90
|
const size = mapLegacySize[sizeProp] ?? sizeProp;
|
|
94
|
-
|
|
95
|
-
const SentimentSurfaceSetting = (props: PropsWithChildren<Pick<CircleProps, 'className'>>) => (
|
|
96
|
-
<SentimentSurface
|
|
97
|
-
as="span"
|
|
98
|
-
// @ts-expect-error sentiment and SentimentSurface types mismatch
|
|
99
|
-
sentiment={
|
|
100
|
-
sentiment === 'positive' ? 'success' : sentiment === 'pending' ? 'warning' : sentiment
|
|
101
|
-
}
|
|
102
|
-
{...props}
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
91
|
+
|
|
105
92
|
return (
|
|
106
93
|
<Circle
|
|
107
|
-
as={SentimentSurfaceSetting}
|
|
108
94
|
size={isTinyViewport && size < 40 ? 32 : size}
|
|
109
95
|
data-testid="status-icon"
|
|
110
96
|
className={clsx('status-circle', sentiment)}
|
|
111
97
|
id={id}
|
|
112
98
|
>
|
|
113
99
|
<Icon
|
|
114
|
-
className=
|
|
100
|
+
className="status-icon"
|
|
115
101
|
title={iconLabel === null ? undefined : iconLabel || defaultIconLabel}
|
|
116
102
|
/>
|
|
117
103
|
</Circle>
|
|
@@ -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
|
+
};
|