@transferwise/components 46.98.1 → 46.100.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/accordion/Accordion.js +4 -0
- package/build/accordion/Accordion.js.map +1 -1
- package/build/accordion/Accordion.mjs +4 -0
- package/build/accordion/Accordion.mjs.map +1 -1
- package/build/accordion/AccordionItem/AccordionItem.js +14 -5
- package/build/accordion/AccordionItem/AccordionItem.js.map +1 -1
- package/build/accordion/AccordionItem/AccordionItem.mjs +14 -5
- package/build/accordion/AccordionItem/AccordionItem.mjs.map +1 -1
- package/build/body/Body.js +2 -1
- package/build/body/Body.js.map +1 -1
- package/build/body/Body.mjs +2 -1
- package/build/body/Body.mjs.map +1 -1
- package/build/instructionsList/InstructionsList.js +1 -0
- package/build/instructionsList/InstructionsList.js.map +1 -1
- package/build/instructionsList/InstructionsList.mjs +1 -0
- package/build/instructionsList/InstructionsList.mjs.map +1 -1
- package/build/main.css +19 -16
- package/build/styles/accordion/Accordion.css +4 -1
- package/build/styles/body/Body.css +3 -0
- package/build/styles/main.css +19 -16
- package/build/styles/switch/Switch.css +22 -41
- package/build/styles/switchOption/SwitchOption.css +4 -0
- package/build/switch/Switch.js +7 -18
- package/build/switch/Switch.js.map +1 -1
- package/build/switch/Switch.mjs +8 -19
- package/build/switch/Switch.mjs.map +1 -1
- package/build/switchOption/SwitchOption.js +1 -0
- package/build/switchOption/SwitchOption.js.map +1 -1
- package/build/switchOption/SwitchOption.mjs +1 -0
- package/build/switchOption/SwitchOption.mjs.map +1 -1
- package/build/types/accordion/Accordion.d.ts +1 -1
- package/build/types/accordion/Accordion.d.ts.map +1 -1
- package/build/types/accordion/AccordionItem/AccordionItem.d.ts +12 -0
- package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/build/types/body/Body.d.ts +5 -0
- package/build/types/body/Body.d.ts.map +1 -1
- package/build/types/switch/Switch.d.ts.map +1 -1
- package/build/types/switchOption/SwitchOption.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/accordion/Accordion.css +4 -1
- package/src/accordion/Accordion.less +10 -5
- package/src/accordion/Accordion.story.tsx +30 -1
- package/src/accordion/Accordion.tsx +5 -4
- package/src/accordion/AccordionItem/AccordionItem.tsx +25 -4
- package/src/body/Body.css +3 -0
- package/src/body/Body.less +3 -0
- package/src/body/Body.spec.tsx +8 -0
- package/src/body/Body.story.tsx +12 -0
- package/src/body/Body.tsx +11 -2
- package/src/instructionsList/InstructionsList.story.tsx +35 -37
- package/src/instructionsList/InstructionsList.tsx +1 -1
- package/src/main.css +19 -16
- package/src/main.less +2 -0
- package/src/switch/Switch.css +22 -41
- package/src/switch/Switch.less +6 -12
- package/src/switch/Switch.spec.tsx +11 -9
- package/src/switch/Switch.story.tsx +158 -33
- package/src/switch/Switch.tsx +6 -15
- package/src/switchOption/SwitchOption.css +4 -0
- package/src/switchOption/SwitchOption.less +8 -0
- package/src/switchOption/SwitchOption.spec.tsx +4 -5
- package/src/switchOption/SwitchOption.story.tsx +42 -38
- package/src/switchOption/SwitchOption.tsx +1 -0
- package/src/switch/__snapshots__/Switch.spec.tsx.snap +0 -44
package/src/switch/Switch.tsx
CHANGED
|
@@ -34,18 +34,11 @@ const Switch = (props: SwitchProps) => {
|
|
|
34
34
|
disabled,
|
|
35
35
|
} = props;
|
|
36
36
|
|
|
37
|
-
const handleKeyDown: KeyboardEventHandler = (event) => {
|
|
38
|
-
if (event.key === ' ') {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
onClick();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
37
|
const ariaLabelledby =
|
|
45
38
|
(ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];
|
|
46
39
|
|
|
47
40
|
return (
|
|
48
|
-
<
|
|
41
|
+
<button
|
|
49
42
|
className={clsx(
|
|
50
43
|
'np-switch',
|
|
51
44
|
{
|
|
@@ -55,20 +48,18 @@ const Switch = (props: SwitchProps) => {
|
|
|
55
48
|
},
|
|
56
49
|
className,
|
|
57
50
|
)}
|
|
58
|
-
|
|
51
|
+
type="button"
|
|
59
52
|
role="switch"
|
|
53
|
+
{...inputAttributes}
|
|
54
|
+
id={id}
|
|
60
55
|
aria-checked={checked}
|
|
61
56
|
aria-label={ariaLabel}
|
|
62
|
-
{...inputAttributes}
|
|
63
57
|
aria-labelledby={ariaLabelledby}
|
|
64
|
-
|
|
65
|
-
aria-disabled={disabled}
|
|
58
|
+
disabled={disabled}
|
|
66
59
|
onClick={!disabled ? onClick : undefined}
|
|
67
|
-
onKeyDown={!disabled ? handleKeyDown : undefined}
|
|
68
60
|
>
|
|
69
61
|
<span className="np-switch--thumb" />
|
|
70
|
-
|
|
71
|
-
</span>
|
|
62
|
+
</button>
|
|
72
63
|
);
|
|
73
64
|
};
|
|
74
65
|
|
|
@@ -22,12 +22,12 @@ describe('SwitchOption', () => {
|
|
|
22
22
|
expect(screen.getByText('title')).toBeInTheDocument();
|
|
23
23
|
expect(screen.getByText('content')).toBeInTheDocument();
|
|
24
24
|
expect(screen.getByTestId('fast-flag')).toBeInTheDocument();
|
|
25
|
-
expect(screen.getAllByRole('
|
|
25
|
+
expect(screen.getAllByRole('switch')[0]).toBeInTheDocument();
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it('checks the switch when the user interacts with it', () => {
|
|
29
29
|
// Uses first in array to bypass the fact theres a hidden readonly input
|
|
30
|
-
const getSwitch = () => screen.getAllByRole('
|
|
30
|
+
const getSwitch = () => screen.getAllByRole('switch')[0];
|
|
31
31
|
|
|
32
32
|
const mockOnChange = jest.fn();
|
|
33
33
|
|
|
@@ -64,8 +64,7 @@ describe('SwitchOption', () => {
|
|
|
64
64
|
);
|
|
65
65
|
|
|
66
66
|
expect(getSwitch()).toBeChecked();
|
|
67
|
-
|
|
68
|
-
fireEvent.keyDown(getSwitch(), { key: ' ' });
|
|
67
|
+
fireEvent.click(getSwitch());
|
|
69
68
|
|
|
70
69
|
expect(mockOnChange).toHaveBeenLastCalledWith(false);
|
|
71
70
|
expect(mockOnChange).toHaveBeenCalledTimes(2);
|
|
@@ -107,7 +106,7 @@ describe('SwitchOption', () => {
|
|
|
107
106
|
|
|
108
107
|
expect(mockOnChange).toHaveBeenCalledTimes(2);
|
|
109
108
|
|
|
110
|
-
fireEvent.click(screen.getAllByRole('
|
|
109
|
+
fireEvent.click(screen.getAllByRole('switch')[0]);
|
|
111
110
|
|
|
112
111
|
expect(mockOnChange).toHaveBeenCalledTimes(3);
|
|
113
112
|
});
|
|
@@ -1,65 +1,69 @@
|
|
|
1
1
|
import { action } from '@storybook/addon-actions';
|
|
2
|
-
import { text, boolean } from '@storybook/addon-knobs';
|
|
3
2
|
import { FastFlag as FastFlagIcon } from '@transferwise/icons';
|
|
4
3
|
import { useState } from 'react';
|
|
5
4
|
|
|
6
5
|
import { Nudge, Title, Typography } from '..';
|
|
7
6
|
|
|
8
|
-
import SwitchOption from './SwitchOption';
|
|
7
|
+
import SwitchOption, { type SwitchOptionProps } from './SwitchOption';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
const meta = {
|
|
11
10
|
component: SwitchOption,
|
|
12
11
|
title: 'Option/SwitchOption',
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
argTypes: {
|
|
14
|
+
title: { control: 'text' },
|
|
15
|
+
content: { control: 'text' },
|
|
16
|
+
disabled: { control: 'boolean' },
|
|
17
|
+
showMediaAtAllSizes: { control: 'boolean' },
|
|
18
|
+
isContainerAligned: { control: 'boolean' },
|
|
19
|
+
checked: { control: 'boolean' },
|
|
20
|
+
},
|
|
21
|
+
args: {
|
|
22
|
+
title: 'Switch option',
|
|
23
|
+
content: 'Normally, the button and icon are vertically centered.',
|
|
24
|
+
disabled: false,
|
|
25
|
+
showMediaAtAllSizes: false,
|
|
26
|
+
isContainerAligned: false,
|
|
27
|
+
checked: false,
|
|
28
|
+
id: 'id',
|
|
29
|
+
complex: false,
|
|
30
|
+
'aria-label': 'Switch option',
|
|
31
|
+
},
|
|
13
32
|
};
|
|
33
|
+
export default meta;
|
|
14
34
|
|
|
15
|
-
|
|
16
|
-
const [checked, setChecked] = useState(
|
|
17
|
-
const title = text('title', 'Switch option');
|
|
18
|
-
const content = text('content', 'Normally, the button and icon are vertically centered.');
|
|
19
|
-
const disabled = boolean('disabled', false);
|
|
20
|
-
const showMediaAtAllSizes = boolean('showMediaAtAllSizes', false);
|
|
21
|
-
const isContainerAligned = boolean('isContainerAligned', false);
|
|
35
|
+
function Template(args: SwitchOptionProps) {
|
|
36
|
+
const [checked, setChecked] = useState(args.checked);
|
|
22
37
|
|
|
23
38
|
return (
|
|
24
|
-
<SwitchOption
|
|
25
|
-
media={<FastFlagIcon />}
|
|
26
|
-
title={title}
|
|
27
|
-
content={content}
|
|
28
|
-
id="id"
|
|
29
|
-
checked={checked}
|
|
30
|
-
complex={false}
|
|
31
|
-
disabled={disabled}
|
|
32
|
-
showMediaAtAllSizes={showMediaAtAllSizes}
|
|
33
|
-
isContainerAligned={isContainerAligned}
|
|
34
|
-
aria-label={title}
|
|
35
|
-
onChange={setChecked}
|
|
36
|
-
/>
|
|
39
|
+
<SwitchOption {...args} media={<FastFlagIcon />} checked={checked} onChange={setChecked} />
|
|
37
40
|
);
|
|
38
|
-
}
|
|
41
|
+
}
|
|
39
42
|
|
|
40
|
-
export const
|
|
41
|
-
|
|
43
|
+
export const Playground = {
|
|
44
|
+
render: (args: SwitchOptionProps) => <Template {...args} />,
|
|
45
|
+
tags: ['!autodocs'],
|
|
42
46
|
};
|
|
43
47
|
|
|
44
|
-
export const Multiple =
|
|
45
|
-
|
|
48
|
+
export const Multiple = {
|
|
49
|
+
render: (args: SwitchOptionProps) => (
|
|
46
50
|
<>
|
|
47
|
-
<Template />
|
|
48
|
-
<Template />
|
|
49
|
-
<Template />
|
|
51
|
+
<Template {...args} />
|
|
52
|
+
<Template {...args} />
|
|
53
|
+
<Template {...args} />
|
|
50
54
|
</>
|
|
51
|
-
)
|
|
55
|
+
),
|
|
52
56
|
};
|
|
53
57
|
|
|
54
|
-
export const WithContainerContent =
|
|
55
|
-
|
|
58
|
+
export const WithContainerContent = {
|
|
59
|
+
render: (args: SwitchOptionProps) => (
|
|
56
60
|
<>
|
|
57
61
|
<Title type={Typography.TITLE_SUBSECTION} className="m-b-1">
|
|
58
62
|
Choose how to pay
|
|
59
63
|
</Title>
|
|
60
|
-
<Template />
|
|
61
|
-
<Template />
|
|
62
|
-
<Template />
|
|
64
|
+
<Template {...args} />
|
|
65
|
+
<Template {...args} />
|
|
66
|
+
<Template {...args} />
|
|
63
67
|
<div>
|
|
64
68
|
<Nudge
|
|
65
69
|
className="m-t-2"
|
|
@@ -72,5 +76,5 @@ export const WithContainerContent = () => {
|
|
|
72
76
|
/>
|
|
73
77
|
</div>
|
|
74
78
|
</>
|
|
75
|
-
)
|
|
79
|
+
),
|
|
76
80
|
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Switch renders component when checked 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<span
|
|
6
|
-
aria-checked="true"
|
|
7
|
-
aria-label="a label"
|
|
8
|
-
class="np-switch np-switch--checked a-class-name"
|
|
9
|
-
id="id"
|
|
10
|
-
role="switch"
|
|
11
|
-
tabindex="0"
|
|
12
|
-
>
|
|
13
|
-
<span
|
|
14
|
-
class="np-switch--thumb"
|
|
15
|
-
/>
|
|
16
|
-
<input
|
|
17
|
-
checked=""
|
|
18
|
-
readonly=""
|
|
19
|
-
type="checkbox"
|
|
20
|
-
/>
|
|
21
|
-
</span>
|
|
22
|
-
</div>
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
exports[`Switch renders component when unchecked 1`] = `
|
|
26
|
-
<div>
|
|
27
|
-
<span
|
|
28
|
-
aria-checked="false"
|
|
29
|
-
aria-label="a label"
|
|
30
|
-
class="np-switch np-switch--unchecked a-class-name"
|
|
31
|
-
id="id"
|
|
32
|
-
role="switch"
|
|
33
|
-
tabindex="0"
|
|
34
|
-
>
|
|
35
|
-
<span
|
|
36
|
-
class="np-switch--thumb"
|
|
37
|
-
/>
|
|
38
|
-
<input
|
|
39
|
-
readonly=""
|
|
40
|
-
type="checkbox"
|
|
41
|
-
/>
|
|
42
|
-
</span>
|
|
43
|
-
</div>
|
|
44
|
-
`;
|