@availity/mui-file-selector 1.3.2 → 1.4.0
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 +7 -0
- package/README.md +5 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -1
- 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,13 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [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)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-file-selector:** add onProgress to useUploadCore ([6bef795](https://github.com/Availity/element/commit/6bef7950f0e392fdbf7b395f45ed16562cda0295))
|
|
11
|
+
|
|
5
12
|
## [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
13
|
|
|
7
14
|
|
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
|
@@ -660,11 +660,12 @@ var import_react_query = require("@tanstack/react-query");
|
|
|
660
660
|
var import_upload_core = __toESM(require("@availity/upload-core"));
|
|
661
661
|
function startUpload(file, options) {
|
|
662
662
|
return __async(this, null, function* () {
|
|
663
|
-
const _a = options, { onSuccess, onError } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError"]);
|
|
663
|
+
const _a = options, { onSuccess, onError, onProgress } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError", "onProgress"]);
|
|
664
664
|
const upload = new import_upload_core.default(file, uploadOptions);
|
|
665
665
|
yield upload.generateId();
|
|
666
666
|
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
667
667
|
if (onError) upload.onError.push(onError);
|
|
668
|
+
if (onProgress) upload.onProgress.push(onProgress);
|
|
668
669
|
upload.start();
|
|
669
670
|
return upload;
|
|
670
671
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -635,11 +635,12 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
635
635
|
import Upload from "@availity/upload-core";
|
|
636
636
|
function startUpload(file, options) {
|
|
637
637
|
return __async(this, null, function* () {
|
|
638
|
-
const _a = options, { onSuccess, onError } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError"]);
|
|
638
|
+
const _a = options, { onSuccess, onError, onProgress } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError", "onProgress"]);
|
|
639
639
|
const upload = new Upload(file, uploadOptions);
|
|
640
640
|
yield upload.generateId();
|
|
641
641
|
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
642
642
|
if (onError) upload.onError.push(onError);
|
|
643
|
+
if (onProgress) upload.onProgress.push(onProgress);
|
|
643
644
|
upload.start();
|
|
644
645
|
return upload;
|
|
645
646
|
});
|
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
|
|