@transferwise/components 46.74.0 → 46.75.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 (112) hide show
  1. package/build/alert/Alert.js +3 -1
  2. package/build/alert/Alert.js.map +1 -1
  3. package/build/alert/Alert.mjs +3 -1
  4. package/build/alert/Alert.mjs.map +1 -1
  5. package/build/dimmer/Dimmer.js +3 -1
  6. package/build/dimmer/Dimmer.js.map +1 -1
  7. package/build/dimmer/Dimmer.mjs +3 -1
  8. package/build/dimmer/Dimmer.mjs.map +1 -1
  9. package/build/drawer/Drawer.js +2 -0
  10. package/build/drawer/Drawer.js.map +1 -1
  11. package/build/drawer/Drawer.mjs +2 -0
  12. package/build/drawer/Drawer.mjs.map +1 -1
  13. package/build/field/Field.js +2 -0
  14. package/build/field/Field.js.map +1 -1
  15. package/build/field/Field.mjs +2 -0
  16. package/build/field/Field.mjs.map +1 -1
  17. package/build/i18n/en.json +5 -0
  18. package/build/i18n/en.json.js +5 -0
  19. package/build/i18n/en.json.js.map +1 -1
  20. package/build/i18n/en.json.mjs +5 -0
  21. package/build/i18n/en.json.mjs.map +1 -1
  22. package/build/inlineAlert/InlineAlert.js +3 -1
  23. package/build/inlineAlert/InlineAlert.js.map +1 -1
  24. package/build/inlineAlert/InlineAlert.mjs +3 -1
  25. package/build/inlineAlert/InlineAlert.mjs.map +1 -1
  26. package/build/modal/Modal.js +3 -0
  27. package/build/modal/Modal.js.map +1 -1
  28. package/build/modal/Modal.mjs +3 -0
  29. package/build/modal/Modal.mjs.map +1 -1
  30. package/build/statusIcon/StatusIcon.js +50 -16
  31. package/build/statusIcon/StatusIcon.js.map +1 -1
  32. package/build/statusIcon/StatusIcon.messages.js +24 -0
  33. package/build/statusIcon/StatusIcon.messages.js.map +1 -0
  34. package/build/statusIcon/StatusIcon.messages.mjs +22 -0
  35. package/build/statusIcon/StatusIcon.messages.mjs.map +1 -0
  36. package/build/statusIcon/StatusIcon.mjs +48 -14
  37. package/build/statusIcon/StatusIcon.mjs.map +1 -1
  38. package/build/types/alert/Alert.d.ts +6 -1
  39. package/build/types/alert/Alert.d.ts.map +1 -1
  40. package/build/types/dimmer/Dimmer.d.ts +2 -1
  41. package/build/types/dimmer/Dimmer.d.ts.map +1 -1
  42. package/build/types/drawer/Drawer.d.ts +2 -1
  43. package/build/types/drawer/Drawer.d.ts.map +1 -1
  44. package/build/types/field/Field.d.ts +6 -1
  45. package/build/types/field/Field.d.ts.map +1 -1
  46. package/build/types/inlineAlert/InlineAlert.d.ts +2 -1
  47. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  48. package/build/types/modal/Modal.d.ts +2 -1
  49. package/build/types/modal/Modal.d.ts.map +1 -1
  50. package/build/types/statusIcon/StatusIcon.d.ts +7 -1
  51. package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
  52. package/build/types/statusIcon/StatusIcon.messages.d.ts +29 -0
  53. package/build/types/statusIcon/StatusIcon.messages.d.ts.map +1 -0
  54. package/build/types/upload/Upload.d.ts +5 -0
  55. package/build/types/upload/Upload.d.ts.map +1 -1
  56. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +1 -0
  57. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
  58. package/build/types/uploadInput/UploadInput.d.ts +9 -0
  59. package/build/types/uploadInput/UploadInput.d.ts.map +1 -1
  60. package/build/types/uploadInput/uploadItem/UploadItem.d.ts +16 -1
  61. package/build/types/uploadInput/uploadItem/UploadItem.d.ts.map +1 -1
  62. package/build/types/uploadInput/uploadItem/UploadItemLink.d.ts.map +1 -1
  63. package/build/upload/Upload.js +4 -2
  64. package/build/upload/Upload.js.map +1 -1
  65. package/build/upload/Upload.mjs +4 -2
  66. package/build/upload/Upload.mjs.map +1 -1
  67. package/build/upload/steps/uploadImageStep/uploadImageStep.js +6 -3
  68. package/build/upload/steps/uploadImageStep/uploadImageStep.js.map +1 -1
  69. package/build/upload/steps/uploadImageStep/uploadImageStep.mjs +6 -3
  70. package/build/upload/steps/uploadImageStep/uploadImageStep.mjs.map +1 -1
  71. package/build/uploadInput/UploadInput.js +71 -66
  72. package/build/uploadInput/UploadInput.js.map +1 -1
  73. package/build/uploadInput/UploadInput.mjs +72 -67
  74. package/build/uploadInput/UploadInput.mjs.map +1 -1
  75. package/build/uploadInput/uploadItem/UploadItem.js +13 -4
  76. package/build/uploadInput/uploadItem/UploadItem.js.map +1 -1
  77. package/build/uploadInput/uploadItem/UploadItem.mjs +13 -4
  78. package/build/uploadInput/uploadItem/UploadItem.mjs.map +1 -1
  79. package/build/uploadInput/uploadItem/UploadItemLink.js +1 -0
  80. package/build/uploadInput/uploadItem/UploadItemLink.js.map +1 -1
  81. package/build/uploadInput/uploadItem/UploadItemLink.mjs +1 -0
  82. package/build/uploadInput/uploadItem/UploadItemLink.mjs.map +1 -1
  83. package/package.json +1 -1
  84. package/src/alert/Alert.spec.tsx +10 -0
  85. package/src/alert/Alert.tsx +7 -1
  86. package/src/dimmer/Dimmer.spec.js +8 -0
  87. package/src/dimmer/Dimmer.tsx +4 -0
  88. package/src/drawer/Drawer.spec.js +25 -6
  89. package/src/drawer/Drawer.tsx +3 -1
  90. package/src/field/Field.spec.tsx +19 -0
  91. package/src/field/Field.story.tsx +20 -4
  92. package/src/field/Field.tsx +7 -1
  93. package/src/i18n/en.json +5 -0
  94. package/src/inlineAlert/InlineAlert.spec.tsx +12 -1
  95. package/src/inlineAlert/InlineAlert.tsx +5 -1
  96. package/src/modal/Modal.spec.js +19 -1
  97. package/src/modal/Modal.tsx +4 -0
  98. package/src/statusIcon/StatusIcon.docs.mdx +28 -0
  99. package/src/statusIcon/StatusIcon.messages.ts +34 -0
  100. package/src/statusIcon/StatusIcon.spec.tsx +39 -4
  101. package/src/statusIcon/StatusIcon.story.tsx +15 -6
  102. package/src/statusIcon/StatusIcon.tsx +63 -14
  103. package/src/upload/Upload.spec.js +19 -0
  104. package/src/upload/Upload.tsx +7 -0
  105. package/src/upload/steps/uploadImageStep/uploadImageStep.spec.js +13 -0
  106. package/src/upload/steps/uploadImageStep/uploadImageStep.tsx +15 -4
  107. package/src/uploadInput/UploadInput.spec.tsx +121 -9
  108. package/src/uploadInput/UploadInput.tests.story.tsx +207 -140
  109. package/src/uploadInput/UploadInput.tsx +110 -77
  110. package/src/uploadInput/uploadItem/UploadItem.spec.tsx +1 -0
  111. package/src/uploadInput/uploadItem/UploadItem.tsx +30 -6
  112. package/src/uploadInput/uploadItem/UploadItemLink.tsx +9 -1
