FileUploader

Overview

FileUploader allows users to upload content of their own to the system. A file uploader is commonly found in forms, but can also live as a standalone element.

When to use:

  • Uploading one or multiple documents or images.
  • Drag and drop one or multiple documents or images.

Implementation

    Drag and drop image here

    Edit the code below to see your changes live!

    function Example() {
      const [files, setFiles] = useState<File[]>([]);
    
      const validateFileSize = (file: File) => {
        const MB = 1024 * 1024;
    
        return file.size <= MB;
      };
    
      return (
        <Form>
          <FormGroup>
            <FileUploader
              dropzoneConfig={{
                label: 'Drag and drop image here',
                action: {
                  label: 'Upload by URL',
                  onClick: () => null,
                },
              }}
              files={files}
              label="Upload files"
              multiple
              onFilesChange={setFiles}
              required
              validators={[
                {
                  validator: validateFileSize,
                  type: 'file-size',
                },
              ]}
            />
          </FormGroup>
        </Form>
      );
    }
    

    Props

    Prop name
    Type
    Default
    Description
    actionTypenormal | destructivenormal

    Indicates whether your item's action is of normal or destructive nature.

    content *string

    Sets the text content of the DropdownItem.

    descriptionstring

    Sets the content description of the DropdownItem.

    disabledboolean

    Sets the item to disabled.

    hashstring

    Stored hash of the item.

    iconIcon

    Pass in an Icon component to display to the left of the text.

    onItemClick *(name: File, idx: number) => void

    Triggers when clicking on action item.

    tooltipstring

    Adds tooltip for disabled item.

    type'text'

    Type of the item.

    Props ending with * are required

    Do's and Don'ts

    Do
    Specify allowed file types and maximum size.