@ttoss/components 2.4.0 → 2.4.2
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/README.md +1 -1
- package/dist/FileUploader/index.d.ts +16 -9
- package/dist/esm/Accordion/index.js +11 -15
- package/dist/esm/Drawer/index.js +14 -18
- package/dist/esm/FileUploader/index.js +185 -191
- package/dist/esm/InstallPwa/index.js +27 -32
- package/dist/esm/JsonEditor/index.js +1 -0
- package/dist/esm/JsonView/index.js +1 -0
- package/dist/esm/List/index.js +9 -12
- package/dist/esm/Markdown/index.js +10 -12
- package/dist/esm/Menu/index.js +75 -87
- package/dist/esm/Modal/index.js +8 -10
- package/dist/esm/NotificationCard/index.js +3 -2
- package/dist/esm/NotificationsMenu/index.js +137 -149
- package/dist/esm/Search/index.js +6 -6
- package/dist/esm/Table/index.js +25 -25
- package/dist/esm/Tabs/index.js +10 -14
- package/dist/esm/Toast/index.js +10 -11
- package/dist/esm/{chunk-JOSQSCZQ.js → chunk-AZTAV4VC.js} +132 -39
- package/dist/esm/chunk-GOISZ4AR.js +156 -0
- package/dist/esm/chunk-V4MHYKRI.js +7 -0
- package/package.json +7 -5
- package/dist/esm/chunk-E6CBXO5W.js +0 -170
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ Drag-and-drop file upload with progress tracking. [📖 Docs](https://storybook.
|
|
|
57
57
|
import { FileUploader } from '@ttoss/components/FileUploader';
|
|
58
58
|
|
|
59
59
|
<FileUploader
|
|
60
|
-
|
|
60
|
+
onUpload={async (file) => ({ url: 'file-url', id: 'file-id' })}
|
|
61
61
|
onUploadComplete={(file, result) => console.log('Uploaded:', result)}
|
|
62
62
|
/>;
|
|
63
63
|
```
|
|
@@ -12,14 +12,21 @@ type FileUploadState = {
|
|
|
12
12
|
result?: UploadResult;
|
|
13
13
|
error?: Error;
|
|
14
14
|
};
|
|
15
|
+
type OnUpload = (file: File, onProgress?: (progress: number) => void) => Promise<UploadResult>;
|
|
16
|
+
type OnUploadStart = (file: File) => void;
|
|
17
|
+
type OnUploadProgress = (file: File, progress: number) => void;
|
|
18
|
+
type OnUploadComplete = (file: File, result: UploadResult) => void;
|
|
19
|
+
type OnUploadError = (file: File, error: Error) => void;
|
|
20
|
+
type OnFilesChange = (files: FileUploadState[]) => void;
|
|
21
|
+
type OnRemoveFile = (file: FileUploadState, index: number) => void;
|
|
15
22
|
type FileUploaderProps = {
|
|
16
|
-
|
|
17
|
-
onUploadStart?:
|
|
18
|
-
onUploadProgress?:
|
|
19
|
-
onUploadComplete?:
|
|
20
|
-
onUploadError?:
|
|
21
|
-
onFilesChange?:
|
|
22
|
-
onRemoveFile?:
|
|
23
|
+
onUpload: OnUpload;
|
|
24
|
+
onUploadStart?: OnUploadStart;
|
|
25
|
+
onUploadProgress?: OnUploadProgress;
|
|
26
|
+
onUploadComplete?: OnUploadComplete;
|
|
27
|
+
onUploadError?: OnUploadError;
|
|
28
|
+
onFilesChange?: OnFilesChange;
|
|
29
|
+
onRemoveFile?: OnRemoveFile;
|
|
23
30
|
accept?: string;
|
|
24
31
|
multiple?: boolean;
|
|
25
32
|
maxSize?: number;
|
|
@@ -36,6 +43,6 @@ type FileUploaderProps = {
|
|
|
36
43
|
onRemoveFile: (index: number) => void;
|
|
37
44
|
}) => React.ReactNode;
|
|
38
45
|
};
|
|
39
|
-
declare const FileUploader: ({
|
|
46
|
+
declare const FileUploader: ({ onUpload, onUploadStart, onUploadProgress, onUploadComplete, onUploadError, onFilesChange, onRemoveFile, accept, multiple, maxSize, maxFiles, disabled, autoUpload, retryAttempts, placeholder, error, children, showFileList, FileListComponent, }: FileUploaderProps) => react_jsx_runtime.JSX.Element;
|
|
40
47
|
|
|
41
|
-
export { type FileUploadState, FileUploader, type FileUploaderProps, type UploadResult };
|
|
48
|
+
export { type FileUploadState, FileUploader, type FileUploaderProps, type OnFilesChange, type OnRemoveFile, type OnUpload, type OnUploadComplete, type OnUploadError, type OnUploadProgress, type OnUploadStart, type UploadResult };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { __name } from "../chunk-V4MHYKRI.js";
|
|
2
3
|
|
|
3
4
|
// src/components/Accordion/Accordion.tsx
|
|
4
5
|
import * as React from "react";
|
|
@@ -6,8 +7,7 @@ import { AccordionItem, AccordionItemButton, AccordionItemHeading, AccordionItem
|
|
|
6
7
|
import { Box, useTheme } from "@ttoss/ui";
|
|
7
8
|
import { css as createClassName } from "@emotion/css";
|
|
8
9
|
import { css as transformStyleObject } from "@theme-ui/css";
|
|
9
|
-
|
|
10
|
-
var Accordion = ({
|
|
10
|
+
var Accordion = /* @__PURE__ */__name(({
|
|
11
11
|
children,
|
|
12
12
|
allowMultipleExpanded,
|
|
13
13
|
allowZeroExpanded,
|
|
@@ -35,19 +35,15 @@ var Accordion = ({
|
|
|
35
35
|
})(theme);
|
|
36
36
|
return createClassName(styles);
|
|
37
37
|
}, [theme]);
|
|
38
|
-
return /* @__PURE__ */
|
|
38
|
+
return /* @__PURE__ */React.createElement(Box, {
|
|
39
39
|
variant: "accordion",
|
|
40
40
|
className,
|
|
41
|
-
...boxProps
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
children
|
|
50
|
-
})
|
|
51
|
-
});
|
|
52
|
-
};
|
|
41
|
+
...boxProps
|
|
42
|
+
}, /* @__PURE__ */React.createElement(ReactAccessibleAccordion, {
|
|
43
|
+
allowMultipleExpanded,
|
|
44
|
+
allowZeroExpanded,
|
|
45
|
+
preExpanded,
|
|
46
|
+
onChange
|
|
47
|
+
}, children));
|
|
48
|
+
}, "Accordion");
|
|
53
49
|
export { Accordion, AccordionItem, AccordionItemButton, AccordionItemHeading, AccordionItemPanel };
|
package/dist/esm/Drawer/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { __name } from "../chunk-V4MHYKRI.js";
|
|
2
3
|
|
|
3
4
|
// src/components/Drawer/Drawer.tsx
|
|
4
5
|
import { Box } from "@ttoss/ui";
|
|
6
|
+
import * as React from "react";
|
|
5
7
|
import DrawerUi from "react-modern-drawer";
|
|
6
|
-
|
|
7
|
-
var Drawer = ({
|
|
8
|
+
var Drawer = /* @__PURE__ */__name(({
|
|
8
9
|
children,
|
|
9
10
|
sx,
|
|
10
11
|
...props
|
|
11
12
|
}) => {
|
|
12
|
-
return /* @__PURE__ */
|
|
13
|
+
return /* @__PURE__ */React.createElement(Box, {
|
|
13
14
|
"data-testid": "drawer-container",
|
|
14
15
|
sx: {
|
|
15
16
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
* https://github.com/Farzin-Firoozi/react-modern-drawer/blob/master/src/styles.css
|
|
18
|
+
*/
|
|
18
19
|
zIndex: "overlay",
|
|
19
20
|
width: "100%",
|
|
20
21
|
height: "100%",
|
|
@@ -47,17 +48,12 @@ var Drawer = ({
|
|
|
47
48
|
overflowY: "auto"
|
|
48
49
|
},
|
|
49
50
|
...sx
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
children
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
});
|
|
62
|
-
};
|
|
51
|
+
}
|
|
52
|
+
}, /* @__PURE__ */React.createElement(DrawerUi, props, /* @__PURE__ */React.createElement(Box, {
|
|
53
|
+
sx: {
|
|
54
|
+
width: "100%",
|
|
55
|
+
height: "100%"
|
|
56
|
+
}
|
|
57
|
+
}, children)));
|
|
58
|
+
}, "Drawer");
|
|
63
59
|
export { Drawer };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { __name } from "../chunk-V4MHYKRI.js";
|
|
2
3
|
|
|
3
4
|
// src/components/FileUploader/FileUploader.tsx
|
|
4
|
-
import {
|
|
5
|
+
import { useI18n } from "@ttoss/react-i18n";
|
|
5
6
|
import { Box, Button, Flex, Stack, Text } from "@ttoss/ui";
|
|
6
7
|
import * as React from "react";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
uploadFn,
|
|
8
|
+
var FileUploader = /* @__PURE__ */__name(({
|
|
9
|
+
onUpload,
|
|
10
10
|
onUploadStart,
|
|
11
11
|
onUploadProgress,
|
|
12
12
|
onUploadComplete,
|
|
@@ -16,7 +16,6 @@ var FileUploader = ({
|
|
|
16
16
|
accept,
|
|
17
17
|
multiple = true,
|
|
18
18
|
maxSize = 10 * 1024 * 1024,
|
|
19
|
-
// 10MB
|
|
20
19
|
maxFiles = 5,
|
|
21
20
|
disabled = false,
|
|
22
21
|
autoUpload = true,
|
|
@@ -27,17 +26,20 @@ var FileUploader = ({
|
|
|
27
26
|
showFileList = true,
|
|
28
27
|
FileListComponent
|
|
29
28
|
}) => {
|
|
29
|
+
const {
|
|
30
|
+
intl
|
|
31
|
+
} = useI18n();
|
|
30
32
|
const [files, setFiles] = React.useState([]);
|
|
31
33
|
const [isDragOver, setIsDragOver] = React.useState(false);
|
|
32
34
|
const fileInputRef = React.useRef(null);
|
|
33
|
-
const formatFileSize = bytes => {
|
|
35
|
+
const formatFileSize = /* @__PURE__ */__name(bytes => {
|
|
34
36
|
if (bytes === 0) return "0 Bytes";
|
|
35
37
|
const k = 1024;
|
|
36
38
|
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
37
39
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
38
40
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
39
|
-
};
|
|
40
|
-
const validateFiles = newFiles => {
|
|
41
|
+
}, "formatFileSize");
|
|
42
|
+
const validateFiles = /* @__PURE__ */__name(newFiles => {
|
|
41
43
|
const fileArray = Array.from(newFiles);
|
|
42
44
|
const validFiles = [];
|
|
43
45
|
const currentFileCount = files.length;
|
|
@@ -51,7 +53,7 @@ var FileUploader = ({
|
|
|
51
53
|
validFiles.push(file);
|
|
52
54
|
}
|
|
53
55
|
return validFiles;
|
|
54
|
-
};
|
|
56
|
+
}, "validateFiles");
|
|
55
57
|
const updateFileState = React.useCallback((file, updates) => {
|
|
56
58
|
setFiles(prevFiles => {
|
|
57
59
|
const newFiles = prevFiles.map(f => {
|
|
@@ -71,7 +73,7 @@ var FileUploader = ({
|
|
|
71
73
|
status: "uploading",
|
|
72
74
|
progress: 0
|
|
73
75
|
});
|
|
74
|
-
const result = await
|
|
76
|
+
const result = await onUpload(fileState.file, progress => {
|
|
75
77
|
updateFileState(fileState.file, {
|
|
76
78
|
progress
|
|
77
79
|
});
|
|
@@ -97,8 +99,8 @@ var FileUploader = ({
|
|
|
97
99
|
onUploadError?.(fileState.file, error2);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
|
-
}, [
|
|
101
|
-
const addFiles = newFiles => {
|
|
102
|
+
}, [onUpload, onUploadStart, onUploadProgress, onUploadComplete, onUploadError, retryAttempts, updateFileState]);
|
|
103
|
+
const addFiles = /* @__PURE__ */__name(newFiles => {
|
|
102
104
|
const newFileStates = newFiles.map(file => {
|
|
103
105
|
return {
|
|
104
106
|
file,
|
|
@@ -115,14 +117,14 @@ var FileUploader = ({
|
|
|
115
117
|
uploadFile(fileState);
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
|
-
};
|
|
119
|
-
const handleFileChange = event => {
|
|
120
|
+
}, "addFiles");
|
|
121
|
+
const handleFileChange = /* @__PURE__ */__name(event => {
|
|
120
122
|
if (event.target.files) {
|
|
121
123
|
const validFiles = validateFiles(event.target.files);
|
|
122
124
|
addFiles(validFiles);
|
|
123
125
|
}
|
|
124
|
-
};
|
|
125
|
-
const handleDrop = event => {
|
|
126
|
+
}, "handleFileChange");
|
|
127
|
+
const handleDrop = /* @__PURE__ */__name(event => {
|
|
126
128
|
event.preventDefault();
|
|
127
129
|
setIsDragOver(false);
|
|
128
130
|
if (disabled) return;
|
|
@@ -131,22 +133,22 @@ var FileUploader = ({
|
|
|
131
133
|
const validFiles = validateFiles(droppedFiles);
|
|
132
134
|
addFiles(validFiles);
|
|
133
135
|
}
|
|
134
|
-
};
|
|
135
|
-
const handleDragOver = event => {
|
|
136
|
+
}, "handleDrop");
|
|
137
|
+
const handleDragOver = /* @__PURE__ */__name(event => {
|
|
136
138
|
event.preventDefault();
|
|
137
139
|
if (!disabled) {
|
|
138
140
|
setIsDragOver(true);
|
|
139
141
|
}
|
|
140
|
-
};
|
|
141
|
-
const handleDragLeave = event => {
|
|
142
|
+
}, "handleDragOver");
|
|
143
|
+
const handleDragLeave = /* @__PURE__ */__name(event => {
|
|
142
144
|
event.preventDefault();
|
|
143
145
|
setIsDragOver(false);
|
|
144
|
-
};
|
|
145
|
-
const handleClick = () => {
|
|
146
|
+
}, "handleDragLeave");
|
|
147
|
+
const handleClick = /* @__PURE__ */__name(() => {
|
|
146
148
|
if (!disabled && fileInputRef.current) {
|
|
147
149
|
fileInputRef.current.click();
|
|
148
150
|
}
|
|
149
|
-
};
|
|
151
|
+
}, "handleClick");
|
|
150
152
|
const handleRemoveFile = React.useCallback(index => {
|
|
151
153
|
const fileToRemove = files[index];
|
|
152
154
|
setFiles(prevFiles => {
|
|
@@ -172,181 +174,173 @@ var FileUploader = ({
|
|
|
172
174
|
return null;
|
|
173
175
|
}
|
|
174
176
|
if (FileListComponent) {
|
|
175
|
-
return /* @__PURE__ */
|
|
177
|
+
return /* @__PURE__ */React.createElement(FileListComponent, {
|
|
176
178
|
files,
|
|
177
179
|
onRemoveFile: handleRemoveFile
|
|
178
180
|
});
|
|
179
181
|
}
|
|
180
|
-
return /* @__PURE__ */
|
|
182
|
+
return /* @__PURE__ */React.createElement(Stack, {
|
|
181
183
|
sx: {
|
|
182
184
|
gap: 1
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
children: [/* @__PURE__ */jsxs(Flex, {
|
|
195
|
-
sx: {
|
|
196
|
-
alignItems: "center",
|
|
197
|
-
gap: 2,
|
|
198
|
-
flex: 1
|
|
199
|
-
},
|
|
200
|
-
children: [/* @__PURE__ */jsx(Text, {
|
|
201
|
-
sx: {
|
|
202
|
-
fontSize: "lg"
|
|
203
|
-
},
|
|
204
|
-
children: fileState.status === "completed" ? "\u2713" : fileState.status === "error" ? "\u2717" : fileState.status === "uploading" ? "\u21BB" : "\u{1F4C4}"
|
|
205
|
-
}), /* @__PURE__ */jsxs(Box, {
|
|
206
|
-
sx: {
|
|
207
|
-
flex: 1
|
|
208
|
-
},
|
|
209
|
-
children: [/* @__PURE__ */jsx(Text, {
|
|
210
|
-
variant: "body",
|
|
211
|
-
sx: {
|
|
212
|
-
fontWeight: "medium"
|
|
213
|
-
},
|
|
214
|
-
children: fileState.file.name
|
|
215
|
-
}), fileState.status === "uploading" && fileState.progress && /* @__PURE__ */jsxs(Text, {
|
|
216
|
-
variant: "caption",
|
|
217
|
-
sx: {
|
|
218
|
-
color: "primary.default"
|
|
219
|
-
},
|
|
220
|
-
children: [fileState.progress.toFixed(0), "%"]
|
|
221
|
-
}), fileState.status === "error" && /* @__PURE__ */jsx(Text, {
|
|
222
|
-
variant: "caption",
|
|
223
|
-
sx: {
|
|
224
|
-
color: "error.default"
|
|
225
|
-
},
|
|
226
|
-
children: "Failed"
|
|
227
|
-
})]
|
|
228
|
-
}), /* @__PURE__ */jsx(Text, {
|
|
229
|
-
variant: "caption",
|
|
230
|
-
sx: {
|
|
231
|
-
color: "text.muted"
|
|
232
|
-
},
|
|
233
|
-
children: formatFileSize(fileState.file.size)
|
|
234
|
-
})]
|
|
235
|
-
}), /* @__PURE__ */jsxs(Flex, {
|
|
236
|
-
sx: {
|
|
237
|
-
gap: 1
|
|
238
|
-
},
|
|
239
|
-
children: [fileState.status === "error" && /* @__PURE__ */jsx(Button, {
|
|
240
|
-
variant: "destructive",
|
|
241
|
-
onClick: () => {
|
|
242
|
-
return retryUpload(index);
|
|
243
|
-
},
|
|
244
|
-
sx: {
|
|
245
|
-
fontSize: "xs"
|
|
246
|
-
},
|
|
247
|
-
children: "Retry"
|
|
248
|
-
}), /* @__PURE__ */jsx(Button, {
|
|
249
|
-
variant: "destructive",
|
|
250
|
-
onClick: () => {
|
|
251
|
-
return handleRemoveFile(index);
|
|
252
|
-
},
|
|
253
|
-
sx: {
|
|
254
|
-
fontSize: "sm",
|
|
255
|
-
color: "text.muted",
|
|
256
|
-
"&:hover": {
|
|
257
|
-
color: "error.default"
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
children: "Remove"
|
|
261
|
-
})]
|
|
262
|
-
})]
|
|
263
|
-
}, index);
|
|
264
|
-
})
|
|
265
|
-
});
|
|
266
|
-
}, [FileListComponent, files, handleRemoveFile, retryUpload, showFileList]);
|
|
267
|
-
return /* @__PURE__ */jsxs(Stack, {
|
|
268
|
-
sx: {
|
|
269
|
-
gap: 3
|
|
270
|
-
},
|
|
271
|
-
children: [/* @__PURE__ */jsxs(Box, {
|
|
272
|
-
onDrop: handleDrop,
|
|
273
|
-
onDragOver: handleDragOver,
|
|
274
|
-
onDragLeave: handleDragLeave,
|
|
275
|
-
onClick: handleClick,
|
|
276
|
-
sx: {
|
|
277
|
-
border: "2px dashed",
|
|
278
|
-
borderColor: error ? "error.default" : isDragOver ? "primary.default" : "display.border.muted.default",
|
|
279
|
-
borderRadius: "xl",
|
|
280
|
-
padding: 6,
|
|
281
|
-
textAlign: "center",
|
|
282
|
-
cursor: disabled || isUploading ? "not-allowed" : "pointer",
|
|
283
|
-
backgroundColor: isDragOver ? "primary.muted" : "display.background.secondary.default",
|
|
284
|
-
transition: "all 0.2s ease",
|
|
285
|
-
opacity: disabled ? 0.6 : 1,
|
|
286
|
-
"&:hover": {
|
|
287
|
-
borderColor: !disabled && !isUploading && !error ? "primary.default" : void 0,
|
|
288
|
-
backgroundColor: !disabled && !isUploading ? "primary.muted" : void 0
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
children: [/* @__PURE__ */jsx("input", {
|
|
292
|
-
ref: fileInputRef,
|
|
293
|
-
type: "file",
|
|
294
|
-
accept,
|
|
295
|
-
multiple,
|
|
296
|
-
onChange: handleFileChange,
|
|
297
|
-
disabled: disabled || isUploading,
|
|
298
|
-
style: {
|
|
299
|
-
display: "none"
|
|
185
|
+
}
|
|
186
|
+
}, files.map((fileState, index) => {
|
|
187
|
+
return /* @__PURE__ */React.createElement(Flex, {
|
|
188
|
+
key: index,
|
|
189
|
+
sx: {
|
|
190
|
+
alignItems: "center",
|
|
191
|
+
justifyContent: "space-between",
|
|
192
|
+
p: 2,
|
|
193
|
+
backgroundColor: "display.background.secondary.default",
|
|
194
|
+
borderRadius: "md",
|
|
195
|
+
gap: 2
|
|
300
196
|
}
|
|
301
|
-
}
|
|
197
|
+
}, /* @__PURE__ */React.createElement(Flex, {
|
|
302
198
|
sx: {
|
|
303
|
-
flexDirection: "column",
|
|
304
199
|
alignItems: "center",
|
|
305
|
-
gap:
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
200
|
+
gap: 2,
|
|
201
|
+
flex: 1
|
|
202
|
+
}
|
|
203
|
+
}, /* @__PURE__ */React.createElement(Text, {
|
|
204
|
+
sx: {
|
|
205
|
+
fontSize: "lg"
|
|
206
|
+
}
|
|
207
|
+
}, fileState.status === "completed" ? "\u2713" : fileState.status === "error" ? "\u2717" : fileState.status === "uploading" ? "\u21BB" : "\u{1F4C4}"), /* @__PURE__ */React.createElement(Box, {
|
|
208
|
+
sx: {
|
|
209
|
+
flex: 1
|
|
210
|
+
}
|
|
211
|
+
}, /* @__PURE__ */React.createElement(Text, {
|
|
212
|
+
variant: "body",
|
|
213
|
+
sx: {
|
|
214
|
+
fontWeight: "medium"
|
|
215
|
+
}
|
|
216
|
+
}, fileState.file.name), fileState.status === "uploading" && fileState.progress && /* @__PURE__ */React.createElement(Text, {
|
|
217
|
+
variant: "caption",
|
|
218
|
+
sx: {
|
|
219
|
+
color: "primary.default"
|
|
220
|
+
}
|
|
221
|
+
}, fileState.progress.toFixed(0), "%"), fileState.status === "error" && /* @__PURE__ */React.createElement(Text, {
|
|
222
|
+
variant: "caption",
|
|
223
|
+
sx: {
|
|
224
|
+
color: "error.default"
|
|
225
|
+
}
|
|
226
|
+
}, "Failed")), /* @__PURE__ */React.createElement(Text, {
|
|
227
|
+
variant: "caption",
|
|
228
|
+
sx: {
|
|
229
|
+
color: "text.muted"
|
|
230
|
+
}
|
|
231
|
+
}, formatFileSize(fileState.file.size))), /* @__PURE__ */React.createElement(Flex, {
|
|
232
|
+
sx: {
|
|
233
|
+
gap: 1
|
|
234
|
+
}
|
|
235
|
+
}, fileState.status === "error" && /* @__PURE__ */React.createElement(Button, {
|
|
236
|
+
variant: "destructive",
|
|
237
|
+
onClick: /* @__PURE__ */__name(() => {
|
|
238
|
+
return retryUpload(index);
|
|
239
|
+
}, "onClick"),
|
|
240
|
+
sx: {
|
|
241
|
+
fontSize: "xs"
|
|
242
|
+
}
|
|
243
|
+
}, "Retry"), /* @__PURE__ */React.createElement(Button, {
|
|
244
|
+
variant: "destructive",
|
|
245
|
+
onClick: /* @__PURE__ */__name(() => {
|
|
246
|
+
return handleRemoveFile(index);
|
|
247
|
+
}, "onClick"),
|
|
248
|
+
sx: {
|
|
249
|
+
fontSize: "sm",
|
|
250
|
+
color: "text.muted",
|
|
251
|
+
"&:hover": {
|
|
252
|
+
color: "error.default"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}, "Remove")));
|
|
256
|
+
}));
|
|
257
|
+
}, [FileListComponent, files, handleRemoveFile, retryUpload, showFileList]);
|
|
258
|
+
return /* @__PURE__ */React.createElement(Stack, {
|
|
259
|
+
sx: {
|
|
260
|
+
gap: 3
|
|
261
|
+
}
|
|
262
|
+
}, /* @__PURE__ */React.createElement(Box, {
|
|
263
|
+
onDrop: handleDrop,
|
|
264
|
+
onDragOver: handleDragOver,
|
|
265
|
+
onDragLeave: handleDragLeave,
|
|
266
|
+
onClick: handleClick,
|
|
267
|
+
sx: {
|
|
268
|
+
border: "2px dashed",
|
|
269
|
+
borderColor: error ? "error.default" : isDragOver ? "primary.default" : "display.border.muted.default",
|
|
270
|
+
borderRadius: "xl",
|
|
271
|
+
padding: 6,
|
|
272
|
+
textAlign: "center",
|
|
273
|
+
cursor: disabled || isUploading ? "not-allowed" : "pointer",
|
|
274
|
+
backgroundColor: isDragOver ? "primary.muted" : "display.background.secondary.default",
|
|
275
|
+
transition: "all 0.2s ease",
|
|
276
|
+
opacity: disabled ? 0.6 : 1,
|
|
277
|
+
"&:hover": {
|
|
278
|
+
borderColor: !disabled && !isUploading && !error ? "primary.default" : void 0,
|
|
279
|
+
backgroundColor: !disabled && !isUploading ? "primary.muted" : void 0
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}, /* @__PURE__ */React.createElement("input", {
|
|
283
|
+
ref: fileInputRef,
|
|
284
|
+
type: "file",
|
|
285
|
+
accept,
|
|
286
|
+
multiple,
|
|
287
|
+
onChange: handleFileChange,
|
|
288
|
+
disabled: disabled || isUploading,
|
|
289
|
+
style: {
|
|
290
|
+
display: "none"
|
|
291
|
+
}
|
|
292
|
+
}), children || /* @__PURE__ */React.createElement(Flex, {
|
|
293
|
+
sx: {
|
|
294
|
+
flexDirection: "column",
|
|
295
|
+
alignItems: "center",
|
|
296
|
+
gap: 3,
|
|
297
|
+
justifyContent: "center"
|
|
298
|
+
}
|
|
299
|
+
}, /* @__PURE__ */React.createElement(Text, {
|
|
300
|
+
sx: {
|
|
301
|
+
fontSize: "3xl"
|
|
302
|
+
}
|
|
303
|
+
}, "\u{1F4C1}"), /* @__PURE__ */React.createElement(Box, {
|
|
304
|
+
sx: {
|
|
305
|
+
textAlign: "center"
|
|
306
|
+
}
|
|
307
|
+
}, /* @__PURE__ */React.createElement(Text, {
|
|
308
|
+
variant: "body",
|
|
309
|
+
sx: {
|
|
310
|
+
color: "text.default",
|
|
311
|
+
mb: 1
|
|
312
|
+
}
|
|
313
|
+
}, isUploading ? intl.formatMessage({
|
|
314
|
+
id: "JEsxDw",
|
|
315
|
+
defaultMessage: [{
|
|
316
|
+
"type": 0,
|
|
317
|
+
"value": "Uploading..."
|
|
318
|
+
}]
|
|
319
|
+
}) : placeholder || intl.formatMessage({
|
|
320
|
+
id: "gy0Ynb",
|
|
321
|
+
defaultMessage: [{
|
|
322
|
+
"type": 0,
|
|
323
|
+
"value": "Click or drag files here"
|
|
324
|
+
}]
|
|
325
|
+
})), /* @__PURE__ */React.createElement(Text, {
|
|
326
|
+
variant: "caption",
|
|
327
|
+
sx: {
|
|
328
|
+
color: "text.muted"
|
|
329
|
+
}
|
|
330
|
+
}, [accept && accept, maxSize && `Max ${formatFileSize(maxSize)}`, multiple && maxFiles && `Up to ${maxFiles} files`].filter(Boolean).join(" \u2022 "))), !isUploading && /* @__PURE__ */React.createElement(Button, {
|
|
331
|
+
variant: "secondary",
|
|
332
|
+
disabled
|
|
333
|
+
}, intl.formatMessage({
|
|
334
|
+
id: "fDCMA6",
|
|
335
|
+
defaultMessage: [{
|
|
336
|
+
"type": 0,
|
|
337
|
+
"value": "Select Files"
|
|
338
|
+
}]
|
|
339
|
+
})))), error && /* @__PURE__ */React.createElement(Text, {
|
|
340
|
+
variant: "caption",
|
|
341
|
+
sx: {
|
|
342
|
+
color: "error.default"
|
|
343
|
+
}
|
|
344
|
+
}, error), fileListNode);
|
|
345
|
+
}, "FileUploader");
|
|
352
346
|
export { FileUploader };
|