@@ -1,52 +1,52 @@
1
1
  import { action } from '@storybook/addon-actions';
2
- import { StoryFn, Meta } from '@storybook/react';
2
+ import { Meta, StoryObj } from '@storybook/react';
3
3
 
4
4
  import { Status } from '../common';
5
-
6
5
  import UploadInput, { UploadInputProps } from './UploadInput';
7
6
  import { UploadedFile, UploadResponse } from './types';
7
+ import { userEvent, within } from '@storybook/test';
8
8
 
9
9
  const meta: Meta<typeof UploadInput> = {
10
10
  title: 'Forms/UploadInput/Tests',
11
11
  component: UploadInput,
12
12
  };
13
-
14
13
  export default meta;
15
- type Story = StoryFn<UploadInputProps>;
16
14
 
17
- const files = [
15
+ type Story = StoryObj<UploadInputProps>;
16
+
17
+ const files: UploadedFile[] = [
18
18
  {
19
- id: 1,
19
+ id: '0hd8hf8',
20
20
  filename: 'purchase-receipt-0.pdf',
21
21
  url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
22
22
  },
23
23
  {
24
- id: 2,
24
+ id: '1r7hgc83',
25
25
  filename: 'purchase-receipt-1.pdf',
26
26
  },
27
27
  {
28
- id: 3,
28
+ id: '2nhc7387hc8h',
29
29
  filename: 'purchase-receipt-2.pdf',
30
30
  url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
31
31
  },
32
32
  {
33
- id: 4,
33
+ id: '39wd8uc',
34
34
  filename: 'receipt failed.png',
35
35
  status: Status.FAILED,
36
36
  },
37
37
  {
38
- id: 5,
38
+ id: '437yyf8hf',
39
39
  filename: 'receipt failed With error string.png',
40
40
  status: Status.FAILED,
41
41
  error: 'Something went wrong',
42
42
  },
43
43
  {
44
- id: 6,
44
+ id: '5biehveifh',
45
45
  filename: 'receipt failed With error object.png',
46
46
  status: Status.FAILED,
47
47
  error: { message: 'Something went wrong' },
48
48
  },
49
- ] satisfies UploadedFile[];
49
+ ];
50
50
 
