1 | # @availity/upload
|
2 |
|
3 | > Availity component for uploading files
|
4 |
|
5 | [![Version](https://img.shields.io/npm/v/@availity/upload.svg?style=for-the-badge)](https://www.npmjs.com/package/@availity/upload)
|
6 |
|
7 | ## Installation
|
8 |
|
9 | ```bash
|
10 | npx install-peerdeps @availity/upload --save
|
11 | ```
|
12 |
|
13 | ## Upload (Default export)
|
14 |
|
15 | The default export is an all-in-one solution which handles uploads, encrypted file password requests and file state management for you.
|
16 |
|
17 | ### Example
|
18 |
|
19 | ```jsx
|
20 | import React from 'react';
|
21 | import Upload from '@availity/upload';
|
22 |
|
23 | <Upload clientId="a" bucketId="b" customerId="c" />;
|
24 | ```
|
25 |
|
26 | ## Props
|
27 |
|
28 | ### `btnText?: ReactNode`
|
29 |
|
30 | `+ Add File` for initial file or `+ Add Another File Attachment` if an attachment already have been selected. | The text that appears on the button.
|
31 |
|
32 | The ID of the bucket you want to upload to.
|
33 |
|
34 | ### `customerId: string`
|
35 |
|
36 | The customer ID for the organization the user is uploading on behalf of.
|
37 |
|
38 | ### `clientId: string`
|
39 |
|
40 | The ID obtained from APIConnect. Must be subscribed to the resumeable uploads API.
|
41 |
|
42 | ### `allowedFileNameCharacters?: string`
|
43 |
|
44 | Restrict the file name characters to a regex set.
|
45 |
|
46 | ### `allowedFileTypes?: Array<string>`
|
47 |
|
48 | Restrict the file types allowed to be uploaded to. eg: `['.jpeg', '.jpg']`.
|
49 |
|
50 | ### `onFileUpload?: (upload: UploadCore) => void`
|
51 |
|
52 | Callback called when file is uploaded. The callback is provided the `Upload` instance from upload-core SDK. Use this callback to track which files have been uploaded (to get references returned by the API).
|
53 |
|
54 | ### `onFileRemove?: (files: Array<File>, fileId: String) => void`
|
55 |
|
56 | Callback called when file is removed. The callback is provided two arguments. 1. the updated files and 2. the id of the file that was removed
|
57 |
|
58 | ### `maxSize?: number`
|
59 |
|
60 | The maximum file size (in bytes) for a file to be uploaded.
|
61 |
|
62 | ### `max?: number`
|
63 |
|
64 | The maximum number of files allowed to be uploaded. `0` (or a falsey value) means unlimited. When the max number has been reached, the add button will disappear.
|
65 |
|
66 | ### `multiple?: boolean`
|
67 |
|
68 | Indicates that the user will be allowed to select multiple files when selecting files from the OS prompt. **Default:** `true`.
|
69 |
|
70 | ### `showFileDropdown?: boolean`
|
71 |
|
72 | Set as true to show a drag and drop file upload option instead of a button (file explorer still available on click).
|
73 |
|
74 | ### Example
|
75 |
|
76 | ```jsx
|
77 | import React from 'react';
|
78 | import Upload from '@availity/upload';
|
79 |
|
80 | <Upload
|
81 | btnText="Upload a claim"
|
82 | clientId="a"
|
83 | bucketId="b"
|
84 | customerId="c"
|
85 | multiple={false}
|
86 | max={1}
|
87 | />;
|
88 | ```
|
89 |
|
90 | #### Callback Function Usage
|
91 |
|
92 | ```jsx
|
93 | <Upload
|
94 | btnText="Upload a claim"
|
95 | clientId="a"
|
96 | bucketId="b"
|
97 | customerId="c"
|
98 | onFileUpload={onUpload} // <-- add file callback function
|
99 | onFileRemove={onRemove} // <-- remove file callback function
|
100 | max={1}
|
101 | />
|
102 |
|
103 | // onUpload callback definition
|
104 | onUpload(upload) {
|
105 | if (upload) {
|
106 | upload.onSuccess.push(async () => {
|
107 | // success action
|
108 | });
|
109 | upload.onError.push(() => {
|
110 | // error action
|
111 | });
|
112 | }
|
113 | }
|
114 | // ...
|
115 |
|
116 | // onRemove callback definition
|
117 | onRemove(file) {
|
118 | // remove action
|
119 | }
|
120 | ```
|
121 |
|
122 |
|
123 | ## FilePickerBtn (Named Export)
|
124 |
|
125 | The raw file picker button that masks the file input with a button.
|
126 |
|
127 | ### Example
|
128 |
|
129 | ```jsx
|
130 | import React from 'react';
|
131 | import { FilePickerBtn } from '@availity/upload';
|
132 |
|
133 | handleFileSelection = event => {
|
134 | const { files } = event.target;
|
135 | // do something with the files.
|
136 | };
|
137 |
|
138 | <FilePickerBtn onChange={this.handleFileSelection} />;
|
139 | ```
|
140 |
|
141 | ## Props
|
142 |
|
143 | ### `onClick?: (event: Event) => void`
|
144 |
|
145 | Callback when the button is clicked.
|
146 |
|
147 | ### `onChange?: (event: Event) => void`
|
148 |
|
149 | Callback when the user has selected a file or multiple files.
|
150 |
|
151 | ### `multiple?: boolean`
|
152 |
|
153 | Indicates that the user will be allowed to select multiple files when selecting files from the OS prompt.
|
154 |
|
155 | ### `allowedFileTypes?: Array<string>`
|
156 |
|
157 | The file types you want to restrict uploading to. eg: `['.jpeg', '.jpg']`.
|
158 |
|
159 | ### `maxSize?: number`
|
160 |
|
161 | The maximum file size (in bytes) for a file to be uploaded.
|
162 |
|
163 |
|
164 | ## FilePicker (Named Export)
|
165 |
|
166 | The raw file picker which automatically resets the value of the input, allowing the same file to be selected multiple consecutive files.
|
167 |
|
168 | ### Example
|
169 |
|
170 | ```jsx
|
171 | import React from 'react';
|
172 | import { FilePicker } from '@availity/upload';
|
173 | import { CustomInput } from 'reactstrap';
|
174 |
|
175 | handleFileSelection = event => {
|
176 | const { files } = event.target;
|
177 | // do something with the files.
|
178 | };
|
179 |
|
180 | <FilePicker tag={CustomInput} onChange={this.handleFileSelection} />;
|
181 | ```
|
182 |
|
183 | ## Props
|
184 |
|
185 | ### `tag?: React.ComponentType | string`
|
186 |
|
187 | The raw underlying component/element that should be rendered. **Default:** Reactstrap `CustomInput`.
|
188 |
|
189 | ### `onChange?: (event: Event) => void`
|
190 |
|
191 | Callback when the user has selected a file or multiple files.
|
192 |
|
193 | ### `multiple?: boolean`
|
194 |
|
195 | Indicates that the user will be allowed to select multiple files when selecting files from the OS prompt.
|
196 |
|
197 | ### `allowedFileTypes?: Array<string>`
|
198 |
|
199 | The file types you want to restrict uploading to. eg: `['.jpeg', '.jpg']`.
|
200 |
|
201 | ### `maxSize?: number`
|
202 |
|
203 | The maximum file size (in bytes) for a file to be uploaded.
|
204 |
|
205 |
|
206 | ## UploadProgressBar
|
207 |
|
208 | The raw progress bar to be used when making your own.
|
209 |
|
210 | ### Example
|
211 |
|
212 | ```jsx
|
213 | import React from 'react';
|
214 | import { UploadProgressBar } from '@availity/upload';
|
215 |
|
216 | <UploadProgressBar upload={uploadInstance} animated />;
|
217 | ```
|
218 |
|
219 | ## Props
|
220 |
|
221 | ### `upload?: UploadCore`
|
222 | The upload instance returned by creating a `new Upload` via [upload-core](https://github.com/Availity/sdk-js/tree/master/packages/upload-core).
|
223 |
|
224 | ### `onProgress?: (upload: UploadCore) => void`
|
225 | Callback function to hook into the `onProgress` within the Upload instance provided in the `upload` prop.
|
226 |
|
227 | ### `onSuccess?: (upload: UploadCore) => void`
|
228 | Callback function to hook into the `onSuccess` within the Upload instance provided in the `upload` prop.
|
229 |
|
230 | ### `onError?: (upload: UploadCore) => void`
|
231 | Callback function to hook into the `onError` within the Upload instance provided in the `upload` prop.
|
232 |
|
233 | ### `complete?: boolean`
|
234 | Triggers the "complete" style in the progress bar. When true, a checkmark appears at the end of the progress bar.
|
235 |
|
236 | ### `striped?: boolean`
|
237 | Triggers the "striped" style in the progress bar.
|
238 |
|
239 | ### `animated?: boolean`
|
240 | When `true` the progress bar has animated stripes while uploading is in progress.
|
241 |
|
242 | ### `color?: string`
|
243 | Color of the progress bar. **Default:** `success`
|