A drop zone for choosing, dropping or pasting files
Drop, or press Enter to choose · V pastes a file
pnpm dlx shadcn@latest add https://notchset.dev/r/file-drop.jsonChoose, drop or paste files, checked before anything uploads.
Every shadcn style · one file
Import it and pass your content. The props that matter most are listed next.
"use client";
import * as React from "react";
import { FileDrop, type FileDropLook } from "@/components/ui/notchset/file-drop";
import { MousePointer2 } from "@/lib/notchset/icons";
import { useLessMotion } from "@/lib/notchset/motion";
import { PlayOnce, useSelfPlay } from "./self-play";
/*
* Three looks of one file drop, each on its own job. "The well breathes" and "Paper stack" are a careers page's
* "drop your CV": on arrival a hand carries the CV in (the well's edges lean out to meet it and bow in round it; it
* falls in, its row's rule fills and a tick lands; the stack takes the CV, then a portfolio image, then a 24.6 MB print
* that bounces back out with its reason in rose). "Plain" is a support form's attachments: a file is dropped, uploads in
* its row and settles with a tick on its mark; then a 14 MB scan is named in rose. Real files work on every look: drop,
* paste or choose. The quiet "Uploads fail" chip is a switch: while it is on, every file's upload stops part way and
* its row says so in rose with Retry (the hand carries one in when it is turned on); off, Retry sends it through.
*/
const MB = 1_000_000;
const LIMIT = "PDF, Word or images, up to 10 MB";
const ACCEPT = ".pdf,.doc,.docx,image/*";
const WORDS = { role: "Careers · Product Designer · Remote", title: "Drop your CV here", cv: "Ana Ruiz, CV.pdf", portfolio: "Portfolio, 2026.png", big: "Portfolio, print.pdf", notes: "Screen recording notes.pdf", scan: "Scan.png", attachments: "Attachments", failed: "Upload failed. Check the connection and retry." };
/* the stage's own files carry their stated size (no real bytes are made) */
const sized = (name: string, bytes: number, type: string, parts: BlobPart[] = []) => {
const f = new File(parts, name, { type, lastModified: 0 });
if (!parts.length) Object.defineProperty(f, "size", { value: bytes });
return f;
};
/* where a failing upload stops: part way, so its rule has visibly filled before the row turns rose */
const FAILS_AT = 0.6;
/* a failed upload's progress (below 0: it reads as the error) */
const FAILED = -1;
/** An upload host: each new file climbs to done over about 1.3 s, eased (instant under less motion). While `failing`
is on, every upload sent stops part way and fails; Retry sends it again (and fails again while it is still on). */
function useHost(instant: boolean, failing: boolean, failed: string) {
const [progress, setProgress] = React.useState(() => new Map<File, number>());
const doomed = React.useRef(new Set<File>());
const fails = React.useRef(failing);
React.useEffect(() => {
fails.current = failing;
}, [failing]);
const busy = [...progress.values()].some((p) => p >= 0 && p < 1);
React.useEffect(() => {
if (!busy) return;
let raf = 0;
const step = () => {
setProgress((m) => new Map([...m].map(([f, p]) => [f, p < 0 || p >= 1 ? p : doomed.current.has(f) && p >= FAILS_AT ? FAILED : Math.min(1, p + 0.012 + (1 - p) * 0.02)])));
raf = requestAnimationFrame(step);
};
raf = requestAnimationFrame(step);
return () => cancelAnimationFrame(raf);
}, [busy]);
const [files, setFiles] = React.useState<File[]>([]);
const send = (f: File) => {
if (fails.current) doomed.current.add(f);
else doomed.current.delete(f);
return instant ? (fails.current ? FAILED : 1) : 0.02;
};
const change = (next: File[]) => {
setFiles(next);
setProgress((m) => {
const out = new Map(m);
next.forEach((f) => !out.has(f) && out.set(f, send(f)));
return out;
});
};
const retry = (f: File) => setProgress((m) => new Map(m).set(f, send(f)));
const status = (f: File) => {
const p = progress.get(f);
return p === undefined ? undefined : p < 0 ? { error: failed } : p >= 1 ? { done: true } : { progress: p };
};
return { files, change, retry, status };
}
type Ghost = { x: number; y: number; r: number; o: number; s: number; name: string; down: boolean };
/** The stage's own hand: it carries a file across the stage and lets it go over the zone, through the zone's own drag events. */
function useHand(box: React.RefObject<HTMLDivElement | null>) {
const [ghost, setGhost] = React.useState<Ghost | null>(null);
const timers = React.useRef<number[]>([]);
const frames = React.useRef<number[]>([]);
const stop = React.useCallback(() => {
timers.current.forEach((t) => window.clearTimeout(t));
frames.current.forEach((f) => cancelAnimationFrame(f));
timers.current = [];
frames.current = [];
setGhost(null);
}, []);
React.useEffect(() => stop, [stop]);
const after = (ms: number, fn: () => void) => void timers.current.push(window.setTimeout(fn, ms));
const tween = (ms: number, frame: (t: number) => void) => {
const t0 = performance.now();
const step = (now: number) => {
const k = Math.min(1, (now - t0) / ms);
frame(k < 0.5 ? 4 * k * k * k : 1 - (-2 * k + 2) ** 3 / 2);
if (k < 1) frames.current.push(requestAnimationFrame(step));
};
frames.current.push(requestAnimationFrame(step));
};
const zone = () => box.current?.querySelector<HTMLElement>("[data-slot=file-drop-panel] [role=button]") ?? null;
const fire = (type: string, f: File, x: number, y: number) => {
const z = zone();
const b = box.current?.getBoundingClientRect();
if (!z || !b || typeof DataTransfer === "undefined") return;
const dt = new DataTransfer();
dt.items.add(f);
z.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: dt, clientX: b.left + x, clientY: b.top + y }));
};
/* from the right of the zone, to its edge, then in; `edge` lingers on the near side so the well can lean out to it */
const carry = (f: File, at: number, { edge = false, lane = 0, back = false } = {}) => {
after(at, () => {
const z = zone()?.getBoundingClientRect();
const b = box.current?.getBoundingClientRect();
if (!z || !b) return;
const zx = z.left - b.left;
const zy = z.top - b.top;
const start = { x: Math.min(b.width - 40, zx + z.width + 120), y: zy + 30 + lane * 16 };
const near = { x: zx + z.width + 30, y: zy + z.height * 0.45 };
const inside = { x: zx + z.width * (edge ? 0.56 : 0.36), y: zy + Math.min(z.height * 0.5, 90) };
const place = (x: number, y: number, r: number, o = 1) => setGhost({ x, y, r, o, s: 1, name: f.name, down: true });
let entered = false;
const go = (from: { x: number; y: number }, to: { x: number; y: number }, ms: number, r0: number, r1: number) =>
tween(ms, (t) => {
const x = from.x + (to.x - from.x) * t;
const y = from.y + (to.y - from.y) * t;
place(x, y, r0 + (r1 - r0) * t);
const inZone = x > zx - 40 && x < zx + z.width + 40;
if (inZone && !entered) {
entered = true;
fire("dragenter", f, x, y);
}
if (entered) fire("dragover", f, x, y);
});
place(start.x, start.y, 8);
if (edge) {
go(start, near, 620, 8, 4);
after(920, () => go(near, inside, 700, 4, -2));
after(1700, () => {
fire("drop", f, inside.x, inside.y);
if (back) tween(520, (t) => setGhost((g) => (g ? { ...g, x: inside.x + (start.x - inside.x) * t, y: inside.y - 40 * Math.sin(Math.PI * t) + (start.y - inside.y) * t, o: 1 - t * t, r: -2 + 14 * t, down: false } : g)));
else tween(360, (t) => setGhost((g) => (g ? { ...g, s: 1 - 0.5 * t, o: 1 - t, y: inside.y + 18 * t, down: false } : g)));
});
after(2240, () => setGhost(null));
} else {
go(start, inside, 640, 10, 2);
after(700, () => {
setGhost(null);
fire("drop", f, inside.x, inside.y);
});
}
});
};
return { ghost, carry, stop };
}
/** The file in the hand, and the hand. */
function Carried({ ghost }: { ghost: Ghost | null }) {
if (!ghost) return null;
const dot = ghost.name.lastIndexOf(".");
const tag = ghost.name.slice(dot + 1).toUpperCase();
return (
<div aria-hidden className="pointer-events-none absolute top-0 left-0 z-30" style={{ translate: `${ghost.x}px ${ghost.y}px` }}>
<span className="absolute block h-[96px] w-[74px] -translate-x-1/2 -translate-y-1/2 rounded-[8px] bg-[var(--ns-raised)] shadow-[0_0_0_1px_var(--ns-line),0_14px_28px_-12px_rgb(0_0_0/0.4)]" style={{ rotate: `${ghost.r}deg`, scale: String(ghost.s), opacity: ghost.o }}>
<span className="absolute inset-x-[14%] top-[16%] flex flex-col gap-[6px]">
<span className="h-[4px] w-[70%] rounded-full bg-[var(--ns-ink-3)] opacity-40" />
{[92, 84, 60].map((w) => (
<span key={w} className="h-[3px] rounded-full bg-[var(--ns-line)]" style={{ width: `${w}%` }} />
))}
</span>
<span className="absolute bottom-[8%] left-[10%] rounded-[3px] bg-[var(--ns-signal-wash)] px-1 text-[9px] leading-[14px] font-semibold text-[var(--ns-signal-ink)]">{tag}</span>
</span>
<MousePointer2 className="absolute top-[30px] left-[22px] size-6 fill-[var(--ns-ink)] text-[var(--ns-raised)] drop-shadow-[0_2px_3px_rgb(0_0_0/0.3)] [transition:scale_120ms]" style={{ scale: ghost.down ? "0.9" : "1" }} />
</div>
);
}
function Look({ look, fail }: { look: FileDropLook; fail: boolean }) {
const words = WORDS;
const cvName = WORDS.cv;
const less = useLessMotion();
const settle = React.useContext(PlayOnce)?.settle ?? false;
const quick = less || settle;
const host = useHost(quick, fail, words.failed);
const root = React.useRef<HTMLDivElement>(null);
const hand = useHand(root);
const play = useSelfPlay(root, { beats: [400], off: less });
const big = React.useMemo(() => (look === "plain" ? sized(words.scan, 14 * MB, "image/png") : sized(words.big, 24.6 * MB, "application/pdf")), [look, words]);
/* the arrival: once, then the visitor's; at once (the end) under less motion or a settled stage */
const ran = React.useRef(false);
React.useEffect(() => {
if (play.step !== 0 || ran.current) return;
ran.current = true;
const cv = look === "plain" ? sized(words.notes, 1.8 * MB, "application/pdf") : sized(cvName, 1.84 * MB, "application/pdf");
if (quick) {
host.change([cv]);
return;
}
if (look === "well") hand.carry(cv, 0, { edge: true });
if (look === "plain") {
hand.carry(cv, 0);
hand.carry(big, 2600);
}
if (look === "stack") {
hand.carry(cv, 0, { lane: 0 });
void fetch("https://notchset.dev/media/petals.webp")
.then((r) => r.blob())
.then((b) => hand.carry(sized(words.portfolio, b.size, "image/png", [b]), 850, { lane: 1 }))
.catch(() => hand.carry(sized(words.portfolio, 3.2 * MB, "image/png"), 850, { lane: 1 }));
hand.carry(big, 1700, { lane: 2 });
}
});
/* the first touch is the visitor's: the hand lets go */
React.useEffect(() => {
if (play.mine) hand.stop();
}, [play.mine, hand]);
/* the quiet switch: turned on, the hand carries a file in and its upload fails part way (as every upload does while
it is on) */
const failed = React.useRef(fail);
const sample = React.useMemo(() => (look === "plain" ? sized(words.notes, 1.8 * MB, "application/pdf") : sized(words.portfolio, 3.2 * MB, "image/png")), [look, words]);
React.useEffect(() => {
if (fail && !failed.current) {
if (quick) hand.stop();
hand.carry(sample, 0, { edge: look === "well", lane: 1 });
}
failed.current = fail;
}, [fail, sample, hand, look, quick]);
const drop = (
<FileDrop
look={look}
label={look === "plain" ? words.attachments : undefined}
hint={look === "plain" ? "PDF or images, up to 10 MB each" : LIMIT}
accept={look === "plain" ? ".pdf,image/*" : ACCEPT}
maxSize={10 * MB}
multiple
maxFiles={3}
value={host.files}
onValueChange={host.change}
status={host.status}
onRetry={host.retry}
/>
);
return (
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="relative flex w-full justify-center">
{look === "plain" ? (
<div className="w-full max-w-[400px]">
<section className="flex h-[312px] w-full flex-col rounded-[var(--ns-radius-xl)] bg-[var(--ns-raised)] p-4 shadow-[var(--ns-bezel)]">{drop}</section>
</div>
) : (
<section className="flex w-[640px] max-w-full flex-col gap-5 rounded-[28px] bg-[var(--ns-raised)] p-7 shadow-[var(--ns-bezel),0_30px_60px_-40px_rgb(0_0_0/0.35)] max-sm:rounded-[22px] max-sm:p-4">
<header className="flex flex-col gap-1.5">
<p className="m-0 text-[13px] text-[var(--ns-ink-3)]">{words.role}</p>
<h3 className="m-0 font-[family-name:var(--ns-font-display)] text-[30px] leading-[1.1] font-[number:var(--ns-weight-strong)] tracking-[-0.025em] text-[var(--ns-ink)] max-sm:text-[24px]">{words.title}</h3>
</header>
<div className={look === "well" ? "h-[300px] max-sm:h-[290px]" : "h-[300px] max-sm:h-[244px]"}>{drop}</div>
</section>
)}
<Carried ghost={hand.ghost} />
</div>
);
}
export default function FileDropDemo() {
const look = "well" as FileDropLook;
const fail = false;
return <Look key={look} look={look} fail={fail} />;
}"use client";
import * as React from "react";
import { FileDrop, type FileDropLook } from "@/components/ui/notchset/file-drop";
import { MousePointer2 } from "@/lib/notchset/icons";
import { useLessMotion } from "@/lib/notchset/motion";
import { PlayOnce, useSelfPlay } from "./self-play";
/*
* Three looks of one file drop, each on its own job. "The well breathes" and "Paper stack" are a careers page's
* "drop your CV": on arrival a hand carries the CV in (the well's edges lean out to meet it and bow in round it; it
* falls in, its row's rule fills and a tick lands; the stack takes the CV, then a portfolio image, then a 24.6 MB print
* that bounces back out with its reason in rose). "Plain" is a support form's attachments: a file is dropped, uploads in
* its row and settles with a tick on its mark; then a 14 MB scan is named in rose. Real files work on every look: drop,
* paste or choose. The quiet "Uploads fail" chip is a switch: while it is on, every file's upload stops part way and
* its row says so in rose with Retry (the hand carries one in when it is turned on); off, Retry sends it through.
*/
const MB = 1_000_000;
const LIMIT = "PDF, Word or images, up to 10 MB";
const ACCEPT = ".pdf,.doc,.docx,image/*";
const WORDS = { role: "Careers · Product Designer · Remote", title: "Drop your CV here", cv: "Ana Ruiz, CV.pdf", portfolio: "Portfolio, 2026.png", big: "Portfolio, print.pdf", notes: "Screen recording notes.pdf", scan: "Scan.png", attachments: "Attachments", failed: "Upload failed. Check the connection and retry." };
/* the stage's own files carry their stated size (no real bytes are made) */
const sized = (name: string, bytes: number, type: string, parts: BlobPart[] = []) => {
const f = new File(parts, name, { type, lastModified: 0 });
if (!parts.length) Object.defineProperty(f, "size", { value: bytes });
return f;
};
/* where a failing upload stops: part way, so its rule has visibly filled before the row turns rose */
const FAILS_AT = 0.6;
/* a failed upload's progress (below 0: it reads as the error) */
const FAILED = -1;
/** An upload host: each new file climbs to done over about 1.3 s, eased (instant under less motion). While `failing`
is on, every upload sent stops part way and fails; Retry sends it again (and fails again while it is still on). */
function useHost(instant: boolean, failing: boolean, failed: string) {
const [progress, setProgress] = React.useState(() => new Map<File, number>());
const doomed = React.useRef(new Set<File>());
const fails = React.useRef(failing);
React.useEffect(() => {
fails.current = failing;
}, [failing]);
const busy = [...progress.values()].some((p) => p >= 0 && p < 1);
React.useEffect(() => {
if (!busy) return;
let raf = 0;
const step = () => {
setProgress((m) => new Map([...m].map(([f, p]) => [f, p < 0 || p >= 1 ? p : doomed.current.has(f) && p >= FAILS_AT ? FAILED : Math.min(1, p + 0.012 + (1 - p) * 0.02)])));
raf = requestAnimationFrame(step);
};
raf = requestAnimationFrame(step);
return () => cancelAnimationFrame(raf);
}, [busy]);
const [files, setFiles] = React.useState<File[]>([]);
const send = (f: File) => {
if (fails.current) doomed.current.add(f);
else doomed.current.delete(f);
return instant ? (fails.current ? FAILED : 1) : 0.02;
};
const change = (next: File[]) => {
setFiles(next);
setProgress((m) => {
const out = new Map(m);
next.forEach((f) => !out.has(f) && out.set(f, send(f)));
return out;
});
};
const retry = (f: File) => setProgress((m) => new Map(m).set(f, send(f)));
const status = (f: File) => {
const p = progress.get(f);
return p === undefined ? undefined : p < 0 ? { error: failed } : p >= 1 ? { done: true } : { progress: p };
};
return { files, change, retry, status };
}
type Ghost = { x: number; y: number; r: number; o: number; s: number; name: string; down: boolean };
/** The stage's own hand: it carries a file across the stage and lets it go over the zone, through the zone's own drag events. */
function useHand(box: React.RefObject<HTMLDivElement | null>) {
const [ghost, setGhost] = React.useState<Ghost | null>(null);
const timers = React.useRef<number[]>([]);
const frames = React.useRef<number[]>([]);
const stop = React.useCallback(() => {
timers.current.forEach((t) => window.clearTimeout(t));
frames.current.forEach((f) => cancelAnimationFrame(f));
timers.current = [];
frames.current = [];
setGhost(null);
}, []);
React.useEffect(() => stop, [stop]);
const after = (ms: number, fn: () => void) => void timers.current.push(window.setTimeout(fn, ms));
const tween = (ms: number, frame: (t: number) => void) => {
const t0 = performance.now();
const step = (now: number) => {
const k = Math.min(1, (now - t0) / ms);
frame(k < 0.5 ? 4 * k * k * k : 1 - (-2 * k + 2) ** 3 / 2);
if (k < 1) frames.current.push(requestAnimationFrame(step));
};
frames.current.push(requestAnimationFrame(step));
};
const zone = () => box.current?.querySelector<HTMLElement>("[data-slot=file-drop-panel] [role=button]") ?? null;
const fire = (type: string, f: File, x: number, y: number) => {
const z = zone();
const b = box.current?.getBoundingClientRect();
if (!z || !b || typeof DataTransfer === "undefined") return;
const dt = new DataTransfer();
dt.items.add(f);
z.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: dt, clientX: b.left + x, clientY: b.top + y }));
};
/* from the right of the zone, to its edge, then in; `edge` lingers on the near side so the well can lean out to it */
const carry = (f: File, at: number, { edge = false, lane = 0, back = false } = {}) => {
after(at, () => {
const z = zone()?.getBoundingClientRect();
const b = box.current?.getBoundingClientRect();
if (!z || !b) return;
const zx = z.left - b.left;
const zy = z.top - b.top;
const start = { x: Math.min(b.width - 40, zx + z.width + 120), y: zy + 30 + lane * 16 };
const near = { x: zx + z.width + 30, y: zy + z.height * 0.45 };
const inside = { x: zx + z.width * (edge ? 0.56 : 0.36), y: zy + Math.min(z.height * 0.5, 90) };
const place = (x: number, y: number, r: number, o = 1) => setGhost({ x, y, r, o, s: 1, name: f.name, down: true });
let entered = false;
const go = (from: { x: number; y: number }, to: { x: number; y: number }, ms: number, r0: number, r1: number) =>
tween(ms, (t) => {
const x = from.x + (to.x - from.x) * t;
const y = from.y + (to.y - from.y) * t;
place(x, y, r0 + (r1 - r0) * t);
const inZone = x > zx - 40 && x < zx + z.width + 40;
if (inZone && !entered) {
entered = true;
fire("dragenter", f, x, y);
}
if (entered) fire("dragover", f, x, y);
});
place(start.x, start.y, 8);
if (edge) {
go(start, near, 620, 8, 4);
after(920, () => go(near, inside, 700, 4, -2));
after(1700, () => {
fire("drop", f, inside.x, inside.y);
if (back) tween(520, (t) => setGhost((g) => (g ? { ...g, x: inside.x + (start.x - inside.x) * t, y: inside.y - 40 * Math.sin(Math.PI * t) + (start.y - inside.y) * t, o: 1 - t * t, r: -2 + 14 * t, down: false } : g)));
else tween(360, (t) => setGhost((g) => (g ? { ...g, s: 1 - 0.5 * t, o: 1 - t, y: inside.y + 18 * t, down: false } : g)));
});
after(2240, () => setGhost(null));
} else {
go(start, inside, 640, 10, 2);
after(700, () => {
setGhost(null);
fire("drop", f, inside.x, inside.y);
});
}
});
};
return { ghost, carry, stop };
}
/** The file in the hand, and the hand. */
function Carried({ ghost }: { ghost: Ghost | null }) {
if (!ghost) return null;
const dot = ghost.name.lastIndexOf(".");
const tag = ghost.name.slice(dot + 1).toUpperCase();
return (
<div aria-hidden className="pointer-events-none absolute top-0 left-0 z-30" style={{ translate: `${ghost.x}px ${ghost.y}px` }}>
<span className="absolute block h-[96px] w-[74px] -translate-x-1/2 -translate-y-1/2 rounded-[8px] bg-[var(--ns-raised)] shadow-[0_0_0_1px_var(--ns-line),0_14px_28px_-12px_rgb(0_0_0/0.4)]" style={{ rotate: `${ghost.r}deg`, scale: String(ghost.s), opacity: ghost.o }}>
<span className="absolute inset-x-[14%] top-[16%] flex flex-col gap-[6px]">
<span className="h-[4px] w-[70%] rounded-full bg-[var(--ns-ink-3)] opacity-40" />
{[92, 84, 60].map((w) => (
<span key={w} className="h-[3px] rounded-full bg-[var(--ns-line)]" style={{ width: `${w}%` }} />
))}
</span>
<span className="absolute bottom-[8%] left-[10%] rounded-[3px] bg-[var(--ns-signal-wash)] px-1 text-[9px] leading-[14px] font-semibold text-[var(--ns-signal-ink)]">{tag}</span>
</span>
<MousePointer2 className="absolute top-[30px] left-[22px] size-6 fill-[var(--ns-ink)] text-[var(--ns-raised)] drop-shadow-[0_2px_3px_rgb(0_0_0/0.3)] [transition:scale_120ms]" style={{ scale: ghost.down ? "0.9" : "1" }} />
</div>
);
}
function Look({ look, fail }: { look: FileDropLook; fail: boolean }) {
const words = WORDS;
const cvName = WORDS.cv;
const less = useLessMotion();
const settle = React.useContext(PlayOnce)?.settle ?? false;
const quick = less || settle;
const host = useHost(quick, fail, words.failed);
const root = React.useRef<HTMLDivElement>(null);
const hand = useHand(root);
const play = useSelfPlay(root, { beats: [400], off: less });
const big = React.useMemo(() => (look === "plain" ? sized(words.scan, 14 * MB, "image/png") : sized(words.big, 24.6 * MB, "application/pdf")), [look, words]);
/* the arrival: once, then the visitor's; at once (the end) under less motion or a settled stage */
const ran = React.useRef(false);
React.useEffect(() => {
if (play.step !== 0 || ran.current) return;
ran.current = true;
const cv = look === "plain" ? sized(words.notes, 1.8 * MB, "application/pdf") : sized(cvName, 1.84 * MB, "application/pdf");
if (quick) {
host.change([cv]);
return;
}
if (look === "well") hand.carry(cv, 0, { edge: true });
if (look === "plain") {
hand.carry(cv, 0);
hand.carry(big, 2600);
}
if (look === "stack") {
hand.carry(cv, 0, { lane: 0 });
void fetch("https://notchset.dev/media/petals.webp")
.then((r) => r.blob())
.then((b) => hand.carry(sized(words.portfolio, b.size, "image/png", [b]), 850, { lane: 1 }))
.catch(() => hand.carry(sized(words.portfolio, 3.2 * MB, "image/png"), 850, { lane: 1 }));
hand.carry(big, 1700, { lane: 2 });
}
});
/* the first touch is the visitor's: the hand lets go */
React.useEffect(() => {
if (play.mine) hand.stop();
}, [play.mine, hand]);
/* the quiet switch: turned on, the hand carries a file in and its upload fails part way (as every upload does while
it is on) */
const failed = React.useRef(fail);
const sample = React.useMemo(() => (look === "plain" ? sized(words.notes, 1.8 * MB, "application/pdf") : sized(words.portfolio, 3.2 * MB, "image/png")), [look, words]);
React.useEffect(() => {
if (fail && !failed.current) {
if (quick) hand.stop();
hand.carry(sample, 0, { edge: look === "well", lane: 1 });
}
failed.current = fail;
}, [fail, sample, hand, look, quick]);
const drop = (
<FileDrop
look={look}
label={look === "plain" ? words.attachments : undefined}
hint={look === "plain" ? "PDF or images, up to 10 MB each" : LIMIT}
accept={look === "plain" ? ".pdf,image/*" : ACCEPT}
maxSize={10 * MB}
multiple
maxFiles={3}
value={host.files}
onValueChange={host.change}
status={host.status}
onRetry={host.retry}
/>
);
return (
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="relative flex w-full justify-center">
{look === "plain" ? (
<div className="w-full max-w-[400px]">
<section className="flex h-[312px] w-full flex-col rounded-[var(--ns-radius-xl)] bg-[var(--ns-raised)] p-4 shadow-[var(--ns-bezel)]">{drop}</section>
</div>
) : (
<section className="flex w-[640px] max-w-full flex-col gap-5 rounded-[28px] bg-[var(--ns-raised)] p-7 shadow-[var(--ns-bezel),0_30px_60px_-40px_rgb(0_0_0/0.35)] max-sm:rounded-[22px] max-sm:p-4">
<header className="flex flex-col gap-1.5">
<p className="m-0 text-[13px] text-[var(--ns-ink-3)]">{words.role}</p>
<h3 className="m-0 font-[family-name:var(--ns-font-display)] text-[30px] leading-[1.1] font-[number:var(--ns-weight-strong)] tracking-[-0.025em] text-[var(--ns-ink)] max-sm:text-[24px]">{words.title}</h3>
</header>
<div className={look === "well" ? "h-[300px] max-sm:h-[290px]" : "h-[300px] max-sm:h-[244px]"}>{drop}</div>
</section>
)}
<Carried ghost={hand.ghost} />
</div>
);
}
export default function FileDropDemo() {
const look = "well" as FileDropLook;
const fail = false;
return <Look key={look} look={look} fail={fail} />;
}"use client";
import * as React from "react";
/*
* A demo that plays itself until the first touch: the script lives in the demo, never in the piece, which only gets
* the props a person would give it. It moves 0.4 s after the piece is first seen, then takes each step on its beat;
* off screen or paused it waits. The first press, key or focus on the piece (bind `handOver` to it; a scroll over it never counts) makes it the
* visitor's for good and drops every queued step; with less motion (`off`) it never plays and rests in its first frame.
* A host can hand it over from outside the piece too (a settings panel beside it the visitor has used): under
* <HandedOver value>, it never plays, a remount included.
*
* const play = useSelfPlay(root, { beats: [2800, 2800], loop: true, off: less });
* <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} onFocusCapture={play.handOver}>
* play.step // the step it is at, -1 before its first
* play.control // "pause" while it plays, "play" once paused (a new take), "replay" once it is over or yours
*
* Each step presses the piece's own controls (pressIn), so the script shows exactly what a hand can do.
*
* A host that shows the piece once (<PlayOnce value={{ settle }}>) changes three things: the script starts when the
* piece is first half in view and never again on coming back, it never loops, and with less motion (or `settle`) it
* takes every step at once, so the piece rests on the END of its moment. `hold` is a reason not to play at all that is
* not motion (a mode with nothing to show): it holds in every host. Under <PlayOnce value={{ active: false }}> (a look
* that is mounted but not shown) it waits until it is shown.
*/
type SelfPlayOptions = {
/** how long each step waits after the one before it, in ms; the first step waits 0.4 s after the piece is seen */
beats: readonly number[];
/** starts over after the last step; without it the script plays once and rests */
loop?: boolean | undefined;
/** no self-play at all (less motion): the piece is the visitor's from the start */
off: boolean;
/** no self-play for a reason other than motion (a mode with nothing to show), in every host */
hold?: boolean | undefined;
};
/** How a host shows the piece: once on arrival (see useSelfPlay). */
type PlayOnceHost = {
/** rest on the end at once, without playing (less motion, or a reset) */
settle?: boolean | undefined;
/** false while the piece is mounted but not shown: it waits */
active?: boolean | undefined;
};
const START = 400;
/**
* Whether a demo plays itself at all. Off: every piece rests in its first frame and is
* the visitor's from the start; nothing presses its controls for them.
*/
const SELF_PLAY: boolean = false;
/** True where the visitor has already taken the piece from outside it: nothing under it plays itself. */
const HandedOver = React.createContext(false);
/** A host that shows the piece once: play once on arrival, rest on the end (null: play as the demo asks). */
const PlayOnce = React.createContext<PlayOnceHost | null>(null);
function useSelfPlay(root: React.RefObject<Element | null>, { beats, loop: looped = false, off: still, hold = false }: SelfPlayOptions) {
const once = React.useContext(PlayOnce);
const active = once?.active !== false;
/* shown once: less motion (or a settled host) takes every step at once and rests on the end */
const quick = once != null && (still || Boolean(once.settle));
const loop = once == null && looped;
/* the first touch hands it over for good */
const [mine, setMine] = React.useState(false);
const handOver = React.useCallback(() => setMine(true), []);
const handedOver = React.useContext(HandedOver);
const off = !SELF_PLAY || hold || (quick ? false : still) || mine || (handedOver && !quick);
const [seen, setSeen] = React.useState(false);
const [paused, setPaused] = React.useState(false);
const [taken, setTaken] = React.useState(0);
const n = Math.max(1, beats.length);
const done = !loop && taken >= n;
React.useEffect(() => {
const el = root.current;
if (!active) return;
/* without an observer (an old browser, a test) it counts as seen */
if (!el || typeof IntersectionObserver === "undefined" || quick) {
const t = window.setTimeout(() => setSeen(true));
return () => window.clearTimeout(t);
}
/* shown once: first half in view starts it, and leaving never stops or restarts it */
const io = once
? new IntersectionObserver((es) => {
if (es.some((e) => e.isIntersecting && e.intersectionRatio >= 0.5)) {
setSeen(true);
io.disconnect();
}
}, { threshold: 0.5 })
: new IntersectionObserver((es) => setSeen(es.some((e) => e.isIntersecting)));
io.observe(el);
return () => io.disconnect();
}, [root, active, once, quick]);
const playing = !off && seen && active && !paused && !done;
const delay = quick ? 0 : taken === 0 ? START : (beats[taken % n] ?? START);
React.useEffect(() => {
if (!playing) return;
const t = window.setTimeout(() => setTaken((k) => k + 1), delay);
return () => window.clearTimeout(t);
}, [playing, taken, delay]);
/* one control in one place: Pause while it plays, Play (a new take) once paused, Replay once it is over or yours */
/* self-play off: never "over", so a demo rests in its FIRST frame, not its end frame */
const control: "pause" | "play" | "replay" = paused || !SELF_PLAY ? "play" : off || done ? "replay" : "pause";
return { step: taken === 0 ? -1 : (taken - 1) % n, taken, playing, control, mine, handOver, pause: () => setPaused(true) };
}
/**
* Presses a real control inside `root`, as the visitor would: the first match of `selector`, or the one whose text is
* `text`. A click only, so it never counts as the visitor's touch.
*/
function pressIn(root: Element | null, selector: string, text?: string) {
const all = [...(root?.querySelectorAll<HTMLElement>(selector) ?? [])];
(text == null ? all[0] : all.find((el) => el.textContent?.trim() === text))?.click();
}
export { HandedOver, PlayOnce, pressIn, useSelfPlay, type PlayOnceHost, type SelfPlayOptions };components/ui/notchset/file-drop.tsx
LevelAtom: uses no other piece.
Made ofRolling number,Tooltip
Free, no account or key. One command for every shadcn style. With the @notchset registry added, @notchset/<name> works too.
Works with React 18.3 or 19 on Tailwind CSS v4, in any shadcn project. What's tested
pnpm add lucide-react@^1The CLI adds the styles to the CSS file named in components.json (tailwind.css). Check that it points at your global stylesheet, that the project uses Tailwind CSS v4, and that the file is imported in your root layout. Installed by hand: paste styles.css into that file.
The sound you hear is this page's: the piece you install plays none, and calls onFeedback on each move so you can add your own.
onFeedback–
(e: FeedbackEvent) => voidcalled once per move, for your sound or haptics
label–
React.ReactNodewhat the files are, heading the panel ("Attachments")
hint–
React.ReactNodewhat it takes ("PDF or images, up to 10 MB")
value–
File[]the chosen files (controlled, with onValueChange)
defaultValue[]
File[]the files at first (uncontrolled)
onValueChange–
(files: File[]) => voidthe files after each change
onReject–
(rejected: Rejected[]) => voidthe files left out of the last add, with why
accept–
stringtypes and extensions (".csv", "image/*")
maxSize–
numberthe largest file, in bytes
multiplefalse
booleantake several files (one by default)
maxFiles–
numberthe most files, with `multiple`
disabled–
booleanrefuses drops and the picker
status–
(file: File) => FileStatus | undefinedeach file's upload, if the host uploads them
onRetry–
(file: File) => voida failed file's Retry
localeDEFAULT_LOCALE
stringthe locale sizes are written in
look"plain"
FileDropLook"plain" (the form default), or a public form's showpiece: "well" (its edges bend to a held file) or "stack" (a pile of cards)
labels–
Partial<FileDropLabels>its words ({name}, {size}, {max}, {accept}, {percent} blanks)
Three usesattachments on a deal · a CSV to import · lab results to a health record
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)v1.2.0 · 2026-11-17
Ships file-size.ts (formatBytes), which it now uses. Internal files split; installs smaller; no change to the piece's own API.
v1.1.0 · 2026-11-17
New props: look, onFeedback. Ships feedback.ts (FeedbackEvent, FeedbackProps), which it now uses. file-drop.tsx now exports splitName, FileDropLook. Ships motion.ts (EASE, lessMotion, roleTiming, useLessMotion), which it now uses.
v1.0.0 · 2026-11-09
Released free with the Notchset system.