@availity/mui-file-selector 0.2.3 → 0.2.5

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 CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.2.5](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.4...@availity/mui-file-selector@0.2.5) (2025-01-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * bump upload-core ([60dc9a3](https://github.com/Availity/element/commit/60dc9a38f27aa93098d593efcd20026b39a2b7d7))
11
+ * generate id before starting ([3514684](https://github.com/Availity/element/commit/3514684dfb9ca218d8d320c43235d4a0866d31a4))
12
+
13
+ ## [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)
14
+
15
+ ### Dependency Updates
16
+
17
+ * `mui-alert` updated to version `0.2.3`
18
+ * `mui-button` updated to version `0.2.3`
19
+ * `mui-form-utils` updated to version `0.2.3`
20
+ * `mui-icon` updated to version `0.2.3`
21
+ * `mui-list` updated to version `0.2.3`
22
+ * `mui-progress` updated to version `0.2.3`
23
+
24
+ ### Bug Fixes
25
+
26
+ * add hover color ([5001b77](https://github.com/Availity/element/commit/5001b77407b26de13d44b3ac3e39f05224aacc08))
27
+ * various fixes for file selector ([26c651d](https://github.com/Availity/element/commit/26c651d7b8e89919fac335f233acbe528d10956a))
28
+
5
29
  ## [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)
6
30
 
7
31
  ### Dependency Updates
package/dist/index.js CHANGED
@@ -55,6 +55,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
55
  mod
56
56
  ));
57
57
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
58
78
 
59
79
  // src/index.ts
60
80
  var src_exports = {};
@@ -75,6 +95,7 @@ var import_mui_typography4 = require("@availity/mui-typography");
75
95
  // src/lib/Dropzone.tsx
76
96
  var import_react = require("react");
77
97
  var import_react_dropzone = require("react-dropzone");
98
+ var import_react_hook_form2 = require("react-hook-form");
78
99
  var import_mui_divider = require("@availity/mui-divider");
79
100
  var import_mui_icon = require("@availity/mui-icon");
80
101
  var import_mui_layout = require("@availity/mui-layout");
@@ -130,13 +151,16 @@ var FilePickerBtn = (_a) => {
130
151
  };
131
152
 
132
153
  // src/lib/Dropzone.tsx
133
- var import_react_hook_form2 = require("react-hook-form");
134
154
  var import_jsx_runtime2 = require("react/jsx-runtime");
135
155
  var outerBoxStyles = {
136
- backgroundColor: "background.canvas",
156
+ backgroundColor: "background.secondary",
137
157
  border: "1px dotted",
158
+ borderColor: "secondary.light",
138
159
  borderRadius: "4px",
139
- padding: "2rem"
160
+ padding: "2rem",
161
+ "&:hover": {
162
+ backgroundColor: "background.primary"
163
+ }
140
164
  };
141
165
  var innerBoxStyles = {
142
166
  width: "100%",
@@ -226,9 +250,10 @@ var Dropzone = ({
226
250
  inputProps.onChange(event);
227
251
  }
228
252
  };
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, divider: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_divider.Divider, { children: "OR" }), alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
230
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.CloudDownloadIcon, { fontSize: "xlarge", color: "secondary" }),
253
+ 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: [
254
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
231
255
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_typography.Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
256
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_divider.Divider, { children: "OR" }),
232
257
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
233
258
  FilePickerBtn,
234
259
  {
@@ -271,8 +296,9 @@ var ErrorAlert = ({ errors, fileName, id, onClose }) => {
271
296
 
272
297
  // src/lib/FileList.tsx
273
298
  var import_mui_list = require("@availity/mui-list");
274
- var import_mui_icon3 = require("@availity/mui-icon");
299
+ var import_mui_icon4 = require("@availity/mui-icon");
275
300
  var import_mui_layout2 = require("@availity/mui-layout");
301
+ var import_mui_divider2 = require("@availity/mui-divider");
276
302
 
277
303
  // src/lib/UploadProgressBar.tsx
278
304
  var import_react2 = require("react");
@@ -311,6 +337,7 @@ var UploadProgressBar = ({ upload, onProgress, onError, onSuccess }) => {
311
337
  };
312
338
 
313
339
  // src/lib/util.ts
340
+ var import_mui_icon3 = require("@availity/mui-icon");
314
341
  function formatBytes(bytes, decimals = 2) {
315
342
  if (!+bytes)
316
343
  return "0 Bytes";
@@ -321,39 +348,43 @@ function formatBytes(bytes, decimals = 2) {
321
348
  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
322
349
  }
323
350
  var FILE_EXT_ICONS = {
324
- png: "file-image",
325
- jpg: "file-image",
326
- jpeg: "file-image",
327
- gif: "file-image",
328
- ppt: "file-powerpoint",
329
- pptx: "file-powerpoint",
330
- xls: "file-excel",
331
- xlsx: "file-excel",
332
- doc: "file-word",
333
- docx: "file-word",
334
- txt: "doc-alt",
335
- text: "doc-alt",
336
- zip: "file-archive",
337
- "7zip": "file-archive",
338
- xml: "file-code",
339
- html: "file-code",
340
- pdf: "file-pdf"
351
+ png: import_mui_icon3.FileImageIcon,
352
+ jpg: import_mui_icon3.FileImageIcon,
353
+ jpeg: import_mui_icon3.FileImageIcon,
354
+ gif: import_mui_icon3.FileImageIcon,
355
+ csv: import_mui_icon3.FileCsvIcon,
356
+ ppt: import_mui_icon3.FilePowerpointIcon,
357
+ pptx: import_mui_icon3.FilePowerpointIcon,
358
+ xls: import_mui_icon3.FileExcelIcon,
359
+ xlsx: import_mui_icon3.FileExcelIcon,
360
+ doc: import_mui_icon3.FileWordIcon,
361
+ docx: import_mui_icon3.FileWordIcon,
362
+ txt: import_mui_icon3.FileLinesIcon,
363
+ text: import_mui_icon3.FileLinesIcon,
364
+ zip: import_mui_icon3.FileArchiveIcon,
365
+ "7zip": import_mui_icon3.FileArchiveIcon,
366
+ xml: import_mui_icon3.FileCodeIcon,
367
+ html: import_mui_icon3.FileCodeIcon,
368
+ pdf: import_mui_icon3.FilePdfIcon
341
369
  };
342
370
  var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
343
371
  var getFileExtIcon = (fileName) => {
344
372
  var _a;
345
373
  const ext = ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
346
- const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : "doc";
347
- return { ext, icon };
374
+ const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : import_mui_icon3.FileIcon;
375
+ return icon;
348
376
  };
349
377
 
350
378
  // src/lib/useUploadCore.tsx
351
379
  var import_react_query = require("@tanstack/react-query");
352
380
  var import_upload_core = __toESM(require("@availity/upload-core"));
353
381
  function startUpload(file, options) {
354
- const upload = new import_upload_core.default(file, options);
355
- upload.start();
356
- return upload;
382
+ return __async(this, null, function* () {
383
+ const upload = new import_upload_core.default(file, options);
384
+ yield upload.generateId();
385
+ upload.start();
386
+ return upload;
387
+ });
357
388
  }
358
389
  function useUploadCore(file, options) {
359
390
  const isQueryEnabled = !!file;
@@ -366,26 +397,28 @@ function useUploadCore(file, options) {
366
397
  // src/lib/FileList.tsx
367
398
  var import_jsx_runtime5 = require("react/jsx-runtime");
368
399
  var FileRow = ({ file, options, onRemoveFile }) => {
369
- const { ext, icon } = getFileExtIcon(file.name);
370
- console.log("ext, icon:", ext, icon);
400
+ const Icon = getFileExtIcon(file.name);
371
401
  const { data: upload } = useUploadCore(file, options);
372
402
  if (!upload)
373
403
  return null;
374
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_mui_layout2.Grid, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", children: [
375
- /* @__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)(import_mui_icon3.FileIcon, {}) }) }),
376
- /* @__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) }) }),
377
- /* @__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) }) }),
378
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 4, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadProgressBar, { upload }) }),
379
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
380
- import_mui_list.ListItemButton,
381
- {
382
- onClick: () => {
383
- onRemoveFile(upload.id, upload);
384
- },
385
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list.ListItemIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_icon3.DeleteIcon, {}) })
386
- }
387
- ) })
388
- ] }) });
404
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
405
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_mui_layout2.Grid, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", borderBottom: "1px", children: [
406
+ /* @__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, {}) }) }),
407
+ /* @__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) }) }),
408
+ /* @__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) }) }),
409
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 4, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadProgressBar, { upload }) }),
410
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_layout2.Grid, { xs: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
411
+ import_mui_list.ListItemButton,
412
+ {
413
+ onClick: () => {
414
+ onRemoveFile(upload.id, upload);
415
+ },
416
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list.ListItemIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_icon4.DeleteIcon, {}) })
417
+ }
418
+ ) })
419
+ ] }),
420
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_divider2.Divider, { component: "li" })
421
+ ] });
389
422
  };
390
423
  var FileList = ({ files, options, onRemoveFile }) => {
391
424
  if (files.length === 0)
@@ -489,7 +522,7 @@ var FileSelector = ({
489
522
  };
490
523
  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
524
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
492
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_mui_typography4.Typography, { children: label }),
525
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_mui_typography4.Typography, { marginBottom: "4px", children: label }),
493
526
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
494
527
  Dropzone,
495
528
  {
package/dist/index.mjs CHANGED
@@ -29,6 +29,26 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
32
52
 
33
53
  // src/lib/FileSelector.tsx
34
54
  import { useState as useState2 } from "react";
@@ -41,8 +61,9 @@ import { Typography as Typography4 } from "@availity/mui-typography";
41
61
  // src/lib/Dropzone.tsx
42
62
  import { useCallback } from "react";
43
63
  import { useDropzone } from "react-dropzone";
64
+ import { useFormContext as useFormContext2 } from "react-hook-form";
44
65
  import { Divider } from "@availity/mui-divider";
45
- import { CloudDownloadIcon } from "@availity/mui-icon";
66
+ import { CloudUploadIcon } from "@availity/mui-icon";
46
67
  import { Box, Stack } from "@availity/mui-layout";
47
68
  import { Typography } from "@availity/mui-typography";
48
69
 
@@ -96,13 +117,16 @@ var FilePickerBtn = (_a) => {
96
117
  };
97
118
 
98
119
  // src/lib/Dropzone.tsx
99
- import { useFormContext as useFormContext2 } from "react-hook-form";
100
120
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
101
121
  var outerBoxStyles = {
102
- backgroundColor: "background.canvas",
122
+ backgroundColor: "background.secondary",
103
123
  border: "1px dotted",
124
+ borderColor: "secondary.light",
104
125
  borderRadius: "4px",
105
- padding: "2rem"
126
+ padding: "2rem",
127
+ "&:hover": {
128
+ backgroundColor: "background.primary"
129
+ }
106
130
  };
107
131
  var innerBoxStyles = {
108
132
  width: "100%",
@@ -192,9 +216,10 @@ var Dropzone = ({
192
216
  inputProps.onChange(event);
193
217
  }
194
218
  };
195
- return /* @__PURE__ */ jsx2(Box, __spreadProps(__spreadValues({ sx: outerBoxStyles }, getRootProps()), { children: /* @__PURE__ */ jsx2(Box, { sx: innerBoxStyles, children: /* @__PURE__ */ jsx2(Stack, { spacing: 2, divider: /* @__PURE__ */ jsx2(Divider, { children: "OR" }), alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs2(Fragment2, { children: [
196
- /* @__PURE__ */ jsx2(CloudDownloadIcon, { fontSize: "xlarge", color: "secondary" }),
219
+ 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: [
220
+ /* @__PURE__ */ jsx2(CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
197
221
  /* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
222
+ /* @__PURE__ */ jsx2(Divider, { children: "OR" }),
198
223
  /* @__PURE__ */ jsx2(
199
224
  FilePickerBtn,
200
225
  {
@@ -237,8 +262,9 @@ var ErrorAlert = ({ errors, fileName, id, onClose }) => {
237
262
 
238
263
  // src/lib/FileList.tsx
239
264
  import { List, ListItem, ListItemText, ListItemIcon, ListItemButton } from "@availity/mui-list";
240
- import { DeleteIcon, FileIcon } from "@availity/mui-icon";
265
+ import { DeleteIcon } from "@availity/mui-icon";
241
266
  import { Grid } from "@availity/mui-layout";
267
+ import { Divider as Divider2 } from "@availity/mui-divider";
242
268
 
243
269
  // src/lib/UploadProgressBar.tsx
244
270
  import { useState } from "react";
@@ -277,6 +303,18 @@ var UploadProgressBar = ({ upload, onProgress, onError, onSuccess }) => {
277
303
  };
278
304
 
279
305
  // src/lib/util.ts
306
+ import {
307
+ FileArchiveIcon,
308
+ FileCodeIcon,
309
+ FileCsvIcon,
310
+ FileExcelIcon,
311
+ FileIcon,
312
+ FileImageIcon,
313
+ FileLinesIcon,
314
+ FilePdfIcon,
315
+ FilePowerpointIcon,
316
+ FileWordIcon
317
+ } from "@availity/mui-icon";
280
318
  function formatBytes(bytes, decimals = 2) {
281
319
  if (!+bytes)
282
320
  return "0 Bytes";
@@ -287,39 +325,43 @@ function formatBytes(bytes, decimals = 2) {
287
325
  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
288
326
  }
289
327
  var FILE_EXT_ICONS = {
290
- png: "file-image",
291
- jpg: "file-image",
292
- jpeg: "file-image",
293
- gif: "file-image",
294
- ppt: "file-powerpoint",
295
- pptx: "file-powerpoint",
296
- xls: "file-excel",
297
- xlsx: "file-excel",
298
- doc: "file-word",
299
- docx: "file-word",
300
- txt: "doc-alt",
301
- text: "doc-alt",
302
- zip: "file-archive",
303
- "7zip": "file-archive",
304
- xml: "file-code",
305
- html: "file-code",
306
- pdf: "file-pdf"
328
+ png: FileImageIcon,
329
+ jpg: FileImageIcon,
330
+ jpeg: FileImageIcon,
331
+ gif: FileImageIcon,
332
+ csv: FileCsvIcon,
333
+ ppt: FilePowerpointIcon,
334
+ pptx: FilePowerpointIcon,
335
+ xls: FileExcelIcon,
336
+ xlsx: FileExcelIcon,
337
+ doc: FileWordIcon,
338
+ docx: FileWordIcon,
339
+ txt: FileLinesIcon,
340
+ text: FileLinesIcon,
341
+ zip: FileArchiveIcon,
342
+ "7zip": FileArchiveIcon,
343
+ xml: FileCodeIcon,
344
+ html: FileCodeIcon,
345
+ pdf: FilePdfIcon
307
346
  };
308
347
  var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
309
348
  var getFileExtIcon = (fileName) => {
310
349
  var _a;
311
350
  const ext = ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
312
- const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : "doc";
313
- return { ext, icon };
351
+ const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
352
+ return icon;
314
353
  };
315
354
 
316
355
  // src/lib/useUploadCore.tsx
317
356
  import { useQuery } from "@tanstack/react-query";
318
357
  import Upload from "@availity/upload-core";
319
358
  function startUpload(file, options) {
320
- const upload = new Upload(file, options);
321
- upload.start();
322
- return upload;
359
+ return __async(this, null, function* () {
360
+ const upload = new Upload(file, options);
361
+ yield upload.generateId();
362
+ upload.start();
363
+ return upload;
364
+ });
323
365
  }
324
366
  function useUploadCore(file, options) {
325
367
  const isQueryEnabled = !!file;
@@ -332,26 +374,28 @@ function useUploadCore(file, options) {
332
374
  // src/lib/FileList.tsx
333
375
  import { Fragment as Fragment5, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
334
376
  var FileRow = ({ file, options, onRemoveFile }) => {
335
- const { ext, icon } = getFileExtIcon(file.name);
336
- console.log("ext, icon:", ext, icon);
377
+ const Icon = getFileExtIcon(file.name);
337
378
  const { data: upload } = useUploadCore(file, options);
338
379
  if (!upload)
339
380
  return null;
340
- return /* @__PURE__ */ jsx5(Fragment5, { children: /* @__PURE__ */ jsxs5(Grid, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", children: [
341
- /* @__PURE__ */ jsx5(Grid, { xs: 1, children: /* @__PURE__ */ jsx5(ListItemIcon, { children: /* @__PURE__ */ jsx5(FileIcon, {}) }) }),
342
- /* @__PURE__ */ jsx5(Grid, { xs: 4, children: /* @__PURE__ */ jsx5(ListItemText, { children: upload.trimFileName(upload.file.name) }) }),
343
- /* @__PURE__ */ jsx5(Grid, { xs: 2, children: /* @__PURE__ */ jsx5(ListItem, { children: formatBytes(upload.file.size) }) }),
344
- /* @__PURE__ */ jsx5(Grid, { xs: 4, children: /* @__PURE__ */ jsx5(UploadProgressBar, { upload }) }),
345
- /* @__PURE__ */ jsx5(Grid, { xs: 1, children: /* @__PURE__ */ jsx5(
346
- ListItemButton,
347
- {
348
- onClick: () => {
349
- onRemoveFile(upload.id, upload);
350
- },
351
- children: /* @__PURE__ */ jsx5(ListItemIcon, { children: /* @__PURE__ */ jsx5(DeleteIcon, {}) })
352
- }
353
- ) })
354
- ] }) });
381
+ return /* @__PURE__ */ jsxs5(Fragment5, { children: [
382
+ /* @__PURE__ */ jsxs5(Grid, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", borderBottom: "1px", children: [
383
+ /* @__PURE__ */ jsx5(Grid, { xs: 1, children: /* @__PURE__ */ jsx5(ListItemIcon, { children: /* @__PURE__ */ jsx5(Icon, {}) }) }),
384
+ /* @__PURE__ */ jsx5(Grid, { xs: 4, children: /* @__PURE__ */ jsx5(ListItemText, { children: upload.trimFileName(upload.file.name) }) }),
385
+ /* @__PURE__ */ jsx5(Grid, { xs: 2, children: /* @__PURE__ */ jsx5(ListItem, { children: formatBytes(upload.file.size) }) }),
386
+ /* @__PURE__ */ jsx5(Grid, { xs: 4, children: /* @__PURE__ */ jsx5(UploadProgressBar, { upload }) }),
387
+ /* @__PURE__ */ jsx5(Grid, { xs: 1, children: /* @__PURE__ */ jsx5(
388
+ ListItemButton,
389
+ {
390
+ onClick: () => {
391
+ onRemoveFile(upload.id, upload);
392
+ },
393
+ children: /* @__PURE__ */ jsx5(ListItemIcon, { children: /* @__PURE__ */ jsx5(DeleteIcon, {}) })
394
+ }
395
+ ) })
396
+ ] }),
397
+ /* @__PURE__ */ jsx5(Divider2, { component: "li" })
398
+ ] });
355
399
  };
356
400
  var FileList = ({ files, options, onRemoveFile }) => {
357
401
  if (files.length === 0)
@@ -455,7 +499,7 @@ var FileSelector = ({
455
499
  };
456
500
  return /* @__PURE__ */ jsx6(FormProvider, __spreadProps(__spreadValues({}, methods), { children: /* @__PURE__ */ jsxs7("form", { onSubmit: methods.handleSubmit(handleOnSubmit), children: [
457
501
  /* @__PURE__ */ jsxs7(Fragment6, { children: [
458
- /* @__PURE__ */ jsx6(Typography4, { children: label }),
502
+ /* @__PURE__ */ jsx6(Typography4, { marginBottom: "4px", children: label }),
459
503
  /* @__PURE__ */ jsx6(
460
504
  Dropzone,
461
505
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-file-selector",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Availity MUI file-selector Component - part of the @availity/element design system",
5
5
  "keywords": [
6
6
  "react",
@@ -33,16 +33,16 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@availity/api-axios": "^9.0.4",
36
- "@availity/mui-alert": "^0.7.1",
37
- "@availity/mui-button": "^0.6.13",
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.1",
40
- "@availity/mui-icon": "^0.12.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.3",
43
- "@availity/mui-progress": "^0.4.2",
42
+ "@availity/mui-list": "^0.2.4",
43
+ "@availity/mui-progress": "^0.4.3",
44
44
  "@availity/mui-typography": "^0.2.1",
45
- "@availity/upload-core": "7.0.0-alpha.5",
45
+ "@availity/upload-core": "7.0.0-alpha.6",
46
46
  "@tanstack/react-query": "^4.36.1",
47
47
  "react-dropzone": "^11.7.1",
48
48
  "react-hook-form": "^7.51.3",
@@ -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 { CloudDownloadIcon } from '@availity/mui-icon';
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.canvas',
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} divider={<Divider>OR</Divider>} alignItems="center" justifyContent="center">
182
+ <Stack spacing={2} alignItems="center" justifyContent="center">
179
183
  <>
180
- <CloudDownloadIcon fontSize="xlarge" color="secondary" />
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"
@@ -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, FileIcon } from '@availity/mui-icon';
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 { ext, icon } = getFileExtIcon(file.name);
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
- <FileIcon />
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
  };
@@ -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
@@ -1,9 +1,11 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import Upload, { UploadOptions } from '@availity/upload-core';
3
3
 
4
- function startUpload(file: File, options: UploadOptions) {
4
+ async function startUpload(file: File, options: UploadOptions) {
5
5
  const upload = new Upload(file, options);
6
6
 
7
+ await upload.generateId();
8
+
7
9
  upload.start();
8
10
 
9
11
  return upload;
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: 'file-image',
15
- jpg: 'file-image',
16
- jpeg: 'file-image',
17
- gif: 'file-image',
18
- ppt: 'file-powerpoint',
19
- pptx: 'file-powerpoint',
20
- xls: 'file-excel',
21
- xlsx: 'file-excel',
22
- doc: 'file-word',
23
- docx: 'file-word',
24
- txt: 'doc-alt',
25
- text: 'doc-alt',
26
- zip: 'file-archive',
27
- '7zip': 'file-archive',
28
- xml: 'file-code',
29
- html: 'file-code',
30
- pdf: 'file-pdf',
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] : 'doc';
53
+ const icon = isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
40
54
 
41
- return { ext, icon };
55
+ return icon;
42
56
  };