@availity/mui-file-selector 0.3.1 → 0.3.3
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 +12 -0
- package/README.md +67 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -2
- package/dist/index.mjs +8 -2
- package/package.json +3 -4
- package/src/lib/FileList.tsx +4 -4
- package/src/lib/FileSelector.stories.tsx +7 -5
- package/src/lib/FileSelector.tsx +4 -3
- package/src/lib/useUploadCore.tsx +13 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.3.3](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.3.2...@availity/mui-file-selector@0.3.3) (2025-02-19)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `mui-progress` updated to version `0.3.2`
|
|
10
|
+
## [0.3.2](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.3.1...@availity/mui-file-selector@0.3.2) (2025-02-19)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* update types and add docs ([c3f9f9e](https://github.com/Availity/element/commit/c3f9f9e1d0946ae5d0a03eab5b250ec47a0c3aab))
|
|
16
|
+
|
|
5
17
|
## [0.3.1](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.3.0...@availity/mui-file-selector@0.3.1) (2025-02-18)
|
|
6
18
|
|
|
7
19
|
### Dependency Updates
|
package/README.md
CHANGED
|
@@ -59,3 +59,70 @@ import { FileSelector } from '@availity/element';
|
|
|
59
59
|
```tsx
|
|
60
60
|
import { FileSelector } from '@availity/mui-file-selector';
|
|
61
61
|
```
|
|
62
|
+
|
|
63
|
+
#### Basic Example
|
|
64
|
+
|
|
65
|
+
Here's a basic example of how to use the FileSelector component:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import React from 'react';
|
|
69
|
+
import { FileSelector } from '@availity/mui-file-selector';
|
|
70
|
+
|
|
71
|
+
const MyComponent = () => {
|
|
72
|
+
const handleSubmit = (uploads, values) => {
|
|
73
|
+
console.log('Submitted files:', uploads);
|
|
74
|
+
console.log('Form values:', values);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<FileSelector
|
|
79
|
+
name="myFiles"
|
|
80
|
+
bucketId="your-bucket-id"
|
|
81
|
+
customerId="your-customer-id"
|
|
82
|
+
clientId="your-client-id"
|
|
83
|
+
maxSize={5 * 1024 * 1024} // 5MB
|
|
84
|
+
allowedFileTypes={['.pdf', '.doc', '.docx']}
|
|
85
|
+
maxFiles={3}
|
|
86
|
+
onSubmit={handleSubmit}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default MyComponent;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### Advanced Examples
|
|
95
|
+
|
|
96
|
+
The `onSuccess` and `onError` callbacks are available to use to add logic for after the file is uploaded or in the event there is an error with the api call.
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import React from 'react';
|
|
100
|
+
import { FileSelector } from '@availity/mui-file-selector';
|
|
101
|
+
|
|
102
|
+
const MyFileUploadComponent = () => {
|
|
103
|
+
const handleSuccess = () => {
|
|
104
|
+
// Handle successful upload - e.g., show success message, update UI
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleError = (error) => {
|
|
108
|
+
// Handle upload error - e.g., show error message, retry upload
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<FileSelector
|
|
113
|
+
name="documentUpload"
|
|
114
|
+
bucketId="your-bucket-id"
|
|
115
|
+
customerId="your-customer-id"
|
|
116
|
+
clientId="your-client-id"
|
|
117
|
+
maxSize={10 * 1024 * 1024} // 10MB
|
|
118
|
+
allowedFileTypes={['.pdf', '.doc', '.docx']}
|
|
119
|
+
multiple={true}
|
|
120
|
+
maxFiles={5}
|
|
121
|
+
onSuccess={handleSuccess}
|
|
122
|
+
onError={handleError}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default MyFileUploadComponent;
|
|
128
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -82,11 +82,11 @@ type FileSelectorProps = {
|
|
|
82
82
|
/**
|
|
83
83
|
* Callback fired when a file is successfully uploaded
|
|
84
84
|
*/
|
|
85
|
-
onSuccess?:
|
|
85
|
+
onSuccess?: () => void;
|
|
86
86
|
/**
|
|
87
87
|
* Callback fired when an error occurs during upload
|
|
88
88
|
*/
|
|
89
|
-
onError?:
|
|
89
|
+
onError?: (error: Error) => void;
|
|
90
90
|
/**
|
|
91
91
|
* Array of functions to execute before file upload begins.
|
|
92
92
|
* Each function should return a boolean indicating whether to proceed with the upload.
|
package/dist/index.d.ts
CHANGED
|
@@ -82,11 +82,11 @@ type FileSelectorProps = {
|
|
|
82
82
|
/**
|
|
83
83
|
* Callback fired when a file is successfully uploaded
|
|
84
84
|
*/
|
|
85
|
-
onSuccess?:
|
|
85
|
+
onSuccess?: () => void;
|
|
86
86
|
/**
|
|
87
87
|
* Callback fired when an error occurs during upload
|
|
88
88
|
*/
|
|
89
|
-
onError?:
|
|
89
|
+
onError?: (error: Error) => void;
|
|
90
90
|
/**
|
|
91
91
|
* Array of functions to execute before file upload begins.
|
|
92
92
|
* Each function should return a boolean indicating whether to proceed with the upload.
|
package/dist/index.js
CHANGED
|
@@ -383,8 +383,13 @@ var import_react_query = require("@tanstack/react-query");
|
|
|
383
383
|
var import_upload_core = __toESM(require("@availity/upload-core"));
|
|
384
384
|
function startUpload(file, options) {
|
|
385
385
|
return __async(this, null, function* () {
|
|
386
|
-
const
|
|
386
|
+
const _a = options, { onSuccess, onError } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError"]);
|
|
387
|
+
const upload = new import_upload_core.default(file, uploadOptions);
|
|
387
388
|
yield upload.generateId();
|
|
389
|
+
if (onSuccess)
|
|
390
|
+
upload.onSuccess.push(onSuccess);
|
|
391
|
+
if (onError)
|
|
392
|
+
upload.onError.push(onError);
|
|
388
393
|
upload.start();
|
|
389
394
|
return upload;
|
|
390
395
|
});
|
|
@@ -393,7 +398,8 @@ function useUploadCore(file, options) {
|
|
|
393
398
|
const isQueryEnabled = !!file;
|
|
394
399
|
return (0, import_react_query.useQuery)(["upload", file.name, options], () => startUpload(file, options), {
|
|
395
400
|
enabled: isQueryEnabled,
|
|
396
|
-
retry: false
|
|
401
|
+
retry: false,
|
|
402
|
+
refetchOnWindowFocus: false
|
|
397
403
|
});
|
|
398
404
|
}
|
|
399
405
|
|
package/dist/index.mjs
CHANGED
|
@@ -360,8 +360,13 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
360
360
|
import Upload from "@availity/upload-core";
|
|
361
361
|
function startUpload(file, options) {
|
|
362
362
|
return __async(this, null, function* () {
|
|
363
|
-
const
|
|
363
|
+
const _a = options, { onSuccess, onError } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError"]);
|
|
364
|
+
const upload = new Upload(file, uploadOptions);
|
|
364
365
|
yield upload.generateId();
|
|
366
|
+
if (onSuccess)
|
|
367
|
+
upload.onSuccess.push(onSuccess);
|
|
368
|
+
if (onError)
|
|
369
|
+
upload.onError.push(onError);
|
|
365
370
|
upload.start();
|
|
366
371
|
return upload;
|
|
367
372
|
});
|
|
@@ -370,7 +375,8 @@ function useUploadCore(file, options) {
|
|
|
370
375
|
const isQueryEnabled = !!file;
|
|
371
376
|
return useQuery(["upload", file.name, options], () => startUpload(file, options), {
|
|
372
377
|
enabled: isQueryEnabled,
|
|
373
|
-
retry: false
|
|
378
|
+
retry: false,
|
|
379
|
+
refetchOnWindowFocus: false
|
|
374
380
|
});
|
|
375
381
|
}
|
|
376
382
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-file-selector",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Availity MUI file-selector Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -48,13 +48,12 @@
|
|
|
48
48
|
"@availity/mui-icon": "^0.14.0",
|
|
49
49
|
"@availity/mui-layout": "^0.3.0",
|
|
50
50
|
"@availity/mui-list": "^0.3.0",
|
|
51
|
-
"@availity/mui-progress": "^0.5.
|
|
51
|
+
"@availity/mui-progress": "^0.5.1",
|
|
52
52
|
"@availity/mui-typography": "^0.3.0",
|
|
53
|
-
"@availity/upload-core": "7.0.
|
|
53
|
+
"@availity/upload-core": "^7.0.1",
|
|
54
54
|
"@tanstack/react-query": "^4.36.1",
|
|
55
55
|
"react-dropzone": "^11.7.1",
|
|
56
56
|
"react-hook-form": "^7.51.3",
|
|
57
|
-
"tus-js-client": "4.2.3",
|
|
58
57
|
"uuid": "^9.0.1"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
package/src/lib/FileList.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { default as Upload
|
|
1
|
+
import type { default as Upload } from '@availity/upload-core';
|
|
2
2
|
import { List, ListItem, ListItemText, ListItemIcon } from '@availity/mui-list';
|
|
3
3
|
import { IconButton } from '@availity/mui-button';
|
|
4
4
|
import { DeleteIcon } from '@availity/mui-icon';
|
|
@@ -7,7 +7,7 @@ import { Divider } from '@availity/mui-divider';
|
|
|
7
7
|
|
|
8
8
|
import { UploadProgressBar } from './UploadProgressBar';
|
|
9
9
|
import { formatBytes, getFileExtIcon } from './util';
|
|
10
|
-
import { useUploadCore } from './useUploadCore';
|
|
10
|
+
import { useUploadCore, Options } from './useUploadCore';
|
|
11
11
|
|
|
12
12
|
type FileRowProps = {
|
|
13
13
|
/** The File object containing information about the uploaded file */
|
|
@@ -19,7 +19,7 @@ type FileRowProps = {
|
|
|
19
19
|
*/
|
|
20
20
|
onRemoveFile: (id: string, upload: Upload) => void;
|
|
21
21
|
/** Configuration options for the upload process */
|
|
22
|
-
options:
|
|
22
|
+
options: Options;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const FileRow = ({ file, options, onRemoveFile }: FileRowProps) => {
|
|
@@ -78,7 +78,7 @@ export type FileListProps = {
|
|
|
78
78
|
/**
|
|
79
79
|
* Configuration options applied to all file uploads in the list
|
|
80
80
|
*/
|
|
81
|
-
options:
|
|
81
|
+
options: Options;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
export const FileList = ({ files, options, onRemoveFile }: FileListProps) => {
|
|
@@ -31,11 +31,13 @@ const meta: Meta<typeof FileSelector> = {
|
|
|
31
31
|
export default meta;
|
|
32
32
|
|
|
33
33
|
export const _FileSelector: StoryObj<typeof FileSelector> = {
|
|
34
|
-
render: (props: FileSelectorProps) =>
|
|
35
|
-
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
render: (props: FileSelectorProps) => {
|
|
35
|
+
return (
|
|
36
|
+
<Paper sx={{ padding: '2rem' }}>
|
|
37
|
+
<FileSelector {...props} />
|
|
38
|
+
</Paper>
|
|
39
|
+
);
|
|
40
|
+
},
|
|
39
41
|
args: {
|
|
40
42
|
name: 'file-selector',
|
|
41
43
|
allowedFileTypes: [],
|
package/src/lib/FileSelector.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import { Dropzone } from './Dropzone';
|
|
|
11
11
|
import { ErrorAlert } from './ErrorAlert';
|
|
12
12
|
import { FileList } from './FileList';
|
|
13
13
|
import { FileTypesMessage } from './FileTypesMessage';
|
|
14
|
+
import { Options } from './useUploadCore';
|
|
14
15
|
|
|
15
16
|
const CLOUD_URL = '/cloud/web/appl/vault/upload/v1/resumable';
|
|
16
17
|
|
|
@@ -94,11 +95,11 @@ export type FileSelectorProps = {
|
|
|
94
95
|
/**
|
|
95
96
|
* Callback fired when a file is successfully uploaded
|
|
96
97
|
*/
|
|
97
|
-
onSuccess?:
|
|
98
|
+
onSuccess?: () => void;
|
|
98
99
|
/**
|
|
99
100
|
* Callback fired when an error occurs during upload
|
|
100
101
|
*/
|
|
101
|
-
onError?:
|
|
102
|
+
onError?: (error: Error) => void;
|
|
102
103
|
/**
|
|
103
104
|
* Array of functions to execute before file upload begins.
|
|
104
105
|
* Each function should return a boolean indicating whether to proceed with the upload.
|
|
@@ -159,7 +160,7 @@ export const FileSelector = ({
|
|
|
159
160
|
},
|
|
160
161
|
});
|
|
161
162
|
|
|
162
|
-
const options:
|
|
163
|
+
const options: Options = {
|
|
163
164
|
bucketId,
|
|
164
165
|
customerId,
|
|
165
166
|
clientId,
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import Upload, { UploadOptions } from '@availity/upload-core';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export type Options = {
|
|
5
|
+
onError?: (error: Error) => void;
|
|
6
|
+
onSuccess?: () => void;
|
|
7
|
+
} & UploadOptions;
|
|
8
|
+
|
|
9
|
+
async function startUpload(file: File, options: Options) {
|
|
10
|
+
const { onSuccess, onError, ...uploadOptions } = options;
|
|
11
|
+
const upload = new Upload(file, uploadOptions);
|
|
6
12
|
|
|
7
13
|
await upload.generateId();
|
|
8
14
|
|
|
15
|
+
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
16
|
+
if (onError) upload.onError.push(onError);
|
|
17
|
+
|
|
9
18
|
upload.start();
|
|
10
19
|
|
|
11
20
|
return upload;
|
|
12
21
|
}
|
|
13
22
|
|
|
14
|
-
export function useUploadCore(file: File, options:
|
|
23
|
+
export function useUploadCore(file: File, options: Options) {
|
|
15
24
|
const isQueryEnabled = !!file;
|
|
16
25
|
|
|
17
26
|
return useQuery(['upload', file.name, options], () => startUpload(file, options), {
|
|
18
27
|
enabled: isQueryEnabled,
|
|
19
28
|
retry: false,
|
|
29
|
+
refetchOnWindowFocus: false,
|
|
20
30
|
});
|
|
21
31
|
}
|