Skip to main content

File Upload

Accept files, mainly images, from a user's device. Supports drag-and-drop.

Examples

By default, only one upload is allowed.

Single File Upload

import { FileUpload } from '@curology/ui-components-web/react';

<FileUpload />

Multiple File Upload with MIME limitations

Using the accept prop, you can pass a list of accepted MIME types and file extensions. You can also allow for more than one file to be uploaded at a time with the multiple prop, and set a maximum number of files using the maxFiles prop.

import { FileUpload } from '@curology/ui-components-web/react';

<FileUpload
accept={{
'image/jpeg': ['.jpg', '.jpeg'],
'image/png': ['.png'],
'image/gif': ['.gif'],
}}
maxFiles={5}
multiple
/>

Image Upload

An image-specific uploader with built-in image preview is also available. It's limited to one file and has default accept values, but it otherwise works the same as the FileUpload component.

import { ImageUpload } from '@curology/ui-components-web/react';

<ImageUpload />

Uploading State

import { FileUpload, ImageUpload } from '@curology/ui-components-web/react';

<FileUpload uploading />
<ImageUpload uploading />

Complete State

import { FileUpload, ImageUpload } from '@curology/ui-components-web/react';

<FileUpload
complete
completeAction={<FileUploadAction href="#">Delete?</FileUploadAction>}
/>
<ImageUpload
complete
completeAction={<FileUploadAction href="#">Delete?</FileUploadAction>}
src={...}
/>

Error State

Passing an instance of Error as the error prop will cause the input's color scheme to change. If an errorAction is provided, it will be added to the bottom of the input.

import { FileUpload, ImageUpload } from '@curology/ui-components-web/react';

<FileUpload
error={errorObject}
errorAction={<FileUploadAction href="#">Retry?</FileUploadAction>}
/>
<ImageUpload
error={errorObject}
errorAction={<FileUploadAction href="#">Retry?</FileUploadAction>}
/>

Disabled State

import { FileUpload, ImageUpload } from '@curology/ui-components-web/react';

<FileUpload disabled />
<ImageUpload disabled />

Props

NameTypeDefault ValueRequiredDescription
acceptAcceptNoSet accepted file types. https://react-dropzone.js.org/#section-accepting-specific-file-types
autoFocusbooleanNoSet to `true` to focus the root element on render.
completebooleanfalseNoIs the upload complete?
completeActionReactNodeNoA component to display when the upload is complete.
completeStateFC<{ completeAction?: ReactNode; id: string; }>No
disabledbooleanfalseNoEnable/disable the input.
dropStateFC<{ disabled: boolean; id: string; }>No
errorErrorNoIs there an error to display?
errorActionReactNodeNoA component to display when the upload has errored.
errorStateFC<{ errorAction?: ReactNode; id: string; message?: string; }>No
icon"head" | "circle" | ReactElement<any, string | JSXElementConstructor<any>> | "placeholder" | IconName | "accordion-caret-down" | ... 13 more ...NoThe icon to display pre-upload.
initialLabelstringNoAn initial CTA to display.
initialStateFC<{ disabled: boolean; icon?: "head" | "circle" | ReactElement<any, string | JSXElementConstructor<any>> | "placeholder" | IconName | ... 14 more ...; id: string; maxFiles: number; text?: string; }> | undefinedNo
maxFilesnumber1NoMaximum accepted number of files. Setting to `0` means there is no limit on many files are accepted.
maxSizenumberInfinityNoMaximum file size (in bytes).
minSizenumber0NoMinimum file size (in bytes).
multiplebooleantrueNoAllow drag 'n' drop (or selection from the file dialog) of multiple files.
onError((err: Error) => void)NoCallback run whenever selecting a file throws an error.
onFileAdded(<T extends File>(files: T[], event: DropEvent) => void)NoCallback run whenever a new file is added.
onFileRejected((fileRejections: FileRejection[], event: DropEvent) => void)NoCallback run whenever a new file is added.
progressnumberNoDisplay a specific upload progress. If `uploading` is `false` this will have no effect.
uploadingbooleanfalseNoShould the uploading state be displayed? If `progress` is `undefined`, this will use a faux progress indicator that never reaches 100% until `complete` becomes `true`.
uploadingStateFC<{ id: string; icon?: "head" | "circle" | ReactElement<any, string | JSXElementConstructor<any>> | "placeholder" | IconName | ... 14 more ...; progress?: number; }> | undefinedNo
validator(<T extends File>(file: T) => FileError | FileError[] | null)NoCustom validation function. It must return null if there's no errors.
NameTypeDefault ValueRequiredDescription
idstringYes
messagestringNo