Skip to main content

File Upload

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

Examples

Single File Upload

By default, only one upload is allowed.

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

<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';

<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/FileUpload/ImageUpload';

<ImageUpload />

Uploading State

When an uploading prop is passed, the component will display a progress indicator. If progress is not passed, the upload will use an UnknownProgress.

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

<FileUpload uploading />
<ImageUpload uploading />

Complete State

When a complete prop is passed, the component will a success state. An optional completeAction can be provided.

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

<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 } from '@curology/ui-components-web/react/FileUpload';
import { ImageUpload } from '@curology/ui-components-web/react/ImageUpload';

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

Disabled State

When a disabled prop is passed, the file upload becomes inactive and turns grayscale.

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

<FileUpload disabled />
<ImageUpload disabled />

Props

FileUploadProps

NameTypeDefault ValueRequiredDescription
All attributes of a <div />
acceptAcceptNoSet accepted file types. https://react-dropzone.js.org/#section-accepting-specific-file-types
autoFocusfalse | trueNoSet to `true` to focus the root element on render.
completefalse | truefalseNoIs the upload complete?
completeActionReactNodeNoA component to display when the upload is complete.
completeStateFC<{ completeAction?: ReactNode; id: string; }>No
disabledfalse | truefalseNoEnable/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; }> | undefinedNo
iconComponentClass<any, any> | FunctionComponent<any> | ReactElement<any, string | JSXElementConstructor<any>> | ForwardRefExoticComponent<any>NoThe icon to display pre-upload.
iconSizenull | number | "md" | "lg" | "sm" | "xl" | "xs" | "xxl"NoThe size of the icon to display pre-upload.
initialLabelstringNoAn initial CTA to display.
initialStateFC<{ disabled: boolean; icon: IconAcceptableValue | undefined; iconSize?: number | "md" | "lg" | "sm" | "xl" | "xs" | "xxl" | null | undefined; id: string; maxFiles: number; text?: string | undefined; }>No
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).
multiplefalse | truetrueNoAllow drag 'n' drop (or selection from the file dialog) of multiple files.
namestringNoThe name of the input.
onError(err: Error) => voidNoCallback run whenever selecting a file throws an error.
onFileAdded<T extends File>(files: T[], event: DropEvent) => voidNoCallback run whenever a new file is added.
onFileRejected(fileRejections: FileRejection[], event: DropEvent) => voidNoCallback run whenever a new file is added.
progressnumberNoDisplay a specific upload progress. If `uploading` is `false` this will have no effect.
uploadingfalse | truefalseNoShould 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?: IconAcceptableValue | undefined; progress?: number | undefined; }>No
validator<T extends File>(file: T) => FileError | FileError[] | nullNoCustom validation function. It must return null if there's no errors.

ImageUploadProps

NameTypeDefault ValueRequiredDescription
All attributes of a <div />
acceptAcceptNoSet accepted file types. https://react-dropzone.js.org/#section-accepting-specific-file-types
aspectRatio"auto" | "square" | "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4"'3:4'NoConstrain the image to a specific aspect ratio.
autoFocusfalse | trueNoSet to `true` to focus the root element on render.
completefalse | truefalseNoIs the upload complete?
completeActionReactNodeNoA component to display when the upload is complete.
disabledfalse | truefalseNoEnable/disable the input.
errorErrorNoIs there an error to display?
errorActionReactNodeNoA component to display when the upload has errored.
iconComponentClass<any, any> | FunctionComponent<any> | ReactElement<any, string | JSXElementConstructor<any>> | ForwardRefExoticComponent<any>NoThe icon to display pre-upload.
iconSizenull | number | "md" | "lg" | "sm" | "xl" | "xs" | "xxl"NoThe size of the icon to display pre-upload.
imageOverflowHiddenfalse | trueNoHide the overflow in the preview image.
initialLabelstringNoAn initial CTA to display.
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).
multiplefalse | truetrueNoAllow drag 'n' drop (or selection from the file dialog) of multiple files.
namestringNoThe name of the input.
onError(err: Error) => voidNoCallback run whenever selecting a file throws an error.
onFileAdded<T extends File>(files: T[], event: DropEvent) => voidNoCallback run whenever a new file is added.
onFileRejected(fileRejections: FileRejection[], event: DropEvent) => voidNoCallback run whenever a new file is added.
progressnumberNoDisplay a specific upload progress. If `uploading` is `false` this will have no effect.
srcstringNoThe image to display.
uploadingfalse | truefalseNoShould the uploading state be displayed? If `progress` is `undefined`, this will use a faux progress indicator that never reaches 100% until `complete` becomes `true`.
validator<T extends File>(file: T) => FileError | FileError[] | nullNoCustom validation function. It must return null if there's no errors.

FileUploadActionProps

NameTypeDefault ValueRequiredDescription
All attributes of a <div />
italicfalse | truefalseNoDisplay the text with emphasis?
size"body" | "h1" | "h2" | "h3" | "meta" | "inherit" | "d1" | "d2" | "subhead" | "body-lg" | "cta"'inherit'NoHow large should the text be? This also affects the font-face for display text.
weight"md" | "light" | "100" | "300" | "400" | "500" | "700" | "800" | "900" | "thin" | "normal" | "bold" | "extrabold" | "black"'normal'NoHow heavy should the text be?