@availity/mui-file-selector 0.2.2 → 0.2.4
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 +26 -0
- package/dist/index.js +53 -43
- package/dist/index.mjs +65 -44
- package/package.json +7 -7
- package/src/lib/Dropzone.tsx +10 -5
- package/src/lib/FileList.tsx +6 -5
- package/src/lib/FileSelector.tsx +1 -2
- package/src/lib/util.ts +33 -19
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.2.4](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.3...@availity/mui-file-selector@0.2.4) (2025-01-06)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `mui-alert` updated to version `0.2.3`
|
|
10
|
+
* `mui-button` updated to version `0.2.3`
|
|
11
|
+
* `mui-form-utils` updated to version `0.2.3`
|
|
12
|
+
* `mui-icon` updated to version `0.2.3`
|
|
13
|
+
* `mui-list` updated to version `0.2.3`
|
|
14
|
+
* `mui-progress` updated to version `0.2.3`
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* add hover color ([5001b77](https://github.com/Availity/element/commit/5001b77407b26de13d44b3ac3e39f05224aacc08))
|
|
19
|
+
* various fixes for file selector ([26c651d](https://github.com/Availity/element/commit/26c651d7b8e89919fac335f233acbe528d10956a))
|
|
20
|
+
|
|
21
|
+
## [0.2.3](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.2...@availity/mui-file-selector@0.2.3) (2025-01-03)
|
|
22
|
+
|
|
23
|
+
### Dependency Updates
|
|
24
|
+
|
|
25
|
+
* `mui-alert` updated to version `0.2.2`
|
|
26
|
+
* `mui-button` updated to version `0.2.2`
|
|
27
|
+
* `mui-form-utils` updated to version `0.2.2`
|
|
28
|
+
* `mui-icon` updated to version `0.2.2`
|
|
29
|
+
* `mui-list` updated to version `0.2.2`
|
|
30
|
+
* `mui-progress` updated to version `0.2.2`
|
|
5
31
|
## [0.2.2](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.1...@availity/mui-file-selector@0.2.2) (2025-01-02)
|
|
6
32
|
|
|
7
33
|
## [0.2.1](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.0...@availity/mui-file-selector@0.2.1) (2024-12-23)
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,7 @@ var import_mui_typography4 = require("@availity/mui-typography");
|
|
|
75
75
|
// src/lib/Dropzone.tsx
|
|
76
76
|
var import_react = require("react");
|
|
77
77
|
var import_react_dropzone = require("react-dropzone");
|
|
78
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
78
79
|
var import_mui_divider = require("@availity/mui-divider");
|
|
79
80
|
var import_mui_icon = require("@availity/mui-icon");
|
|
80
81
|
var import_mui_layout = require("@availity/mui-layout");
|
|
@@ -130,13 +131,16 @@ var FilePickerBtn = (_a) => {
|
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
// src/lib/Dropzone.tsx
|
|
133
|
-
var import_react_hook_form2 = require("react-hook-form");
|
|
134
134
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
135
135
|
var outerBoxStyles = {
|
|
136
|
-
backgroundColor: "background.
|
|
136
|
+
backgroundColor: "background.secondary",
|
|
137
137
|
border: "1px dotted",
|
|
138
|
+
borderColor: "secondary.light",
|
|
138
139
|
borderRadius: "4px",
|
|
139
|
-
padding: "2rem"
|
|
140
|
+
padding: "2rem",
|
|
141
|
+
"&:hover": {
|
|
142
|
+
backgroundColor: "background.primary"
|
|
143
|
+
}
|
|
140
144
|
};
|
|
141
145
|
var innerBoxStyles = {
|
|
142
146
|
width: "100%",
|
|
@@ -226,9 +230,10 @@ var Dropzone = ({
|
|
|
226
230
|
inputProps.onChange(event);
|
|
227
231
|
}
|
|
228
232
|
};
|
|
229
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Box, __spreadProps(__spreadValues({ sx: outerBoxStyles }, getRootProps()), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Box, { sx: innerBoxStyles, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Stack, { spacing: 2,
|
|
230
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.
|
|
233
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Box, __spreadProps(__spreadValues({ sx: outerBoxStyles }, getRootProps()), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Box, { sx: innerBoxStyles, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Stack, { spacing: 2, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
234
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
231
235
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_typography.Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_divider.Divider, { children: "OR" }),
|
|
232
237
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
233
238
|
FilePickerBtn,
|
|
234
239
|
{
|
|
@@ -271,8 +276,9 @@ var ErrorAlert = ({ errors, fileName, id, onClose }) => {
|
|
|
271
276
|
|
|
272
277
|
// src/lib/FileList.tsx
|
|
273
278
|
var import_mui_list = require("@availity/mui-list");
|
|
274
|
-
var
|
|
279
|
+
var import_mui_icon4 = require("@availity/mui-icon");
|
|
275
280
|
var import_mui_layout2 = require("@availity/mui-layout");
|
|
281
|
+
var import_mui_divider2 = require("@availity/mui-divider");
|
|
276
282
|
|
|
277
283
|
// src/lib/UploadProgressBar.tsx
|
|
278
284
|
var import_react2 = require("react");
|
|
@@ -311,6 +317,7 @@ var UploadProgressBar = ({ upload, onProgress, onError, onSuccess }) => {
|
|
|
311
317
|
};
|
|
312
318
|
|
|
313
319
|
// src/lib/util.ts
|
|
320
|
+
var import_mui_icon3 = require("@availity/mui-icon");
|
|
314
321
|
function formatBytes(bytes, decimals = 2) {
|
|
315
322
|
if (!+bytes)
|
|
316
323
|
return "0 Bytes";
|
|
@@ -321,30 +328,31 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
321
328
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
322
329
|
}
|
|
323
330
|
var FILE_EXT_ICONS = {
|
|
324
|
-
png:
|
|
325
|
-
jpg:
|
|
326
|
-
jpeg:
|
|
327
|
-
gif:
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
331
|
+
png: import_mui_icon3.FileImageIcon,
|
|
332
|
+
jpg: import_mui_icon3.FileImageIcon,
|
|
333
|
+
jpeg: import_mui_icon3.FileImageIcon,
|
|
334
|
+
gif: import_mui_icon3.FileImageIcon,
|
|
335
|
+
csv: import_mui_icon3.FileCsvIcon,
|
|
336
|
+
ppt: import_mui_icon3.FilePowerpointIcon,
|
|
337
|
+
pptx: import_mui_icon3.FilePowerpointIcon,
|
|
338
|
+
xls: import_mui_icon3.FileExcelIcon,
|
|
339
|
+
xlsx: import_mui_icon3.FileExcelIcon,
|
|
340
|
+
doc: import_mui_icon3.FileWordIcon,
|
|
341
|
+
docx: import_mui_icon3.FileWordIcon,
|
|
342
|
+
txt: import_mui_icon3.FileLinesIcon,
|
|
343
|
+
text: import_mui_icon3.FileLinesIcon,
|
|
344
|
+
zip: import_mui_icon3.FileArchiveIcon,
|
|
345
|
+
"7zip": import_mui_icon3.FileArchiveIcon,
|
|
346
|
+
xml: import_mui_icon3.FileCodeIcon,
|
|
347
|
+
html: import_mui_icon3.FileCodeIcon,
|
|
348
|
+
pdf: import_mui_icon3.FilePdfIcon
|
|
341
349
|
};
|
|
342
350
|
var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
|
|
343
351
|
var getFileExtIcon = (fileName) => {
|
|
344
352
|
var _a;
|
|
345
353
|
const ext = ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
346
|
-
const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] :
|
|
347
|
-
return
|
|
354
|
+
const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : import_mui_icon3.FileIcon;
|
|
355
|
+
return icon;
|
|
348
356
|
};
|
|
349
357
|
|
|
350
358
|
// src/lib/useUploadCore.tsx
|
|
@@ -366,26 +374,28 @@ function useUploadCore(file, options) {
|
|
|
366
374
|
// src/lib/FileList.tsx
|
|
367
375
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
368
376
|
var FileRow = ({ file, options, onRemoveFile }) => {
|
|
369
|
-
const
|
|
370
|
-
console.log("ext, icon:", ext, icon);
|
|
377
|
+
const Icon = getFileExtIcon(file.name);
|
|
371
378
|
const { data: upload } = useUploadCore(file, options);
|
|
372
379
|
if (!upload)
|
|
373
380
|
return null;
|
|
374
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.
|
|
375
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
382
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_mui_layout2.Grid, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", borderBottom: "1px", children: [
|
|
383
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list.ListItemIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, {}) }) }),
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 4, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list.ListItemText, { children: upload.trimFileName(upload.file.name) }) }),
|
|
385
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 2, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list.ListItem, { children: formatBytes(upload.file.size) }) }),
|
|
386
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 4, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadProgressBar, { upload }) }),
|
|
387
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
388
|
+
import_mui_list.ListItemButton,
|
|
389
|
+
{
|
|
390
|
+
onClick: () => {
|
|
391
|
+
onRemoveFile(upload.id, upload);
|
|
392
|
+
},
|
|
393
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list.ListItemIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_icon4.DeleteIcon, {}) })
|
|
394
|
+
}
|
|
395
|
+
) })
|
|
396
|
+
] }),
|
|
397
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_divider2.Divider, { component: "li" })
|
|
398
|
+
] });
|
|
389
399
|
};
|
|
390
400
|
var FileList = ({ files, options, onRemoveFile }) => {
|
|
391
401
|
if (files.length === 0)
|
|
@@ -489,7 +499,7 @@ var FileSelector = ({
|
|
|
489
499
|
};
|
|
490
500
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_hook_form3.FormProvider, __spreadProps(__spreadValues({}, methods), { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("form", { onSubmit: methods.handleSubmit(handleOnSubmit), children: [
|
|
491
501
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
492
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_mui_typography4.Typography, { children: label }),
|
|
502
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_mui_typography4.Typography, { marginBottom: "4px", children: label }),
|
|
493
503
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
494
504
|
Dropzone,
|
|
495
505
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -41,8 +41,9 @@ import { Typography as Typography4 } from "@availity/mui-typography";
|
|
|
41
41
|
// src/lib/Dropzone.tsx
|
|
42
42
|
import { useCallback } from "react";
|
|
43
43
|
import { useDropzone } from "react-dropzone";
|
|
44
|
+
import { useFormContext as useFormContext2 } from "react-hook-form";
|
|
44
45
|
import { Divider } from "@availity/mui-divider";
|
|
45
|
-
import {
|
|
46
|
+
import { CloudUploadIcon } from "@availity/mui-icon";
|
|
46
47
|
import { Box, Stack } from "@availity/mui-layout";
|
|
47
48
|
import { Typography } from "@availity/mui-typography";
|
|
48
49
|
|
|
@@ -96,13 +97,16 @@ var FilePickerBtn = (_a) => {
|
|
|
96
97
|
};
|
|
97
98
|
|
|
98
99
|
// src/lib/Dropzone.tsx
|
|
99
|
-
import { useFormContext as useFormContext2 } from "react-hook-form";
|
|
100
100
|
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
101
101
|
var outerBoxStyles = {
|
|
102
|
-
backgroundColor: "background.
|
|
102
|
+
backgroundColor: "background.secondary",
|
|
103
103
|
border: "1px dotted",
|
|
104
|
+
borderColor: "secondary.light",
|
|
104
105
|
borderRadius: "4px",
|
|
105
|
-
padding: "2rem"
|
|
106
|
+
padding: "2rem",
|
|
107
|
+
"&:hover": {
|
|
108
|
+
backgroundColor: "background.primary"
|
|
109
|
+
}
|
|
106
110
|
};
|
|
107
111
|
var innerBoxStyles = {
|
|
108
112
|
width: "100%",
|
|
@@ -192,9 +196,10 @@ var Dropzone = ({
|
|
|
192
196
|
inputProps.onChange(event);
|
|
193
197
|
}
|
|
194
198
|
};
|
|
195
|
-
return /* @__PURE__ */ jsx2(Box, __spreadProps(__spreadValues({ sx: outerBoxStyles }, getRootProps()), { children: /* @__PURE__ */ jsx2(Box, { sx: innerBoxStyles, children: /* @__PURE__ */ jsx2(Stack, { spacing: 2,
|
|
196
|
-
/* @__PURE__ */ jsx2(
|
|
199
|
+
return /* @__PURE__ */ jsx2(Box, __spreadProps(__spreadValues({ sx: outerBoxStyles }, getRootProps()), { children: /* @__PURE__ */ jsx2(Box, { sx: innerBoxStyles, children: /* @__PURE__ */ jsx2(Stack, { spacing: 2, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
200
|
+
/* @__PURE__ */ jsx2(CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
197
201
|
/* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
202
|
+
/* @__PURE__ */ jsx2(Divider, { children: "OR" }),
|
|
198
203
|
/* @__PURE__ */ jsx2(
|
|
199
204
|
FilePickerBtn,
|
|
200
205
|
{
|
|
@@ -237,8 +242,9 @@ var ErrorAlert = ({ errors, fileName, id, onClose }) => {
|
|
|
237
242
|
|
|
238
243
|
// src/lib/FileList.tsx
|
|
239
244
|
import { List, ListItem, ListItemText, ListItemIcon, ListItemButton } from "@availity/mui-list";
|
|
240
|
-
import { DeleteIcon
|
|
245
|
+
import { DeleteIcon } from "@availity/mui-icon";
|
|
241
246
|
import { Grid } from "@availity/mui-layout";
|
|
247
|
+
import { Divider as Divider2 } from "@availity/mui-divider";
|
|
242
248
|
|
|
243
249
|
// src/lib/UploadProgressBar.tsx
|
|
244
250
|
import { useState } from "react";
|
|
@@ -277,6 +283,18 @@ var UploadProgressBar = ({ upload, onProgress, onError, onSuccess }) => {
|
|
|
277
283
|
};
|
|
278
284
|
|
|
279
285
|
// src/lib/util.ts
|
|
286
|
+
import {
|
|
287
|
+
FileArchiveIcon,
|
|
288
|
+
FileCodeIcon,
|
|
289
|
+
FileCsvIcon,
|
|
290
|
+
FileExcelIcon,
|
|
291
|
+
FileIcon,
|
|
292
|
+
FileImageIcon,
|
|
293
|
+
FileLinesIcon,
|
|
294
|
+
FilePdfIcon,
|
|
295
|
+
FilePowerpointIcon,
|
|
296
|
+
FileWordIcon
|
|
297
|
+
} from "@availity/mui-icon";
|
|
280
298
|
function formatBytes(bytes, decimals = 2) {
|
|
281
299
|
if (!+bytes)
|
|
282
300
|
return "0 Bytes";
|
|
@@ -287,30 +305,31 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
287
305
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
288
306
|
}
|
|
289
307
|
var FILE_EXT_ICONS = {
|
|
290
|
-
png:
|
|
291
|
-
jpg:
|
|
292
|
-
jpeg:
|
|
293
|
-
gif:
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
308
|
+
png: FileImageIcon,
|
|
309
|
+
jpg: FileImageIcon,
|
|
310
|
+
jpeg: FileImageIcon,
|
|
311
|
+
gif: FileImageIcon,
|
|
312
|
+
csv: FileCsvIcon,
|
|
313
|
+
ppt: FilePowerpointIcon,
|
|
314
|
+
pptx: FilePowerpointIcon,
|
|
315
|
+
xls: FileExcelIcon,
|
|
316
|
+
xlsx: FileExcelIcon,
|
|
317
|
+
doc: FileWordIcon,
|
|
318
|
+
docx: FileWordIcon,
|
|
319
|
+
txt: FileLinesIcon,
|
|
320
|
+
text: FileLinesIcon,
|
|
321
|
+
zip: FileArchiveIcon,
|
|
322
|
+
"7zip": FileArchiveIcon,
|
|
323
|
+
xml: FileCodeIcon,
|
|
324
|
+
html: FileCodeIcon,
|
|
325
|
+
pdf: FilePdfIcon
|
|
307
326
|
};
|
|
308
327
|
var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
|
|
309
328
|
var getFileExtIcon = (fileName) => {
|
|
310
329
|
var _a;
|
|
311
330
|
const ext = ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
312
|
-
const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] :
|
|
313
|
-
return
|
|
331
|
+
const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
|
|
332
|
+
return icon;
|
|
314
333
|
};
|
|
315
334
|
|
|
316
335
|
// src/lib/useUploadCore.tsx
|
|
@@ -332,26 +351,28 @@ function useUploadCore(file, options) {
|
|
|
332
351
|
// src/lib/FileList.tsx
|
|
333
352
|
import { Fragment as Fragment5, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
334
353
|
var FileRow = ({ file, options, onRemoveFile }) => {
|
|
335
|
-
const
|
|
336
|
-
console.log("ext, icon:", ext, icon);
|
|
354
|
+
const Icon = getFileExtIcon(file.name);
|
|
337
355
|
const { data: upload } = useUploadCore(file, options);
|
|
338
356
|
if (!upload)
|
|
339
357
|
return null;
|
|
340
|
-
return /* @__PURE__ */
|
|
341
|
-
/* @__PURE__ */
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
358
|
+
return /* @__PURE__ */ jsxs5(Fragment5, { children: [
|
|
359
|
+
/* @__PURE__ */ jsxs5(Grid, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", borderBottom: "1px", children: [
|
|
360
|
+
/* @__PURE__ */ jsx5(Grid, { xs: 1, children: /* @__PURE__ */ jsx5(ListItemIcon, { children: /* @__PURE__ */ jsx5(Icon, {}) }) }),
|
|
361
|
+
/* @__PURE__ */ jsx5(Grid, { xs: 4, children: /* @__PURE__ */ jsx5(ListItemText, { children: upload.trimFileName(upload.file.name) }) }),
|
|
362
|
+
/* @__PURE__ */ jsx5(Grid, { xs: 2, children: /* @__PURE__ */ jsx5(ListItem, { children: formatBytes(upload.file.size) }) }),
|
|
363
|
+
/* @__PURE__ */ jsx5(Grid, { xs: 4, children: /* @__PURE__ */ jsx5(UploadProgressBar, { upload }) }),
|
|
364
|
+
/* @__PURE__ */ jsx5(Grid, { xs: 1, children: /* @__PURE__ */ jsx5(
|
|
365
|
+
ListItemButton,
|
|
366
|
+
{
|
|
367
|
+
onClick: () => {
|
|
368
|
+
onRemoveFile(upload.id, upload);
|
|
369
|
+
},
|
|
370
|
+
children: /* @__PURE__ */ jsx5(ListItemIcon, { children: /* @__PURE__ */ jsx5(DeleteIcon, {}) })
|
|
371
|
+
}
|
|
372
|
+
) })
|
|
373
|
+
] }),
|
|
374
|
+
/* @__PURE__ */ jsx5(Divider2, { component: "li" })
|
|
375
|
+
] });
|
|
355
376
|
};
|
|
356
377
|
var FileList = ({ files, options, onRemoveFile }) => {
|
|
357
378
|
if (files.length === 0)
|
|
@@ -455,7 +476,7 @@ var FileSelector = ({
|
|
|
455
476
|
};
|
|
456
477
|
return /* @__PURE__ */ jsx6(FormProvider, __spreadProps(__spreadValues({}, methods), { children: /* @__PURE__ */ jsxs7("form", { onSubmit: methods.handleSubmit(handleOnSubmit), children: [
|
|
457
478
|
/* @__PURE__ */ jsxs7(Fragment6, { children: [
|
|
458
|
-
/* @__PURE__ */ jsx6(Typography4, { children: label }),
|
|
479
|
+
/* @__PURE__ */ jsx6(Typography4, { marginBottom: "4px", children: label }),
|
|
459
480
|
/* @__PURE__ */ jsx6(
|
|
460
481
|
Dropzone,
|
|
461
482
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-file-selector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Availity MUI file-selector Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@availity/api-axios": "^9.0.4",
|
|
36
|
-
"@availity/mui-alert": "^0.7.
|
|
37
|
-
"@availity/mui-button": "^0.6.
|
|
36
|
+
"@availity/mui-alert": "^0.7.2",
|
|
37
|
+
"@availity/mui-button": "^0.6.14",
|
|
38
38
|
"@availity/mui-divider": "^0.4.0",
|
|
39
|
-
"@availity/mui-form-utils": "^0.16.
|
|
40
|
-
"@availity/mui-icon": "^0.
|
|
39
|
+
"@availity/mui-form-utils": "^0.16.2",
|
|
40
|
+
"@availity/mui-icon": "^0.12.1",
|
|
41
41
|
"@availity/mui-layout": "^0.2.0",
|
|
42
|
-
"@availity/mui-list": "^0.2.
|
|
43
|
-
"@availity/mui-progress": "^0.4.
|
|
42
|
+
"@availity/mui-list": "^0.2.4",
|
|
43
|
+
"@availity/mui-progress": "^0.4.3",
|
|
44
44
|
"@availity/mui-typography": "^0.2.1",
|
|
45
45
|
"@availity/upload-core": "7.0.0-alpha.5",
|
|
46
46
|
"@tanstack/react-query": "^4.36.1",
|
package/src/lib/Dropzone.tsx
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { Dispatch, MouseEvent, useCallback, ChangeEvent } from 'react';
|
|
2
2
|
import { useDropzone, FileRejection } from 'react-dropzone';
|
|
3
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
4
|
import { Divider } from '@availity/mui-divider';
|
|
4
|
-
import {
|
|
5
|
+
import { CloudUploadIcon } from '@availity/mui-icon';
|
|
5
6
|
import { Box, Stack } from '@availity/mui-layout';
|
|
6
7
|
import { Typography } from '@availity/mui-typography';
|
|
7
8
|
|
|
8
9
|
import { FilePickerBtn } from './FilePickerBtn';
|
|
9
|
-
import { useFormContext } from 'react-hook-form';
|
|
10
10
|
|
|
11
11
|
const outerBoxStyles = {
|
|
12
|
-
backgroundColor: 'background.
|
|
12
|
+
backgroundColor: 'background.secondary',
|
|
13
13
|
border: '1px dotted',
|
|
14
|
+
borderColor: 'secondary.light',
|
|
14
15
|
borderRadius: '4px',
|
|
15
16
|
padding: '2rem',
|
|
17
|
+
'&:hover': {
|
|
18
|
+
backgroundColor: 'background.primary',
|
|
19
|
+
},
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
const innerBoxStyles = {
|
|
@@ -175,12 +179,13 @@ export const Dropzone = ({
|
|
|
175
179
|
return (
|
|
176
180
|
<Box sx={outerBoxStyles} {...getRootProps()}>
|
|
177
181
|
<Box sx={innerBoxStyles}>
|
|
178
|
-
<Stack spacing={2}
|
|
182
|
+
<Stack spacing={2} alignItems="center" justifyContent="center">
|
|
179
183
|
<>
|
|
180
|
-
<
|
|
184
|
+
<CloudUploadIcon fontSize="xlarge" color="secondary" />
|
|
181
185
|
<Typography variant="subtitle2" fontWeight="700">
|
|
182
186
|
Drag and Drop Files Here
|
|
183
187
|
</Typography>
|
|
188
|
+
<Divider>OR</Divider>
|
|
184
189
|
<FilePickerBtn
|
|
185
190
|
name={name}
|
|
186
191
|
color="primary"
|
package/src/lib/FileList.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { default as Upload, UploadOptions } from '@availity/upload-core';
|
|
2
2
|
import { List, ListItem, ListItemText, ListItemIcon, ListItemButton } from '@availity/mui-list';
|
|
3
|
-
import { DeleteIcon
|
|
3
|
+
import { DeleteIcon } from '@availity/mui-icon';
|
|
4
4
|
import { Grid } from '@availity/mui-layout';
|
|
5
|
+
import { Divider } from '@availity/mui-divider';
|
|
5
6
|
|
|
6
7
|
import { UploadProgressBar } from './UploadProgressBar';
|
|
7
8
|
import { formatBytes, getFileExtIcon } from './util';
|
|
@@ -21,8 +22,7 @@ type FileRowProps = {
|
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
const FileRow = ({ file, options, onRemoveFile }: FileRowProps) => {
|
|
24
|
-
const
|
|
25
|
-
console.log('ext, icon:', ext, icon);
|
|
25
|
+
const Icon = getFileExtIcon(file.name);
|
|
26
26
|
|
|
27
27
|
const { data: upload } = useUploadCore(file, options);
|
|
28
28
|
|
|
@@ -30,10 +30,10 @@ const FileRow = ({ file, options, onRemoveFile }: FileRowProps) => {
|
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<>
|
|
33
|
-
<Grid container spacing={2} alignItems="center" justifyContent="space-between" width="100%">
|
|
33
|
+
<Grid container spacing={2} alignItems="center" justifyContent="space-between" width="100%" borderBottom="1px">
|
|
34
34
|
<Grid xs={1}>
|
|
35
35
|
<ListItemIcon>
|
|
36
|
-
<
|
|
36
|
+
<Icon />
|
|
37
37
|
</ListItemIcon>
|
|
38
38
|
</Grid>
|
|
39
39
|
<Grid xs={4}>
|
|
@@ -57,6 +57,7 @@ const FileRow = ({ file, options, onRemoveFile }: FileRowProps) => {
|
|
|
57
57
|
</ListItemButton>
|
|
58
58
|
</Grid>
|
|
59
59
|
</Grid>
|
|
60
|
+
<Divider component="li" />
|
|
60
61
|
</>
|
|
61
62
|
);
|
|
62
63
|
};
|
package/src/lib/FileSelector.tsx
CHANGED
|
@@ -213,7 +213,7 @@ export const FileSelector = ({
|
|
|
213
213
|
<FormProvider {...methods}>
|
|
214
214
|
<form onSubmit={methods.handleSubmit(handleOnSubmit)}>
|
|
215
215
|
<>
|
|
216
|
-
<Typography>{label}</Typography>
|
|
216
|
+
<Typography marginBottom="4px">{label}</Typography>
|
|
217
217
|
<Dropzone
|
|
218
218
|
name={name}
|
|
219
219
|
allowedFileTypes={allowedFileTypes}
|
|
@@ -228,7 +228,6 @@ export const FileSelector = ({
|
|
|
228
228
|
<FileTypesMessage allowedFileTypes={allowedFileTypes} maxFileSize={maxSize} />
|
|
229
229
|
</>
|
|
230
230
|
{children}
|
|
231
|
-
|
|
232
231
|
{fileRejections.length > 0
|
|
233
232
|
? fileRejections.map((rejection) => (
|
|
234
233
|
<ErrorAlert
|
package/src/lib/util.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FileArchiveIcon,
|
|
3
|
+
FileCodeIcon,
|
|
4
|
+
FileCsvIcon,
|
|
5
|
+
FileExcelIcon,
|
|
6
|
+
FileIcon,
|
|
7
|
+
FileImageIcon,
|
|
8
|
+
FileLinesIcon,
|
|
9
|
+
FilePdfIcon,
|
|
10
|
+
FilePowerpointIcon,
|
|
11
|
+
FileWordIcon,
|
|
12
|
+
} from '@availity/mui-icon';
|
|
13
|
+
|
|
1
14
|
export function formatBytes(bytes: number, decimals = 2) {
|
|
2
15
|
if (!+bytes) return '0 Bytes';
|
|
3
16
|
|
|
@@ -11,23 +24,24 @@ export function formatBytes(bytes: number, decimals = 2) {
|
|
|
11
24
|
}
|
|
12
25
|
|
|
13
26
|
export const FILE_EXT_ICONS = {
|
|
14
|
-
png:
|
|
15
|
-
jpg:
|
|
16
|
-
jpeg:
|
|
17
|
-
gif:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
png: FileImageIcon,
|
|
28
|
+
jpg: FileImageIcon,
|
|
29
|
+
jpeg: FileImageIcon,
|
|
30
|
+
gif: FileImageIcon,
|
|
31
|
+
csv: FileCsvIcon,
|
|
32
|
+
ppt: FilePowerpointIcon,
|
|
33
|
+
pptx: FilePowerpointIcon,
|
|
34
|
+
xls: FileExcelIcon,
|
|
35
|
+
xlsx: FileExcelIcon,
|
|
36
|
+
doc: FileWordIcon,
|
|
37
|
+
docx: FileWordIcon,
|
|
38
|
+
txt: FileLinesIcon,
|
|
39
|
+
text: FileLinesIcon,
|
|
40
|
+
zip: FileArchiveIcon,
|
|
41
|
+
'7zip': FileArchiveIcon,
|
|
42
|
+
xml: FileCodeIcon,
|
|
43
|
+
html: FileCodeIcon,
|
|
44
|
+
pdf: FilePdfIcon,
|
|
31
45
|
} as const;
|
|
32
46
|
|
|
33
47
|
export type FileExtensionKey = keyof typeof FILE_EXT_ICONS;
|
|
@@ -36,7 +50,7 @@ export const isValidKey = (key: string): key is FileExtensionKey => (key ? key i
|
|
|
36
50
|
|
|
37
51
|
export const getFileExtIcon = (fileName: string) => {
|
|
38
52
|
const ext = fileName.split('.').pop()?.toLowerCase() || '';
|
|
39
|
-
const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] :
|
|
53
|
+
const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
|
|
40
54
|
|
|
41
|
-
return
|
|
55
|
+
return icon;
|
|
42
56
|
};
|