File library
NewA team’s file library: drag a file row onto a folder tile, its ghost following the pointer, and the folder opens to take it.
file-library/file-library.tsxFolders 4
Files 9
The live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.
The choices it offers, each value drawn live and the default marked, with how to pick one.
When to use
- A shared folder where people sort files into sub-folders: a team library, a client’s documents, a project’s assets.
- Moves that happen often and in bulk, where dragging rows onto a folder is faster than opening a dialog for each file.
- A view that has both levels at once: the folders as tiles to drop onto, the loose files as a table to pick from.
- Folders whose contents people recognise at a glance: the cover shows the last files that went in.
When not to use
- Deep trees where files move several levels away. Use a Move dialog with a folder picker and a search field.
- Hundreds of folders. A row of tiles holds a handful; past that, drop onto the tree in the sidebar or use the Move to menu alone.
- A read-only archive or a download page. Without moves, a plain table with links is lighter.
- Phones as the main place it is used. Dragging works with a held finger, but the Move to menu is the better path there.
Three ways to move
- Drag a row onto a tile or onto the folder in the sidebar’s tree. A mouse drag starts after 4 px of travel; a finger holds for 320 ms first, so a swipe still scrolls.
- Tick rows, then drag any of them: the ticked rows go together, as a stack with their count.
- Tick rows, then Move to in the bar: a menu of the folders, for the keyboard, for a screen reader and for small screens.
- Escape during a drag sends the ghost back to its row; dropping anywhere but a folder does the same.
Feedback after a move
- The row folds away in 240 ms and the rows under it slide up; the Files count drops.
- The folder changes: a new paper drops in as its cover, its count goes up and turns blue for a moment, and its row in the tree flashes.
- A toast with Undo, which puts the files back where they were in the table and takes the paper out of the folder.
Files from the desktop
- Over a tile, an “Upload to …” pill shows under it; dropped, a bar fills the folder’s front and the count reads the percentage.
- When it’s done, a green check shows on the front, the cover takes the new file and the toast says it was added.
- Upload in the header picks files from the device; they land in General, at the top of the table.
Each one drawn with the component itself, used well or badly.
The words are folder and file names, the counts, the toast and the bar.
- Counts in words under each tile:
12 files,1 file,No files; while uploading,Uploading 42%. - The toast names both ends:
Moved Pitch-Deck-v4.pdf to Contracts, orMoved 3 files to Contractsfor several. The file’s name is in the stronger colour. - Verbs on buttons:
Move to,Share,Upload,Undo. No “OK”. - File names as they are, extension included, cut with an ellipsis when the column is narrow; the full name stays in the tick box’s label.
You can add this component with the shadcn CLI or by hand:
Into components/file-library of any React project, with no setup:
npx shadcn@latest add https://brunodelorence.com/r/file-library.json- Copy the component files
Copy these files into one folder of your project, keeping their relative imports together, or download them as a ZIP:
- Import it
As shown under Usage, below.
Either way it needs React 19.2 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.
Usage
import { FileLibrary } from './file-library';export function TeamFiles() { return ( <FileLibrary autoplay={false} onMove={(files, folder) => console.log(`${files.length} → ${folder}`)} /> );}Each state below is a live instance, locked so you can study it.
The pieces it is built from, each with its measurements read live.
A workspace window with a folder tree, a row of folder tiles and a table of loose files. Drag a row onto a folder and a tilted chip follows the pointer; the folder lights up, its frosted front tips forward and the papers inside rise. Drop it and the chip shrinks into the folder, a new paper drops in as its cover, the row folds away and a toast says what moved, with Undo. Tick several rows to drag them as a stack, or use Move to in the bar that rises at the bottom. Files dragged in from the desktop upload into a folder with a progress bar on its front.
- The drag is pointer events, not native drag and drop, so the ghost can be drawn: a 40 px chip with the file’s icon, name and size, tilted 3°, moved by a transform written straight to its style on each pointer move, with no React render. A mouse drag starts after 4 px; a finger holds 320 ms first, so a swipe still scrolls, and a non-passive touchmove keeps the page still once it has started.
- The folder under the pointer is found with elementFromPoint and the nearest [data-drop], so the tiles and the folders in the sidebar’s tree take drops the same way. Lit, a tile gets a blue ring and glow in 160 ms, its front panel tips forward 24° on its bottom edge (perspective 420 px, a slight overshoot over 280 ms) and its papers rise 6 px.
- Each folder picture is a 134 × 104 SVG back with a tab, its last three files as papers fanned at set offsets, and a frosted front (backdrop-filter blur 9 px) over their lower half. A document is a white page with its type’s coloured square, a picture a gradient card, so the cover changes as files go in.
- On a drop the ghost flies into the folder and shrinks to 35% in 200 ms (Web Animations API); then the new paper drops in from 34 px above on an overshooting curve (460 ms), the row folds from 1fr to 0fr in 240 ms while the rows under it slide up, and the count turns blue for a moment.
- Several ticked rows drag as a stack: two chips fanned behind the first and a blue count badge. Escape, or a drop outside any folder, flies the ghost back to its row in 220 ms.
- The toast comes down 6 px in 220 ms and stays 5 s, held while the pointer or the focus is on it; Undo puts each file back at its old place in the table (the row unfolds) and takes its paper out of the folder.
- Files from the desktop use native drag events: over a tile an “Upload to” pill shows under it, and dropped, a bar fills the front over 1.1 s (fast, then slowing) before the papers go in and a green check pops.
- The selection bar is sticky at the foot of the scrolling column (of the screen on a narrow library) and rises 14 px in 180 ms. Under 720 px of library the rail goes, the sidebar becomes a drawer and the tiles scroll sideways.
- While on screen and untouched, a demo pointer plays the story: one file into Contracts, three ticked and dragged together, then a picture from outside into Brand Assets; then it all resets. Any input stops it.
- Every colour is a token with light-dark(): the dark scheme is near-black with graphite folders, the light one paper whites with cool grey folder backs and milkier glass.
| Prop | Type | Default | Description |
|---|---|---|---|
onMove | (files: string[], folder: string, undone: boolean) => void | — | Called after files move, with their names and the folder’s; called again with General and undone true when the move is undone. |
defaultView | 'rest' | 'selected' | 'dragging' | 'moved' | 'uploading' | 'rest' | Starts at a moment of the story, as a still for docs and screenshots: rows ticked, a file mid-drag over a folder, a file just moved with its toast, or an upload under way. Anything but rest turns the demo off. |
autoplay | boolean | true | While on screen and untouched, a demo pointer drags files into folders; any input from the reader stops it. |
colorScheme | 'light' | 'dark' | 'system' | — | Light or dark colours, or the reader’s; without it, the page’s color-scheme. |
className | string | — | A class for the outer stage. |
Keyboard
- Tab reaches each row’s tick box; Space ticks it. Once a row is ticked, the bar’s Move to button is the next stop after the table.
- Move to opens a menu with the focus on the first folder: the arrows, Home and End move, Enter moves the ticked files there, Escape closes it and returns to the button.
- After a move the focus waits on the table’s Select all box, since the bar goes away with the selection. Undo in the toast is a button too.
- Escape cancels a drag in progress, and closes the sidebar’s drawer on a narrow library.
Screen readers
- The files are a
tablewith column headers; each tick box is named “Select Pitch-Deck-v4.pdf”. Each tile is a list item named with its folder, its count and whether it is private. - A polite live region says each drag, move, undo and upload: “Moved 3 files to Contracts.” The selection bar’s count is live too.
- The folder pictures, the ghost, the icons and the demo pointer are hidden from screen readers; the closed drawer and the hidden bar are inert.
Pointer and touch
A drag needs a press and a move, so the Move to menu is the single-pointer alternative WCAG 2.5.7 asks for. On touch, a 320 ms hold starts the drag and a moving finger scrolls instead; a tap ticks the row.
Motion
With reduced motion, rows go and come back at once, the papers appear without dropping in, the front doesn’t tip, the ghost doesn’t fly and the demo doesn’t play. The ring and the toast still say what happened.
In this build
- Dragging has a keyboard and single-pointer alternative (WCAG 2.5.7): tick rows with Space, then Move to in the selection bar opens a menu of the folders; arrows, Home and End move, Enter moves the files, Escape closes.
- The files are a table with column headers; each tick box is named after its file. Each folder tile is a list item named with its count and whether it is private.
- A polite live region says each drag, move, undo and upload (“Moved 3 files to Contracts.”); the bar’s count is live too.
- Escape cancels a drag and closes the sidebar’s drawer. After a move from the menu the focus waits on Select all, since the bar goes away.
- The toast holds open while the pointer or the focus is on it, so Undo can be reached in time.
- Every control shows a focus ring. The folder pictures, the ghost, the icons and the demo pointer are hidden from screen readers; the closed drawer and the hidden bar are inert.
- With reduced motion, rows go and come at once, nothing flies, tips or drops in, and the demo does not play.
The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useEffectEvent, useId, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent,} from 'react';import { DEMO_UPLOAD, FILES, FOLDERS, GENERAL_COUNT, OTHER_FOLDERS, PEOPLE, SHARED_FOLDERS, formatSize, huesOf,/* File library (file-library.tsx): a workspace window, icon rail and folder tree on the left, General's folders as tiles over a table of its loose files. Rows drag onto tiles. Sizes are px, measured from the reference at 1440 × 900: a 48 px top bar, a 52 px rail, a 218 px sidebar, a 47 px header over the main column; tiles 163 × 172 with a 134 × 104 folder picture, 12 apart; table rows 44 px. Under 720 px of library the rail goes, the sidebar becomes a drawer, and the tiles scroll sideways. Motion, from the reference's frames (10 a second): the ghost lifts in 160 ms, a tile lights in 160 ms and its front tips forward on a slight overshoot (280 ms); dropped, the ghost shrinks into the folder in 200 ms, a paper drops in (460 ms, overshooting), the row folds in 240 ms and the toast comes down in 220 ms. The selection bar rises in 180 ms. Colours are the tokens below, light-dark(light, dark) where the two differ: the reference is the dark one; the light one is the same window on paper whites. */.root { --canvas: #e9ebf0; --glow: rgb(80 120 255 / 0.12); --app: #ffffff; --side: #fbfbfc; --table: #ffffff; --line: #e7e7eb; --line-soft: #efeff2;// Copyright (c) 2026 Bruno Delorence. MIT License.import type { CSSProperties } from 'react';import { PEOPLE, type Folder, type PersonId } from './data';import { Icon } from './icons';import styles from './file-library.module.css';/* * A folder tile's picture, 134 × 104 px: the folder's back with its tab, up to three papers * peeking out of it, and a frosted front panel over their lower half. The papers are the * folder's last three files, the newest in front, so the cover changes as files go in: a white * page with its type's coloured square for a document, a gradient card for a picture. The front * carries the members, a Private chip, or an upload's progress and its check. * * Everything that moves is CSS on the tile's data attributes (file-library.module.css): over a * drag, the front tips forward on its bottom edge and the papers rise; a new paper drops in. *//** The small round face used across the library: initials on a pastel. */export function Avatar({ id, className }: { id: PersonId; className?: string }) { return ( <span className={`${styles.avatar} ${className ?? ''}`} data-person={id} aria-hidden="true"> {PEOPLE[id].initials} </span>// Copyright (c) 2026 Bruno Delorence. MIT License./* * The library's starting contents: the people, the folders under General with the papers that * peek out of each, and the nine files loose in General. Counts add up: General's 34 is its four * folders (12 + 8 + 0 + 5) and its nine files, so a move between them leaves it unchanged. */export type PersonId = 'mc' | 'aw' | 'kd' | 'sl' | 'you';export type Person = { id: PersonId; name: string; initials: string };export const PEOPLE: Record<PersonId, Person> = { mc: { id: 'mc', name: 'Maya Chen', initials: 'MC' }, aw: { id: 'aw', name: 'Arno Weiss', initials: 'AW' }, kd: { id: 'kd', name: 'Kai Doyle', initials: 'KD' }, sl: { id: 'sl', name: 'Sara Lind', initials: 'SL' }, you: { id: 'you', name: 'You', initials: 'YO' },};/** A file's type: its badge colour in the table and the square on its paper in a folder. */export type Kind = 'pdf' | 'doc' | 'sheet' | 'slides' | 'image';export type FileItem = { id: string;// Copyright (c) 2026 Bruno Delorence. MIT License.import type { ReactNode, SVGProps } from 'react';/* * The library's icons, drawn for it on a 16-unit grid with a 1.4 stroke in currentColor. All of * them are decorative: the control around each one carries its name. */export type IconName = | 'mark' | 'home' | 'folder' | 'folderOpen' | 'clock' | 'people' | 'trash' | 'plus' | 'panel' | 'search' | 'chevron' | 'updown' | 'link' | 'upload'// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends * the step in progress at once: its promise rejects, which ends the script right there, and the * pointer fades out. * * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame. * The points of the flight are handed to whoever wants to move along with it (nothing here uses * them yet). The arrow and the hand are HTML boxes * that swap by their visibility: a change of style inside an SVG would lay the SVG out again. */export type Point = { x: number; y: number };/** A glide's path and timing, for an animation that plays along with it. */export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };export type Demo = {// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and never again once the reader has used it: `take()` hands it to the * reader for good (until the component mounts again), so it can't come back on its own. */export function useAutoplay<T extends HTMLElement>() { const ref = useRef<T>(null); const [visible, setVisible] = useState(false); const [reduced, setReduced] = useState(true); const [taken, setTaken] = useState(false); useEffect(() => { const element = ref.current; if (!element) return; let onScreen = false; const update = () => setVisible(onScreen && !document.hidden); const observer = new IntersectionObserver( ([entry]) => {