@transferwise/components 46.100.1 → 46.101.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/avatarLayout/AvatarLayout.js +1 -1
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +1 -1
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/dateLookup/DateLookup.js +3 -2
- package/build/dateLookup/DateLookup.js.map +1 -1
- package/build/dateLookup/DateLookup.mjs +3 -2
- package/build/dateLookup/DateLookup.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/main.css +4 -94
- package/build/styles/accordion/Accordion.css +27 -16
- package/build/styles/avatar/Avatar.css +95 -50
- package/build/styles/inputs/Input.css +37 -21
- package/build/styles/inputs/TextArea.css +35 -20
- package/build/styles/loader/Loader.css +4 -90
- package/build/styles/main.css +4 -94
- package/build/styles/popover/Popover.css +19 -12
- package/build/styles/select/Select.css +131 -68
- package/build/styles/switch/Switch.css +27 -16
- package/build/styles/tile/Tile.css +31 -18
- package/build/types/dateLookup/DateLookup.d.ts +2 -2
- package/build/types/dateLookup/DateLookup.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/test-utils/story-config.d.ts +2 -3
- package/build/types/test-utils/story-config.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 +19 -27
- package/src/accordion/Accordion.css +27 -16
- package/src/accordion/Accordion.story.tsx +1 -1
- package/src/actionButton/ActionButton.story.tsx +3 -2
- package/src/actionOption/ActionOption.story.tsx +2 -2
- package/src/alert/Alert.story.tsx +2 -2
- package/src/alert/Alert.tests.story.tsx +2 -2
- package/src/avatar/Avatar.css +95 -50
- package/src/avatar/Avatar.spec.tsx +1 -1
- package/src/avatar/Avatar.story.tsx +3 -2
- package/src/avatarLayout/AvatarLayout.story.tsx +1 -1
- package/src/avatarLayout/AvatarLayout.tsx +1 -1
- package/src/avatarView/AvatarView.story.tsx +1 -1
- package/src/avatarWrapper/AvatarWrapper.story.tsx +3 -2
- package/src/badge/Badge.story.tsx +49 -28
- package/src/button/Button.accessibility.docs.mdx +1 -1
- package/src/button/Button.story.tsx +2 -2
- package/src/button/Button.tests.story.tsx +2 -2
- package/src/button/LegacyButton.story.tsx +3 -2
- package/src/card/Card.story.tsx +2 -2
- package/src/carousel/Carousel.story.tsx +1 -1
- package/src/checkbox/Checkbox.story.tsx +2 -2
- package/src/checkboxButton/CheckboxButton.story.tsx +2 -2
- package/src/checkboxOption/CheckboxOption.story.tsx +35 -29
- package/src/chevron/Chevron.story.tsx +1 -1
- package/src/chips/Chips.story.tsx +1 -1
- package/src/circularButton/CircularButton.story.tsx +1 -1
- package/src/circularButton/CircularButton.tests.story.tsx +1 -1
- package/src/common/bottomSheet/BottomSheet.story.tsx +2 -2
- package/src/common/card/Card.story.tsx +1 -1
- package/src/common/circle/Circle.story.tsx +2 -2
- package/src/common/locale/index.spec.ts +28 -16
- package/src/common/responsivePanel/ResponsivePanel.spec.js +8 -29
- package/src/criticalBanner/CriticalCommsBanner.story.tsx +1 -1
- package/src/dateInput/DateInput.story.tsx +2 -2
- package/src/dateInput/DateInput.tests.story.tsx +2 -2
- package/src/dateLookup/DateLookup.spec.tsx +5 -5
- package/src/dateLookup/DateLookup.story.tsx +43 -71
- package/src/dateLookup/DateLookup.tests.story.tsx +3 -3
- package/src/dateLookup/DateLookup.tsx +4 -1
- package/src/decision/Decision.story.tsx +24 -49
- package/src/definitionList/DefinitionList.story.tsx +1 -1
- package/src/dimmer/Dimmer.story.tsx +2 -2
- package/src/divider/Divider.accessibility.docs.mdx +1 -1
- package/src/divider/Divider.story.tsx +1 -1
- package/src/drawer/Drawer.story.tsx +13 -7
- package/src/dropFade/DropFade.story.tsx +1 -1
- package/src/emphasis/Emphasis.spec.tsx +8 -8
- package/src/emphasis/Emphasis.story.tsx +1 -1
- package/src/field/Field.story.tsx +3 -3
- package/src/flowNavigation/FlowNavigation.story.tsx +305 -260
- package/src/i18n/en.json +2 -0
- package/src/iconButton/IconButton.story.tsx +2 -2
- package/src/image/Image.story.tsx +27 -54
- package/src/info/Info.story.tsx +2 -2
- package/src/inlineAlert/InlineAlert.story.tsx +1 -1
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.tsx +2 -2
- package/src/inputs/Input.css +37 -21
- package/src/inputs/InputGroup.story.tsx +1 -1
- package/src/inputs/SearchInput.story.tsx +1 -1
- package/src/inputs/SelectInput.docs.mdx +1 -1
- package/src/inputs/SelectInput.story.tsx +2 -2
- package/src/inputs/TextArea.css +35 -20
- package/src/instructionsList/InstructionsList.story.tsx +2 -2
- package/src/legacylistItem/LegacyListItem.story.tsx +1 -1
- package/src/loader/Loader.css +4 -90
- package/src/loader/Loader.story.tsx +1 -1
- package/src/logo/Logo.story.tsx +1 -1
- package/src/main.css +4 -94
- package/src/markdown/Markdown.story.tsx +1 -1
- package/src/modal/Modal.story.tsx +2 -2
- package/src/money/Money.story.tsx +1 -1
- package/src/moneyInput/MoneyInput.docs.mdx +1 -1
- package/src/moneyInput/MoneyInput.spec.tsx +8 -5
- package/src/moneyInput/MoneyInput.story.tsx +2 -2
- package/src/moneyInput/currencyFormatting.spec.ts +1 -1
- package/src/navigationOption/NavigationOption.story.tsx +265 -226
- package/src/nudge/Nudge.story.tsx +1 -1
- package/src/overlayHeader/OverlayHeader.story.tsx +32 -24
- package/src/phoneNumberInput/PhoneNumberInput.story.tsx +1 -1
- package/src/phoneNumberInput/utils/setDefaultPrefix/setDefaultPrefix.spec.ts +6 -3
- package/src/popover/Popover.css +19 -12
- package/src/popover/Popover.story.tsx +2 -2
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.story.tsx +2 -2
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.tests.story.tsx +2 -2
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.story.tsx +2 -2
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.tests.story.tsx +2 -2
- package/src/processIndicator/ProcessIndicator.story.tsx +1 -1
- package/src/progress/Progress.story.tsx +1 -1
- package/src/progressBar/ProgressBar.story.tsx +1 -1
- package/src/promoCard/PromoCard.story.tsx +1 -1
- package/src/promoCard/PromoCardGroup.story.tsx +1 -1
- package/src/provider/Provider.spec.tsx +2 -2
- package/src/provider/Provider.story.tsx +1 -1
- package/src/provider/direction/DirectionProvider.spec.tsx +1 -1
- package/src/provider/language/LanguageProvider.spec.tsx +1 -1
- package/src/provider/theme/ThemeProvider.story.tsx +1 -1
- package/src/radio/Radio.story.tsx +59 -42
- package/src/radioGroup/RadioGroup.story.tsx +2 -2
- package/src/radioOption/RadioOption.story.tsx +73 -38
- package/src/segmentedControl/SegmentedControl.story.tsx +1 -1
- package/src/select/Select.css +131 -68
- package/src/select/Select.story.tsx +385 -397
- package/src/slidingPanel/SlidingPanel.story.tsx +30 -13
- package/src/snackbar/Snackbar.story.tsx +50 -36
- package/src/snackbar/Snackbar.tests.story.tsx +3 -2
- package/src/statusIcon/StatusIcon.docs.mdx +1 -1
- package/src/statusIcon/StatusIcon.spec.tsx +8 -5
- package/src/statusIcon/StatusIcon.story.tsx +1 -1
- package/src/stepper/Stepper.story.tsx +2 -2
- package/src/stepper/Stepper.tests.story.tsx +2 -2
- package/src/sticky/Sticky.story.tsx +1 -1
- package/src/summary/Summary.story.tsx +18 -17
- package/src/switch/Switch.css +27 -16
- package/src/switch/Switch.story.tsx +2 -2
- package/src/switchOption/SwitchOption.story.tsx +1 -1
- package/src/table/Table.story.tsx +1 -1
- package/src/test-utils/story-config.ts +9 -6
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +2 -2
- package/src/tile/Tile.css +31 -18
- package/src/tile/Tile.story.tsx +43 -43
- package/src/tooltip/Tooltip.story.tsx +2 -2
- package/src/typeahead/Typeahead.story.tsx +2 -2
- package/src/upload/Upload.messages.ts +8 -0
- package/src/upload/Upload.spec.tsx +6 -0
- package/src/upload/Upload.story.tsx +120 -5
- package/src/upload/Upload.tests.story.tsx +5 -3
- package/src/upload/Upload.tsx +24 -15
- package/src/upload/utils/isTypeValid/isTypeValid.spec.ts +3 -1
- package/src/uploadInput/UploadInput.story.tsx +1 -1
- package/src/uploadInput/UploadInput.tests.story.tsx +10 -3
- 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/withId/withId.docs.mdx +1 -1
- package/src/withId/withId.story.tsx +1 -1
- package/src/common/responsivePanel/__snapshots__/ResponsivePanel.spec.js.snap +0 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { userEvent, within } from '
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
2
|
+
import { userEvent, within } from 'storybook/test';
|
|
3
3
|
|
|
4
4
|
import Button from '../button';
|
|
5
5
|
import { storyConfig } from '../test-utils';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
2
2
|
import { Search as SearchIcon } from '@transferwise/icons';
|
|
3
|
-
import { userEvent, within, fn } from '
|
|
3
|
+
import { userEvent, within, fn } from 'storybook/test';
|
|
4
4
|
|
|
5
5
|
import Typeahead, { type TypeaheadOption } from './Typeahead';
|
|
6
6
|
import { Size } from '../common';
|
|
@@ -17,6 +17,10 @@ export default defineMessages({
|
|
|
17
17
|
id: 'neptune.Upload.csTooLargeMessage',
|
|
18
18
|
defaultMessage: 'Please provide a file smaller than {maxSize}MB',
|
|
19
19
|
},
|
|
20
|
+
csTooLargeNoLimitMessage: {
|
|
21
|
+
id: 'neptune.Upload.csTooLargeNoLimitMessage',
|
|
22
|
+
defaultMessage: 'Please provide a smaller file',
|
|
23
|
+
},
|
|
20
24
|
csWrongTypeMessage: {
|
|
21
25
|
id: 'neptune.Upload.csWrongTypeMessage',
|
|
22
26
|
defaultMessage: 'File type not supported. Please try again with a different file',
|
|
@@ -41,6 +45,10 @@ export default defineMessages({
|
|
|
41
45
|
id: 'neptune.Upload.usPlaceholder',
|
|
42
46
|
defaultMessage: 'Drag and drop a file less than {maxSize}MB',
|
|
43
47
|
},
|
|
48
|
+
usPlaceholderNoLimit: {
|
|
49
|
+
id: 'neptune.Upload.usPlaceholderNoLimit',
|
|
50
|
+
defaultMessage: 'Drag and drop a file',
|
|
51
|
+
},
|
|
44
52
|
retry: {
|
|
45
53
|
id: 'neptune.Upload.retry',
|
|
46
54
|
defaultMessage: 'Retry',
|
|
@@ -355,4 +355,10 @@ describe('Upload Component', () => {
|
|
|
355
355
|
expect(container.querySelector('.droppable-processing')).not.toBeInTheDocument();
|
|
356
356
|
expect(props.onStart).not.toHaveBeenCalled();
|
|
357
357
|
});
|
|
358
|
+
|
|
359
|
+
test('should remove max size limit, when maxSize is the `null`', async () => {
|
|
360
|
+
render(<Upload {...props} usPlaceholder={undefined} maxSize={null} />);
|
|
361
|
+
expect(await screen.findByText(/Drag and drop a file/i)).toBeInTheDocument();
|
|
362
|
+
expect(screen.queryByText(/less than/i)).not.toBeInTheDocument();
|
|
363
|
+
});
|
|
358
364
|
});
|
|
@@ -1,20 +1,136 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { fn } from '
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
3
|
|
|
4
4
|
import Upload from '.';
|
|
5
5
|
import { MAX_SIZE_DEFAULT } from './Upload';
|
|
6
|
-
import { Field } from '../field/Field';
|
|
7
6
|
|
|
8
7
|
const meta = {
|
|
9
8
|
component: Upload,
|
|
10
9
|
title: 'Forms/Upload',
|
|
11
|
-
|
|
10
|
+
args: {
|
|
11
|
+
// Set all props to undefined so Storybook can auto-detect them
|
|
12
|
+
animationDelay: undefined,
|
|
13
|
+
csButtonText: undefined,
|
|
14
|
+
csFailureText: undefined,
|
|
15
|
+
csSuccessText: undefined,
|
|
16
|
+
csTooLargeMessage: undefined,
|
|
17
|
+
csWrongTypeMessage: undefined,
|
|
18
|
+
httpOptions: undefined,
|
|
19
|
+
fetcher: undefined,
|
|
20
|
+
maxSize: undefined,
|
|
21
|
+
psButtonText: undefined,
|
|
22
|
+
psButtonDisabled: undefined,
|
|
23
|
+
psProcessingText: undefined,
|
|
24
|
+
size: undefined,
|
|
25
|
+
usAccept: undefined,
|
|
26
|
+
usButtonText: undefined,
|
|
27
|
+
usButtonRetryText: undefined,
|
|
28
|
+
usDisabled: undefined,
|
|
29
|
+
usDropMessage: undefined,
|
|
30
|
+
usHelpImage: undefined,
|
|
31
|
+
usLabel: undefined,
|
|
32
|
+
usPlaceholder: undefined,
|
|
33
|
+
errorIconLabel: undefined,
|
|
34
|
+
onCancel: undefined,
|
|
35
|
+
onFailure: undefined,
|
|
36
|
+
onStart: undefined,
|
|
37
|
+
onSuccess: undefined,
|
|
38
|
+
uploadStep: undefined,
|
|
39
|
+
},
|
|
12
40
|
argTypes: {
|
|
13
41
|
maxSize: {
|
|
14
42
|
control: {
|
|
15
43
|
type: 'number',
|
|
16
44
|
min: 0,
|
|
17
45
|
},
|
|
46
|
+
description:
|
|
47
|
+
'Filesize expressed in Bytes.<br />If set to `null`, no size limit will be applied.',
|
|
48
|
+
table: {
|
|
49
|
+
type: {
|
|
50
|
+
summary: 'number | null',
|
|
51
|
+
},
|
|
52
|
+
defaultValue: {
|
|
53
|
+
summary: MAX_SIZE_DEFAULT.toString(),
|
|
54
|
+
detail: '5 MB',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
fetcher: {
|
|
59
|
+
description:
|
|
60
|
+
'You can provide a fetcher function with the same interface as the global fetch function, which is used by default.',
|
|
61
|
+
table: {
|
|
62
|
+
type: {
|
|
63
|
+
summary: 'PostDataFetcher',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
control: false,
|
|
67
|
+
},
|
|
68
|
+
usAccept: {
|
|
69
|
+
description:
|
|
70
|
+
'You can provide multiple rules separated by comma, e.g.: "application/pdf,image/*".\nUsing "*" will allow every file type to be uploaded.',
|
|
71
|
+
},
|
|
72
|
+
errorIconLabel: {
|
|
73
|
+
description:
|
|
74
|
+
"Override for the InlineAlert icon's default, accessible name announced by the screen readers",
|
|
75
|
+
},
|
|
76
|
+
usHelpImage: {
|
|
77
|
+
control: false,
|
|
78
|
+
table: {
|
|
79
|
+
type: {
|
|
80
|
+
summary: 'ReactNode',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
httpOptions: {
|
|
85
|
+
table: {
|
|
86
|
+
type: {
|
|
87
|
+
summary:
|
|
88
|
+
'PostDataHTTPOptions & { fileInputName?: string; data?: Record<string, string | Blob>; }',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
size: {
|
|
93
|
+
table: {
|
|
94
|
+
type: {
|
|
95
|
+
summary: `Size.SMALL | Size.MEDIUM | Size.LARGE`,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
uploadStep: {
|
|
100
|
+
description: '**@deprecated** Only a single variant exists, please remove this prop.',
|
|
101
|
+
table: {
|
|
102
|
+
type: {
|
|
103
|
+
summary: '"uploadImageStep"',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
onCancel: {
|
|
108
|
+
table: {
|
|
109
|
+
type: {
|
|
110
|
+
summary: '() => void',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
onFailure: {
|
|
115
|
+
table: {
|
|
116
|
+
type: {
|
|
117
|
+
summary: '(error: unknown) => void',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
onStart: {
|
|
122
|
+
table: {
|
|
123
|
+
type: {
|
|
124
|
+
summary: '(file: File) => void',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
onSuccess: {
|
|
129
|
+
table: {
|
|
130
|
+
type: {
|
|
131
|
+
summary: '(response: string | Response, fileName: string) => void',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
18
134
|
},
|
|
19
135
|
},
|
|
20
136
|
} satisfies Meta<typeof Upload>;
|
|
@@ -24,7 +140,6 @@ type Story = StoryObj<typeof meta>;
|
|
|
24
140
|
|
|
25
141
|
export const Basic: Story = {
|
|
26
142
|
args: {
|
|
27
|
-
maxSize: MAX_SIZE_DEFAULT,
|
|
28
143
|
usAccept: 'image/*',
|
|
29
144
|
usLabel: 'Front of your ID document',
|
|
30
145
|
usDisabled: false,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { Meta
|
|
2
|
-
import { fn } from '@storybook/test';
|
|
1
|
+
import type { Meta } from '@storybook/react-webpack5';
|
|
3
2
|
|
|
4
3
|
import Upload from '.';
|
|
5
|
-
import { MAX_SIZE_DEFAULT } from './Upload';
|
|
6
4
|
import { Field } from '../field/Field';
|
|
7
5
|
|
|
8
6
|
const meta = {
|
|
@@ -59,6 +57,10 @@ export const MaxSizes = () => {
|
|
|
59
57
|
<Upload usLabel="Pick a file, any file" maxSize={maxSize} />
|
|
60
58
|
</Field>
|
|
61
59
|
))}
|
|
60
|
+
|
|
61
|
+
<Field label="Max size: null (no limit)">
|
|
62
|
+
<Upload usLabel="Pick a file, any file" maxSize={null} />
|
|
63
|
+
</Field>
|
|
62
64
|
</div>
|
|
63
65
|
<div style={{ flex: 1 }}>
|
|
64
66
|
{decimalSizes.map((maxSize) => (
|
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' &&
|
|
@@ -12,7 +12,9 @@ const data64Img = 'data:image/png;something';
|
|
|
12
12
|
|
|
13
13
|
describe('isTypeValid', () => {
|
|
14
14
|
describe('when type is provided', () => {
|
|
15
|
-
|
|
15
|
+
const files = [pdfFile, pngFile] as const;
|
|
16
|
+
|
|
17
|
+
it.each(files)('returns true for wildcard rule %s', (file: (typeof files)[number]) => {
|
|
16
18
|
expect(isTypeValid(file, '*')).toBe(true);
|
|
17
19
|
});
|
|
18
20
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { action } from '
|
|
2
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
1
|
+
import { action } from 'storybook/actions';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
3
3
|
|
|
4
4
|
import { Status } from '../common';
|
|
5
5
|
import UploadInput, { UploadInputProps } from './UploadInput';
|
|
6
6
|
import { UploadedFile, UploadResponse } from './types';
|
|
7
|
-
import { userEvent } from '
|
|
7
|
+
import { userEvent } from 'storybook/test';
|
|
8
8
|
|
|
9
9
|
const meta: Meta<typeof UploadInput> = {
|
|
10
10
|
title: 'Forms/UploadInput/Tests',
|
|
@@ -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'> {
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`ResponsivePanel on desktop renders Panel 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<div
|
|
6
|
-
class="np-panel np-panel--open"
|
|
7
|
-
>
|
|
8
|
-
children
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
exports[`ResponsivePanel on mobile renders bottomSheet 1`] = `
|
|
14
|
-
<div>
|
|
15
|
-
<div
|
|
16
|
-
class="np-bottom-sheet"
|
|
17
|
-
>
|
|
18
|
-
children
|
|
19
|
-
</div>
|
|
20
|
-
</div>
|
|
21
|
-
`;
|