@availity/mui-file-selector 1.3.2 → 1.4.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 +13 -0
- package/README.md +5 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -9
- package/dist/index.mjs +16 -9
- package/package.json +1 -1
- package/src/lib/bs4migration.mdx +120 -0
- package/src/lib/useUploadCore.tsx +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [1.4.1](https://github.com/Availity/element/compare/@availity/mui-file-selector@1.4.0...@availity/mui-file-selector@1.4.1) (2025-04-04)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `mui-dialog` updated to version `1.4.0`
|
|
10
|
+
* `mui-textfield` updated to version `1.4.0`
|
|
11
|
+
## [1.4.0](https://github.com/Availity/element/compare/@availity/mui-file-selector@1.3.2...@availity/mui-file-selector@1.4.0) (2025-04-04)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **mui-file-selector:** add onProgress to useUploadCore ([6bef795](https://github.com/Availity/element/commit/6bef7950f0e392fdbf7b395f45ed16562cda0295))
|
|
17
|
+
|
|
5
18
|
## [1.3.2](https://github.com/Availity/element/compare/@availity/mui-file-selector@1.3.1...@availity/mui-file-selector@1.3.2) (2025-03-31)
|
|
6
19
|
|
|
7
20
|
|
package/README.md
CHANGED
|
@@ -170,6 +170,10 @@ const MyFileUploadComponent = () => {
|
|
|
170
170
|
// Handle upload error - e.g., show error message, retry upload
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
+
const handleOnProgress = (error) => {
|
|
174
|
+
// Handle upload error - e.g., show error message, retry upload
|
|
175
|
+
};
|
|
176
|
+
|
|
173
177
|
return (
|
|
174
178
|
<FileSelector
|
|
175
179
|
name="documentUpload"
|
|
@@ -183,6 +187,7 @@ const MyFileUploadComponent = () => {
|
|
|
183
187
|
uploadOptions={{
|
|
184
188
|
onSuccess: handleOnSuccess,
|
|
185
189
|
onError: handleOnError,
|
|
190
|
+
onProgress: handleOnProgress,
|
|
186
191
|
}}
|
|
187
192
|
/>
|
|
188
193
|
);
|
package/dist/index.d.mts
CHANGED
|
@@ -87,6 +87,7 @@ declare const ErrorAlert: ({ errors, fileName, id, onClose }: ErrorAlertProps) =
|
|
|
87
87
|
type Options = {
|
|
88
88
|
onError?: (error: Error) => void;
|
|
89
89
|
onSuccess?: () => void;
|
|
90
|
+
onProgress?: () => void;
|
|
90
91
|
} & UploadOptions;
|
|
91
92
|
type UploadQueryOptions = UseQueryOptions<Upload, Error, Upload, [string, string, Options]>;
|
|
92
93
|
declare function useUploadCore(file: File, options: Options, queryOptions?: UploadQueryOptions): _tanstack_react_query.UseQueryResult<Upload, Error>;
|
package/dist/index.d.ts
CHANGED
|
@@ -87,6 +87,7 @@ declare const ErrorAlert: ({ errors, fileName, id, onClose }: ErrorAlertProps) =
|
|
|
87
87
|
type Options = {
|
|
88
88
|
onError?: (error: Error) => void;
|
|
89
89
|
onSuccess?: () => void;
|
|
90
|
+
onProgress?: () => void;
|
|
90
91
|
} & UploadOptions;
|
|
91
92
|
type UploadQueryOptions = UseQueryOptions<Upload, Error, Upload, [string, string, Options]>;
|
|
92
93
|
declare function useUploadCore(file: File, options: Options, queryOptions?: UploadQueryOptions): _tanstack_react_query.UseQueryResult<Upload, Error>;
|
package/dist/index.js
CHANGED
|
@@ -462,15 +462,21 @@ var SelectPlaceholder = (0, import_styles4.styled)("span", {
|
|
|
462
462
|
slot: "SelectPlaceholder",
|
|
463
463
|
overridesResolver: (props, styles) => styles.avFilled
|
|
464
464
|
})(({ theme }) => ({ opacity: 1, color: theme.palette.grey[400] }));
|
|
465
|
-
var TextFieldFormHelperText = ({
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
465
|
+
var TextFieldFormHelperText = (_a) => {
|
|
466
|
+
var _b = _a, {
|
|
467
|
+
charCount,
|
|
468
|
+
helperText,
|
|
469
|
+
maxLength,
|
|
470
|
+
showCharacterCount
|
|
471
|
+
} = _b, FormHelperTextProps2 = __objRest(_b, [
|
|
472
|
+
"charCount",
|
|
473
|
+
"helperText",
|
|
474
|
+
"maxLength",
|
|
475
|
+
"showCharacterCount"
|
|
476
|
+
]);
|
|
471
477
|
if (showCharacterCount) {
|
|
472
478
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_mui_layout2.Grid, { container: true, justifyContent: "space-between", flexWrap: "nowrap", children: [
|
|
473
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_mui_form_utils2.FormHelperText, { sx: { marginRight: "12px" }, children: helperText }),
|
|
479
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_mui_form_utils2.FormHelperText, __spreadProps(__spreadValues({}, FormHelperTextProps2), { sx: { marginRight: "12px" }, children: helperText })),
|
|
474
480
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_mui_typography2.Typography, { variant: "caption", marginTop: "4px", lineHeight: "1.25rem", children: [
|
|
475
481
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_mui_typography2.Typography, { component: "span", variant: "inherit", color: charCount > maxLength ? "error" : "textPrimary", children: charCount || 0 }),
|
|
476
482
|
"/",
|
|
@@ -478,7 +484,7 @@ var TextFieldFormHelperText = ({
|
|
|
478
484
|
] })
|
|
479
485
|
] });
|
|
480
486
|
}
|
|
481
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_mui_form_utils2.FormHelperText, { children: helperText });
|
|
487
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_mui_form_utils2.FormHelperText, __spreadProps(__spreadValues({}, FormHelperTextProps2), { children: helperText }));
|
|
482
488
|
};
|
|
483
489
|
var TextField = (0, import_react2.forwardRef)((props, ref) => {
|
|
484
490
|
var _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -660,11 +666,12 @@ var import_react_query = require("@tanstack/react-query");
|
|
|
660
666
|
var import_upload_core = __toESM(require("@availity/upload-core"));
|
|
661
667
|
function startUpload(file, options) {
|
|
662
668
|
return __async(this, null, function* () {
|
|
663
|
-
const _a = options, { onSuccess, onError } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError"]);
|
|
669
|
+
const _a = options, { onSuccess, onError, onProgress } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError", "onProgress"]);
|
|
664
670
|
const upload = new import_upload_core.default(file, uploadOptions);
|
|
665
671
|
yield upload.generateId();
|
|
666
672
|
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
667
673
|
if (onError) upload.onError.push(onError);
|
|
674
|
+
if (onProgress) upload.onProgress.push(onProgress);
|
|
668
675
|
upload.start();
|
|
669
676
|
return upload;
|
|
670
677
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -426,15 +426,21 @@ var SelectPlaceholder = styled4("span", {
|
|
|
426
426
|
slot: "SelectPlaceholder",
|
|
427
427
|
overridesResolver: (props, styles) => styles.avFilled
|
|
428
428
|
})(({ theme }) => ({ opacity: 1, color: theme.palette.grey[400] }));
|
|
429
|
-
var TextFieldFormHelperText = ({
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
429
|
+
var TextFieldFormHelperText = (_a) => {
|
|
430
|
+
var _b = _a, {
|
|
431
|
+
charCount,
|
|
432
|
+
helperText,
|
|
433
|
+
maxLength,
|
|
434
|
+
showCharacterCount
|
|
435
|
+
} = _b, FormHelperTextProps2 = __objRest(_b, [
|
|
436
|
+
"charCount",
|
|
437
|
+
"helperText",
|
|
438
|
+
"maxLength",
|
|
439
|
+
"showCharacterCount"
|
|
440
|
+
]);
|
|
435
441
|
if (showCharacterCount) {
|
|
436
442
|
return /* @__PURE__ */ jsxs6(Grid, { container: true, justifyContent: "space-between", flexWrap: "nowrap", children: [
|
|
437
|
-
/* @__PURE__ */ jsx9(FormHelperText, { sx: { marginRight: "12px" }, children: helperText }),
|
|
443
|
+
/* @__PURE__ */ jsx9(FormHelperText, __spreadProps(__spreadValues({}, FormHelperTextProps2), { sx: { marginRight: "12px" }, children: helperText })),
|
|
438
444
|
/* @__PURE__ */ jsxs6(Typography2, { variant: "caption", marginTop: "4px", lineHeight: "1.25rem", children: [
|
|
439
445
|
/* @__PURE__ */ jsx9(Typography2, { component: "span", variant: "inherit", color: charCount > maxLength ? "error" : "textPrimary", children: charCount || 0 }),
|
|
440
446
|
"/",
|
|
@@ -442,7 +448,7 @@ var TextFieldFormHelperText = ({
|
|
|
442
448
|
] })
|
|
443
449
|
] });
|
|
444
450
|
}
|
|
445
|
-
return /* @__PURE__ */ jsx9(FormHelperText, { children: helperText });
|
|
451
|
+
return /* @__PURE__ */ jsx9(FormHelperText, __spreadProps(__spreadValues({}, FormHelperTextProps2), { children: helperText }));
|
|
446
452
|
};
|
|
447
453
|
var TextField = forwardRef((props, ref) => {
|
|
448
454
|
var _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -635,11 +641,12 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
635
641
|
import Upload from "@availity/upload-core";
|
|
636
642
|
function startUpload(file, options) {
|
|
637
643
|
return __async(this, null, function* () {
|
|
638
|
-
const _a = options, { onSuccess, onError } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError"]);
|
|
644
|
+
const _a = options, { onSuccess, onError, onProgress } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError", "onProgress"]);
|
|
639
645
|
const upload = new Upload(file, uploadOptions);
|
|
640
646
|
yield upload.generateId();
|
|
641
647
|
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
642
648
|
if (onError) upload.onError.push(onError);
|
|
649
|
+
if (onProgress) upload.onProgress.push(onProgress);
|
|
643
650
|
upload.start();
|
|
644
651
|
return upload;
|
|
645
652
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
<Meta title="BS4 Migration/Upload" />
|
|
4
|
+
|
|
5
|
+
# Upload Migration
|
|
6
|
+
|
|
7
|
+
The `Upload` component from `@availity/upload` and `@availity/form-upload` has been renamed to the `FileSelector` component. It still uses `@availity/upload-core` package to do the lifting, however, we have renamed, removed, and added some things.
|
|
8
|
+
|
|
9
|
+
For more in depth component information, visit:
|
|
10
|
+
|
|
11
|
+
- [Availity Design Documentation](https://design.availity.com/2e36e50c7/p/121639-file-selector)
|
|
12
|
+
- [Component Documentation](./?path=/docs/components-file-selector-file-selector--docs)
|
|
13
|
+
|
|
14
|
+
## Key Differences (not exhaustive list)
|
|
15
|
+
|
|
16
|
+
### Props
|
|
17
|
+
|
|
18
|
+
#### ✅ New
|
|
19
|
+
|
|
20
|
+
- `onDrop`: this prop serves as an `onChange` callback. Use it to get access to the files and the change event
|
|
21
|
+
- `disableRemove`: used to prevent removing the file from the list
|
|
22
|
+
- `validator`: allows for custom validation
|
|
23
|
+
- `customFileRow`: pass in your own component to be used in the FileList
|
|
24
|
+
- `queryOptions`: options for the `useQuery` hook
|
|
25
|
+
|
|
26
|
+
#### ⚠️ Changed
|
|
27
|
+
|
|
28
|
+
- `max` -> `maxFiles`
|
|
29
|
+
- `showFileDrop` -> `enableDropArea`
|
|
30
|
+
|
|
31
|
+
#### 🚫 Removed
|
|
32
|
+
|
|
33
|
+
- `onFileUpload`: this prop has been removed in favor of adding `onProgress`, `onSuccess`, and `onError`. Previously, you were required to add these functions yourself. Now they can be passed directly to the component
|
|
34
|
+
- `buttonText` (use children prop instead)
|
|
35
|
+
- `buttonClassName`
|
|
36
|
+
- `dropZoneText`
|
|
37
|
+
- `component`
|
|
38
|
+
|
|
39
|
+
### Form Management
|
|
40
|
+
|
|
41
|
+
- The FileSelector uses `react-hook-form` instead of `Formik`
|
|
42
|
+
- Must wrap component with FormProvider from `react-hook-form`
|
|
43
|
+
- The `react-hook-form` provider maintains the state of the selected files. It does not use `@availity/upload-core`.
|
|
44
|
+
|
|
45
|
+
## Code Examples
|
|
46
|
+
|
|
47
|
+
`availity-react` Example:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { Upload } from '@availity/form-upload';
|
|
51
|
+
import { Form } from '@availity/form';
|
|
52
|
+
|
|
53
|
+
const UploadForm = () => (
|
|
54
|
+
<Form initialValues={{ fileUpload: [] }} onSubmit={(values) => console.log(values)}>
|
|
55
|
+
<Upload
|
|
56
|
+
name="fileUpload"
|
|
57
|
+
clientId="my-client-id"
|
|
58
|
+
bucketId="my-bucket-id"
|
|
59
|
+
customerId="my-customer-id"
|
|
60
|
+
maxSize={5 * 1024 * 1024}
|
|
61
|
+
multiple={true}
|
|
62
|
+
allowedFileTypes={['.pdf', '.doc', '.docx']}
|
|
63
|
+
/>
|
|
64
|
+
</Form>
|
|
65
|
+
);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`@availity/element` Example:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { FileSelector } from '@availity/mui-file-selector';
|
|
72
|
+
import { FormProvider, useForm } from 'react-hook-form';
|
|
73
|
+
|
|
74
|
+
const UploadForm = () => {
|
|
75
|
+
const methods = useForm({
|
|
76
|
+
defaultValues: {
|
|
77
|
+
fileUpload: [],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const onSubmit = (data) => console.log(data);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<FormProvider {...methods}>
|
|
85
|
+
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
86
|
+
<FileSelector
|
|
87
|
+
name="fileUpload"
|
|
88
|
+
clientId="my-client-id"
|
|
89
|
+
bucketId="my-bucket-id"
|
|
90
|
+
customerId="my-customer-id"
|
|
91
|
+
maxSize={5 * 1024 * 1024}
|
|
92
|
+
maxFiles={5}
|
|
93
|
+
multiple={true}
|
|
94
|
+
allowedFileTypes={['.pdf', '.doc', '.docx']}
|
|
95
|
+
/>
|
|
96
|
+
</form>
|
|
97
|
+
</FormProvider>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Additional Considerations
|
|
103
|
+
|
|
104
|
+
### Error Handling
|
|
105
|
+
|
|
106
|
+
- The new component provides more detailed error feedback
|
|
107
|
+
- Errors are displayed using Element Alert components
|
|
108
|
+
- Custom error handling can be implemented through the validator prop
|
|
109
|
+
|
|
110
|
+
### File List Display
|
|
111
|
+
|
|
112
|
+
- Files are now displayed in a MUI List component
|
|
113
|
+
- Can be customized using the customFileRow prop
|
|
114
|
+
- Shows upload progress and status more clearly
|
|
115
|
+
|
|
116
|
+
### Accessibility
|
|
117
|
+
|
|
118
|
+
- Improved keyboard navigation
|
|
119
|
+
- Better screen reader support
|
|
120
|
+
- Clear focus indicators
|
|
@@ -6,18 +6,20 @@ import type { UploadOptions } from '@availity/upload-core';
|
|
|
6
6
|
export type Options = {
|
|
7
7
|
onError?: (error: Error) => void;
|
|
8
8
|
onSuccess?: () => void;
|
|
9
|
+
onProgress?: () => void;
|
|
9
10
|
} & UploadOptions;
|
|
10
11
|
|
|
11
12
|
export type UploadQueryOptions = UseQueryOptions<Upload, Error, Upload, [string, string, Options]>;
|
|
12
13
|
|
|
13
14
|
async function startUpload(file: File, options: Options) {
|
|
14
|
-
const { onSuccess, onError, ...uploadOptions } = options;
|
|
15
|
+
const { onSuccess, onError, onProgress, ...uploadOptions } = options;
|
|
15
16
|
const upload = new Upload(file, uploadOptions);
|
|
16
17
|
|
|
17
18
|
await upload.generateId();
|
|
18
19
|
|
|
19
20
|
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
20
21
|
if (onError) upload.onError.push(onError);
|
|
22
|
+
if (onProgress) upload.onProgress.push(onProgress);
|
|
21
23
|
|
|
22
24
|
upload.start();
|
|
23
25
|
|