@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.
Files changed (78) 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 +47 -9
  12. package/build/moneyInput/MoneyInput.js +28 -12
  13. package/build/moneyInput/MoneyInput.js.map +1 -1
  14. package/build/moneyInput/MoneyInput.mjs +30 -14
  15. package/build/moneyInput/MoneyInput.mjs.map +1 -1
  16. package/build/moneyInput/currencyFormatting.js +8 -2
  17. package/build/moneyInput/currencyFormatting.js.map +1 -1
  18. package/build/moneyInput/currencyFormatting.mjs +5 -4
  19. package/build/moneyInput/currencyFormatting.mjs.map +1 -1
  20. package/build/statusIcon/StatusIcon.js +1 -12
  21. package/build/statusIcon/StatusIcon.js.map +1 -1
  22. package/build/statusIcon/StatusIcon.mjs +1 -12
  23. package/build/statusIcon/StatusIcon.mjs.map +1 -1
  24. package/build/styles/listItem/ListItem.css +4 -4
  25. package/build/styles/listItem/ListItem.grid.css +3 -3
  26. package/build/styles/main.css +47 -9
  27. package/build/styles/sentimentSurface/SentimentSurface.css +1 -1
  28. package/build/styles/statusIcon/StatusIcon.css +35 -4
  29. package/build/types/chips/Chips.d.ts +1 -1
  30. package/build/types/chips/Chips.d.ts.map +1 -1
  31. package/build/types/common/commonProps.d.ts +0 -6
  32. package/build/types/common/commonProps.d.ts.map +1 -1
  33. package/build/types/label/Label.d.ts.map +1 -1
  34. package/build/types/logo/Logo.d.ts +10 -1
  35. package/build/types/logo/Logo.d.ts.map +1 -1
  36. package/build/types/moneyInput/MoneyInput.d.ts +6 -0
  37. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  38. package/build/types/moneyInput/currencyFormatting.d.ts +4 -3
  39. package/build/types/moneyInput/currencyFormatting.d.ts.map +1 -1
  40. package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
  41. package/package.json +8 -8
  42. package/src/button/_stories/Button.story.tsx +15 -5
  43. package/src/checkboxButton/CheckboxButton.story.tsx +125 -44
  44. package/src/checkboxButton/CheckboxButton.test.story.tsx +236 -0
  45. package/src/chips/Chips.story.tsx +141 -102
  46. package/src/chips/Chips.test.story.tsx +177 -0
  47. package/src/chips/Chips.tsx +1 -1
  48. package/src/circularButton/CircularButton.story.tsx +261 -49
  49. package/src/circularButton/CircularButton.test.story.tsx +192 -2
  50. package/src/common/commonProps.ts +0 -6
  51. package/src/iconButton/IconButton.story.tsx +315 -110
  52. package/src/iconButton/IconButton.test.story.tsx +217 -44
  53. package/src/label/Label.tsx +1 -2
  54. package/src/listItem/ListItem.css +4 -4
  55. package/src/listItem/ListItem.grid.css +3 -3
  56. package/src/listItem/ListItem.grid.less +5 -3
  57. package/src/listItem/ListItem.less +1 -1
  58. package/src/listItem/ListItem.vars.less +2 -2
  59. package/src/listItem/_stories/ListItem.layout.test.story.tsx +55 -0
  60. package/src/logo/Logo.story.tsx +181 -21
  61. package/src/logo/Logo.test.story.tsx +40 -7
  62. package/src/logo/Logo.tsx +10 -1
  63. package/src/main.css +47 -9
  64. package/src/moneyInput/MoneyInput.story.tsx +10 -1
  65. package/src/moneyInput/MoneyInput.test.story.tsx +141 -1
  66. package/src/moneyInput/MoneyInput.test.tsx +45 -0
  67. package/src/moneyInput/MoneyInput.tsx +27 -3
  68. package/src/moneyInput/currencyFormatting.ts +11 -5
  69. package/src/sentimentSurface/SentimentSurface.css +1 -1
  70. package/src/sentimentSurface/SentimentSurface.less +1 -1
  71. package/src/statusIcon/StatusIcon.css +35 -4
  72. package/src/statusIcon/StatusIcon.less +35 -4
  73. package/src/statusIcon/StatusIcon.story.tsx +119 -79
  74. package/src/statusIcon/StatusIcon.test.story.tsx +125 -0
  75. package/src/statusIcon/StatusIcon.test.tsx +16 -23
  76. package/src/statusIcon/StatusIcon.tsx +2 -16
  77. package/src/switch/Switch.story.tsx +64 -42
  78. 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
- // eslint-disable-next-line react/no-unstable-nested-components
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={clsx('status-icon', iconColor)}
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': undefined,
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 Basic: Story = {
27
- tags: ['!autodocs', '!dev'],
28
- };
38
+ export const Playground: Story = storySourceWithoutNoise({
39
+ render: function Render(args: SwitchProps) {
40
+ const [checked, setChecked] = useState(args.checked ?? false);
29
41
 
30
- export const Playground: Story = {
31
- tags: ['!autodocs'],
32
- argTypes: {
33
- onClick: { table: { disable: true } },
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
- export const Interactivity: Story = {
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(false);
40
- const [checked2, setCheck2] = useState(true);
41
- const [checked3, setCheck3] = useState(false);
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">Using Label component</Label>
71
+ <Label htmlFor="labelId">Enable two-factor authentication</Label>
51
72
  <Switch
52
73
  id="labelId"
53
- checked={checked2}
74
+ checked={checked1}
54
75
  disabled={disabled}
55
- onClick={() => setCheck2(!checked2)}
76
+ onClick={() => setCheck1(!checked1)}
56
77
  />
57
78
  </div>
58
79
 
59
80
  <div>
60
81
  <strong id="ariaId" className="d-block">
61
- Using `aria-labelledby`
82
+ Marketing emails
62
83
  </strong>
63
84
  <Switch
64
85
  aria-labelledby="ariaId"
65
- checked={checked3}
86
+ checked={checked2}
66
87
  disabled={disabled}
67
- onClick={() => setCheck3(!checked3)}
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(args) {
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="Switch label">
157
+ <Field label="Disabled unchecked">
136
158
  <Switch checked={checked1} disabled onClick={() => setCheck1(!checked1)} />
137
159
  </Field>
138
160
 
139
- <Field label="Switch 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="Switch label">
177
+ <Field label="Disabled unchecked">
156
178
  <Switch
157
179
  checked={checked1}
158
180
  disabled
159
181
  onClick={() => setCheck1(!checked1)}
160
182
  />
161
- </Fie
162
- <Field label="Switch 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
+ };