FileDrop

A dashed zone that takes a file by click or drop.

Overview

Uploading a file: a statement, a photo, an import.

Chosen

Do
import { useState } from "react";
import { FileDrop } from "@hackcove/ui";

function Example() {
  const [name, setName] = useState("");
  return (
    <FileDrop accept=".csv" onChange={(event) => setName(event.target.files?.[0]?.name ?? "")}>
      {name === "" ? "Drop a bank statement here or click to choose" : name}
    </FileDrop>
  );
}
Name the file the zone wants in its prompt, restrict it with accept, and show the chosen file's name from onChange.
Don't
import { FileDrop } from "@hackcove/ui";

<FileDrop>Drop here</FileDrop>
A prompt that never changes leaves the person unsure the file was taken, and with no accept any file is.

Usage

  • Say what the zone wants in its children, and restrict the type with accept.
  • Show the chosen file's name in the children from onChange; the zone does not do it for you.
  • size="sm" is a compact chip or tile.
  • multiple, name and disabled go on the zone like any file input.
  • Put a FileDrop in a Field when it needs a label of its own above it.

Accessibility

  • A real <input type="file"> covers the whole zone, invisible, so a click opens the file dialog, a dragged file is taken as by any file input, and the browser's keyboard handling applies.
  • The zone is a <label>, so its children are the input's accessible name.
  • The zone shows the keyboard focus ring while the input has focus.

API

FileDrop

A dashed drop zone around a file input. The input covers the whole zone, invisible, so a click opens the file dialog and a file dragged onto it is taken by the browser as it is by any file input. children is the prompt; show the chosen file's name there from onChange. The label also shows the keyboard focus ring, the input being invisible. Every prop (accept, multiple, name, disabled, onChange) goes on the input.


size

sm is a compact chip or tile: dense padding. Defaults to md.

Type
"sm" | "md"
Default
md