UNPKG

6.29 kBMarkdownView Raw
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
10npx install-peerdeps @availity/upload --save
11```
12
13## Upload (Default export)
14
15The 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
20import React from 'react';
21import 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
32The ID of the bucket you want to upload to.
33
34### `customerId: string`
35
36The customer ID for the organization the user is uploading on behalf of.
37
38### `clientId: string`
39
40The ID obtained from APIConnect. Must be subscribed to the resumeable uploads API.
41
42### `allowedFileNameCharacters?: string`
43
44Restrict the file name characters to a regex set.
45
46### `allowedFileTypes?: Array<string>`
47
48Restrict the file types allowed to be uploaded to. eg: `['.jpeg', '.jpg']`.
49
50### `onFileUpload?: (upload: UploadCore) => void`
51
52Callback 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
56Callback 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
60The maximum file size (in bytes) for a file to be uploaded.
61
62### `max?: number`
63
64The 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
68Indicates that the user will be allowed to select multiple files when selecting files from the OS prompt. **Default:** `true`.
69
70### `showFileDropdown?: boolean`
71
72Set 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
77import React from 'react';
78import 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
104onUpload(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
117onRemove(file) {
118 // remove action
119}
120```
121
122
123## FilePickerBtn (Named Export)
124
125The raw file picker button that masks the file input with a button.
126
127### Example
128
129```jsx
130import React from 'react';
131import { FilePickerBtn } from '@availity/upload';
132
133handleFileSelection = 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
145Callback when the button is clicked.
146
147### `onChange?: (event: Event) => void`
148
149Callback when the user has selected a file or multiple files.
150
151### `multiple?: boolean`
152
153Indicates that the user will be allowed to select multiple files when selecting files from the OS prompt.
154
155### `allowedFileTypes?: Array<string>`
156
157The file types you want to restrict uploading to. eg: `['.jpeg', '.jpg']`.
158
159### `maxSize?: number`
160
161The maximum file size (in bytes) for a file to be uploaded.
162
163
164## FilePicker (Named Export)
165
166The 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
171import React from 'react';
172import { FilePicker } from '@availity/upload';
173import { CustomInput } from 'reactstrap';
174
175handleFileSelection = 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
187The raw underlying component/element that should be rendered. **Default:** Reactstrap `CustomInput`.
188
189### `onChange?: (event: Event) => void`
190
191Callback when the user has selected a file or multiple files.
192
193### `multiple?: boolean`
194
195Indicates that the user will be allowed to select multiple files when selecting files from the OS prompt.
196
197### `allowedFileTypes?: Array<string>`
198
199The file types you want to restrict uploading to. eg: `['.jpeg', '.jpg']`.
200
201### `maxSize?: number`
202
203The maximum file size (in bytes) for a file to be uploaded.
204
205
206## UploadProgressBar
207
208The raw progress bar to be used when making your own.
209
210### Example
211
212```jsx
213import React from 'react';
214import { UploadProgressBar } from '@availity/upload';
215
216<UploadProgressBar upload={uploadInstance} animated />;
217```
218
219## Props
220
221### `upload?: UploadCore`
222The 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`
225Callback function to hook into the `onProgress` within the Upload instance provided in the `upload` prop.
226
227### `onSuccess?: (upload: UploadCore) => void`
228Callback function to hook into the `onSuccess` within the Upload instance provided in the `upload` prop.
229
230### `onError?: (upload: UploadCore) => void`
231Callback function to hook into the `onError` within the Upload instance provided in the `upload` prop.
232
233### `complete?: boolean`
234Triggers the "complete" style in the progress bar. When true, a checkmark appears at the end of the progress bar.
235
236### `striped?: boolean`
237Triggers the "striped" style in the progress bar.
238
239### `animated?: boolean`
240When `true` the progress bar has animated stripes while uploading is in progress.
241
242### `color?: string`
243Color of the progress bar. **Default:** `success`