Dropzone

A place to drop files, or choose them with its link. Built on ui-sdk's File Input: drops, pastes and the picker all pass through accept, maxSize and maxFiles, and files that fail come back in onReject. In a Field, its error shows under it.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { Dropzone, Field } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Drop a file here, or

Props

title
chooseLabel
description
disabled

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it where files are the point of the step, like importing a spreadsheet of contacts or attaching a signed costs agreement.
DoPut it in a Field for its label and error, and set accept, maxSize and maxFiles, so a drop, a paste and the picker are all checked the same way.
DoPut the limits in description, like "Up to 10 MB.", so people know them before they drop a file.
DoTurn what comes back in onReject into an error that says what to do, like "Please choose a CSV or Excel file".
DoList the files under it in a <ul> of DropzoneFile, with the size in detail and the reason a file failed in error.
Don'tDrop a failed file from the list. Keep it with its error and an onRemove, so the person can see which file to send again.

Props

Also takes ui-sdk's File Input options: value, defaultValue, onValueChange, onReject, accept, multiple, directory, maxFiles, maxSize, minSize, validate, name, required and disabled.

Dropzone

PropTypeDefaultDescription
titleReactNode"Drop a file here, or"What to drop, like "Drop a CSV or Excel file here, or". The link to choose a file follows it.
chooseLabelstring"choose one"The link that opens the file picker.
descriptionReactNode—The quieter line under the title, like what happens next or the size limit.
iconReactNode—The icon in the tile. An upload arrow when left out.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

DropzoneFile

PropTypeDefaultDescription
name *string—The file's name. It clips with an ellipsis and shows in full on hover.
status *"uploading" | "done" | "error"—Uploading fills the ring; done finishes it and turns it into a tick; error turns it into a cross.
progressnumber0How much has gone up, 0 to 100, while uploading.
detailReactNode—A quiet line on the right, like the file's size.
errorReactNode—Why it failed, under the name.
onRemove() => void—Shows a × that removes the file from the list.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import { Dropzone } from "@leap-crm/design-system";

<Dropzone />

Importing a spreadsheet

Drag a file over it for the navy drag state; a file that isn't a CSV or Excel file shows the error. Tab to choose one for the focus edge.

Drop a CSV or Excel file here, or

Firm Pilot reads it and shows you the result before anything is imported.

Chosen: nothing yet

Uploading

List each file under the zone in a <ul> of DropzoneFile. Its ring fills as the file goes up; once the fill finishes, the ring turns into a tick that draws itself in. A failed upload turns into a cross and its reason opens beneath the name. The outcome is announced politely.

Drop documents here, or

File states

  • Signed costs agreement.pdf
    248 KB40% uploaded
  • Driver licence (front and back).jpg
    1.2 MBUploaded
  • Bank statement March.pdf
    The connection dropped. Try again.
    3.4 MBUpload failed

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { useState } from "react";

import { Button, Dropzone, DropzoneFile, Field, type DropzoneFileStatus } from "@leap-crm/design-system";

type Upload = {
  id: number;
  name: string;
  size: string;
  status: DropzoneFileStatus;
  progress: number;
};

const samples = [
  { name: "Signed costs agreement.pdf", size: "248 KB", fails: false },
  { name: "Driver licence (front and back).jpg", size: "1.2 MB", fails: false },
  { name: "Bank statement March.pdf", size: "3.4 MB", fails: true },
];

function UploadDemo() {
  const [uploads, setUploads] = useState<Upload[]>([]);
  const update = (id: number, change: Partial<Upload>) =>
    setUploads(current =>
      current.map(upload =>
        upload.id === id ? { ...upload, ...change } : upload,
      ),
    );

  const start = () => {
    const now = Date.now();
    setUploads(
      samples.map((sample, index) => ({
        id: now + index,
        name: sample.name,
        size: sample.size,
        status: "uploading",
        progress: 0,
      })),
    );
    samples.forEach((sample, index) => {
      const id = now + index;
      const steps = [20, 45, 70, 90, 100];
      steps.forEach((progress, step) => {
        setTimeout(
          () => {
            if (sample.fails && progress > 45) {
              update(id, { status: "error" });
              return;
            }
            update(id, {
              progress,
              status: progress === 100 ? "done" : "uploading",
            });
          },
          (step + 1) * (350 + index * 180),
        );
      });
    });
  };

  return (
    <div className="flex w-md flex-col gap-3">
      <Dropzone
        multiple
        title="Drop documents here, or"
        onValueChange={start}
      />
      <Button intent="outline" size="sm" className="self-start" onClick={start}>
        Simulate an upload
      </Button>
      {uploads.length > 0 && (
        <ul aria-label="Uploads" className="flex flex-col">
          {uploads.map(upload => (
            <DropzoneFile
              key={upload.id}
              name={upload.name}
              status={upload.status}
              progress={upload.progress}
              detail={upload.size}
              error="The connection dropped. Try again."
              onRemove={() =>
                setUploads(current =>
                  current.filter(item => item.id !== upload.id),
                )
              }
            />
          ))}
        </ul>
      )}
    </div>
  );
}

const spreadsheet = ".csv,.xlsx,.xls";

function ImportDemo() {
  const [error, setError] = useState<string | undefined>(undefined);
  const [chosen, setChosen] = useState<string | undefined>(undefined);
  return (
    <div className="flex w-md flex-col gap-6">
      <Field label="Contacts file" error={error}>
        <Dropzone
          accept={spreadsheet}
          title="Drop a CSV or Excel file here, or"
          description="Firm Pilot reads it and shows you the result before anything is imported."
          onValueChange={files => {
            setError(undefined);
            setChosen(files[0]?.name);
          }}
          onReject={() => setError("That file isn’t a CSV or Excel file.")}
        />
      </Field>
      <span className="text-small text-neutral-text-muted">
        Chosen: {chosen ?? "nothing yet"}
      </span>
    </div>
  );
}

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
EnterSpaceOn the choose link, open the file chooser.
EnterSpaceOn a file's ×, press it.