@transferwise/components 46.100.2 → 46.102.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/common/initials.js +4 -1
- package/build/common/initials.js.map +1 -1
- package/build/common/initials.mjs +4 -1
- package/build/common/initials.mjs.map +1 -1
- package/build/i18n/de.json +2 -0
- package/build/i18n/de.json.js +2 -0
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +2 -0
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/en.json +2 -0
- package/build/i18n/en.json.js +2 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +2 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/i18n/fr.json +2 -0
- package/build/i18n/fr.json.js +2 -0
- package/build/i18n/fr.json.js.map +1 -1
- package/build/i18n/fr.json.mjs +2 -0
- package/build/i18n/fr.json.mjs.map +1 -1
- package/build/i18n/hu.json +2 -0
- package/build/i18n/hu.json.js +2 -0
- package/build/i18n/hu.json.js.map +1 -1
- package/build/i18n/hu.json.mjs +2 -0
- package/build/i18n/hu.json.mjs.map +1 -1
- package/build/i18n/it.json +2 -0
- package/build/i18n/it.json.js +2 -0
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +2 -0
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/ja.json +2 -0
- package/build/i18n/ja.json.js +2 -0
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +2 -0
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/pl.json +2 -0
- package/build/i18n/pl.json.js +2 -0
- package/build/i18n/pl.json.js.map +1 -1
- package/build/i18n/pl.json.mjs +2 -0
- package/build/i18n/pl.json.mjs.map +1 -1
- package/build/i18n/ro.json +2 -0
- package/build/i18n/ro.json.js +2 -0
- package/build/i18n/ro.json.js.map +1 -1
- package/build/i18n/ro.json.mjs +2 -0
- package/build/i18n/ro.json.mjs.map +1 -1
- package/build/i18n/ru.json +2 -0
- package/build/i18n/ru.json.js +2 -0
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +2 -0
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/tr.json +2 -0
- package/build/i18n/tr.json.js +2 -0
- package/build/i18n/tr.json.js.map +1 -1
- package/build/i18n/tr.json.mjs +2 -0
- package/build/i18n/tr.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +2 -0
- package/build/i18n/zh-CN.json.js +2 -0
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +2 -0
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +2 -0
- package/build/i18n/zh-HK.json.js +2 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +2 -0
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/types/common/initials.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +4 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts +6 -2
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/types/upload/Upload.messages.d.ts +8 -0
- package/build/types/upload/Upload.messages.d.ts.map +1 -1
- package/build/types/uploadInput/UploadInput.d.ts +1 -1
- package/build/types/uploadInput/uploadButton/UploadButton.d.ts +4 -2
- package/build/types/uploadInput/uploadButton/UploadButton.d.ts.map +1 -1
- package/build/upload/Upload.js +16 -9
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.messages.js +6 -0
- package/build/upload/Upload.messages.js.map +1 -1
- package/build/upload/Upload.messages.mjs +6 -0
- package/build/upload/Upload.messages.mjs.map +1 -1
- package/build/upload/Upload.mjs +16 -9
- package/build/upload/Upload.mjs.map +1 -1
- package/build/uploadInput/UploadInput.js +1 -1
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/build/uploadInput/UploadInput.mjs.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.js +7 -4
- package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.mjs +7 -4
- package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
- package/package.json +3 -3
- package/src/common/initials.spec.tsx +13 -0
- package/src/common/initials.ts +5 -0
- package/src/i18n/de.json +2 -0
- package/src/i18n/en.json +2 -0
- package/src/i18n/fr.json +2 -0
- package/src/i18n/hu.json +2 -0
- package/src/i18n/it.json +2 -0
- package/src/i18n/ja.json +2 -0
- package/src/i18n/pl.json +2 -0
- package/src/i18n/ro.json +2 -0
- package/src/i18n/ru.json +2 -0
- package/src/i18n/tr.json +2 -0
- package/src/i18n/zh-CN.json +2 -0
- package/src/i18n/zh-HK.json +2 -0
- package/src/upload/Upload.messages.ts +8 -0
- package/src/upload/Upload.spec.tsx +6 -0
- package/src/upload/Upload.story.tsx +118 -3
- package/src/upload/Upload.tests.story.tsx +5 -3
- package/src/upload/Upload.tsx +24 -15
- package/src/uploadInput/UploadInput.tests.story.tsx +7 -0
- package/src/uploadInput/UploadInput.tsx +2 -2
- package/src/uploadInput/uploadButton/UploadButton.spec.tsx +6 -0
- package/src/uploadInput/uploadButton/UploadButton.tsx +12 -6
package/src/upload/Upload.tsx
CHANGED
|
@@ -10,7 +10,6 @@ import messages from './Upload.messages';
|
|
|
10
10
|
import { UploadImageStep, ProcessingStep, CompleteStep } from './steps';
|
|
11
11
|
import { postData, asyncFileRead, isSizeValid, isTypeValid, getFileType } from './utils';
|
|
12
12
|
import { PostDataFetcher, PostDataHTTPOptions, ResponseError } from './utils/postData/postData';
|
|
13
|
-
import { ProcessIndicatorStatus } from '../processIndicator';
|
|
14
13
|
|
|
15
14
|
export const MAX_SIZE_DEFAULT = 5000000;
|
|
16
15
|
|
|
@@ -31,10 +30,14 @@ export interface UploadProps extends WrappedComponentProps {
|
|
|
31
30
|
};
|
|
32
31
|
/**
|
|
33
32
|
* You can provide a fetcher function with the same interface as the global fetch function, which is used by default.
|
|
34
|
-
* function fetcher(input: RequestInfo, init?: RequestInit): Promise<Response
|
|
33
|
+
* `function fetcher(input: RequestInfo, init?: RequestInit): Promise<Response>`
|
|
35
34
|
*/
|
|
36
35
|
fetcher?: PostDataFetcher;
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Filesize expressed in B.<br />If set to `null`, no size limit will be applied.
|
|
38
|
+
* @default 5000000 (5 MB)
|
|
39
|
+
*/
|
|
40
|
+
maxSize?: number | null;
|
|
38
41
|
psButtonText?: string;
|
|
39
42
|
psButtonDisabled?: boolean;
|
|
40
43
|
psProcessingText?: string;
|
|
@@ -114,9 +117,9 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
114
117
|
case 413:
|
|
115
118
|
return (
|
|
116
119
|
csTooLargeMessage ||
|
|
117
|
-
|
|
118
|
-
maxSize: roundFileSize(maxSize)
|
|
119
|
-
|
|
120
|
+
(typeof maxSize === 'number'
|
|
121
|
+
? intl.formatMessage(messages.csTooLargeMessage, { maxSize: roundFileSize(maxSize) })
|
|
122
|
+
: intl.formatMessage(messages.csTooLargeNoLimitMessage))
|
|
120
123
|
);
|
|
121
124
|
case 415:
|
|
122
125
|
return csWrongTypeMessage || intl.formatMessage(messages.csWrongTypeMessage);
|
|
@@ -279,7 +282,7 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
279
282
|
return false;
|
|
280
283
|
}
|
|
281
284
|
|
|
282
|
-
if (!isSizeValid(file, maxSize)) {
|
|
285
|
+
if (typeof maxSize === 'number' && !isSizeValid(file, maxSize)) {
|
|
283
286
|
this.asyncResponse(
|
|
284
287
|
new ResponseError(
|
|
285
288
|
new Response(null, {
|
|
@@ -344,6 +347,18 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
344
347
|
uploadedImage,
|
|
345
348
|
} = this.state;
|
|
346
349
|
|
|
350
|
+
const placeholder = ((): string => {
|
|
351
|
+
if (usPlaceholder) {
|
|
352
|
+
return usPlaceholder;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (typeof maxSize === 'number') {
|
|
356
|
+
return intl.formatMessage(messages.usPlaceholder, { maxSize: roundFileSize(maxSize) });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return intl.formatMessage(messages.usPlaceholderNoLimit);
|
|
360
|
+
})();
|
|
361
|
+
|
|
347
362
|
return (
|
|
348
363
|
<div
|
|
349
364
|
className={clsx('droppable-area', {
|
|
@@ -370,10 +385,7 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
370
385
|
usDisabled={usDisabled}
|
|
371
386
|
usHelpImage={usHelpImage}
|
|
372
387
|
usLabel={usLabel}
|
|
373
|
-
usPlaceholder={
|
|
374
|
-
usPlaceholder ||
|
|
375
|
-
intl.formatMessage(messages.usPlaceholder, { maxSize: roundFileSize(maxSize) })
|
|
376
|
-
}
|
|
388
|
+
usPlaceholder={placeholder}
|
|
377
389
|
/>
|
|
378
390
|
)}
|
|
379
391
|
|
|
@@ -400,10 +412,7 @@ export class Upload extends Component<UploadProps, UploadState> {
|
|
|
400
412
|
usDisabled={usDisabled}
|
|
401
413
|
usHelpImage={null}
|
|
402
414
|
usLabel={usLabel}
|
|
403
|
-
usPlaceholder={
|
|
404
|
-
usPlaceholder ||
|
|
405
|
-
intl.formatMessage(messages.usPlaceholder, { maxSize: roundFileSize(maxSize) })
|
|
406
|
-
}
|
|
415
|
+
usPlaceholder={placeholder}
|
|
407
416
|
errorMessage={this.getErrorMessage(
|
|
408
417
|
response != null &&
|
|
409
418
|
typeof response === 'object' &&
|
|
@@ -233,6 +233,13 @@ export const WithFileSizeErrorMessage: Story = {
|
|
|
233
233
|
},
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
+
export const WithNoSizeLimit: Story = {
|
|
237
|
+
args: {
|
|
238
|
+
...props,
|
|
239
|
+
sizeLimit: null,
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
|
|
236
243
|
export const WithCustomUploadButtonTitle: Story = {
|
|
237
244
|
args: {
|
|
238
245
|
...props,
|
|
@@ -91,7 +91,7 @@ export type UploadInputProps = {
|
|
|
91
91
|
maxFilesErrorMessage?: string;
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* Error message to show when files over
|
|
94
|
+
* Error message to show when files over allowed size limit are uploaded
|
|
95
95
|
*/
|
|
96
96
|
sizeLimitErrorMessage?: string;
|
|
97
97
|
} & Pick<
|
|
@@ -269,7 +269,7 @@ const UploadInput = ({
|
|
|
269
269
|
continue;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
if (!isSizeValid(file, sizeLimit * 1000)) {
|
|
272
|
+
if (typeof sizeLimit === 'number' && !isSizeValid(file, sizeLimit * 1000)) {
|
|
273
273
|
const failureMessage = sizeLimitErrorMessage || formatMessage(MESSAGES.fileIsTooLarge);
|
|
274
274
|
handleFileUploadFailure(file, failureMessage);
|
|
275
275
|
continue;
|
|
@@ -96,6 +96,12 @@ describe('UploadButton', () => {
|
|
|
96
96
|
expect(screen.getByText('All file types, less than 5MB')).toBeInTheDocument();
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
+
it('should show no file size limit if sizeLimit is set to `null`', () => {
|
|
100
|
+
renderComponent({ ...props, fileTypes: ['*'], sizeLimit: null });
|
|
101
|
+
expect(screen.getByText('All file types')).toBeInTheDocument();
|
|
102
|
+
expect(screen.queryByText(/less than/i)).not.toBeInTheDocument();
|
|
103
|
+
});
|
|
104
|
+
|
|
99
105
|
it('should show custom description if provided', () => {
|
|
100
106
|
const description = 'Test description';
|
|
101
107
|
renderComponent({ ...props, fileTypes: ['*'], description });
|
|
@@ -42,9 +42,11 @@ export type UploadButtonProps = {
|
|
|
42
42
|
fileTypes?: AllowedFileTypes;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Size limit in KBs 1000 KB = 1 MB
|
|
45
|
+
* Size limit in KBs (1000 KB = 1 MB).
|
|
46
|
+
* If set to `null`, no size limit will be applied.
|
|
47
|
+
* @default 5000
|
|
46
48
|
*/
|
|
47
|
-
sizeLimit?: number;
|
|
49
|
+
sizeLimit?: number | null;
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* Description for the upload button
|
|
@@ -173,10 +175,14 @@ const UploadButton = forwardRef<HTMLInputElement | null, UploadButtonProps>(
|
|
|
173
175
|
const derivedFileDescription =
|
|
174
176
|
fileTypesDescription === '*' ? formatMessage(MESSAGES.allFileTypes) : fileTypesDescription;
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
if (typeof sizeLimit === 'number') {
|
|
179
|
+
return formatMessage(MESSAGES.instructions, {
|
|
180
|
+
fileTypes: derivedFileDescription,
|
|
181
|
+
size: Math.round(sizeLimit / 1000),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return derivedFileDescription;
|
|
180
186
|
}
|
|
181
187
|
|
|
182
188
|
function getAcceptedTypes(): Pick<React.ComponentPropsWithoutRef<'input'>, 'accept'> {
|