@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.
Files changed (114) hide show
  1. package/build/common/initials.js +4 -1
  2. package/build/common/initials.js.map +1 -1
  3. package/build/common/initials.mjs +4 -1
  4. package/build/common/initials.mjs.map +1 -1
  5. package/build/i18n/de.json +2 -0
  6. package/build/i18n/de.json.js +2 -0
  7. package/build/i18n/de.json.js.map +1 -1
  8. package/build/i18n/de.json.mjs +2 -0
  9. package/build/i18n/de.json.mjs.map +1 -1
  10. package/build/i18n/en.json +2 -0
  11. package/build/i18n/en.json.js +2 -0
  12. package/build/i18n/en.json.js.map +1 -1
  13. package/build/i18n/en.json.mjs +2 -0
  14. package/build/i18n/en.json.mjs.map +1 -1
  15. package/build/i18n/fr.json +2 -0
  16. package/build/i18n/fr.json.js +2 -0
  17. package/build/i18n/fr.json.js.map +1 -1
  18. package/build/i18n/fr.json.mjs +2 -0
  19. package/build/i18n/fr.json.mjs.map +1 -1
  20. package/build/i18n/hu.json +2 -0
  21. package/build/i18n/hu.json.js +2 -0
  22. package/build/i18n/hu.json.js.map +1 -1
  23. package/build/i18n/hu.json.mjs +2 -0
  24. package/build/i18n/hu.json.mjs.map +1 -1
  25. package/build/i18n/it.json +2 -0
  26. package/build/i18n/it.json.js +2 -0
  27. package/build/i18n/it.json.js.map +1 -1
  28. package/build/i18n/it.json.mjs +2 -0
  29. package/build/i18n/it.json.mjs.map +1 -1
  30. package/build/i18n/ja.json +2 -0
  31. package/build/i18n/ja.json.js +2 -0
  32. package/build/i18n/ja.json.js.map +1 -1
  33. package/build/i18n/ja.json.mjs +2 -0
  34. package/build/i18n/ja.json.mjs.map +1 -1
  35. package/build/i18n/pl.json +2 -0
  36. package/build/i18n/pl.json.js +2 -0
  37. package/build/i18n/pl.json.js.map +1 -1
  38. package/build/i18n/pl.json.mjs +2 -0
  39. package/build/i18n/pl.json.mjs.map +1 -1
  40. package/build/i18n/ro.json +2 -0
  41. package/build/i18n/ro.json.js +2 -0
  42. package/build/i18n/ro.json.js.map +1 -1
  43. package/build/i18n/ro.json.mjs +2 -0
  44. package/build/i18n/ro.json.mjs.map +1 -1
  45. package/build/i18n/ru.json +2 -0
  46. package/build/i18n/ru.json.js +2 -0
  47. package/build/i18n/ru.json.js.map +1 -1
  48. package/build/i18n/ru.json.mjs +2 -0
  49. package/build/i18n/ru.json.mjs.map +1 -1
  50. package/build/i18n/tr.json +2 -0
  51. package/build/i18n/tr.json.js +2 -0
  52. package/build/i18n/tr.json.js.map +1 -1
  53. package/build/i18n/tr.json.mjs +2 -0
  54. package/build/i18n/tr.json.mjs.map +1 -1
  55. package/build/i18n/zh-CN.json +2 -0
  56. package/build/i18n/zh-CN.json.js +2 -0
  57. package/build/i18n/zh-CN.json.js.map +1 -1
  58. package/build/i18n/zh-CN.json.mjs +2 -0
  59. package/build/i18n/zh-CN.json.mjs.map +1 -1
  60. package/build/i18n/zh-HK.json +2 -0
  61. package/build/i18n/zh-HK.json.js +2 -0
  62. package/build/i18n/zh-HK.json.js.map +1 -1
  63. package/build/i18n/zh-HK.json.mjs +2 -0
  64. package/build/i18n/zh-HK.json.mjs.map +1 -1
  65. package/build/types/common/initials.d.ts.map +1 -1
  66. package/build/types/test-utils/index.d.ts +4 -0
  67. package/build/types/test-utils/index.d.ts.map +1 -1
  68. package/build/types/upload/Upload.d.ts +6 -2
  69. package/build/types/upload/Upload.d.ts.map +1 -1
  70. package/build/types/upload/Upload.messages.d.ts +8 -0
  71. package/build/types/upload/Upload.messages.d.ts.map +1 -1
  72. package/build/types/uploadInput/UploadInput.d.ts +1 -1
  73. package/build/types/uploadInput/uploadButton/UploadButton.d.ts +4 -2
  74. package/build/types/uploadInput/uploadButton/UploadButton.d.ts.map +1 -1
  75. package/build/upload/Upload.js +16 -9
  76. package/build/upload/Upload.js.map +1 -1
  77. package/build/upload/Upload.messages.js +6 -0
  78. package/build/upload/Upload.messages.js.map +1 -1
  79. package/build/upload/Upload.messages.mjs +6 -0
  80. package/build/upload/Upload.messages.mjs.map +1 -1
  81. package/build/upload/Upload.mjs +16 -9
  82. package/build/upload/Upload.mjs.map +1 -1
  83. package/build/uploadInput/UploadInput.js +1 -1
  84. package/build/uploadInput/UploadInput.js.map +1 -1
  85. package/build/uploadInput/UploadInput.mjs +1 -1
  86. package/build/uploadInput/UploadInput.mjs.map +1 -1
  87. package/build/uploadInput/uploadButton/UploadButton.js +7 -4
  88. package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
  89. package/build/uploadInput/uploadButton/UploadButton.mjs +7 -4
  90. package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
  91. package/package.json +3 -3
  92. package/src/common/initials.spec.tsx +13 -0
  93. package/src/common/initials.ts +5 -0
  94. package/src/i18n/de.json +2 -0
  95. package/src/i18n/en.json +2 -0
  96. package/src/i18n/fr.json +2 -0
  97. package/src/i18n/hu.json +2 -0
  98. package/src/i18n/it.json +2 -0
  99. package/src/i18n/ja.json +2 -0
  100. package/src/i18n/pl.json +2 -0
  101. package/src/i18n/ro.json +2 -0
  102. package/src/i18n/ru.json +2 -0
  103. package/src/i18n/tr.json +2 -0
  104. package/src/i18n/zh-CN.json +2 -0
  105. package/src/i18n/zh-HK.json +2 -0
  106. package/src/upload/Upload.messages.ts +8 -0
  107. package/src/upload/Upload.spec.tsx +6 -0
  108. package/src/upload/Upload.story.tsx +118 -3
  109. package/src/upload/Upload.tests.story.tsx +5 -3
  110. package/src/upload/Upload.tsx +24 -15
  111. package/src/uploadInput/UploadInput.tests.story.tsx +7 -0
  112. package/src/uploadInput/UploadInput.tsx +2 -2
  113. package/src/uploadInput/uploadButton/UploadButton.spec.tsx +6 -0
  114. package/src/uploadInput/uploadButton/UploadButton.tsx +12 -6
@@ -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
- maxSize?: number;
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
- intl.formatMessage(messages.csTooLargeMessage, {
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 a allowed size limit are uploaded
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 (default: 5000 KB)
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
- return formatMessage(MESSAGES.instructions, {
177
- fileTypes: derivedFileDescription,
178
- size: Math.round(sizeLimit / 1000),
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'> {