@availity/mui-file-selector 1.0.0 → 1.1.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 +25 -0
- package/README.md +107 -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 +1 -1
- 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/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,160 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { MouseEvent, Dispatch, ChangeEvent, RefObject, ReactNode, ElementType } from 'react';
|
|
3
|
+
import { DropEvent, FileRejection, FileError, DropzoneInputProps } from 'react-dropzone';
|
|
3
4
|
import Upload, { UploadOptions } from '@availity/upload-core';
|
|
5
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
|
+
import { UseQueryOptions } from '@tanstack/react-query';
|
|
7
|
+
import { ButtonProps } from '@availity/mui-button';
|
|
8
|
+
import { FileRejection as FileRejection$1, DropEvent as DropEvent$1, FileError as FileError$1 } from 'react-dropzone/typings/react-dropzone';
|
|
9
|
+
|
|
10
|
+
type DropzoneProps = {
|
|
11
|
+
/**
|
|
12
|
+
* Name given to the input field. Used by react-hook-form
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* List of allowed file extensions (e.g. ['.pdf', '.doc']). Each extension must start with a dot
|
|
17
|
+
*/
|
|
18
|
+
allowedFileTypes?: `.${string}`[];
|
|
19
|
+
/**
|
|
20
|
+
* Whether the dropzone is disabled
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to enable the dropzone area
|
|
25
|
+
*/
|
|
26
|
+
enableDropArea?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of files that can be uploaded
|
|
29
|
+
*/
|
|
30
|
+
maxFiles?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Maximum size of each file in bytes
|
|
33
|
+
*/
|
|
34
|
+
maxSize?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Whether multiple file selection is allowed
|
|
37
|
+
*/
|
|
38
|
+
multiple?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Handler called when the file input's value changes
|
|
41
|
+
*/
|
|
42
|
+
onChange?: (event: DropEvent) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Handler called when the file picker button is clicked
|
|
45
|
+
*/
|
|
46
|
+
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
47
|
+
/**
|
|
48
|
+
* More sophisticated version of "onChange". This is the recommend function to use for changes to the form state
|
|
49
|
+
*/
|
|
50
|
+
onDrop?: (acceptedFiles: File[], fileRejections: (FileRejection & {
|
|
51
|
+
id: number;
|
|
52
|
+
})[], event: DropEvent) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback to handle rejected files that don't meet validation criteria
|
|
55
|
+
*/
|
|
56
|
+
setFileRejections?: (fileRejections: (FileRejection & {
|
|
57
|
+
id: number;
|
|
58
|
+
})[]) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Callback to update the total size of all uploaded files
|
|
61
|
+
*/
|
|
62
|
+
setTotalSize: Dispatch<React.SetStateAction<number>>;
|
|
63
|
+
/**
|
|
64
|
+
* Validation function used for custom validation that is not covered with the other props
|
|
65
|
+
* */
|
|
66
|
+
validator?: (file: File) => FileError | FileError[] | null;
|
|
67
|
+
};
|
|
68
|
+
declare const Dropzone: ({ allowedFileTypes, disabled, enableDropArea, maxFiles, maxSize, multiple, name, onChange, onClick, onDrop, setFileRejections, setTotalSize, validator, }: DropzoneProps) => react_jsx_runtime.JSX.Element;
|
|
69
|
+
|
|
70
|
+
type ErrorAlertProps = {
|
|
71
|
+
/**
|
|
72
|
+
* Array of file rejection errors
|
|
73
|
+
*/
|
|
74
|
+
errors: FileRejection['errors'];
|
|
75
|
+
/**
|
|
76
|
+
* Name of the file that encountered errors
|
|
77
|
+
*/
|
|
78
|
+
fileName: string;
|
|
79
|
+
/**
|
|
80
|
+
* Unique identifier for the error alert
|
|
81
|
+
*/
|
|
82
|
+
id: number;
|
|
83
|
+
onClose: () => void;
|
|
84
|
+
};
|
|
85
|
+
declare const ErrorAlert: ({ errors, fileName, id, onClose }: ErrorAlertProps) => react_jsx_runtime.JSX.Element | null;
|
|
86
|
+
|
|
87
|
+
type Options = {
|
|
88
|
+
onError?: (error: Error) => void;
|
|
89
|
+
onSuccess?: () => void;
|
|
90
|
+
} & UploadOptions;
|
|
91
|
+
type UploadQueryOptions = UseQueryOptions<Upload, Error, Upload, [string, string, Options]>;
|
|
92
|
+
declare function useUploadCore(file: File, options: Options, queryOptions?: UploadQueryOptions): _tanstack_react_query.UseQueryResult<Upload, Error>;
|
|
93
|
+
|
|
94
|
+
type FileRowProps = {
|
|
95
|
+
/**
|
|
96
|
+
* The File object containing information about the uploaded file
|
|
97
|
+
* */
|
|
98
|
+
file: File;
|
|
99
|
+
/**
|
|
100
|
+
* Callback function called when a file is removed
|
|
101
|
+
* @param id - The unique identifier of the file being removed
|
|
102
|
+
* @param upload - The Upload instance associated with the file
|
|
103
|
+
*/
|
|
104
|
+
onRemoveFile: (id: string, upload: Upload) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Configuration options for the upload call
|
|
107
|
+
* */
|
|
108
|
+
options: Options;
|
|
109
|
+
/**
|
|
110
|
+
* Query options from `react-query` for the upload call
|
|
111
|
+
* */
|
|
112
|
+
queryOptions?: UploadQueryOptions;
|
|
113
|
+
customFileRow?: React.ElementType<{
|
|
114
|
+
upload?: Upload;
|
|
115
|
+
options: Options;
|
|
116
|
+
onRemoveFile: (id: string, upload: Upload) => void;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the remove button is disabled
|
|
120
|
+
* @default false
|
|
121
|
+
*/
|
|
122
|
+
disableRemove?: boolean;
|
|
123
|
+
};
|
|
124
|
+
declare const FileRow: ({ file, options, onRemoveFile, queryOptions, customFileRow: CustomRow, disableRemove, }: FileRowProps) => react_jsx_runtime.JSX.Element | null;
|
|
125
|
+
type FileListProps = {
|
|
126
|
+
/**
|
|
127
|
+
* Array of File objects to be displayed in the list
|
|
128
|
+
*/
|
|
129
|
+
files: File[];
|
|
130
|
+
} & Omit<FileRowProps, 'file'>;
|
|
131
|
+
declare const FileList: ({ files, options, onRemoveFile, queryOptions, customFileRow, disableRemove, }: FileListProps) => JSX.Element | null;
|
|
132
|
+
|
|
133
|
+
type FilePickerBtnProps = {
|
|
134
|
+
/**
|
|
135
|
+
* Name attribute for the input field, used by react-hook-form for form state management.
|
|
136
|
+
*/
|
|
137
|
+
name: string;
|
|
138
|
+
/**
|
|
139
|
+
* Callback function triggered when files are selected through the input.
|
|
140
|
+
*/
|
|
141
|
+
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
142
|
+
/**
|
|
143
|
+
* Optional ID attribute for the file input element.
|
|
144
|
+
*/
|
|
145
|
+
inputId?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Additional props to customize the underlying input element.
|
|
148
|
+
*/
|
|
149
|
+
inputProps?: DropzoneInputProps & {
|
|
150
|
+
ref?: RefObject<HTMLInputElement>;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Maximum allowed size per file in bytes. Files exceeding this size will be rejected.
|
|
154
|
+
*/
|
|
155
|
+
maxSize?: number;
|
|
156
|
+
} & Omit<ButtonProps, 'onChange'>;
|
|
157
|
+
declare const FilePickerBtn: ({ name, children, color, inputId, inputProps, maxSize, onChange, onClick, ...rest }: FilePickerBtnProps) => react_jsx_runtime.JSX.Element;
|
|
4
158
|
|
|
5
159
|
type FileSelectorProps = {
|
|
6
160
|
/**
|
|
@@ -40,10 +194,18 @@ type FileSelectorProps = {
|
|
|
40
194
|
* @default false
|
|
41
195
|
*/
|
|
42
196
|
disabled?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Whether to enable the dropzone area
|
|
199
|
+
*/
|
|
200
|
+
enableDropArea?: boolean;
|
|
43
201
|
/**
|
|
44
202
|
* Custom endpoint URL for file uploads. If not provided, default endpoint will be used
|
|
45
203
|
*/
|
|
46
204
|
endpoint?: string;
|
|
205
|
+
/**
|
|
206
|
+
* Componet to render the File information. This should return a `ListItem`
|
|
207
|
+
*/
|
|
208
|
+
customFileRow?: ElementType<FileListProps>;
|
|
47
209
|
/**
|
|
48
210
|
* Whether to use the cloud upload endpoint
|
|
49
211
|
* When true, uses '/cloud/web/appl/vault/upload/v1/resumable'
|
|
@@ -57,7 +219,7 @@ type FileSelectorProps = {
|
|
|
57
219
|
/**
|
|
58
220
|
* Maximum number of files that can be uploaded simultaneously
|
|
59
221
|
*/
|
|
60
|
-
maxFiles
|
|
222
|
+
maxFiles: number;
|
|
61
223
|
/**
|
|
62
224
|
* Maximum file size allowed per file in bytes
|
|
63
225
|
* Use Kibi or Mibibytes. eg: 1kb = 1024 bytes; 1mb = 1024kb
|
|
@@ -74,37 +236,61 @@ type FileSelectorProps = {
|
|
|
74
236
|
*/
|
|
75
237
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
76
238
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param uploads - Array of Upload instances for the submitted files
|
|
79
|
-
* @param values - Object containing the form values, with files indexed by the name prop
|
|
239
|
+
*
|
|
80
240
|
*/
|
|
81
|
-
|
|
241
|
+
onDrop?: (acceptedFiles: File[], fileRejections: (FileRejection$1 & {
|
|
242
|
+
id: number;
|
|
243
|
+
})[], event: DropEvent$1) => void;
|
|
82
244
|
/**
|
|
83
|
-
* Callback fired when a file is
|
|
245
|
+
* Callback fired when a file is removed from the upload list
|
|
246
|
+
* @param files - Array of remaining files
|
|
247
|
+
* @param removedUploadId - ID of the removed upload
|
|
84
248
|
*/
|
|
85
|
-
|
|
249
|
+
onUploadRemove?: (files: File[], removedUploadId: string) => void;
|
|
250
|
+
/**
|
|
251
|
+
* Query options from `react-query` for the upload call
|
|
252
|
+
* */
|
|
253
|
+
queryOptions?: UploadQueryOptions;
|
|
86
254
|
/**
|
|
87
|
-
*
|
|
255
|
+
* Options that are passed to the Upload class from `@availity/upload-core`
|
|
88
256
|
*/
|
|
89
|
-
|
|
257
|
+
uploadOptions?: Partial<Options>;
|
|
90
258
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
259
|
+
* Validation function used for custom validation that is not covered with the other props
|
|
260
|
+
* */
|
|
261
|
+
validator?: (file: File) => FileError$1 | FileError$1[] | null;
|
|
262
|
+
/**
|
|
263
|
+
* Whether the remove button is disabled
|
|
264
|
+
* @default false
|
|
265
|
+
*/
|
|
266
|
+
disableRemove?: boolean;
|
|
267
|
+
};
|
|
268
|
+
declare const FileSelector: ({ name, allowedFileNameCharacters, allowedFileTypes, bucketId, clientId, children, customerId, customFileRow, disabled, enableDropArea, endpoint, isCloud, label, maxFiles, maxSize, multiple, onChange, onDrop, onUploadRemove, queryOptions, uploadOptions, validator, disableRemove, }: FileSelectorProps) => react_jsx_runtime.JSX.Element;
|
|
269
|
+
|
|
270
|
+
type FileTypesMessageProps = {
|
|
271
|
+
/**
|
|
272
|
+
* Allowed file type extensions. Each extension should be prefixed with a ".". eg: .txt, .pdf, .png
|
|
94
273
|
*/
|
|
95
|
-
|
|
274
|
+
allowedFileTypes?: `.${string}`[];
|
|
96
275
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param files - Array of remaining files
|
|
99
|
-
* @param removedUploadId - ID of the removed upload
|
|
276
|
+
* Maximum size per file in bytes. This will be formatted. eg: 1024 * 20 = 20 KB
|
|
100
277
|
*/
|
|
101
|
-
|
|
278
|
+
maxFileSize?: number;
|
|
279
|
+
variant?: 'caption' | 'body2';
|
|
280
|
+
};
|
|
281
|
+
declare const FileTypesMessage: ({ allowedFileTypes, maxFileSize, variant, }: FileTypesMessageProps) => react_jsx_runtime.JSX.Element;
|
|
282
|
+
|
|
283
|
+
type HeaderMessageProps = {
|
|
102
284
|
/**
|
|
103
|
-
*
|
|
285
|
+
* Maximum number of files allowed
|
|
104
286
|
*/
|
|
105
|
-
|
|
287
|
+
maxFiles: number;
|
|
288
|
+
/**
|
|
289
|
+
* Maximum combined total size of all files
|
|
290
|
+
*/
|
|
291
|
+
maxSize: number;
|
|
106
292
|
};
|
|
107
|
-
declare const
|
|
293
|
+
declare const HeaderMessage: ({ maxFiles, maxSize }: HeaderMessageProps) => react_jsx_runtime.JSX.Element;
|
|
108
294
|
|
|
109
295
|
type UploadProgressBarProps = {
|
|
110
296
|
/**
|
|
@@ -126,4 +312,4 @@ type UploadProgressBarProps = {
|
|
|
126
312
|
};
|
|
127
313
|
declare const UploadProgressBar: ({ upload, onProgress, onError, onSuccess }: UploadProgressBarProps) => react_jsx_runtime.JSX.Element;
|
|
128
314
|
|
|
129
|
-
export { FileSelector, type FileSelectorProps, UploadProgressBar, type UploadProgressBarProps };
|
|
315
|
+
export { Dropzone, type DropzoneProps, ErrorAlert, type ErrorAlertProps, FileList, type FileListProps, FilePickerBtn, type FilePickerBtnProps, FileRow, type FileRowProps, FileSelector, type FileSelectorProps, FileTypesMessage, type FileTypesMessageProps, HeaderMessage, type HeaderMessageProps, type Options, UploadProgressBar, type UploadProgressBarProps, type UploadQueryOptions, useUploadCore };
|