51
51
  const createDelayedPromise = async ({
52
52
  successful = true,
@@ -65,163 +65,230 @@ const createDelayedPromise = async ({
65
65
  });
66
66
 
67
67
  const props = {
68
- onUploadFile: async (formData: FormData) => {
69
- return createDelayedPromise();
68
+ onUploadFile: async (formData: FormData) => createDelayedPromise(),
69
+ onDeleteFile: async (id: string | number) => createDelayedPromise(),
70
+ };
71
+
72
+ export const UploadInputWithDescriptionFromProps: Story = {
73
+ args: {
74
+ ...props,
75
+ multiple: true,
76
+ description: 'Custom file description from prop',
70
77
  },
71
- onDeleteFile: async (id: string | number) => {
72
- return createDelayedPromise();
78
+ };
79
+
80
+ export const Disabled: Story = {
81
+ args: {
82
+ ...props,
83
+ disabled: true,
73
84
  },
74
85
  };
75
86
 
76
- const Template: Story = (args: UploadInputProps) => <UploadInput {...args} />;
87
+ export const WithAnyFileType: Story = {
88
+ args: {
89
+ ...props,
90
+ fileTypes: '*',
91
+ },
92
+ };
77
93
 
78
- export const UploadInputWithDescriptionFromProps: Story = Template.bind({});
79
- UploadInputWithDescriptionFromProps.args = {
80
- ...props,
81
- multiple: true,
82
- description: 'Custom file description from prop',
94
+ export const WithSingleFileType: Story = {
95
+ args: {
96
+ ...props,
97
+ fileTypes: '.zip,application/zip',
98
+ },
83
99
  };
84
100
 
85
- export const Disabled: Story = Template.bind({});
86
- Disabled.args = { ...props, disabled: true };
101
+ export const WithMultipleExistingFiles: Story = {
102
+ args: {
103
+ ...props,
104
+ files,
105
+ multiple: true,
106
+ },
107
+ };
87
108
 
88
- export const WithAnyFileType: Story = Template.bind({});
89
- WithAnyFileType.args = { ...props, fileTypes: '*' };
109
+ export const WithFileErrors: Story = {
110
+ args: {
111
+ ...props,
112
+ files: [
113
+ { id: 1, filename: 'Error with default message.png', status: Status.FAILED },
114
+ {
115
+ id: 2,
116
+ filename: 'Error with `string` error.png',
117
+ status: Status.FAILED,
118
+ error: 'Single string error',
119
+ },
120
+ {
121
+ id: 3,
122
+ filename: 'Error with `obj` error ({ message : `string` }).png',
123
+ status: Status.FAILED,
124
+ error: { message: 'Single obj error' },
125
+ },
126
+ {
127
+ id: 4,
128
+ filename: 'Error with single error passed in `array`.png',
129
+ status: Status.FAILED,
130
+ errors: ['Single error in array'],
131
+ },
132
+ {
133
+ id: 5,
134
+ filename: 'Error with multiple `string` errors passed in `array`.png',
135
+ status: Status.FAILED,
136
+ errors: [
137
+ 'Error 1',
138
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
139
+ 'Error 3',
140
+ ],
141
+ },
142
+ {
143
+ id: 6,
144
+ filename: 'Error with multiple `obj` errors passed in `array`.png',
145
+ status: Status.FAILED,
146
+ errors: [
147
+ { message: 'Error 1' },
148
+ {
149
+ message:
150
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
151
+ },
152
+ { message: 'Error 3' },
153
+ ],
154
+ },
155
+ ],
156
+ multiple: true,
157
+ },
158
+ };
90
159
 
91
- export const WithSingleFileType: Story = Template.bind({});
92
- WithSingleFileType.args = { ...props, fileTypes: '.zip,application/zip' };
160
+ export const WithoutDelete: Story = {
161
+ args: {
162
+ ...props,
163
+ files,
164
+ onDeleteFile: undefined,
165
+ multiple: true,
166
+ },
167
+ };
93
168
 
94
- export const WithMultipleExistingFiles: Story = Template.bind({});
95
- WithMultipleExistingFiles.args = {
96
- ...props,
97
- files,
98
- multiple: true,
169
+ export const WithUploadFailed: Story = {
170
+ args: {
171
+ ...props,
172
+ files: files.slice(0),
173
+ onUploadFile: async () => createDelayedPromise({ successful: false }),
174
+ multiple: true,
175
+ },
99
176
  };
100
177
 
101
- export const WithFileErrors: Story = Template.bind({});
102
- WithFileErrors.args = {
103
- ...props,
104
- files: [
105
- {
106
- id: 1,
107
- filename: 'Error with default message.png',
108
- status: Status.FAILED,
109
- },
110
- {
111
- id: 2,
112
- filename: 'Error with `string` error.png',
113
- status: Status.FAILED,
114
- error: 'Single string error',
115
- },
116
- {
117
- id: 3,
118
- filename: 'Error with `obj` error ({ message : `string` }).png',
119
- status: Status.FAILED,
120
- error: { message: 'Single obj error' },
121
- },
122
- {
123
- id: 4,
124
- filename: 'Error with single error passed in `array`.png',
125
- status: Status.FAILED,
126
- errors: ['Single error in array'],
127
- },
128
- {
129
- id: 5,
130
- filename: 'Error with multiple `string` errors passed in `array`.png',
131
- status: Status.FAILED,
132
- errors: [
133
- 'Error 1',
134
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
135
- 'Error 3',
136
- ],
137
- },
138
- {
139
- id: 6,
140
- filename: 'Error with multiple `obj` errors passed in `array`.png',
141
- status: Status.FAILED,
142
- errors: [
143
- { message: 'Error 1' },
144
- {
145
- message:
146
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
147
- },
148
- { message: 'Error 3' },
149
- ],
150
- },
151
- ],
152
- multiple: true,
178
+ export const WithDeleteFailed: Story = {
179
+ args: {
180
+ ...props,
181
+ files: files.slice(0),
182
+ onDeleteFile: async () => createDelayedPromise({ successful: false }),
183
+ multiple: true,
184
+ },
153
185
  };
154
186
 
155
- export const WithoutDelete: Story = Template.bind({});
156
- WithoutDelete.args = {
157
- ...props,
158
- files,
159
- onDeleteFile: undefined,
160
- multiple: true,
187
+ export const CustomConfirmMessage: Story = {
188
+ args: {
189
+ ...props,
190
+ files: files.slice(0),
191
+ deleteConfirm: {
192
+ title: 'Sure you want to remove this invoice?',
193
+ body: (
194
+ <img
195
+ alt="brand logo"
196
+ src="https://wise.com/public-resources/assets/logos/wise/brand_logo.svg"
197
+ />
198
+ ),
199
+ },
200
+ },
161
201
  };
162
202
 
163
- export const WithUploadFailed: Story = Template.bind({});
164
- WithUploadFailed.args = {
165
- ...props,
166
- files: files.slice(0),
167
- onUploadFile: async () => createDelayedPromise({ successful: false }),
168
- multiple: true,
203
+ export const WithManualDownloadHandler: Story = {
204
+ args: {
205
+ ...props,
206
+ files,
207
+ onDownload: action('Manual download handler'),
208
+ },
169
209
  };
170
210
 
171
- export const WithDeleteFailed: Story = Template.bind({});
172
- WithDeleteFailed.args = {
173
- ...props,
174
- files: files.slice(0),
175
- onDeleteFile: async () => createDelayedPromise({ successful: false }),
176
- multiple: true,
211
+ export const WithFilesChangeHandler: Story = {
212
+ args: {
213
+ ...props,
214
+ files,
215
+ onFilesChange: action('Files change handler'),
216
+ },
177
217
  };
178
218
 
179
- export const CustomConfirmMessage: Story = Template.bind({});
180
- CustomConfirmMessage.args = {
181
- ...props,
182
- files: files.slice(0),
183
- deleteConfirm: {
184
- title: 'Sure you want to remove this invoice?',
185
- body: (
186
- <img
187
- alt="brand logo"
188
- src="https://wise.com/public-resources/assets/logos/wise/brand_logo.svg"
189
- />
190
- ),
219
+ export const WithMaxFilesToUploadLimit: Story = {
220
+ args: {
221
+ ...props,
222
+ multiple: true,
223
+ maxFiles: 5,
224
+ maxFilesErrorMessage: "Can't upload as maximum number of files allowed are already uploaded",
191
225
  },
192
226
  };
193
227
 
194
- export const WithManualDownloadHandler: Story = Template.bind({});
195
- WithManualDownloadHandler.args = {
196
- ...props,
197
- files,
198
- onDownload: action('Manual download handler'),
228
+ export const WithFileSizeErrorMessage: Story = {
229
+ args: {
230
+ ...props,
231
+ sizeLimit: 1,
232
+ sizeLimitErrorMessage: 'The file is oversized',
233
+ },
199
234
  };
200
235
 
201
- export const WithFilesChangeHandler: Story = Template.bind({});
202
- WithFilesChangeHandler.args = {
203
- ...props,
204
- files,
205
- onFilesChange: action('Files change handler'),
236
+ export const WithCustomUploadButtonTitle: Story = {
237
+ args: {
238
+ ...props,
239
+ uploadButtonTitle: 'Upload the VAT receipts for FY 2022-23',
240
+ },
206
241
  };
207
242
 
208
- export const WithMaxFilesToUploadLimit: Story = Template.bind({});
209
- WithMaxFilesToUploadLimit.args = {
210
- ...props,
211
- multiple: true,
212
- maxFiles: 5,
213
- maxFilesErrorMessage: "Can't upload as maximum number of files allowed are already uploaded",
243
+ const triggerModalAndConfirm = async ({ isLink = true } = {}) => {
244
+ if (isLink) {
245
+ await wait();
246
+ await userEvent.tab();
247
+ }
248
+ await wait();
249
+ await userEvent.keyboard('{Enter}');
250
+ await wait();
251
+ await userEvent.tab();
252
+ await wait();
253
+ await userEvent.tab();
254
+ await wait();
255
+ await userEvent.tab();
256
+ await wait();
257
+ await userEvent.keyboard('{Enter}');
258
+ await wait();
214
259
  };
260
+ const wait = async (time = 250) =>
261
+ new Promise((resolve) => {
262
+ setTimeout(resolve, time);
263
+ });
215
264
 
216
- export const WithFileSizeErrorMessage: Story = Template.bind({});
217
- WithFileSizeErrorMessage.args = {
218
- ...props,
219
- sizeLimit: 1,
220
- sizeLimitErrorMessage: 'The file is oversized',
265
+ export const DeletingTop: Story = {
266
+ args: {
267
+ ...props,
268
+ files: [files[0], files[1], files[2]],
269
+ multiple: true,
270
+ },
271
+ play: async ({ canvasElement }) => {
272
+ await userEvent.tab();
273
+ await triggerModalAndConfirm();
274
+ await triggerModalAndConfirm({ isLink: false });
275
+ await triggerModalAndConfirm();
276
+ },
221
277
  };
222
278
 
223
- export const WithCustomUploadButtonTitle: Story = Template.bind({});
224
- WithCustomUploadButtonTitle.args = {
225
- ...props,
226
- uploadButtonTitle: 'Upload the VAT receipts for FY 2022-23',
279
+ export const DeletingBottom: Story = {
280
+ args: {
281
+ ...props,
282
+ files: [files[0], files[1], files[2]],
283
+ multiple: true,
284
+ },
285
+ play: async ({ canvasElement }) => {
286
+ await userEvent.tab();
287
+ await userEvent.tab();
288
+ await userEvent.tab();
289
+ await userEvent.tab();
290
+ await triggerModalAndConfirm();
291
+ await triggerModalAndConfirm({ isLink: false });
292
+ await triggerModalAndConfirm();
293
+ },
227
294
  };