@spaced-out/ui-design-system 0.1.49 → 0.1.50
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/CHANGELOG.md +7 -0
- package/lib/components/FileUpload/FileBlock/FileBlock.js.flow +1 -1
- package/lib/components/FileUpload/FileUpload.js +4 -2
- package/lib/components/FileUpload/FileUpload.js.flow +20 -7
- package/lib/utils/helpers/helpers.js +2 -1
- package/lib/utils/helpers/helpers.js.flow +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.50](https://github.com/spaced-out/ui-design-system/compare/v0.1.49...v0.1.50) (2023-09-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* external file deletion support for file upload ([32cf857](https://github.com/spaced-out/ui-design-system/commit/32cf857a9688c2a20b1214381caccde699c192c4))
|
|
11
|
+
|
|
5
12
|
### [0.1.49](https://github.com/spaced-out/ui-design-system/compare/v0.1.48...v0.1.49) (2023-09-15)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -18,7 +18,7 @@ type ClassNames = $ReadOnly<{
|
|
|
18
18
|
export type FileBlockProps = {
|
|
19
19
|
classNames?: ClassNames,
|
|
20
20
|
fileObject: FileObject,
|
|
21
|
-
onFileRefreshClick?: (file: FileObject) =>
|
|
21
|
+
onFileRefreshClick?: (file: FileObject) => mixed,
|
|
22
22
|
handleFileClear?: (id: string) => mixed,
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -31,7 +31,8 @@ const FileUploadBase = (props, ref) => {
|
|
|
31
31
|
onRejectedFilesDrop,
|
|
32
32
|
onFileClear,
|
|
33
33
|
onFileRefreshClick,
|
|
34
|
-
maxFiles = 1
|
|
34
|
+
maxFiles = 1,
|
|
35
|
+
handleFileDeletionExternally
|
|
35
36
|
} = props;
|
|
36
37
|
|
|
37
38
|
// Get file upload state from useFileUpload hook
|
|
@@ -62,6 +63,7 @@ const FileUploadBase = (props, ref) => {
|
|
|
62
63
|
moveFileToProgress,
|
|
63
64
|
moveFileToSuccess,
|
|
64
65
|
moveFileToReject,
|
|
66
|
+
handleFileClear,
|
|
65
67
|
setShowReUpload,
|
|
66
68
|
validFiles,
|
|
67
69
|
rejectedFiles,
|
|
@@ -95,7 +97,7 @@ const FileUploadBase = (props, ref) => {
|
|
|
95
97
|
}, /*#__PURE__*/React.createElement(_FileBlock.FileBlock, {
|
|
96
98
|
fileObject: fileObject,
|
|
97
99
|
onFileRefreshClick: onFileRefreshClick,
|
|
98
|
-
handleFileClear: handleFileClear
|
|
100
|
+
handleFileClear: handleFileDeletionExternally ? onFileClear : handleFileClear
|
|
99
101
|
})))));
|
|
100
102
|
};
|
|
101
103
|
const FileUpload = /*#__PURE__*/React.forwardRef(FileUploadBase);
|
|
@@ -23,8 +23,15 @@ type ClassNames = $ReadOnly<{
|
|
|
23
23
|
|
|
24
24
|
export type FileProgress = number | 'indeterminate';
|
|
25
25
|
|
|
26
|
+
type LocalFileProps = {
|
|
27
|
+
name?: string,
|
|
28
|
+
type?: string,
|
|
29
|
+
size?: number,
|
|
30
|
+
...
|
|
31
|
+
};
|
|
32
|
+
|
|
26
33
|
export type FileObject = {
|
|
27
|
-
file: File,
|
|
34
|
+
file: File | LocalFileProps,
|
|
28
35
|
id: string,
|
|
29
36
|
reject?: boolean,
|
|
30
37
|
rejectReason?: string,
|
|
@@ -53,6 +60,7 @@ export type FileUploadRef = {
|
|
|
53
60
|
moveFileToSuccess: (id: string, successMessage?: string) => mixed,
|
|
54
61
|
moveFileToReject: (id: string, rejectReason?: string) => mixed,
|
|
55
62
|
setShowReUpload: (id: string, showReUpload?: boolean) => mixed,
|
|
63
|
+
handleFileClear: (id: string) => mixed,
|
|
56
64
|
validFiles: Array<FileObject>,
|
|
57
65
|
rejectedFiles: Array<FileObject>,
|
|
58
66
|
files: Array<FileObject>,
|
|
@@ -66,12 +74,12 @@ export type FileUploadBaseProps = {
|
|
|
66
74
|
disabled?: boolean,
|
|
67
75
|
|
|
68
76
|
// File drop callbacks
|
|
69
|
-
onValidFilesDrop?: (acceptedFiles: Array<FileObject>) =>
|
|
70
|
-
onRejectedFilesDrop?: (fileRejections: Array<FileObject>) =>
|
|
77
|
+
onValidFilesDrop?: (acceptedFiles: Array<FileObject>) => mixed,
|
|
78
|
+
onRejectedFilesDrop?: (fileRejections: Array<FileObject>) => mixed,
|
|
71
79
|
|
|
72
80
|
// File clear callbacks
|
|
73
|
-
onFileClear?: (id: string) =>
|
|
74
|
-
onClear?: () =>
|
|
81
|
+
onFileClear?: (id: string) => mixed,
|
|
82
|
+
onClear?: () => mixed,
|
|
75
83
|
};
|
|
76
84
|
|
|
77
85
|
export type FileUploadProps = {
|
|
@@ -83,9 +91,10 @@ export type FileUploadProps = {
|
|
|
83
91
|
draggingInstruction?: React.Node,
|
|
84
92
|
secondaryInstruction?: React.Node,
|
|
85
93
|
required?: boolean,
|
|
94
|
+
handleFileDeletionExternally?: boolean,
|
|
86
95
|
|
|
87
96
|
// File refresh callback
|
|
88
|
-
onFileRefreshClick?: (file: FileObject) =>
|
|
97
|
+
onFileRefreshClick?: (file: FileObject) => mixed,
|
|
89
98
|
};
|
|
90
99
|
|
|
91
100
|
const FileUploadBase = (props: FileUploadProps, ref) => {
|
|
@@ -105,6 +114,7 @@ const FileUploadBase = (props: FileUploadProps, ref) => {
|
|
|
105
114
|
onFileClear,
|
|
106
115
|
onFileRefreshClick,
|
|
107
116
|
maxFiles = 1,
|
|
117
|
+
handleFileDeletionExternally,
|
|
108
118
|
} = props;
|
|
109
119
|
|
|
110
120
|
// Get file upload state from useFileUpload hook
|
|
@@ -135,6 +145,7 @@ const FileUploadBase = (props: FileUploadProps, ref) => {
|
|
|
135
145
|
moveFileToProgress,
|
|
136
146
|
moveFileToSuccess,
|
|
137
147
|
moveFileToReject,
|
|
148
|
+
handleFileClear,
|
|
138
149
|
setShowReUpload,
|
|
139
150
|
validFiles,
|
|
140
151
|
rejectedFiles,
|
|
@@ -183,7 +194,9 @@ const FileUploadBase = (props: FileUploadProps, ref) => {
|
|
|
183
194
|
<FileBlock
|
|
184
195
|
fileObject={fileObject}
|
|
185
196
|
onFileRefreshClick={onFileRefreshClick}
|
|
186
|
-
handleFileClear={
|
|
197
|
+
handleFileClear={
|
|
198
|
+
handleFileDeletionExternally ? onFileClear : handleFileClear
|
|
199
|
+
}
|
|
187
200
|
/>
|
|
188
201
|
</React.Fragment>
|
|
189
202
|
))}
|
|
@@ -21,7 +21,8 @@ const range = (start, end) => {
|
|
|
21
21
|
}, (_, i) => start + i);
|
|
22
22
|
};
|
|
23
23
|
exports.range = range;
|
|
24
|
-
const convertFileSize =
|
|
24
|
+
const convertFileSize = function () {
|
|
25
|
+
let fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
25
26
|
let sizeInBytes = fileSize;
|
|
26
27
|
// Check if the file size is less than 1024
|
|
27
28
|
if (sizeInBytes < 0) {
|
|
@@ -15,7 +15,7 @@ export const range = (start: number, end: number): Array<number> => {
|
|
|
15
15
|
return Array.from({length}, (_, i) => start + i);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const convertFileSize = (fileSize: number): string => {
|
|
18
|
+
export const convertFileSize = (fileSize: number = 0): string => {
|
|
19
19
|
let sizeInBytes = fileSize;
|
|
20
20
|
// Check if the file size is less than 1024
|
|
21
21
|
if (sizeInBytes < 0) {
|