Blocks / Drop zone

Drop zone

Where files land: a framed area with its button, or an overlay over a whole view.

import { DropZone, acceptsFile } from "@forgeron/ui";
/01 → Default

Drop files here

PDF, images and sheets, up to 100 MB each.

import { DropZone } from "@forgeron/ui";
import { useState } from "react";

export default function Default() {
  const [names, setNames] = useState<string[]>([]);
  return (
    <div style={{ display: "grid", gap: 8, width: "100%", maxWidth: 420 }}>
      <DropZone
        onFiles={(files) => setNames(files.map((f) => f.name))}
        description="PDF, images and sheets, up to 100 MB each."
      />
      {names.length ? (
        <span style={{ color: "var(--ink-dim)", font: "400 11px/16px var(--font-mono)" }}>
          {names.join(", ")}
        </span>
      ) : null}
    </div>
  );
}
/02 → Over a view
SelectedActions
Dock plan.pdf240 KB
// With children, the zone covers a view and shows itself only while files are dragged over it.
// Drag a file from your computer onto the list. Only PDFs are taken here.
import { DropZone, FileBrowser, type DriveItem } from "@forgeron/ui";
import { useState } from "react";

export default function OverAView() {
  const [items, setItems] = useState<DriveItem[]>([
    { id: "a", name: "Dock plan.pdf", size: 240_000, modified: "2026-11-18 09:12" },
  ]);
  const [refused, setRefused] = useState("");
  return (
    <div style={{ display: "grid", gap: 8, width: "100%" }}>
      <DropZone
        accept=".pdf"
        overlayLabel="Drop to upload to Contracts"
        onFiles={(files) =>
          setItems((all) => [
            ...all,
            ...files.map((f, i) => ({
              id: `${f.name}-${all.length + i}`,
              name: f.name,
              size: f.size,
            })),
          ])
        }
        onReject={(files) => setRefused(`Not a PDF: ${files.map((f) => f.name).join(", ")}`)}
      >
        <FileBrowser items={items} columns={["size"]} />
      </DropZone>
      <span style={{ color: "var(--danger)", font: "400 11px/16px var(--font-mono)" }}>
        {refused}
      </span>
    </div>
  );
}
API → Props
PropTypeDefaultDescription
onFiles(files: File[]) => void—The files that match.
onReject(files: File[]) => void—The ones left out.
acceptstring—As on an input: .pdf,image/*.
multiplebooleantrueSeveral files.
title / description / buttonLabelReactNode; ReactNode; string"Drop files here"; —; "Choose files"The words of the framed zone.
children / overlayLabelReactNode—A view to cover: invisible until files are dragged over, then the hatched overlay.
disabledboolean—No drop, no chooser.
classNamestring—Extra classes.