# Drop zone · Membrane

> A drop zone whose border is a membrane: it reaches for the file, holds it, swallows it and passes it through to its row.

Most drop zones are a dashed box that changes colour. Here the border is a 1px membrane made of points tied together by tension. Drag files over the page and it takes the accent; bring them near and the nearest stretch of line bends out to meet them while the arrow turns to watch. Close to the edge the bulge reaches past the file, so it is held before it crosses, and crossing lets the line snap back with a wobble. A drop makes the whole border gulp and ring out from where it landed. Each file then leaves as a chip, drags the line with it on the way out until it slips off, and lands as its row, where the row's own hairline fills with progress, the percent rolls and a ring closes into a drawn check. A type it can't take makes the line recoil and turn red, and a refused drop is pushed back out where it landed.

## Install

```bash
npx shadcn@latest add @hairline/drop-zone-membrane
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`, `number-roll`
- Docs and live preview: https://hairlineui.com/ui/drop-zone-membrane
- Registry item (source): https://hairlineui.com/r/drop-zone-membrane.json

## Usage

```tsx
import { DropZoneMembrane } from "@/components/drop-zone-membrane";

<DropZoneMembrane
  accept="image/*,.pdf"
  maxSize={10_000_000}
  hint="images or PDFs, up to 10 MB"
  onUpload={async (file, { progress, signal }) => {
    await uploadFile(file, { onProgress: progress, signal });
  }}
/>
```

## Upload to your storage with progress

onUpload runs once per file. Report progress as a fraction, honour the abort signal (remove and cancel use it) and throw to show the error with Retry. Here each file goes to a presigned URL through XMLHttpRequest, which reports upload progress.

```tsx
"use client";
import { DropZoneMembrane } from "@/components/drop-zone-membrane";

export function AssetUpload({ projectId }: { projectId: string }) {
  return (
    <DropZoneMembrane
      accept="image/*,.pdf"
      maxSize={10_000_000}
      maxFiles={6}
      hint="images or PDFs, up to 10 MB"
      onUpload={async (file, { progress, signal }) => {
        const res = await fetch("/api/uploads", {
          method: "POST",
          body: JSON.stringify({ projectId, name: file.name, type: file.type }),
          signal,
        });
        const { url } = await res.json();
        await new Promise<void>((resolve, reject) => {
          const xhr = new XMLHttpRequest();
          xhr.open("PUT", url);
          xhr.upload.onprogress = (e) => e.lengthComputable && progress(e.loaded / e.total);
          xhr.onload = () => (xhr.status < 300 ? resolve() : reject(new Error("Upload failed")));
          xhr.onerror = () => reject(new Error("Connection lost"));
          signal.addEventListener("abort", () => xhr.abort());
          xhr.send(file);
        });
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onUpload` | `(file, { progress, signal }) => void \| Promise<void>` | – | Uploads one file. Call progress(0–1), honour the signal, resolve when done or throw to show an error with Retry. Without it, files are listed as ready. |
| `onFilesChange` | `(files: File[]) => void` | – | The files in the list after every add and remove, e.g. to keep a form field in step. |
| `accept` | `string` | – | MIME types, wildcards and extensions, like an input's accept: "image/*,.pdf". |
| `maxSize` | `number` | – | Largest file in bytes. Bigger files are refused with the limit as the reason. |
| `maxFiles` | `number` | – | How many files the list holds. |
| `multiple` | `boolean` | `true` | false takes one file at a time; a new drop replaces it. |
| `title` | `string` | `"Drop files here"` | The resting label. |
| `hint` | `string` | – | Under the label after "Browse or paste", and the label while a type is refused. |
| `disabled` | `boolean` | `false` | Ignores drags, drops and clicks. |
| `ref` | `Ref<DropZoneMembraneHandle>` | – | drag(x, y, types) → held, cancel(), drop(files, at?) and browse(), for drags your app runs itself (a file from a sidebar) and for touch. |

## States

- **armed**: A file drag anywhere over the page swells the border by 1.5px and turns it toward the accent. The label counts the files when the browser reports them.
- **reach**: Within 200px the nearest stretch of border bends toward the file, up to about 20px, as a tent shaped by tension. The arrow turns to face it. Within 16px of the edge the file is already held, and a drop lands.
- **over**: Crossing in releases the stretched line with a snap and a wobble that travels round the edge. The zone swells 3px and the label morphs to "Release to add".
- **drop**: The border is pulled in and rings out from the drop point. Each accepted file flies as a chip from where it landed to its row (640ms, 80ms apart), stretching the line as it passes through until it slips off.
- **upload**: The row opens by height; its hairline fills from the left with progress, the percent rolls, and a ring closes and gives way to a check that draws itself. Failures turn the line red and offer Retry.
- **refuse**: A type that can't match makes the line recoil from the file and turn red, with the hint as the label. A refused drop (type, size or count) is pushed back out where it landed and the reason is shown for 2.8s.

## What it handles

Most drop zones are a dashed box that changes colour. Here the border reaches toward the file, and the list below it handles progress, failures and limits.

- **It reacts before you drop**: Within 200px the nearest stretch of border bends toward the file, and the arrow turns to face it.
- **It checks the files**: Set accept, maxSize and maxFiles. A refused drop is pushed back out and the reason shows for a few seconds.
- **Progress for each file**: Each file lands as a row with its own progress line, a rolling percent and a drawn check when done.
- **Cancel and Retry**: Remove and Cancel abort the upload through the signal. A failed file offers Retry.
- **Connects to your storage**: onUpload runs once per file with a progress function and an abort signal.
- **Click and paste too**: The zone is a button that opens the file picker, and pasted files are added. A ref lets your app run its own drags.

## Replaces

a dashed drop box, drag event handling, file type and size checks, upload progress rows, cancel and retry

## Where it fits

- **File upload screens**: Attachments and uploads where the drop target should be noticed.
- **AI and file tools**: Tools that start with a file, such as converting, compressing or transcribing it.
- **Media libraries**: Add images, video or documents to a library with progress for each file.
- **Document requests**: Ask customers for documents and show each one arriving.

## Notes

- The zone is a button: Enter or Space opens the file picker, and paste adds files while it has focus.
- The window is watched only for drags that carry files, so the line can reach out before the file arrives. Drops are taken only inside the zone or within 16px of it, where the bulge already holds the file.
- Results are announced in a status region outside the button: added, refused with the reason, uploaded and failed. Remove and Cancel buttons are named after the file.
- The border is one SVG path written by a single frame loop with fixed 1/240s steps; the loop sleeps when the line is still, and a resting line is drawn as an exact rounded rectangle on half pixels. Chips move by transform only.
- Reduced motion keeps the line still and the files appear in place; colour, labels and the drawn check still say what happened.

License: MIT (https://hairlineui.com/license#components)
