Skip to content

FileDrop

A place to drop files from the computer, with a button for those who prefer to choose them. It lists what was chosen with its size, and says why a file was refused.

import { FileDrop } from '@sypnia/ui/react'

On this page
  1. One file, with rules
  2. Several files
  3. Disabled
  4. When to use it
  5. For everyone
  6. Props

One file, with rules

Takes one CSV of up to 5 MB. Try another kind of file: it says what it takes instead.

Drop a file here or choose one

A CSV file of up to 5 MB, with the names of the columns in the first line.

Code
import { useState } from 'react';
import { Field, FileDrop } from '@sypnia/ui/react';

export default function Basic() {
  const [files, setFiles] = useState<File[]>([]);
  return (
    <Field label="Rows to import" hint={files.length ? 'The first line must be the names of the columns.' : 'A CSV file of up to 5 MB, with the names of the columns in the first line.'}>
      <FileDrop files={files} onChange={setFiles} accept={['.csv']} maxSize={5 * 1024 * 1024} />
    </Field>
  );
}

Several files

Each new file is added to the list, and each can be removed.

Drop the screenshots here or choose them

Pictures or PDF, up to 10 MB each.

Code
import { Field, FileDrop } from '@sypnia/ui/react';

export default function Several() {
  return (
    <Field label="Attachments" hint="Pictures or PDF, up to 10 MB each.">
      <FileDrop multiple accept={['image/*', '.pdf']} maxSize={10 * 1024 * 1024}>Drop the screenshots here or choose them</FileDrop>
    </Field>
  );
}

Disabled

It says why nothing can be dropped.

Drop a file here or choose one

An import is already running. Wait for it to finish.

Code
import { Field, FileDrop } from '@sypnia/ui/react';

export default function States() {
  return (
    <Field label="Rows to import" hint="An import is already running. Wait for it to finish.">
      <FileDrop disabled accept={['.csv']} />
    </Field>
  );
}

When to use it

Use it when

  • The person brings a file from their computer: a CSV to import, a logo, a certificate.
  • There are rules about what is taken: accept for the kind of file, maxSize for its weight.

Do not use it when

  • The file is a picture that should be seen and cropped: ImageUpload or AvatarUpload.
  • It is one small file in a tight form: FileInput takes one line.
  • The content is short text the person could paste: Textarea or CodeInput.

For everyone

  • Everything can be done without dragging: the button opens the file chooser of the device, and it is the part that takes the focus.
  • A refused file is announced at once as an alert that names the file, says what is wrong and what to choose instead.
  • Each chosen file has its own button, named «Remove» plus the name of the file.
  • While a file is dragged over it, the zone lights up, so it is clear where to let go.
  • Inside a Field it takes the label, the hint and the error by itself; alone, give it an aria-label.

Props

FileDropTypeDefault
accept

What it takes: extensions (`.csv`) or types (`text/csv`, `image/*`). Anything else is refused with a message.

string[]
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
children

The sentence inside the zone. By default «Drop a file here or choose one».

ReactNode
className string
disabled boolean
files

The chosen files. Leave it out to let the component keep them.

File[]
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
maxSize

The largest file it takes, in bytes.

number
multiple

Takes several files. With one, a new file replaces the old one.

boolean
onChange ((files: File[]) => void)
  1. One file, with rules
  2. Several files
  3. Disabled
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms