terra vidhal

File Drop

Forms

About

An accessible multi-file drop zone with validation, a drag overlay, an aggregate summary, list or thumbnail-grid layouts, per-file progress rows, open, retry, removal, sorting, localisable labels and paste support.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds File Drop to your project and fits it to your theme.

Code

How File Drop is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

/**
 * PrequelUI Animate — MIT — https://prequeluianimate.terravidhal.me
 */

import * as React from "react";
import { FileDrop, type FileDropItem } from "@/components/ui/file-drop";

function thumb(from: string, to: string, accent: string) {
  return (
    "data:image/svg+xml;charset=utf-8," +
    encodeURIComponent(
      `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120">
        <defs>
          <linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
            <stop offset="0%" stop-color="${from}"/>
            <stop offset="100%" stop-color="${to}"/>
          </linearGradient>
        </defs>
        <rect width="120" height="120" fill="url(#g)"/>
        <circle cx="88" cy="34" r="24" fill="${accent}" fill-opacity="0.5"/>
        <circle cx="30" cy="92" r="32" fill="#ffffff" fill-opacity="0.16"/>
        <path d="M0 94C22 72 42 90 62 76s36-10 58-2v46H0z" fill="#ffffff" fill-opacity="0.18"/>
        <path d="M14 38c22-16 50-18 74-4" fill="none" stroke="#ffffff" stroke-opacity="0.35" stroke-width="2"/>
      </svg>`,
    )
  );
}

const INITIAL_FILES: FileDropItem[] = [
  {
    id: "aurora",
    name: "northern-lights.png",
    size: 2_480_000,
    type: "image/png",
    status: "done",
    thumbnail: thumb("#0ea5e9", "#6366f1", "#22d3ee"),
  },
  {
    id: "studio",
    name: "studio-setup.webp",
    size: 3_260_000,
    type: "image/webp",
    status: "uploading",
    progress: 42,
    thumbnail: thumb("#8b5cf6", "#ec4899", "#f0abfc"),
  },
  {
    id: "brief",
    name: "brand-mark.svg",
    size: 86_000,
    type: "image/svg+xml",
    status: "error",
    error: "Upload failed — the connection was interrupted.",
    thumbnail: thumb("#14b8a6", "#0f766e", "#5eead4"),
  },
  {
    id: "mood",
    name: "moodboard.jpg",
    size: 1_920_000,
    type: "image/jpeg",
    status: "idle",
    thumbnail: thumb("#22d3ee", "#2563eb", "#a5f3fc"),
  },
];

export default function FileDropDemo() {
  const [files, setFiles] = React.useState<FileDropItem[]>(INITIAL_FILES);
  const nextId = React.useRef(0);
  const uploading = files.some((file) => file.status === "uploading");

  React.useEffect(() => {
    if (!uploading) return;
    const timer = window.setInterval(() => {
      setFiles((previous) =>
        previous.map((file) => {
          if (file.status !== "uploading") return file;
          const current = file.progress ?? 0;
          const next = Math.min(100, current + 1 + Math.random() * 2.2);
          return next >= 100
            ? { ...file, progress: 100, status: "done" as const }
            : { ...file, progress: next };
        }),
      );
    }, 300);
    return () => window.clearInterval(timer);
  }, [uploading]);

  return (
    <main className="flex min-h-screen w-full items-center justify-center bg-background p-6">
      <FileDrop
        className="w-full max-w-md"
        title="Drop your shots here"
        hint="PNG, JPG, SVG or WEBP · up to 10 MB"
        accept=".png,.jpg,.jpeg,.webp,.svg"
        maxSize={10 * 1024 * 1024}
        multiple
        maxFiles={9}
        files={files}
        onFiles={(accepted) => {
          const additions: FileDropItem[] = accepted.map((file) => ({
            id: `upload-${nextId.current++}`,
            name: file.name,
            size: file.size,
            type: file.type,
            status: "uploading",
            progress: 0,
            thumbnail: file.type.startsWith("image/")
              ? URL.createObjectURL(file)
              : undefined,
          }));
          setFiles((previous) => [...previous, ...additions].slice(0, 9));
        }}
        onFileRemove={(removed) => {
          if (removed.thumbnail?.startsWith("blob:")) {
            URL.revokeObjectURL(removed.thumbnail);
          }
          setFiles((previous) =>
            previous.filter((file) => file.id !== removed.id),
          );
        }}
        onFileOpen={(file) => {
          if (!file.thumbnail) return;
          const link = document.createElement("a");
          link.href = file.thumbnail;
          link.download = file.name;
          link.click();
        }}
        onRetry={(retried) => {
          setFiles((previous) =>
            previous.map((file) =>
              file.id === retried.id
                ? { ...file, status: "uploading", progress: 0, error: undefined }
                : file,
            ),
          );
        }}
      />
    </main>
  );
}

Dependencies

More by terra vidhal

View all
  • Topographic Lines

    Topographic Lines

    4
  • Gravity Stars Background

    Gravity Stars Background

    4
  • Spotlight Card

    Spotlight Card

    3
  • Marquee

    Marquee

    2
  • Firework Burst

    Firework Burst

    1
  • Aurora Bubbles

    Aurora Bubbles

    1
  • Glyph Field

    Glyph Field

  • Shimmering Text

    Shimmering Text

More in Forms

View all
  • Premium Auth

    Premium Auth

    593
  • Contact Form

    Contact Form

    28
  • Form

    Form

    4
  • Login 1

    Login 1

    70
  • Book A Demo 1

    Book A Demo 1

    94
  • Contact Card

    Contact Card

    1.1K
  • HeroUI Field Error

    HeroUI Field Error

    13
  • Form [react-aria-components]

    Form [react-aria-components]

    19