@availity/mui-file-selector 1.0.0 → 1.1.1
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 +39 -0
- package/README.md +167 -15
- package/dist/index.d.mts +208 -22
- package/dist/index.d.ts +208 -22
- package/dist/index.js +234 -97
- package/dist/index.mjs +226 -97
- package/package.json +11 -11
- package/src/index.ts +7 -0
- package/src/lib/Dropzone.test.tsx +2 -2
- package/src/lib/Dropzone.tsx +92 -32
- package/src/lib/FileList.test.tsx +25 -1
- package/src/lib/FileList.tsx +66 -28
- package/src/lib/FilePickerBtn.test.tsx +3 -1
- package/src/lib/FilePickerBtn.tsx +23 -21
- package/src/lib/FileSelector.stories.tsx +66 -4
- package/src/lib/FileSelector.test.tsx +11 -1
- package/src/lib/FileSelector.tsx +109 -90
- package/src/lib/FileTypesMessage.test.tsx +2 -2
- package/src/lib/FileTypesMessage.tsx +11 -6
- package/src/lib/HeaderMessage.tsx +1 -1
- package/src/lib/useFileDelivery.tsx +3 -1
- package/src/lib/useUploadCore.tsx +10 -3
- package/tsconfig.spec.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -50,32 +50,25 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
// src/lib/FileSelector.tsx
|
|
54
|
-
import { useState as useState2 } from "react";
|
|
55
|
-
import { useForm, FormProvider } from "react-hook-form";
|
|
56
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
57
|
-
import { Button as Button2 } from "@availity/mui-button";
|
|
58
|
-
import { Grid as Grid2 } from "@availity/mui-layout";
|
|
59
|
-
import { Typography as Typography3 } from "@availity/mui-typography";
|
|
60
|
-
|
|
61
53
|
// src/lib/Dropzone.tsx
|
|
62
54
|
import { useCallback } from "react";
|
|
55
|
+
import { styled } from "@mui/material/styles";
|
|
63
56
|
import { useDropzone } from "react-dropzone";
|
|
64
|
-
import { useFormContext
|
|
57
|
+
import { useFormContext } from "react-hook-form";
|
|
65
58
|
import { Divider } from "@availity/mui-divider";
|
|
66
|
-
import { CloudUploadIcon } from "@availity/mui-icon";
|
|
59
|
+
import { CloudUploadIcon, PlusIcon } from "@availity/mui-icon";
|
|
67
60
|
import { Box, Stack } from "@availity/mui-layout";
|
|
68
61
|
import { Typography } from "@availity/mui-typography";
|
|
69
62
|
|
|
70
63
|
// src/lib/FilePickerBtn.tsx
|
|
71
|
-
import {
|
|
64
|
+
import { Controller } from "react-hook-form";
|
|
72
65
|
import { Button } from "@availity/mui-button";
|
|
73
66
|
import { Input } from "@availity/mui-form-utils";
|
|
74
67
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
75
68
|
var FilePickerBtn = (_a) => {
|
|
76
69
|
var _b = _a, {
|
|
77
70
|
name,
|
|
78
|
-
children
|
|
71
|
+
children,
|
|
79
72
|
color,
|
|
80
73
|
inputId,
|
|
81
74
|
inputProps = {},
|
|
@@ -92,25 +85,30 @@ var FilePickerBtn = (_a) => {
|
|
|
92
85
|
"onChange",
|
|
93
86
|
"onClick"
|
|
94
87
|
]);
|
|
95
|
-
const { register } = useFormContext();
|
|
96
88
|
const { accept, multiple, ref, style, type: inputType } = inputProps;
|
|
97
|
-
const field = register(name);
|
|
98
89
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
99
90
|
/* @__PURE__ */ jsx(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
91
|
+
Controller,
|
|
92
|
+
{
|
|
93
|
+
name,
|
|
94
|
+
defaultValue: [],
|
|
95
|
+
render: ({ field }) => /* @__PURE__ */ jsx(
|
|
96
|
+
Input,
|
|
97
|
+
__spreadProps(__spreadValues({}, field), {
|
|
98
|
+
onChange,
|
|
99
|
+
value: [],
|
|
100
|
+
inputRef: ref,
|
|
101
|
+
type: inputType,
|
|
102
|
+
sx: style,
|
|
103
|
+
inputProps: {
|
|
104
|
+
accept,
|
|
105
|
+
size: maxSize != null ? maxSize : void 0,
|
|
106
|
+
multiple
|
|
107
|
+
},
|
|
108
|
+
id: inputId
|
|
109
|
+
})
|
|
110
|
+
)
|
|
111
|
+
}
|
|
114
112
|
),
|
|
115
113
|
/* @__PURE__ */ jsx(Button, __spreadProps(__spreadValues({ color }, rest), { onClick, fullWidth: false, children }))
|
|
116
114
|
] });
|
|
@@ -142,43 +140,64 @@ var createCounter = () => {
|
|
|
142
140
|
};
|
|
143
141
|
};
|
|
144
142
|
var counter = createCounter();
|
|
143
|
+
var DropzoneContainer = styled(Box, { name: "AvDropzoneContainer", slot: "root" })({
|
|
144
|
+
".MuiDivider-root": {
|
|
145
|
+
width: "196px",
|
|
146
|
+
marginLeft: "auto",
|
|
147
|
+
marginRight: "auto"
|
|
148
|
+
}
|
|
149
|
+
});
|
|
145
150
|
var Dropzone = ({
|
|
146
151
|
allowedFileTypes = [],
|
|
147
152
|
disabled,
|
|
153
|
+
enableDropArea = true,
|
|
148
154
|
maxFiles,
|
|
149
155
|
maxSize,
|
|
150
156
|
multiple,
|
|
151
157
|
name,
|
|
152
158
|
onChange,
|
|
153
159
|
onClick,
|
|
160
|
+
onDrop,
|
|
154
161
|
setFileRejections,
|
|
155
|
-
setTotalSize
|
|
162
|
+
setTotalSize,
|
|
163
|
+
validator
|
|
156
164
|
}) => {
|
|
157
|
-
const { setValue, watch } =
|
|
158
|
-
const
|
|
165
|
+
const { getValues, setValue, watch } = useFormContext();
|
|
166
|
+
const handleValidation = useCallback(
|
|
159
167
|
(file) => {
|
|
160
168
|
var _a2;
|
|
161
169
|
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
170
|
+
const errors = [];
|
|
162
171
|
const isDuplicate = previous.some((prev) => prev.name === file.name);
|
|
163
172
|
if (isDuplicate) {
|
|
164
|
-
|
|
173
|
+
errors.push({
|
|
165
174
|
code: "duplicate-name",
|
|
166
175
|
message: "A file with this name already exists"
|
|
167
|
-
};
|
|
176
|
+
});
|
|
168
177
|
}
|
|
169
178
|
const hasMaxFiles = maxFiles && previous.length >= maxFiles;
|
|
170
179
|
if (hasMaxFiles) {
|
|
171
|
-
|
|
180
|
+
errors.push({
|
|
172
181
|
code: "too-many-files",
|
|
173
182
|
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
174
|
-
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (validator) {
|
|
186
|
+
const validatorErrors = validator(file);
|
|
187
|
+
if (validatorErrors) {
|
|
188
|
+
if (Array.isArray(validatorErrors)) {
|
|
189
|
+
errors.push(...validatorErrors);
|
|
190
|
+
} else {
|
|
191
|
+
errors.push(validatorErrors);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
175
194
|
}
|
|
176
|
-
return null;
|
|
195
|
+
return errors.length > 0 ? errors : null;
|
|
177
196
|
},
|
|
178
|
-
[maxFiles]
|
|
197
|
+
[maxFiles, validator]
|
|
179
198
|
);
|
|
180
|
-
const
|
|
181
|
-
(acceptedFiles, fileRejections) => {
|
|
199
|
+
const handleOnDrop = useCallback(
|
|
200
|
+
(acceptedFiles, fileRejections, event) => {
|
|
182
201
|
var _a2;
|
|
183
202
|
let newSize = 0;
|
|
184
203
|
for (const file of acceptedFiles) {
|
|
@@ -193,34 +212,44 @@ var Dropzone = ({
|
|
|
193
212
|
}
|
|
194
213
|
}
|
|
195
214
|
if (setFileRejections) setFileRejections(fileRejections);
|
|
215
|
+
if (onDrop) onDrop(acceptedFiles, fileRejections, event);
|
|
196
216
|
},
|
|
197
217
|
[setFileRejections]
|
|
198
218
|
);
|
|
199
219
|
const accept = allowedFileTypes.join(",");
|
|
200
220
|
const { getRootProps, getInputProps } = useDropzone({
|
|
201
|
-
onDrop,
|
|
221
|
+
onDrop: handleOnDrop,
|
|
202
222
|
maxSize,
|
|
203
223
|
maxFiles,
|
|
204
224
|
disabled,
|
|
205
225
|
multiple,
|
|
206
226
|
accept,
|
|
207
|
-
validator
|
|
227
|
+
validator: handleValidation
|
|
208
228
|
});
|
|
209
229
|
const inputProps = getInputProps({
|
|
210
230
|
multiple,
|
|
211
231
|
accept,
|
|
212
232
|
onChange
|
|
213
233
|
});
|
|
234
|
+
const _a = getRootProps(), { role, tabIndex } = _a, rootProps = __objRest(_a, ["role", "tabIndex"]);
|
|
214
235
|
const handleOnChange = (event) => {
|
|
215
236
|
if (inputProps.onChange) {
|
|
216
237
|
inputProps.onChange(event);
|
|
217
238
|
}
|
|
218
239
|
};
|
|
219
|
-
const
|
|
220
|
-
|
|
240
|
+
const handleOnClick = (event) => {
|
|
241
|
+
if (!enableDropArea && rootProps.onClick) rootProps.onClick(event);
|
|
242
|
+
if (onClick) onClick;
|
|
243
|
+
};
|
|
244
|
+
const getFieldValue = () => {
|
|
245
|
+
const field = getValues();
|
|
246
|
+
return field[name] || [];
|
|
247
|
+
};
|
|
248
|
+
const hasFiles = getFieldValue().length > 0;
|
|
249
|
+
return enableDropArea ? /* @__PURE__ */ jsx2(DropzoneContainer, __spreadProps(__spreadValues({ sx: outerBoxStyles }, rootProps), { children: /* @__PURE__ */ jsx2(Box, { sx: innerBoxStyles, children: /* @__PURE__ */ jsx2(Stack, { spacing: 2, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
221
250
|
/* @__PURE__ */ jsx2(CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
222
251
|
/* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
223
|
-
/* @__PURE__ */ jsx2(Divider, { children: "OR" }),
|
|
252
|
+
/* @__PURE__ */ jsx2(Divider, { flexItem: true, children: /* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", children: "OR" }) }),
|
|
224
253
|
/* @__PURE__ */ jsx2(
|
|
225
254
|
FilePickerBtn,
|
|
226
255
|
{
|
|
@@ -230,10 +259,24 @@ var Dropzone = ({
|
|
|
230
259
|
maxSize,
|
|
231
260
|
onClick,
|
|
232
261
|
inputProps,
|
|
233
|
-
onChange: handleOnChange
|
|
262
|
+
onChange: handleOnChange,
|
|
263
|
+
children: "Browse Files"
|
|
234
264
|
}
|
|
235
265
|
)
|
|
236
|
-
] }) }) }) }))
|
|
266
|
+
] }) }) }) })) : /* @__PURE__ */ jsx2(
|
|
267
|
+
FilePickerBtn,
|
|
268
|
+
{
|
|
269
|
+
name,
|
|
270
|
+
color: "tertiary",
|
|
271
|
+
disabled,
|
|
272
|
+
maxSize,
|
|
273
|
+
onClick: handleOnClick,
|
|
274
|
+
inputProps,
|
|
275
|
+
onChange: handleOnChange,
|
|
276
|
+
startIcon: /* @__PURE__ */ jsx2(PlusIcon, {}),
|
|
277
|
+
children: hasFiles ? "Add More Files" : "Add File(s)"
|
|
278
|
+
}
|
|
279
|
+
);
|
|
237
280
|
};
|
|
238
281
|
|
|
239
282
|
// src/lib/ErrorAlert.tsx
|
|
@@ -363,25 +406,36 @@ function startUpload(file, options) {
|
|
|
363
406
|
return upload;
|
|
364
407
|
});
|
|
365
408
|
}
|
|
366
|
-
function useUploadCore(file, options) {
|
|
409
|
+
function useUploadCore(file, options, queryOptions) {
|
|
367
410
|
const isQueryEnabled = !!file;
|
|
368
|
-
return useQuery(
|
|
411
|
+
return useQuery(__spreadValues({
|
|
412
|
+
queryKey: ["upload", file.name, options],
|
|
413
|
+
queryFn: () => startUpload(file, options),
|
|
369
414
|
enabled: isQueryEnabled,
|
|
370
415
|
retry: false,
|
|
371
416
|
refetchOnWindowFocus: false
|
|
372
|
-
});
|
|
417
|
+
}, queryOptions));
|
|
373
418
|
}
|
|
374
419
|
|
|
375
420
|
// src/lib/FileList.tsx
|
|
376
421
|
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
377
|
-
var FileRow = ({
|
|
422
|
+
var FileRow = ({
|
|
423
|
+
file,
|
|
424
|
+
options,
|
|
425
|
+
onRemoveFile,
|
|
426
|
+
queryOptions,
|
|
427
|
+
customFileRow: CustomRow,
|
|
428
|
+
disableRemove = false
|
|
429
|
+
}) => {
|
|
378
430
|
const Icon = getFileExtIcon(file.name);
|
|
379
|
-
const { data: upload } = useUploadCore(file, options);
|
|
431
|
+
const { data: upload } = useUploadCore(file, options, queryOptions);
|
|
432
|
+
if (CustomRow) return /* @__PURE__ */ jsx5(CustomRow, { upload, options, onRemoveFile });
|
|
380
433
|
if (!upload) return null;
|
|
381
434
|
return /* @__PURE__ */ jsxs5(
|
|
382
435
|
ListItem,
|
|
383
436
|
{
|
|
384
|
-
|
|
437
|
+
disableGutters: true,
|
|
438
|
+
secondaryAction: !disableRemove && /* @__PURE__ */ jsx5(
|
|
385
439
|
IconButton,
|
|
386
440
|
{
|
|
387
441
|
title: "remove file",
|
|
@@ -404,27 +458,68 @@ var FileRow = ({ file, options, onRemoveFile }) => {
|
|
|
404
458
|
}
|
|
405
459
|
);
|
|
406
460
|
};
|
|
407
|
-
var FileList = ({
|
|
461
|
+
var FileList = ({
|
|
462
|
+
files,
|
|
463
|
+
options,
|
|
464
|
+
onRemoveFile,
|
|
465
|
+
queryOptions,
|
|
466
|
+
customFileRow,
|
|
467
|
+
disableRemove
|
|
468
|
+
}) => {
|
|
408
469
|
if (files.length === 0) return null;
|
|
409
470
|
return /* @__PURE__ */ jsx5(List, { children: files.map((file) => {
|
|
410
|
-
return /* @__PURE__ */ jsx5(
|
|
471
|
+
return /* @__PURE__ */ jsx5(
|
|
472
|
+
FileRow,
|
|
473
|
+
{
|
|
474
|
+
file,
|
|
475
|
+
options,
|
|
476
|
+
onRemoveFile,
|
|
477
|
+
queryOptions,
|
|
478
|
+
customFileRow,
|
|
479
|
+
disableRemove
|
|
480
|
+
},
|
|
481
|
+
file.name
|
|
482
|
+
);
|
|
411
483
|
}) });
|
|
412
484
|
};
|
|
413
485
|
|
|
486
|
+
// src/lib/FileSelector.tsx
|
|
487
|
+
import { useState as useState2 } from "react";
|
|
488
|
+
import { useFormContext as useFormContext2 } from "react-hook-form";
|
|
489
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
490
|
+
import { Grid as Grid2 } from "@availity/mui-layout";
|
|
491
|
+
import { Typography as Typography4 } from "@availity/mui-typography";
|
|
492
|
+
|
|
414
493
|
// src/lib/FileTypesMessage.tsx
|
|
415
494
|
import { Typography as Typography2 } from "@availity/mui-typography";
|
|
416
495
|
import { jsxs as jsxs6 } from "react/jsx-runtime";
|
|
417
|
-
var FileTypesMessage = ({
|
|
496
|
+
var FileTypesMessage = ({
|
|
497
|
+
allowedFileTypes = [],
|
|
498
|
+
maxFileSize,
|
|
499
|
+
variant = "caption"
|
|
500
|
+
}) => {
|
|
418
501
|
const fileSizeMsg = typeof maxFileSize === "number" ? `Maximum file size is ${formatBytes(maxFileSize)}. ` : null;
|
|
419
|
-
const fileTypesMsg = allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}
|
|
420
|
-
return /* @__PURE__ */ jsxs6(Typography2, { variant
|
|
502
|
+
const fileTypesMsg = allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}` : "All file types allowed.";
|
|
503
|
+
return /* @__PURE__ */ jsxs6(Typography2, { variant, children: [
|
|
421
504
|
fileSizeMsg,
|
|
422
505
|
fileTypesMsg
|
|
423
506
|
] });
|
|
424
507
|
};
|
|
425
508
|
|
|
509
|
+
// src/lib/HeaderMessage.tsx
|
|
510
|
+
import { Typography as Typography3 } from "@availity/mui-typography";
|
|
511
|
+
import { jsxs as jsxs7 } from "react/jsx-runtime";
|
|
512
|
+
var HeaderMessage = ({ maxFiles, maxSize }) => {
|
|
513
|
+
return /* @__PURE__ */ jsxs7(Typography3, { variant: "h6", children: [
|
|
514
|
+
"Attach up to ",
|
|
515
|
+
maxFiles,
|
|
516
|
+
" file(s), with a maximum individual size of ",
|
|
517
|
+
formatBytes(maxSize)
|
|
518
|
+
] });
|
|
519
|
+
};
|
|
520
|
+
|
|
426
521
|
// src/lib/FileSelector.tsx
|
|
427
|
-
import { Fragment as Fragment5, jsx as jsx6, jsxs as
|
|
522
|
+
import { Fragment as Fragment5, jsx as jsx6, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
428
523
|
var CLOUD_URL = "/cloud/web/appl/vault/upload/v1/resumable";
|
|
429
524
|
var FileSelector = ({
|
|
430
525
|
name,
|
|
@@ -434,7 +529,9 @@ var FileSelector = ({
|
|
|
434
529
|
clientId,
|
|
435
530
|
children,
|
|
436
531
|
customerId,
|
|
532
|
+
customFileRow,
|
|
437
533
|
disabled = false,
|
|
534
|
+
enableDropArea = true,
|
|
438
535
|
endpoint,
|
|
439
536
|
isCloud,
|
|
440
537
|
label = "Upload file",
|
|
@@ -442,79 +539,94 @@ var FileSelector = ({
|
|
|
442
539
|
maxSize,
|
|
443
540
|
multiple = true,
|
|
444
541
|
onChange,
|
|
445
|
-
|
|
446
|
-
onSuccess,
|
|
447
|
-
onError,
|
|
448
|
-
onFilePreUpload = [],
|
|
542
|
+
onDrop,
|
|
449
543
|
onUploadRemove,
|
|
450
|
-
|
|
544
|
+
queryOptions,
|
|
545
|
+
uploadOptions,
|
|
546
|
+
validator,
|
|
547
|
+
disableRemove
|
|
451
548
|
}) => {
|
|
452
549
|
const [totalSize, setTotalSize] = useState2(0);
|
|
453
550
|
const [fileRejections, setFileRejections] = useState2([]);
|
|
454
551
|
const client = useQueryClient();
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
[name]: []
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
const options = {
|
|
552
|
+
const formMethods = useFormContext2();
|
|
553
|
+
const options = __spreadProps(__spreadValues({}, uploadOptions), {
|
|
461
554
|
bucketId,
|
|
462
555
|
customerId,
|
|
463
556
|
clientId,
|
|
464
557
|
fileTypes: allowedFileTypes,
|
|
465
558
|
maxSize,
|
|
466
|
-
allowedFileNameCharacters
|
|
467
|
-
|
|
468
|
-
onSuccess,
|
|
469
|
-
retryDelays
|
|
470
|
-
};
|
|
471
|
-
if (onFilePreUpload) options.onPreStart = onFilePreUpload;
|
|
559
|
+
allowedFileNameCharacters
|
|
560
|
+
});
|
|
472
561
|
if (endpoint) options.endpoint = endpoint;
|
|
473
562
|
if (isCloud) options.endpoint = CLOUD_URL;
|
|
474
563
|
const handleOnRemoveFile = (uploadId, upload) => {
|
|
475
|
-
const prevFiles =
|
|
564
|
+
const prevFiles = formMethods.getValues(name);
|
|
476
565
|
const newFiles = prevFiles.filter((file) => file.name !== upload.file.name);
|
|
477
566
|
if (newFiles.length !== prevFiles.length) {
|
|
478
567
|
const removedFile = prevFiles.find((file) => file.name === upload.file.name);
|
|
479
|
-
|
|
568
|
+
try {
|
|
569
|
+
upload.abort();
|
|
570
|
+
} catch (e) {
|
|
571
|
+
console.error("Encountered an issue stopping the file upload");
|
|
572
|
+
}
|
|
573
|
+
formMethods.setValue(name, newFiles);
|
|
574
|
+
client.removeQueries(["upload", upload.file.name]);
|
|
480
575
|
if (removedFile == null ? void 0 : removedFile.size) setTotalSize(totalSize - removedFile.size);
|
|
481
576
|
if (onUploadRemove) onUploadRemove(newFiles, uploadId);
|
|
482
577
|
}
|
|
483
578
|
};
|
|
484
|
-
const files =
|
|
485
|
-
const handleOnSubmit = (values) => {
|
|
486
|
-
if (values[name].length === 0) return;
|
|
487
|
-
const queries = client.getQueriesData(["upload"]);
|
|
488
|
-
const uploads = [];
|
|
489
|
-
for (const [, data] of queries) {
|
|
490
|
-
if (data) uploads.push(data);
|
|
491
|
-
}
|
|
492
|
-
if (onSubmit) onSubmit(uploads, values);
|
|
493
|
-
};
|
|
579
|
+
const files = formMethods.watch(name);
|
|
494
580
|
const handleRemoveRejection = (id) => {
|
|
495
581
|
const rejections = fileRejections.filter((value) => value.id !== id);
|
|
496
582
|
setFileRejections(rejections);
|
|
497
583
|
};
|
|
498
|
-
return /* @__PURE__ */
|
|
499
|
-
/* @__PURE__ */
|
|
500
|
-
/* @__PURE__ */ jsx6(
|
|
584
|
+
return /* @__PURE__ */ jsxs8(Fragment5, { children: [
|
|
585
|
+
enableDropArea ? /* @__PURE__ */ jsxs8(Fragment5, { children: [
|
|
586
|
+
label ? /* @__PURE__ */ jsx6(Typography4, { marginBottom: "4px", children: label }) : null,
|
|
501
587
|
/* @__PURE__ */ jsx6(
|
|
502
588
|
Dropzone,
|
|
503
589
|
{
|
|
504
590
|
name,
|
|
505
591
|
allowedFileTypes,
|
|
506
592
|
disabled,
|
|
593
|
+
enableDropArea,
|
|
507
594
|
maxFiles,
|
|
508
595
|
maxSize,
|
|
509
596
|
multiple,
|
|
510
597
|
onChange,
|
|
598
|
+
onDrop,
|
|
511
599
|
setFileRejections,
|
|
512
|
-
setTotalSize
|
|
600
|
+
setTotalSize,
|
|
601
|
+
validator
|
|
513
602
|
}
|
|
514
603
|
),
|
|
515
|
-
/* @__PURE__ */ jsx6(FileTypesMessage, { allowedFileTypes, maxFileSize: maxSize })
|
|
604
|
+
/* @__PURE__ */ jsx6(FileTypesMessage, { allowedFileTypes, maxFileSize: maxSize, variant: "caption" }),
|
|
605
|
+
children
|
|
606
|
+
] }) : /* @__PURE__ */ jsxs8(Grid2, { container: true, rowSpacing: 3, flexDirection: "column", children: [
|
|
607
|
+
/* @__PURE__ */ jsxs8(Grid2, { children: [
|
|
608
|
+
/* @__PURE__ */ jsx6(HeaderMessage, { maxFiles, maxSize }),
|
|
609
|
+
/* @__PURE__ */ jsx6(FileTypesMessage, { allowedFileTypes, variant: "body2" })
|
|
610
|
+
] }),
|
|
611
|
+
children ? /* @__PURE__ */ jsx6(Grid2, { children }) : null,
|
|
612
|
+
/* @__PURE__ */ jsx6(Grid2, { children: /* @__PURE__ */ jsx6(
|
|
613
|
+
Dropzone,
|
|
614
|
+
{
|
|
615
|
+
name,
|
|
616
|
+
allowedFileTypes,
|
|
617
|
+
disabled,
|
|
618
|
+
enableDropArea,
|
|
619
|
+
maxFiles,
|
|
620
|
+
maxSize,
|
|
621
|
+
multiple,
|
|
622
|
+
onChange,
|
|
623
|
+
onDrop,
|
|
624
|
+
setFileRejections,
|
|
625
|
+
setTotalSize,
|
|
626
|
+
validator
|
|
627
|
+
}
|
|
628
|
+
) })
|
|
516
629
|
] }),
|
|
517
|
-
children,
|
|
518
630
|
fileRejections.length > 0 ? fileRejections.map((rejection) => /* @__PURE__ */ jsx6(
|
|
519
631
|
ErrorAlert,
|
|
520
632
|
{
|
|
@@ -525,11 +637,28 @@ var FileSelector = ({
|
|
|
525
637
|
},
|
|
526
638
|
rejection.id
|
|
527
639
|
)) : null,
|
|
528
|
-
/* @__PURE__ */ jsx6(
|
|
529
|
-
|
|
530
|
-
|
|
640
|
+
/* @__PURE__ */ jsx6(
|
|
641
|
+
FileList,
|
|
642
|
+
{
|
|
643
|
+
files: files || [],
|
|
644
|
+
options,
|
|
645
|
+
onRemoveFile: handleOnRemoveFile,
|
|
646
|
+
queryOptions,
|
|
647
|
+
customFileRow,
|
|
648
|
+
disableRemove
|
|
649
|
+
}
|
|
650
|
+
)
|
|
651
|
+
] });
|
|
531
652
|
};
|
|
532
653
|
export {
|
|
654
|
+
Dropzone,
|
|
655
|
+
ErrorAlert,
|
|
656
|
+
FileList,
|
|
657
|
+
FilePickerBtn,
|
|
658
|
+
FileRow,
|
|
533
659
|
FileSelector,
|
|
534
|
-
|
|
660
|
+
FileTypesMessage,
|
|
661
|
+
HeaderMessage,
|
|
662
|
+
UploadProgressBar,
|
|
663
|
+
useUploadCore
|
|
535
664
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-file-selector",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Availity MUI file-selector Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@availity/api-axios": "^10.0.0",
|
|
44
|
-
"@availity/mui-alert": "^1.0.
|
|
45
|
-
"@availity/mui-button": "^1.0.
|
|
46
|
-
"@availity/mui-divider": "^1.0.
|
|
47
|
-
"@availity/mui-form-utils": "^1.0.
|
|
48
|
-
"@availity/mui-icon": "^1.0.
|
|
49
|
-
"@availity/mui-layout": "^1.0.
|
|
50
|
-
"@availity/mui-list": "^1.0.
|
|
51
|
-
"@availity/mui-progress": "^1.0.
|
|
52
|
-
"@availity/mui-typography": "^1.0.
|
|
44
|
+
"@availity/mui-alert": "^1.0.1",
|
|
45
|
+
"@availity/mui-button": "^1.0.1",
|
|
46
|
+
"@availity/mui-divider": "^1.0.1",
|
|
47
|
+
"@availity/mui-form-utils": "^1.0.1",
|
|
48
|
+
"@availity/mui-icon": "^1.0.1",
|
|
49
|
+
"@availity/mui-layout": "^1.0.1",
|
|
50
|
+
"@availity/mui-list": "^1.0.1",
|
|
51
|
+
"@availity/mui-progress": "^1.0.1",
|
|
52
|
+
"@availity/mui-typography": "^1.0.1",
|
|
53
53
|
"@availity/upload-core": "^7.0.1",
|
|
54
54
|
"@tanstack/react-query": "^4.36.1",
|
|
55
55
|
"react-dropzone": "^11.7.1",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"uuid": "^9.0.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@availity/mui-paper": "^1.0.
|
|
61
|
+
"@availity/mui-paper": "^1.0.1",
|
|
62
62
|
"@mui/material": "^6.4.5",
|
|
63
63
|
"react": "18.2.0",
|
|
64
64
|
"react-dom": "18.2.0",
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
export * from './lib/Dropzone';
|
|
2
|
+
export * from './lib/ErrorAlert';
|
|
3
|
+
export * from './lib/FileList';
|
|
4
|
+
export * from './lib/FilePickerBtn';
|
|
1
5
|
export * from './lib/FileSelector';
|
|
6
|
+
export * from './lib/FileTypesMessage';
|
|
7
|
+
export * from './lib/HeaderMessage';
|
|
2
8
|
export * from './lib/UploadProgressBar';
|
|
9
|
+
export * from './lib/useUploadCore';
|
|
@@ -11,10 +11,10 @@ const TestForm = ({ children }: { children: ReactNode }) => {
|
|
|
11
11
|
return <FormProvider {...methods}>{children}</FormProvider>;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const client = new QueryClient();
|
|
15
|
+
|
|
14
16
|
describe('Dropzone', () => {
|
|
15
17
|
test('should render successfully', () => {
|
|
16
|
-
const client = new QueryClient();
|
|
17
|
-
|
|
18
18
|
render(
|
|
19
19
|
<QueryClientProvider client={client}>
|
|
20
20
|
<TestForm>
|