@transferwise/components 0.0.0-experimental-e295338 → 0.0.0-experimental-424b5be
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/avatarLayout/AvatarLayout.js +9 -2
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +9 -2
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/button/Button/src/Button.js +91 -0
- package/build/button/Button/src/Button.js.map +1 -0
- package/build/button/Button/src/Button.mjs +89 -0
- package/build/button/Button/src/Button.mjs.map +1 -0
- package/build/button/{Button.js → LegacyButton/Button.js} +25 -24
- package/build/button/LegacyButton/Button.js.map +1 -0
- package/build/button/{Button.mjs → LegacyButton/Button.mjs} +25 -24
- package/build/button/LegacyButton/Button.mjs.map +1 -0
- package/build/button/LegacyButton/classMap.js +42 -0
- package/build/button/LegacyButton/classMap.js.map +1 -0
- package/build/button/LegacyButton/classMap.mjs +39 -0
- package/build/button/LegacyButton/classMap.mjs.map +1 -0
- package/build/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.js +21 -21
- package/build/button/LegacyButton/legacyUtils/legacyUtils.js.map +1 -0
- package/build/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.mjs +21 -21
- package/build/button/LegacyButton/legacyUtils/legacyUtils.mjs.map +1 -0
- package/build/button/src/Button.js +66 -0
- package/build/button/src/Button.js.map +1 -0
- package/build/button/src/Button.mjs +64 -0
- package/build/button/src/Button.mjs.map +1 -0
- package/build/chips/Chips.js +1 -4
- package/build/chips/Chips.js.map +1 -1
- package/build/chips/Chips.mjs +1 -4
- package/build/chips/Chips.mjs.map +1 -1
- package/build/circularButton/CircularButton.js +1 -1
- package/build/circularButton/CircularButton.js.map +1 -1
- package/build/circularButton/CircularButton.mjs +1 -1
- package/build/circularButton/CircularButton.mjs.map +1 -1
- package/build/common/action/Action.js +1 -1
- package/build/common/action/Action.js.map +1 -1
- package/build/common/action/Action.mjs +1 -1
- package/build/common/action/Action.mjs.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.js +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
- package/build/header/Header.js +1 -1
- package/build/header/Header.mjs +1 -1
- package/build/index.js +1 -1
- package/build/index.mjs +1 -1
- package/build/link/Link.js +8 -3
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +8 -3
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +288 -29
- package/build/nudge/Nudge.js +1 -1
- package/build/nudge/Nudge.js.map +1 -1
- package/build/nudge/Nudge.mjs +1 -1
- package/build/nudge/Nudge.mjs.map +1 -1
- package/build/select/Select.js +1 -1
- package/build/select/Select.mjs +1 -1
- package/build/styles/avatarLayout/AvatarLayout.css +11 -0
- package/build/styles/button/Button/less/Button.css +253 -0
- package/build/styles/button/Button/less/Button.vars.css +57 -0
- package/build/styles/iconButton/IconButton.css +24 -29
- package/build/styles/main.css +288 -29
- package/build/types/avatarLayout/AvatarLayout.d.ts +1 -2
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/avatarLayout/index.d.ts +1 -0
- package/build/types/avatarLayout/index.d.ts.map +1 -1
- package/build/types/button/Button/index.d.ts +3 -0
- package/build/types/button/Button/index.d.ts.map +1 -0
- package/build/types/button/Button/src/Button.d.ts +4 -0
- package/build/types/button/Button/src/Button.d.ts.map +1 -0
- package/build/types/button/Button/src/Button.types.d.ts +49 -0
- package/build/types/button/Button/src/Button.types.d.ts.map +1 -0
- package/build/types/button/Button/src/index.d.ts +2 -0
- package/build/types/button/Button/src/index.d.ts.map +1 -0
- package/build/types/button/{Button.d.ts → LegacyButton/Button.d.ts} +7 -5
- package/build/types/button/LegacyButton/Button.d.ts.map +1 -0
- package/build/types/button/LegacyButton/classMap.d.ts.map +1 -0
- package/build/types/button/LegacyButton/index.d.ts +3 -0
- package/build/types/button/LegacyButton/index.d.ts.map +1 -0
- package/build/types/button/LegacyButton/legacyUtils/index.d.ts.map +1 -0
- package/build/types/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.d.ts +1 -1
- package/build/types/button/LegacyButton/legacyUtils/legacyUtils.d.ts.map +1 -0
- package/build/types/button/index.d.ts +2 -2
- package/build/types/button/index.d.ts.map +1 -1
- package/build/types/button/src/Button.d.ts +39 -0
- package/build/types/button/src/Button.d.ts.map +1 -0
- package/build/types/button/src/index.d.ts +3 -0
- package/build/types/button/src/index.d.ts.map +1 -0
- package/build/types/chips/Chips.d.ts +0 -1
- package/build/types/chips/Chips.d.ts.map +1 -1
- package/build/types/link/Link.d.ts +2 -2
- package/build/types/link/Link.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/upload/steps/completeStep/completeStep.js +1 -1
- package/build/upload/steps/completeStep/completeStep.mjs +1 -1
- package/build/upload/steps/processingStep/processingStep.js +1 -1
- package/build/upload/steps/processingStep/processingStep.mjs +1 -1
- package/build/uploadInput/UploadInput.js +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/package.json +3 -3
- package/src/avatarLayout/AvatarLayout.css +11 -0
- package/src/avatarLayout/AvatarLayout.less +18 -1
- package/src/avatarLayout/AvatarLayout.tsx +11 -3
- package/src/avatarLayout/index.ts +1 -0
- package/src/avatarWrapper/AvatarWrapper.story.tsx +2 -0
- package/src/button/Button/index.ts +2 -0
- package/src/button/Button/less/Button.css +253 -0
- package/src/button/Button/less/Button.less +221 -0
- package/src/button/Button/less/Button.vars.css +57 -0
- package/src/button/Button/less/Button.vars.less +65 -0
- package/src/button/Button/src/Button.tsx +114 -0
- package/src/button/Button/src/Button.types.ts +68 -0
- package/src/button/Button/src/index.ts +1 -0
- package/src/button/Button/stories/Button.story.tsx +314 -0
- package/src/button/Button/stories/Button.tests.story.tsx +288 -0
- package/src/button/Button/test/Button.spec.tsx +328 -0
- package/src/button/{Button.less → LegacyButton/Button.less} +1 -1
- package/src/button/{Button.spec.tsx → LegacyButton/Button.spec.tsx} +3 -3
- package/src/button/LegacyButton/Button.story.tsx +224 -0
- package/src/button/{Button.tsx → LegacyButton/Button.tsx} +13 -9
- package/src/button/{classMap.ts → LegacyButton/classMap.ts} +1 -1
- package/src/button/LegacyButton/index.ts +3 -0
- package/src/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.spec.tsx +2 -2
- package/src/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.ts +2 -2
- package/src/button/index.ts +2 -3
- package/src/button/src/Button.tsx +64 -0
- package/src/button/src/index.ts +2 -0
- package/src/button/test/Button.spec.tsx +32 -0
- package/src/chips/Chips.spec.tsx +0 -8
- package/src/chips/Chips.tsx +1 -5
- package/src/circularButton/CircularButton.tsx +1 -1
- package/src/common/action/Action.tsx +1 -1
- package/src/iconButton/IconButton.css +24 -29
- package/src/iconButton/IconButton.less +4 -4
- package/src/link/Link.tsx +15 -6
- package/src/main.css +288 -29
- package/src/main.less +2 -1
- package/src/nudge/Nudge.tsx +1 -1
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.story.tsx +1 -1
- package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -1
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.story.tsx +1 -1
- package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +2 -3
- package/src/test-utils/index.tsx +0 -1
- package/build/button/Button.js.map +0 -1
- package/build/button/Button.mjs.map +0 -1
- package/build/button/classMap.js +0 -42
- package/build/button/classMap.js.map +0 -1
- package/build/button/classMap.mjs +0 -39
- package/build/button/classMap.mjs.map +0 -1
- package/build/button/legacyUtils/legacyUtils.js.map +0 -1
- package/build/button/legacyUtils/legacyUtils.mjs.map +0 -1
- package/build/types/button/Button.d.ts.map +0 -1
- package/build/types/button/classMap.d.ts.map +0 -1
- package/build/types/button/legacyUtils/index.d.ts.map +0 -1
- package/build/types/button/legacyUtils/legacyUtils.d.ts.map +0 -1
- package/src/button/Button.story.tsx +0 -163
- /package/build/styles/button/{Button.css → LegacyButton/Button.css} +0 -0
- /package/build/types/button/{classMap.d.ts → LegacyButton/classMap.d.ts} +0 -0
- /package/build/types/button/{legacyUtils → LegacyButton/legacyUtils}/index.d.ts +0 -0
- /package/src/button/{Button.css → LegacyButton/Button.css} +0 -0
- /package/src/button/{__snapshots__ → LegacyButton/__snapshots__}/Button.spec.tsx.snap +0 -0
- /package/src/button/{legacyUtils → LegacyButton/legacyUtils}/index.ts +0 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
3
|
+
import Button from '../../src';
|
|
4
|
+
import { Freeze, ArrowRight } from '@transferwise/icons';
|
|
5
|
+
|
|
6
|
+
const withContainer = (Story: any) => (
|
|
7
|
+
<div style={{ display: 'flex', flexDirection: 'initial', justifyContent: 'center' }}>
|
|
8
|
+
<Story />
|
|
9
|
+
</div>
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const meta: Meta<typeof Button> = {
|
|
13
|
+
component: Button,
|
|
14
|
+
title: 'Actions/Button',
|
|
15
|
+
argTypes: {
|
|
16
|
+
as: {
|
|
17
|
+
type: {
|
|
18
|
+
name: 'enum',
|
|
19
|
+
value: ['button', 'a'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
size: {
|
|
23
|
+
type: {
|
|
24
|
+
name: 'enum',
|
|
25
|
+
value: ['sm', 'md', 'lg'],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
href: {
|
|
29
|
+
type: {
|
|
30
|
+
name: 'string',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
priority: {
|
|
34
|
+
type: {
|
|
35
|
+
name: 'enum',
|
|
36
|
+
value: ['primary', 'secondary', 'tertiary', 'minimal'],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
appearance: {
|
|
40
|
+
type: {
|
|
41
|
+
name: 'enum',
|
|
42
|
+
value: ['default', 'negative'],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
iconLeft: {
|
|
46
|
+
control: 'object',
|
|
47
|
+
},
|
|
48
|
+
iconRight: {
|
|
49
|
+
control: 'object',
|
|
50
|
+
},
|
|
51
|
+
avatars: {
|
|
52
|
+
control: 'object',
|
|
53
|
+
},
|
|
54
|
+
htmlType: {
|
|
55
|
+
table: {
|
|
56
|
+
disable: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
'data-testid': {
|
|
60
|
+
table: {
|
|
61
|
+
disable: true,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
args: {
|
|
66
|
+
children: 'Button text',
|
|
67
|
+
as: 'button',
|
|
68
|
+
href: undefined,
|
|
69
|
+
disabled: false,
|
|
70
|
+
loading: false,
|
|
71
|
+
size: 'md',
|
|
72
|
+
iconLeft: undefined,
|
|
73
|
+
iconRight: undefined,
|
|
74
|
+
priority: 'primary',
|
|
75
|
+
appearance: 'default',
|
|
76
|
+
avatars: undefined,
|
|
77
|
+
useNewButton: true,
|
|
78
|
+
onClick: fn(),
|
|
79
|
+
onBlur: fn(),
|
|
80
|
+
onFocus: fn(),
|
|
81
|
+
onKeyDown: fn(),
|
|
82
|
+
onMouseEnter: fn(),
|
|
83
|
+
onMouseLeave: fn(),
|
|
84
|
+
},
|
|
85
|
+
tags: ['autodocs'],
|
|
86
|
+
decorators: [withContainer],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default meta;
|
|
90
|
+
|
|
91
|
+
type Story = StoryObj<typeof Button>;
|
|
92
|
+
|
|
93
|
+
export const Basic: Story = {
|
|
94
|
+
parameters: {
|
|
95
|
+
docs: {
|
|
96
|
+
description: {
|
|
97
|
+
story: 'A basic example of the Button component.',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const Secondary: Story = {
|
|
104
|
+
args: {
|
|
105
|
+
priority: 'secondary',
|
|
106
|
+
},
|
|
107
|
+
parameters: {
|
|
108
|
+
docs: {
|
|
109
|
+
description: {
|
|
110
|
+
story: 'A Button with secondary priority.',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const Tertiary: Story = {
|
|
117
|
+
args: {
|
|
118
|
+
priority: 'tertiary',
|
|
119
|
+
},
|
|
120
|
+
parameters: {
|
|
121
|
+
docs: {
|
|
122
|
+
description: {
|
|
123
|
+
story: 'A Button with tertiary priority.',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const Minimal: Story = {
|
|
130
|
+
args: {
|
|
131
|
+
priority: 'minimal',
|
|
132
|
+
},
|
|
133
|
+
parameters: {
|
|
134
|
+
docs: {
|
|
135
|
+
description: {
|
|
136
|
+
story: 'A Button with minimal priority.',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const Negative: Story = {
|
|
143
|
+
args: {
|
|
144
|
+
appearance: 'negative',
|
|
145
|
+
},
|
|
146
|
+
parameters: {
|
|
147
|
+
docs: {
|
|
148
|
+
description: {
|
|
149
|
+
story: 'A Button with negative appearance.',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const NegativeSecondary: Story = {
|
|
156
|
+
args: {
|
|
157
|
+
appearance: 'negative',
|
|
158
|
+
priority: 'secondary',
|
|
159
|
+
},
|
|
160
|
+
parameters: {
|
|
161
|
+
docs: {
|
|
162
|
+
description: {
|
|
163
|
+
story: 'A Button with negative appearance and secondary priority.',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const AsAnchor: Story = {
|
|
170
|
+
args: {
|
|
171
|
+
as: 'a',
|
|
172
|
+
href: 'https://wise.com',
|
|
173
|
+
},
|
|
174
|
+
parameters: {
|
|
175
|
+
docs: {
|
|
176
|
+
description: {
|
|
177
|
+
story: 'A Button rendered as an anchor element.',
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const Disabled: Story = {
|
|
184
|
+
args: {
|
|
185
|
+
disabled: true,
|
|
186
|
+
},
|
|
187
|
+
parameters: {
|
|
188
|
+
docs: {
|
|
189
|
+
description: {
|
|
190
|
+
story: 'A disabled Button.',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const Loading: Story = {
|
|
197
|
+
args: {
|
|
198
|
+
loading: true,
|
|
199
|
+
},
|
|
200
|
+
parameters: {
|
|
201
|
+
docs: {
|
|
202
|
+
description: {
|
|
203
|
+
story: 'A Button in a loading state.',
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export const SizeSmall: Story = {
|
|
210
|
+
args: {
|
|
211
|
+
size: 'sm',
|
|
212
|
+
},
|
|
213
|
+
parameters: {
|
|
214
|
+
docs: {
|
|
215
|
+
description: {
|
|
216
|
+
story: 'A small Button.',
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export const SizeLarge: Story = {
|
|
223
|
+
args: {
|
|
224
|
+
size: 'lg',
|
|
225
|
+
},
|
|
226
|
+
parameters: {
|
|
227
|
+
docs: {
|
|
228
|
+
description: {
|
|
229
|
+
story: 'A large Button.',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const DisplayBlock: Story = {
|
|
236
|
+
args: {
|
|
237
|
+
block: true,
|
|
238
|
+
},
|
|
239
|
+
parameters: {
|
|
240
|
+
docs: {
|
|
241
|
+
description: {
|
|
242
|
+
story: 'A Button that takes up the full width of its container.',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export const WithIcon: Story = {
|
|
249
|
+
args: {
|
|
250
|
+
iconRight: ArrowRight,
|
|
251
|
+
},
|
|
252
|
+
parameters: {
|
|
253
|
+
docs: {
|
|
254
|
+
description: {
|
|
255
|
+
story:
|
|
256
|
+
'A Button with an icon on the right. Can also use `iconLeft` to place the icon on the left or have both at the same time.',
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export const WithAvatars: Story = {
|
|
263
|
+
args: {
|
|
264
|
+
avatars: [{ asset: <Freeze /> }, { asset: <Freeze /> }],
|
|
265
|
+
},
|
|
266
|
+
parameters: {
|
|
267
|
+
docs: {
|
|
268
|
+
description: {
|
|
269
|
+
story:
|
|
270
|
+
'A Button with avatars. Will supersed any `iconLeft` property and will always render avatars.',
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export const WithProfileName: Story = {
|
|
277
|
+
args: {
|
|
278
|
+
avatars: [{ profileName: 'John Doe' }],
|
|
279
|
+
},
|
|
280
|
+
parameters: {
|
|
281
|
+
docs: {
|
|
282
|
+
description: {
|
|
283
|
+
story: 'A Button with a Profile name.',
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export const WithProfileImage: Story = {
|
|
290
|
+
args: {
|
|
291
|
+
avatars: [{ imgSrc: '../avatar-rectangle-fox.webp' }],
|
|
292
|
+
},
|
|
293
|
+
parameters: {
|
|
294
|
+
docs: {
|
|
295
|
+
description: {
|
|
296
|
+
story: 'A Button with a Profile image.',
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export const WithAvatarAndIcon: Story = {
|
|
303
|
+
args: {
|
|
304
|
+
avatars: [{ asset: <Freeze /> }],
|
|
305
|
+
iconRight: ArrowRight,
|
|
306
|
+
},
|
|
307
|
+
parameters: {
|
|
308
|
+
docs: {
|
|
309
|
+
description: {
|
|
310
|
+
story: 'A Button with an avatar and an icon.',
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { userEvent, within, expect, waitFor } from '@storybook/test';
|
|
3
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import Button from '../../src';
|
|
5
|
+
import { Freeze } from '@transferwise/icons';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Actions/Button/Tests',
|
|
9
|
+
component: Button,
|
|
10
|
+
args: {
|
|
11
|
+
children: 'Button text',
|
|
12
|
+
as: 'button',
|
|
13
|
+
},
|
|
14
|
+
} satisfies Meta<typeof Button>;
|
|
15
|
+
|
|
16
|
+
export default meta;
|
|
17
|
+
|
|
18
|
+
type Story = StoryObj<typeof meta>;
|
|
19
|
+
|
|
20
|
+
const wait = async (duration = 500) =>
|
|
21
|
+
new Promise<void>((resolve) => {
|
|
22
|
+
setTimeout(resolve, duration);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const ClickInteraction: Story = {
|
|
26
|
+
play: async ({ canvasElement, step }) => {
|
|
27
|
+
const canvas = within(canvasElement);
|
|
28
|
+
const button = canvas.getByRole('button');
|
|
29
|
+
|
|
30
|
+
await step('Click the button', async () => {
|
|
31
|
+
await userEvent.click(button);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await step('Check if button text changes to "Clicked!"', async () => {
|
|
35
|
+
await waitFor(async () => expect(button).toHaveTextContent('Clicked!'));
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
39
|
+
const [clicked, setClicked] = useState(false);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Button {...args} onClick={() => setClicked(true)}>
|
|
43
|
+
{clicked ? 'Clicked!' : 'Button text'}
|
|
44
|
+
</Button>
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const FocusInteraction: Story = {
|
|
50
|
+
play: async ({ canvasElement, step }) => {
|
|
51
|
+
const canvas = within(canvasElement);
|
|
52
|
+
const button = canvas.getByRole('button');
|
|
53
|
+
|
|
54
|
+
await step('Tab to the button', async () => {
|
|
55
|
+
await userEvent.tab();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await step('Check if button has focus and text changes to "Focused!"', async () => {
|
|
59
|
+
await waitFor(async () => expect(button).toHaveFocus());
|
|
60
|
+
await waitFor(async () => expect(button).toHaveTextContent('Focused!'));
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
64
|
+
const [focused, setFocused] = useState(false);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Button {...args} onFocus={() => setFocused(true)}>
|
|
68
|
+
{focused ? 'Focused!' : 'Button text'}
|
|
69
|
+
</Button>
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const BlurInteraction: Story = {
|
|
75
|
+
play: async ({ canvasElement, step }) => {
|
|
76
|
+
const canvas = within(canvasElement);
|
|
77
|
+
const button = canvas.getByRole('button');
|
|
78
|
+
|
|
79
|
+
await step('Tab to the button', async () => {
|
|
80
|
+
await userEvent.tab();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await step('Check if button has focus', async () => {
|
|
84
|
+
await waitFor(async () => expect(button).toHaveFocus());
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await step('Tab away from the button', async () => {
|
|
88
|
+
await userEvent.tab();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await step('Check if button loses focus and text changes to "Blurred!"', async () => {
|
|
92
|
+
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
93
|
+
await waitFor(async () => expect(button).toHaveTextContent('Blurred!'));
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
97
|
+
const [blurred, setBlurred] = useState(false);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Button {...args} onBlur={() => setBlurred(true)}>
|
|
101
|
+
{blurred ? 'Blurred!' : 'Button text'}
|
|
102
|
+
</Button>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const MouseEnterInteraction: Story = {
|
|
108
|
+
play: async ({ canvasElement, step }) => {
|
|
109
|
+
const canvas = within(canvasElement);
|
|
110
|
+
const button = canvas.getByRole('button');
|
|
111
|
+
|
|
112
|
+
await step('Hover over the button', async () => {
|
|
113
|
+
await userEvent.hover(button);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await step('Check if button text changes to "Hovered!"', async () => {
|
|
117
|
+
await waitFor(async () => expect(button).toHaveTextContent('Hovered!'));
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
121
|
+
const [hovered, setHovered] = useState(false);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Button {...args} onMouseEnter={() => setHovered(true)}>
|
|
125
|
+
{hovered ? 'Hovered!' : 'Button text'}
|
|
126
|
+
</Button>
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const MouseLeaveInteraction: Story = {
|
|
132
|
+
play: async ({ canvasElement, step }) => {
|
|
133
|
+
const canvas = within(canvasElement);
|
|
134
|
+
const button = canvas.getByRole('button');
|
|
135
|
+
|
|
136
|
+
await step('Hover over the button', async () => {
|
|
137
|
+
await userEvent.hover(button);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
await step('Unhover the button', async () => {
|
|
141
|
+
await userEvent.unhover(button);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await step('Check if button text changes to "Left!"', async () => {
|
|
145
|
+
await waitFor(async () => expect(button).toHaveTextContent('Left!'));
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
149
|
+
const [left, setLeft] = useState(false);
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<Button {...args} onMouseLeave={() => setLeft(true)}>
|
|
153
|
+
{left ? 'Left!' : 'Button text'}
|
|
154
|
+
</Button>
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const KeyDownInteraction: Story = {
|
|
160
|
+
play: async ({ canvasElement, step }) => {
|
|
161
|
+
const canvas = within(canvasElement);
|
|
162
|
+
const button = canvas.getByRole('button');
|
|
163
|
+
|
|
164
|
+
await step('Press Enter key on the button', async () => {
|
|
165
|
+
await userEvent.type(button, '{enter}');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
await step('Check if button text changes to "Key Pressed!"', async () => {
|
|
169
|
+
await waitFor(async () => expect(button).toHaveTextContent('Key Pressed!'));
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
173
|
+
const [keyPressed, setKeyPressed] = useState(false);
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<Button {...args} onKeyDown={() => setKeyPressed(true)}>
|
|
177
|
+
{keyPressed ? 'Key Pressed!' : 'Button text'}
|
|
178
|
+
</Button>
|
|
179
|
+
);
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
export const DisabledClickInteraction: Story = {
|
|
183
|
+
play: async ({ canvasElement, step }) => {
|
|
184
|
+
const canvas = within(canvasElement);
|
|
185
|
+
const button = canvas.getByRole('button');
|
|
186
|
+
|
|
187
|
+
await step('Click the disabled button', async () => {
|
|
188
|
+
await userEvent.click(button);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
192
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
196
|
+
return <Button {...args} disabled />;
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const DisabledFocusInteraction: Story = {
|
|
201
|
+
play: async ({ canvasElement, step }) => {
|
|
202
|
+
const canvas = within(canvasElement);
|
|
203
|
+
const button = canvas.getByRole('button');
|
|
204
|
+
|
|
205
|
+
await step('Tab to the disabled button', async () => {
|
|
206
|
+
await userEvent.tab();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
await step('Check if button does not have focus', async () => {
|
|
210
|
+
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
214
|
+
return <Button {...args} disabled />;
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const DisabledBlurInteraction: Story = {
|
|
219
|
+
play: async ({ canvasElement, step }) => {
|
|
220
|
+
const canvas = within(canvasElement);
|
|
221
|
+
const button = canvas.getByRole('button');
|
|
222
|
+
|
|
223
|
+
await step('Tab to the disabled button', async () => {
|
|
224
|
+
await userEvent.tab();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
await step('Check if button does not have focus', async () => {
|
|
228
|
+
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
232
|
+
return <Button {...args} disabled />;
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export const DisabledKeyDownInteraction: Story = {
|
|
237
|
+
play: async ({ canvasElement, step }) => {
|
|
238
|
+
const canvas = within(canvasElement);
|
|
239
|
+
const button = canvas.getByRole('button');
|
|
240
|
+
|
|
241
|
+
await step('Press Enter key on the disabled button', async () => {
|
|
242
|
+
await userEvent.type(button, '{enter}');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
246
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
250
|
+
return <Button {...args} disabled />;
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const DisabledMouseEnterInteraction: Story = {
|
|
255
|
+
play: async ({ canvasElement, step }) => {
|
|
256
|
+
const canvas = within(canvasElement);
|
|
257
|
+
const button = canvas.getByRole('button');
|
|
258
|
+
|
|
259
|
+
await step('Hover over the disabled button', async () => {
|
|
260
|
+
await userEvent.hover(button);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
264
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
268
|
+
return <Button {...args} disabled />;
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export const DisabledMouseLeaveInteraction: Story = {
|
|
273
|
+
play: async ({ canvasElement, step }) => {
|
|
274
|
+
const canvas = within(canvasElement);
|
|
275
|
+
const button = canvas.getByRole('button');
|
|
276
|
+
|
|
277
|
+
await step('Unhover the disabled button', async () => {
|
|
278
|
+
await userEvent.unhover(button);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
282
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
286
|
+
return <Button {...args} disabled />;
|
|
287
|
+
},
|
|
288
|
+
};
|