@popsure/dirty-swan 0.38.1 → 0.38.3
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/cjs/index.js +19 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/icon/IconWrapper/IconWrapper.js +4 -1
- package/dist/esm/components/icon/IconWrapper/IconWrapper.js.map +1 -1
- package/dist/esm/components/icon/icons.stories.js +1 -1
- package/dist/esm/components/icon/index.stories.js +1 -1
- package/dist/esm/components/multiDropzone/index.js +15 -12
- package/dist/esm/components/multiDropzone/index.js.map +1 -1
- package/dist/esm/components/multiDropzone/index.test.js +71 -51
- package/dist/esm/components/multiDropzone/index.test.js.map +1 -1
- package/dist/esm/{index-38cf6d96.js → index-dcf47451.js} +1 -1
- package/dist/esm/{index-38cf6d96.js.map → index-dcf47451.js.map} +1 -1
- package/package.json +1 -1
- package/src/lib/components/icon/IconWrapper/IconWrapper.tsx +5 -1
- package/src/lib/components/multiDropzone/index.test.tsx +101 -81
- package/src/lib/components/multiDropzone/index.tsx +52 -40
- package/src/lib/components/multiDropzone/style.module.scss +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react';
|
|
1
|
+
import { useCallback, useState, useRef } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import { useDropzone, FileRejection } from 'react-dropzone';
|
|
4
4
|
import AnimateHeight from 'react-animate-height';
|
|
@@ -6,20 +6,20 @@ import generateId from '../../util/generateId';
|
|
|
6
6
|
import styles from './style.module.scss';
|
|
7
7
|
import icons from './icons/index'; // TODO: inline all of the svgs
|
|
8
8
|
import UploadFileCell from './UploadFileCell';
|
|
9
|
-
import {
|
|
10
|
-
formatAcceptFileList,
|
|
11
|
-
getErrorMessage,
|
|
12
|
-
getFormattedAcceptObject,
|
|
13
|
-
getUploadStatus
|
|
9
|
+
import {
|
|
10
|
+
formatAcceptFileList,
|
|
11
|
+
getErrorMessage,
|
|
12
|
+
getFormattedAcceptObject,
|
|
13
|
+
getUploadStatus,
|
|
14
14
|
} from './utils';
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
AcceptType,
|
|
18
|
-
ErrorMessage,
|
|
16
|
+
import {
|
|
17
|
+
AcceptType,
|
|
18
|
+
ErrorMessage,
|
|
19
19
|
FileType,
|
|
20
|
-
TextOverrides,
|
|
21
|
-
UploadedFile,
|
|
22
|
-
UploadStatus
|
|
20
|
+
TextOverrides,
|
|
21
|
+
UploadedFile,
|
|
22
|
+
UploadStatus,
|
|
23
23
|
} from './types';
|
|
24
24
|
|
|
25
25
|
import { formatBytes } from '../../util/formatBytes';
|
|
@@ -50,21 +50,23 @@ const MultiDropzone = ({
|
|
|
50
50
|
const [errors, setErrors] = useState<ErrorMessage[]>([]);
|
|
51
51
|
const formattedAccept = getFormattedAcceptObject(accept);
|
|
52
52
|
const fileList = formatAcceptFileList(formattedAccept);
|
|
53
|
-
const maxSizePlaceholder =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const maxSizePlaceholder =
|
|
54
|
+
maxSize && maxSize > 0
|
|
55
|
+
? `${textOverrides?.sizeUpToText || 'up to'} ${formatBytes(maxSize)}`
|
|
56
|
+
: '';
|
|
57
|
+
const placeholder = `${textOverrides?.supportsTextShort || 'Supports'} ${
|
|
58
|
+
fileList || 'JPEG, PNG, PDF'
|
|
59
|
+
} ${maxSizePlaceholder}`;
|
|
57
60
|
const isOverMaxFiles = maxFiles > 0 && uploadedFiles.length > maxFiles;
|
|
58
61
|
|
|
59
|
-
const removeError = (removeId: string) =>
|
|
60
|
-
setErrors(errors.filter(({ id }) => id !== removeId))
|
|
61
|
-
);
|
|
62
|
+
const removeError = (removeId: string) =>
|
|
63
|
+
setErrors(errors.filter(({ id }) => id !== removeId));
|
|
62
64
|
|
|
63
65
|
const onDrop = useCallback(
|
|
64
66
|
(acceptedFiles: File[], filesRejected: FileRejection[]) => {
|
|
65
67
|
onFileSelect(acceptedFiles);
|
|
66
68
|
|
|
67
|
-
setErrors((previousErrors) =>
|
|
69
|
+
setErrors((previousErrors) => [
|
|
68
70
|
...previousErrors,
|
|
69
71
|
...filesRejected.map(({ errors }) => ({
|
|
70
72
|
id: generateId(),
|
|
@@ -73,13 +75,12 @@ const placeholder = `${textOverrides?.supportsTextShort || "Supports"} ${fileLis
|
|
|
73
75
|
{ fileList, maxSize },
|
|
74
76
|
textOverrides
|
|
75
77
|
),
|
|
76
|
-
}))
|
|
77
|
-
])
|
|
78
|
+
})),
|
|
79
|
+
]);
|
|
78
80
|
},
|
|
79
81
|
[fileList, maxSize, onFileSelect, textOverrides]
|
|
80
82
|
);
|
|
81
83
|
|
|
82
|
-
|
|
83
84
|
const { getRootProps, getInputProps } = useDropzone({
|
|
84
85
|
accept: formattedAccept,
|
|
85
86
|
disabled: uploading,
|
|
@@ -87,6 +88,8 @@ const placeholder = `${textOverrides?.supportsTextShort || "Supports"} ${fileLis
|
|
|
87
88
|
onDrop,
|
|
88
89
|
});
|
|
89
90
|
|
|
91
|
+
const uniqueId = useRef(generateId());
|
|
92
|
+
|
|
90
93
|
return (
|
|
91
94
|
<div className={styles.container}>
|
|
92
95
|
<div
|
|
@@ -100,6 +103,7 @@ const placeholder = `${textOverrides?.supportsTextShort || "Supports"} ${fileLis
|
|
|
100
103
|
>
|
|
101
104
|
<input
|
|
102
105
|
data-testid="ds-drop-input"
|
|
106
|
+
id={uniqueId.current}
|
|
103
107
|
{...getInputProps()}
|
|
104
108
|
/>
|
|
105
109
|
<img
|
|
@@ -107,31 +111,39 @@ const placeholder = `${textOverrides?.supportsTextShort || "Supports"} ${fileLis
|
|
|
107
111
|
src={isCondensed ? icons.uploadSmallIcon : icons.uploadIcon}
|
|
108
112
|
alt="purple cloud with an arrow"
|
|
109
113
|
/>
|
|
110
|
-
<
|
|
114
|
+
<label
|
|
115
|
+
htmlFor={uniqueId.current}
|
|
116
|
+
className={`p-h4 mt8 d-block c-pointer ${
|
|
117
|
+
isCondensed ? styles.textInline : ''
|
|
118
|
+
}`}
|
|
119
|
+
>
|
|
111
120
|
{uploading
|
|
112
121
|
? textOverrides?.currentlyUploadingText ||
|
|
113
122
|
'Please wait while uploading file...'
|
|
114
123
|
: textOverrides?.instructionsText || 'Choose file or drag & drop'}
|
|
115
|
-
</
|
|
124
|
+
</label>
|
|
116
125
|
<div className="p-p--small tc-grey-500">
|
|
117
126
|
{textOverrides?.supportsText || placeholder}
|
|
118
127
|
</div>
|
|
119
128
|
</div>
|
|
120
129
|
|
|
121
|
-
{errors.map(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
{errors.map(
|
|
131
|
+
({ id, message }) =>
|
|
132
|
+
message && (
|
|
133
|
+
<UploadFileCell
|
|
134
|
+
uploadStatus="ERROR"
|
|
135
|
+
file={{
|
|
136
|
+
error: message,
|
|
137
|
+
id,
|
|
138
|
+
name: message,
|
|
139
|
+
progress: 0,
|
|
140
|
+
}}
|
|
141
|
+
key={id}
|
|
142
|
+
onRemoveFile={() => removeError(id)}
|
|
143
|
+
uploading={false}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
)}
|
|
135
147
|
|
|
136
148
|
{uploadedFiles.length > 0 && (
|
|
137
149
|
<div className="w100 mt16">
|
|
@@ -149,7 +161,7 @@ const placeholder = `${textOverrides?.supportsTextShort || "Supports"} ${fileLis
|
|
|
149
161
|
|
|
150
162
|
<AnimateHeight duration={300} height={isOverMaxFiles ? 'auto' : 0}>
|
|
151
163
|
<p className="tc-red-500 p-p--small">
|
|
152
|
-
{textOverrides?.tooManyFilesError ||
|
|
164
|
+
{textOverrides?.tooManyFilesError || 'Too many files.'}
|
|
153
165
|
</p>
|
|
154
166
|
</AnimateHeight>
|
|
155
167
|
</div>
|