@react-magma/dropzone 15.0.0-rc.1 → 15.0.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/dist/fileuploader.js +1 -1
- package/dist/fileuploader.js.map +1 -1
- package/dist/fileuploader.modern.js +85 -0
- package/dist/fileuploader.modern.js.map +1 -0
- package/dist/fileuploader.modern.module.js +1 -1
- package/dist/fileuploader.modern.module.js.map +1 -1
- package/dist/fileuploader.umd.js +1 -1
- package/dist/fileuploader.umd.js.map +1 -1
- package/dist/src/src/components/dropzone/Dropzone.d.ts +101 -101
- package/dist/src/src/components/dropzone/Dropzone.stories.d.ts +48 -0
- package/dist/src/src/components/dropzone/Dropzone.test.d.ts +1 -1
- package/dist/src/src/components/dropzone/FileIcon.d.ts +8 -7
- package/dist/src/src/components/dropzone/FilePreview.d.ts +15 -15
- package/dist/src/src/components/dropzone/Preview.d.ts +18 -18
- package/dist/src/src/components/dropzone/index.d.ts +4 -4
- package/dist/src/src/components/dropzone/utils.d.ts +1 -1
- package/dist/src/src/index.d.ts +1 -1
- package/package.json +13 -16
- package/src/components/dropzone/Dropzone.stories.tsx +5 -9
- package/src/components/dropzone/Dropzone.test.js +251 -8
- package/src/components/dropzone/Dropzone.tsx +76 -36
- package/src/components/dropzone/FileIcon.tsx +48 -12
- package/src/components/dropzone/Preview.tsx +64 -23
- package/src/components/dropzone/utils.ts +0 -1
- package/dist/fileuploader.modern.mjs +0 -83
- package/dist/fileuploader.modern.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './FileIcon';
|
|
2
|
-
export * from './FilePreview';
|
|
3
|
-
export * from './Dropzone';
|
|
4
|
-
export * from './FilePreview';
|
|
1
|
+
export * from './FileIcon';
|
|
2
|
+
export * from './FilePreview';
|
|
3
|
+
export * from './Dropzone';
|
|
4
|
+
export * from './FilePreview';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const formatFileSize: (bytes: number | undefined, decimalPoint?: number, bytesLabel?: string) => string;
|
|
1
|
+
export declare const formatFileSize: (bytes: number | undefined, decimalPoint?: number, bytesLabel?: string) => string | undefined;
|
package/dist/src/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './components/dropzone';
|
|
1
|
+
export * from './components/dropzone';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/dropzone",
|
|
3
|
-
"version": "15.0.0
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,30 +20,27 @@
|
|
|
20
20
|
"build": "microbundle build --jsx jsx --jsxImportSource react --globals react/jsx-runtime=jsx",
|
|
21
21
|
"build-watch": "microbundle watch --jsx jsx --jsxImportSource react --globals react/jsx-runtime=jsx",
|
|
22
22
|
"lint": "eslint ./src",
|
|
23
|
-
"lint:fix": "eslint ./src --fix",
|
|
24
|
-
"lint:check": "eslint ./src --max-warnings=0",
|
|
25
23
|
"test": "jest",
|
|
26
|
-
"test-watch": "jest --watch"
|
|
27
|
-
"compiler-checks": "tsc --noEmit --project ./tsconfig.json"
|
|
24
|
+
"test-watch": "jest --watch"
|
|
28
25
|
},
|
|
29
26
|
"dependencies": {
|
|
30
|
-
"polished": "3.7.2",
|
|
27
|
+
"polished": "^3.7.2",
|
|
31
28
|
"react-dropzone": "11.3.2"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@emotion/react": "11.
|
|
35
|
-
"@emotion/styled": "11.
|
|
36
|
-
"react": "
|
|
37
|
-
"react-dom": "
|
|
38
|
-
"react-magma-dom": "^
|
|
31
|
+
"@emotion/react": "^11.13.0",
|
|
32
|
+
"@emotion/styled": "^11.13.0",
|
|
33
|
+
"react": "^17.0.2",
|
|
34
|
+
"react-dom": "^17.0.2",
|
|
35
|
+
"react-magma-dom": "^6.0.0",
|
|
39
36
|
"react-magma-icons": "^3.2.5"
|
|
40
37
|
},
|
|
41
38
|
"peerDependencies": {
|
|
42
|
-
"@emotion/react": "11.
|
|
43
|
-
"@emotion/styled": "11.
|
|
44
|
-
"react": "
|
|
45
|
-
"react-dom": "
|
|
46
|
-
"react-magma-dom": "^
|
|
39
|
+
"@emotion/react": "^11.13.0",
|
|
40
|
+
"@emotion/styled": "^11.13.0",
|
|
41
|
+
"react": "^17.0.2",
|
|
42
|
+
"react-dom": "^17.0.2",
|
|
43
|
+
"react-magma-dom": "^6.0.0",
|
|
47
44
|
"react-magma-icons": "^3.2.5"
|
|
48
45
|
},
|
|
49
46
|
"engines": {
|
|
@@ -86,7 +86,7 @@ export const Default = {
|
|
|
86
86
|
return (
|
|
87
87
|
<div
|
|
88
88
|
style={{
|
|
89
|
-
background: args.isInverse ? magma.colors.
|
|
89
|
+
background: args.isInverse ? magma.colors.neutral1100 : 'none',
|
|
90
90
|
padding: '24px',
|
|
91
91
|
}}
|
|
92
92
|
>
|
|
@@ -116,7 +116,7 @@ export const NoLimits = {
|
|
|
116
116
|
return (
|
|
117
117
|
<div
|
|
118
118
|
style={{
|
|
119
|
-
background: args.isInverse ? magma.colors.
|
|
119
|
+
background: args.isInverse ? magma.colors.neutral1100 : 'none',
|
|
120
120
|
padding: '24px',
|
|
121
121
|
}}
|
|
122
122
|
>
|
|
@@ -138,7 +138,6 @@ export const Image = {
|
|
|
138
138
|
const onSendFile = (props: OnSendFileProps) => {
|
|
139
139
|
const { file, onFinish } = props;
|
|
140
140
|
const reader = new FileReader();
|
|
141
|
-
|
|
142
141
|
reader.onload = function (evt) {
|
|
143
142
|
setFile(
|
|
144
143
|
(evt &&
|
|
@@ -159,7 +158,7 @@ export const Image = {
|
|
|
159
158
|
return (
|
|
160
159
|
<div
|
|
161
160
|
style={{
|
|
162
|
-
background: args.isInverse ? magma.colors.
|
|
161
|
+
background: args.isInverse ? magma.colors.neutral1100 : 'none',
|
|
163
162
|
padding: '24px',
|
|
164
163
|
}}
|
|
165
164
|
>
|
|
@@ -184,7 +183,6 @@ export const Text = {
|
|
|
184
183
|
const onSendFile = (props: OnSendFileProps) => {
|
|
185
184
|
const { file, onFinish } = props;
|
|
186
185
|
const reader = new FileReader();
|
|
187
|
-
|
|
188
186
|
reader.onload = function (evt) {
|
|
189
187
|
setFile(
|
|
190
188
|
(evt &&
|
|
@@ -205,7 +203,7 @@ export const Text = {
|
|
|
205
203
|
return (
|
|
206
204
|
<div
|
|
207
205
|
style={{
|
|
208
|
-
background: args.isInverse ? magma.colors.
|
|
206
|
+
background: args.isInverse ? magma.colors.neutral1100 : 'none',
|
|
209
207
|
padding: '24px',
|
|
210
208
|
}}
|
|
211
209
|
>
|
|
@@ -231,7 +229,6 @@ export const Csv = {
|
|
|
231
229
|
const onSendFile = (props: OnSendFileProps) => {
|
|
232
230
|
const { file, onFinish } = props;
|
|
233
231
|
const reader = new FileReader();
|
|
234
|
-
|
|
235
232
|
reader.onload = function (evt) {
|
|
236
233
|
const [columns, rows] =
|
|
237
234
|
(evt &&
|
|
@@ -239,7 +236,6 @@ export const Csv = {
|
|
|
239
236
|
evt.target.result &&
|
|
240
237
|
csvJSON(evt.target.result.toString())) ||
|
|
241
238
|
[];
|
|
242
|
-
|
|
243
239
|
setColumns(columns);
|
|
244
240
|
setFile(rows);
|
|
245
241
|
onFinish && onFinish({ file });
|
|
@@ -253,7 +249,7 @@ export const Csv = {
|
|
|
253
249
|
return (
|
|
254
250
|
<div
|
|
255
251
|
style={{
|
|
256
|
-
background: args.isInverse ? magma.colors.
|
|
252
|
+
background: args.isInverse ? magma.colors.neutral1100 : 'none',
|
|
257
253
|
padding: '24px',
|
|
258
254
|
}}
|
|
259
255
|
>
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
cleanup,
|
|
5
|
+
render,
|
|
6
|
+
fireEvent,
|
|
7
|
+
waitFor,
|
|
8
|
+
within,
|
|
9
|
+
} from '@testing-library/react';
|
|
4
10
|
import userEvent from '@testing-library/user-event';
|
|
11
|
+
import { transparentize } from 'polished';
|
|
5
12
|
import { I18nContext, defaultI18n, magma } from 'react-magma-dom';
|
|
6
13
|
|
|
14
|
+
import { FileIcon } from './FileIcon';
|
|
15
|
+
import { Preview } from './Preview';
|
|
7
16
|
import { axe } from '../../../axe-helper.js';
|
|
8
17
|
|
|
9
18
|
import { Dropzone } from '.';
|
|
@@ -113,6 +122,212 @@ describe('File Uploader', () => {
|
|
|
113
122
|
expect(input).toHaveAttribute('multiple');
|
|
114
123
|
});
|
|
115
124
|
|
|
125
|
+
it('uses the regular rebrand colors', () => {
|
|
126
|
+
const helperMessage = 'Upload a supported file.';
|
|
127
|
+
const labelText = 'Upload files';
|
|
128
|
+
const { container, getByTestId, getByText } = render(
|
|
129
|
+
<Dropzone
|
|
130
|
+
helperMessage={helperMessage}
|
|
131
|
+
labelText={labelText}
|
|
132
|
+
testId="testId"
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(getByTestId('testId')).toHaveStyle({
|
|
137
|
+
backgroundColor: magma.colors.neutral100,
|
|
138
|
+
border: `2px dashed ${magma.colors.neutral300}`,
|
|
139
|
+
borderRadius: magma.borderRadiusSmall,
|
|
140
|
+
});
|
|
141
|
+
expect(
|
|
142
|
+
within(container).getByText(defaultI18n.dropzone.dragMessage)
|
|
143
|
+
).toHaveStyle({
|
|
144
|
+
color: magma.colors.brand.navy,
|
|
145
|
+
});
|
|
146
|
+
expect(within(container).getByText(helperMessage)).toHaveStyle({
|
|
147
|
+
color: magma.colors.neutral700,
|
|
148
|
+
});
|
|
149
|
+
expect(within(container).getByText(labelText)).toHaveStyle({
|
|
150
|
+
color: magma.colors.brand.navy,
|
|
151
|
+
});
|
|
152
|
+
expect(container.querySelector('svg[aria-hidden="true"]')).toHaveAttribute(
|
|
153
|
+
'fill',
|
|
154
|
+
magma.colors.neutral700
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('uses the inverse rebrand colors', () => {
|
|
159
|
+
const helperMessage = 'Upload a supported file.';
|
|
160
|
+
const { getByTestId, getByText } = render(
|
|
161
|
+
<Dropzone helperMessage={helperMessage} isInverse testId="testId" />
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(getByTestId('testId')).toHaveStyle({
|
|
165
|
+
backgroundColor: transparentize(0.6, magma.colors.neutral1200),
|
|
166
|
+
border: `2px dashed ${magma.colors.neutral800}`,
|
|
167
|
+
});
|
|
168
|
+
expect(getByText(helperMessage)).toHaveStyle({
|
|
169
|
+
color: magma.colors.neutral500,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('uses the rebrand colors for default file icons', () => {
|
|
174
|
+
const file = createFile('file.bin', 1111, 'application/octet-stream');
|
|
175
|
+
const { container, rerender } = render(<FileIcon file={file} />);
|
|
176
|
+
|
|
177
|
+
expect(container.querySelector('svg')).toHaveStyle({
|
|
178
|
+
color: magma.colors.neutral700,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
rerender(<FileIcon file={file} isInverse />);
|
|
182
|
+
|
|
183
|
+
expect(container.querySelector('svg')).toHaveStyle({
|
|
184
|
+
color: magma.colors.neutral300,
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it.each([
|
|
189
|
+
['word', 'docx', 'application/msword', 'blue500', 'blue500'],
|
|
190
|
+
['excel', 'xlsx', 'application/vnd.ms-excel', 'green500', 'green500'],
|
|
191
|
+
[
|
|
192
|
+
'powerpoint',
|
|
193
|
+
'pptx',
|
|
194
|
+
'application/vnd.ms-powerpoint',
|
|
195
|
+
'tangerine600',
|
|
196
|
+
'tangerine500',
|
|
197
|
+
],
|
|
198
|
+
['pdf', 'pdf', 'application/pdf', 'red600', 'red500'],
|
|
199
|
+
['image', 'png', 'image/png', 'neutral700', 'neutral300'],
|
|
200
|
+
['video', 'mp4', 'video/mp4', 'neutral700', 'neutral300'],
|
|
201
|
+
['audio', 'mp3', 'audio/mpeg', 'neutral700', 'neutral300'],
|
|
202
|
+
['archive', 'zip', 'application/zip', 'neutral700', 'neutral300'],
|
|
203
|
+
])(
|
|
204
|
+
'uses the rebrand colors for %s file icons',
|
|
205
|
+
(_name, extension, type, regularColor, inverseColor) => {
|
|
206
|
+
const file = createFile(`file.${extension}`, 1111, type);
|
|
207
|
+
Object.defineProperty(file, 'path', {
|
|
208
|
+
value: `file.${extension}`,
|
|
209
|
+
});
|
|
210
|
+
const { container, rerender } = render(<FileIcon file={file} />);
|
|
211
|
+
|
|
212
|
+
expect(container.querySelector('svg')).toHaveStyle({
|
|
213
|
+
color: magma.colors[regularColor],
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
rerender(<FileIcon file={file} isInverse />);
|
|
217
|
+
|
|
218
|
+
expect(container.querySelector('svg')).toHaveStyle({
|
|
219
|
+
color: magma.colors[inverseColor],
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
it('uses brand navy for regular preview text', () => {
|
|
225
|
+
const { getByText } = render(
|
|
226
|
+
<Preview
|
|
227
|
+
file={files[0]}
|
|
228
|
+
isInverse={false}
|
|
229
|
+
testId="preview"
|
|
230
|
+
thumbnails={false}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const previewCard = getByText(files[0].name).parentElement.parentElement;
|
|
235
|
+
|
|
236
|
+
expect(previewCard).toHaveStyle({
|
|
237
|
+
borderColor: magma.colors.neutral200,
|
|
238
|
+
borderRadius: magma.borderRadiusSmall,
|
|
239
|
+
color: magma.colors.brand.navy,
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('uses the inverse rebrand colors for the default preview', () => {
|
|
244
|
+
const { getByText } = render(
|
|
245
|
+
<Preview file={files[0]} isInverse thumbnails={false} />
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const previewCard = getByText(files[0].name).parentElement.parentElement;
|
|
249
|
+
|
|
250
|
+
expect(previewCard).toHaveStyle({
|
|
251
|
+
borderColor: magma.colors.neutral800,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('uses the inverse rebrand colors for pending and successful previews', async () => {
|
|
256
|
+
const pendingFile = files[0];
|
|
257
|
+
pendingFile.processor = { status: 'pending', percent: '25%' };
|
|
258
|
+
|
|
259
|
+
const { container, getByLabelText, rerender } = render(
|
|
260
|
+
<Preview file={pendingFile} isInverse thumbnails={false} />
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
await waitFor(() => {
|
|
264
|
+
expect(getByLabelText('Loading')).toHaveAttribute(
|
|
265
|
+
'color',
|
|
266
|
+
magma.colors.brand.skyBlue
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const successfulFile = createFile(
|
|
271
|
+
'successful-file.pdf',
|
|
272
|
+
1111,
|
|
273
|
+
'application/pdf'
|
|
274
|
+
);
|
|
275
|
+
successfulFile.processor = { status: 'success', percent: '100%' };
|
|
276
|
+
|
|
277
|
+
rerender(<Preview file={successfulFile} isInverse thumbnails={false} />);
|
|
278
|
+
|
|
279
|
+
await waitFor(() => {
|
|
280
|
+
expect(
|
|
281
|
+
container.querySelector(`svg[fill="${magma.colors.green500}"]`)
|
|
282
|
+
).toBeInTheDocument();
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('uses the inverse rebrand colors for preview errors', () => {
|
|
287
|
+
const errorFile = files[0];
|
|
288
|
+
errorFile.errors = [
|
|
289
|
+
{
|
|
290
|
+
code: 'file-invalid-type',
|
|
291
|
+
message: 'Invalid file type',
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
const { container, getByText } = render(
|
|
296
|
+
<Preview
|
|
297
|
+
accept="application/pdf"
|
|
298
|
+
file={errorFile}
|
|
299
|
+
isInverse
|
|
300
|
+
thumbnails={false}
|
|
301
|
+
/>
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const previewCard = getByText(errorFile.name).parentElement.parentElement;
|
|
305
|
+
|
|
306
|
+
expect(previewCard).toHaveStyle({
|
|
307
|
+
borderColor: magma.colors.red500,
|
|
308
|
+
});
|
|
309
|
+
expect(
|
|
310
|
+
container.querySelector(`svg[fill="${magma.colors.red500}"]`)
|
|
311
|
+
).toBeInTheDocument();
|
|
312
|
+
|
|
313
|
+
const errorHeading = getByText('Invalid File Type');
|
|
314
|
+
expect(errorHeading).toHaveStyle({ color: magma.colors.red500 });
|
|
315
|
+
expect(errorHeading.parentElement).toHaveStyle({
|
|
316
|
+
borderTopColor: magma.colors.neutral500,
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('uses a subtle link IconButton for preview actions', () => {
|
|
321
|
+
const { getByLabelText } = render(
|
|
322
|
+
<Preview file={files[0]} isInverse={false} thumbnails={false} />
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect(getByLabelText(`Remove file ${files[0].name}`)).toHaveAttribute(
|
|
326
|
+
'color',
|
|
327
|
+
'subtle'
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
|
|
116
331
|
it('allows adding files via drop', () => {
|
|
117
332
|
const { container } = render(<Dropzone />);
|
|
118
333
|
|
|
@@ -136,7 +351,7 @@ describe('File Uploader', () => {
|
|
|
136
351
|
const dropzone = getByTestId(testId);
|
|
137
352
|
|
|
138
353
|
expect(dropzone).toHaveStyle(
|
|
139
|
-
`border:
|
|
354
|
+
`border: 2px dashed ${magma.colors.neutral300}`
|
|
140
355
|
);
|
|
141
356
|
|
|
142
357
|
fireDragEnter(dropzone, data);
|
|
@@ -145,7 +360,7 @@ describe('File Uploader', () => {
|
|
|
145
360
|
|
|
146
361
|
await waitFor(() => {
|
|
147
362
|
expect(dropzone).toHaveStyle(
|
|
148
|
-
`border:
|
|
363
|
+
`border: 2px dashed ${magma.colors.green500}`
|
|
149
364
|
);
|
|
150
365
|
});
|
|
151
366
|
});
|
|
@@ -160,7 +375,7 @@ describe('File Uploader', () => {
|
|
|
160
375
|
|
|
161
376
|
const dropzone = getByTestId(testId);
|
|
162
377
|
expect(dropzone).toHaveStyle(
|
|
163
|
-
`border:
|
|
378
|
+
`border: 2px dashed ${magma.colors.neutral300}`
|
|
164
379
|
);
|
|
165
380
|
|
|
166
381
|
fireDragEnter(dropzone, data);
|
|
@@ -168,7 +383,35 @@ describe('File Uploader', () => {
|
|
|
168
383
|
rerender(ui);
|
|
169
384
|
|
|
170
385
|
await waitFor(() => {
|
|
171
|
-
expect(dropzone).toHaveStyle(`border:
|
|
386
|
+
expect(dropzone).toHaveStyle(`border: 2px dashed ${magma.colors.danger}`);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('uses red400 for inverse rejection borders', async () => {
|
|
391
|
+
const data = createDtWithFiles(files);
|
|
392
|
+
const testId = 'testId';
|
|
393
|
+
const ui = <Dropzone accept="image/*" isInverse testId={testId} />;
|
|
394
|
+
const { getByTestId, rerender } = render(ui);
|
|
395
|
+
const dropzone = getByTestId(testId);
|
|
396
|
+
|
|
397
|
+
fireDragEnter(dropzone, data);
|
|
398
|
+
rerender(ui);
|
|
399
|
+
|
|
400
|
+
await waitFor(() => {
|
|
401
|
+
expect(dropzone).toHaveStyle(`border: 2px dashed ${magma.colors.red400}`);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it('uses red500 for inverse error borders', async () => {
|
|
406
|
+
const { getByTestId } = render(
|
|
407
|
+
<Dropzone isInverse minFiles={1} testId="testId" />
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
await waitFor(() => {
|
|
411
|
+
expect(getByTestId('testId')).toHaveStyle({
|
|
412
|
+
borderColor: magma.colors.red500,
|
|
413
|
+
borderWidth: '1px',
|
|
414
|
+
});
|
|
172
415
|
});
|
|
173
416
|
});
|
|
174
417
|
|
|
@@ -521,7 +764,7 @@ describe('File Uploader', () => {
|
|
|
521
764
|
});
|
|
522
765
|
|
|
523
766
|
// TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
|
|
524
|
-
|
|
767
|
+
it.skip('changes to delete file on finish', async () => {
|
|
525
768
|
const onSendFile = ({ file, onFinish }) => {
|
|
526
769
|
onFinish({ file });
|
|
527
770
|
};
|
|
@@ -545,7 +788,7 @@ describe('File Uploader', () => {
|
|
|
545
788
|
});
|
|
546
789
|
|
|
547
790
|
// TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
|
|
548
|
-
|
|
791
|
+
it.skip('deletes the file when the Delete File icon is clicked', async () => {
|
|
549
792
|
const onSendFile = ({ file, onFinish }) => {
|
|
550
793
|
onFinish({ file });
|
|
551
794
|
};
|
|
@@ -579,7 +822,7 @@ describe('File Uploader', () => {
|
|
|
579
822
|
});
|
|
580
823
|
|
|
581
824
|
// TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
|
|
582
|
-
|
|
825
|
+
it.skip('calls onDeleteFile when the Delete File icon is clicked', async () => {
|
|
583
826
|
const onDeleteFileSpy = jest.fn();
|
|
584
827
|
const onSendFile = ({ file, onFinish }) => {
|
|
585
828
|
onFinish({ file });
|
|
@@ -46,12 +46,13 @@ export interface OnSendFileProps {
|
|
|
46
46
|
onProgress?: ({}: { percent: number; file: FilePreview }) => void;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
enum DragState {
|
|
50
|
+
error = 'error',
|
|
51
|
+
dragAccept = 'dragAccept',
|
|
52
|
+
dragReject = 'dragReject',
|
|
53
|
+
dragActive = 'dragActive',
|
|
54
|
+
default = 'default',
|
|
55
|
+
}
|
|
55
56
|
|
|
56
57
|
// NOTE: These props are manually copied to dropzone.mdx
|
|
57
58
|
export interface DropzoneProps
|
|
@@ -133,6 +134,54 @@ export interface DropzoneProps
|
|
|
133
134
|
thumbnails?: boolean;
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
const getErrorBorderColor = (
|
|
138
|
+
dragState: DragState,
|
|
139
|
+
theme: ThemeInterface,
|
|
140
|
+
isInverse?: boolean
|
|
141
|
+
) => {
|
|
142
|
+
if (!isInverse) {
|
|
143
|
+
return theme.colors.danger;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return dragState === DragState.error
|
|
147
|
+
? theme.colors.red500
|
|
148
|
+
: theme.colors.red400;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const getContainerBorder = ({
|
|
152
|
+
dragState = DragState.default,
|
|
153
|
+
noDrag,
|
|
154
|
+
theme,
|
|
155
|
+
isInverse,
|
|
156
|
+
}: {
|
|
157
|
+
dragState?: DragState;
|
|
158
|
+
noDrag?: boolean;
|
|
159
|
+
theme: ThemeInterface;
|
|
160
|
+
isInverse?: boolean;
|
|
161
|
+
}) => {
|
|
162
|
+
if (noDrag) {
|
|
163
|
+
return '0px';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (dragState === DragState.dragReject || dragState === DragState.error) {
|
|
167
|
+
const width = dragState === DragState.error ? '1px' : '2px';
|
|
168
|
+
|
|
169
|
+
return `${width} dashed ${getErrorBorderColor(dragState, theme, isInverse)}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (dragState === DragState.dragActive) {
|
|
173
|
+
return `2px dashed ${theme.colors.blue500}`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (dragState === DragState.dragAccept) {
|
|
177
|
+
return `2px dashed ${theme.colors.green500}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return `2px dashed ${
|
|
181
|
+
isInverse ? theme.colors.neutral800 : theme.colors.neutral300
|
|
182
|
+
}`;
|
|
183
|
+
};
|
|
184
|
+
|
|
136
185
|
const Container = styled(Flex)<
|
|
137
186
|
DropzoneRootProps &
|
|
138
187
|
FlexProps & {
|
|
@@ -146,35 +195,25 @@ const Container = styled(Flex)<
|
|
|
146
195
|
justify-content: ${({ noDrag }) => (noDrag ? 'left' : 'center')};
|
|
147
196
|
text-align: ${({ noDrag }) => (noDrag ? 'left' : 'center')};
|
|
148
197
|
padding: ${({ noDrag }) => (noDrag ? '0px' : '24px')};
|
|
149
|
-
border-radius: ${({ noDrag }) =>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
? `1px dashed ${theme.colors.danger300}`
|
|
156
|
-
: `1px dashed ${theme.colors.danger}`
|
|
157
|
-
: dragState === 'dragActive'
|
|
158
|
-
? `1px dashed ${theme.colors.primary}`
|
|
159
|
-
: dragState === 'dragAccept'
|
|
160
|
-
? `1px dashed ${theme.colors.success}`
|
|
161
|
-
: `1px dashed ${theme.colors.neutral400}`};
|
|
162
|
-
|
|
163
|
-
border-style: ${({ dragState = 'default' }) =>
|
|
164
|
-
dragState === 'error' ? 'solid' : 'dashed'};
|
|
198
|
+
border-radius: ${({ noDrag, theme }) =>
|
|
199
|
+
noDrag ? theme.borderRadiusNone : theme.borderRadiusSmall};
|
|
200
|
+
border: ${getContainerBorder};
|
|
201
|
+
|
|
202
|
+
border-style: ${({ dragState = DragState.default }) =>
|
|
203
|
+
dragState === DragState.error ? 'solid' : 'dashed'};
|
|
165
204
|
background-color: ${({ theme, noDrag, isInverse }) =>
|
|
166
205
|
noDrag
|
|
167
206
|
? 'transparent'
|
|
168
207
|
: isInverse
|
|
169
|
-
? transparentize(0.
|
|
170
|
-
: theme.colors.
|
|
208
|
+
? transparentize(0.6, theme.colors.neutral1200)
|
|
209
|
+
: theme.colors.neutral100};
|
|
171
210
|
outline: none;
|
|
172
211
|
transition: ${({ noDrag }) => `border ${noDrag ? 0 : '.24s'} ease-in-out`};
|
|
173
212
|
`;
|
|
174
213
|
|
|
175
214
|
const HelperMessage = styled.span<{ isInverse?: boolean }>`
|
|
176
215
|
color: ${({ theme, isInverse }) =>
|
|
177
|
-
isInverse ? theme.colors.
|
|
216
|
+
isInverse ? theme.colors.neutral500 : theme.colors.neutral700};
|
|
178
217
|
display: block;
|
|
179
218
|
font-size: 14px;
|
|
180
219
|
margin: -8px 0 16px 0;
|
|
@@ -182,7 +221,7 @@ const HelperMessage = styled.span<{ isInverse?: boolean }>`
|
|
|
182
221
|
|
|
183
222
|
const Wrapper = styled.div<{ isInverse?: boolean }>`
|
|
184
223
|
color: ${({ theme, isInverse }) =>
|
|
185
|
-
isInverse ? theme.colors.
|
|
224
|
+
isInverse ? theme.colors.neutral0 : theme.colors.brand.navy};
|
|
186
225
|
margin: 0 0 24px 0;
|
|
187
226
|
font-size: ${({ theme }) => theme.typeScale.size02.fontSize};
|
|
188
227
|
line-height: ${({ theme }) => theme.typeScale.size02.lineHeight};
|
|
@@ -203,7 +242,7 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
203
242
|
accept,
|
|
204
243
|
containerStyle,
|
|
205
244
|
disabled,
|
|
206
|
-
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
207
246
|
dropzoneOptions = {
|
|
208
247
|
multiple: true,
|
|
209
248
|
},
|
|
@@ -303,16 +342,16 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
303
342
|
|
|
304
343
|
const inputProps = getInputProps({ id });
|
|
305
344
|
|
|
306
|
-
let dragState
|
|
345
|
+
let dragState = DragState.default;
|
|
307
346
|
|
|
308
347
|
if (errorMessage) {
|
|
309
|
-
dragState =
|
|
348
|
+
dragState = DragState.error;
|
|
310
349
|
} else if (isDragAccept) {
|
|
311
|
-
dragState =
|
|
350
|
+
dragState = DragState.dragAccept;
|
|
312
351
|
} else if (isDragReject) {
|
|
313
|
-
dragState =
|
|
352
|
+
dragState = DragState.dragReject;
|
|
314
353
|
} else if (isDragActive) {
|
|
315
|
-
dragState =
|
|
354
|
+
dragState = DragState.dragActive;
|
|
316
355
|
}
|
|
317
356
|
|
|
318
357
|
const handleRemoveFile = (removedFile: FilePreview) => {
|
|
@@ -493,7 +532,10 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
493
532
|
inputSize={inputSize}
|
|
494
533
|
isInverse={isInverse}
|
|
495
534
|
isLabelVisuallyHidden={isLabelVisuallyHidden}
|
|
496
|
-
labelStyle={
|
|
535
|
+
labelStyle={{
|
|
536
|
+
color: isInverse ? theme.colors.neutral0 : theme.colors.brand.navy,
|
|
537
|
+
...labelStyle,
|
|
538
|
+
}}
|
|
497
539
|
labelText={labelText}
|
|
498
540
|
messageStyle={{ minHeight: 0 }}
|
|
499
541
|
data-testid={testId}
|
|
@@ -548,9 +590,7 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
548
590
|
<CloudUploadIcon
|
|
549
591
|
aria-hidden="true"
|
|
550
592
|
color={
|
|
551
|
-
isInverse
|
|
552
|
-
? theme.colors.neutral100
|
|
553
|
-
: theme.colors.neutral500
|
|
593
|
+
isInverse ? theme.colors.neutral0 : theme.colors.neutral700
|
|
554
594
|
}
|
|
555
595
|
size={48}
|
|
556
596
|
/>
|