File manager
Folders, files and storage.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add file-manager --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { FileManager } from "asta-ui";import { FileManager } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { useMemo, useState, type ReactNode } from "react"; import { Breadcrumb } from "@/components/kit/breadcrumb"; import { Button } from "@/components/kit/button"; import { FileCard } from "@/components/kit/file-card"; import { Meter } from "@/components/kit/meter"; import { SegmentedControl } from "@/components/kit/segmented-control"; import { TreeView, type TreeViewNode } from "@/components/kit/tree-view"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const KEYFRAMES = `@keyframes asta-fm-in { from { opacity: 0; transform: translateY(6px) } } @keyframes asta-fm-bar { from { opacity: 0; transform: translateY(8px) } } @media (prefers-reduced-motion: reduce) { .asta-fm-a { animation: none !important } }`; export interface FileItem { id: string; name: string; kind: "folder" | "image" | "doc" | "sheet" | "video" | "archive"; /** The folder it sits in. Omit for the root. */ parent?: string; /** Bytes. Folders add up their contents. */ size?: number; /** Already formatted, e.g. "Edited 2 h ago". */ modified?: string; /** Image URL for the preview. */ thumbnail?: string; starred?: boolean; } export interface FileManagerProps { items: FileItem[]; /** Name of the root folder. */ rootLabel?: string; /** Storage limit in bytes. Shows a meter in the sidebar. */ quota?: number; defaultView?: "grid" | "list"; /** Called with the ids that were deleted. */ onDelete?: (ids: string[]) => void; onOpenFile?: (item: FileItem) => void; /** Extra buttons in the toolbar, e.g. Upload. */ actions?: ReactNode; className?: string; } const ROOT = "__root"; export function formatBytes(n: number) { if (n < 1024) return `${n} B`; const u = ["KB", "MB", "GB", "TB"]; let i = -1; do { n /= 1024; i++; } while (n >= 1024 && i < u.length - 1); return `${n >= 100 ? Math.round(n) : n.toFixed(1)} ${u[i]}`; } const PATHS: Record<FileItem["kind"], string> = { folder: "M3.5 7A1.5 1.5 0 0 1 5 5.5h4.5l2 2.5H19a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 19 19H5a1.5 1.5 0 0 1-1.5-1.5Z", image: "M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM7.25 9.5a1.75 1.75 0 1 0 3.5 0a1.75 1.75 0 1 0-3.5 0M4 17l5-5 4 4 2.5-2.5 4.5 4.5", doc: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M9 13h6M9 16.5h4", sheet: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M8.5 12h7v6h-7ZM8.5 15h7M12 12v6", video: "M5 6h8.5a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8.5a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2ZM15.5 10.5l5.5-3.5v10l-5.5-3.5", archive: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M9.5 5.5h2M11.5 8h2M9.5 10.5h2M10.5 13h2a1 1 0 0 1 1 1v2.5a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2.5a1 1 0 0 1 1-1Z", }; export const FileKindIcon = ({ kind, className = "h-4 w-4" }: { kind: FileItem["kind"]; className?: string }) => ( <svg viewBox="0 0 24 24" className={className} fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d={PATHS[kind]} /> </svg> ); /** * A file browser: folders in a tree on the left, the open folder as a grid or a list, a breadcrumb, search and a * storage meter. Folders open on click; files select on click, and the selection bar can star or delete them, * which the storage meter follows. Under 640px of container width the tree folds away and the breadcrumb leads. */ export function FileManager({ items: initial, rootLabel = "My files", quota, defaultView = "grid", onDelete, onOpenFile, actions, className }: FileManagerProps) { const [items, setItems] = useState(initial); const [folder, setFolder] = useState<string>(ROOT); const [view, setView] = useState<"grid" | "list">(defaultView); const [query, setQuery] = useState(""); const [sel, setSel] = useState<string[]>([]); const [expanded, setExpanded] = useState<string[]>([ROOT]); const byId = useMemo(() => new Map(items.map((i) => [i.id, i])), [items]); const sizeOf = useMemo(() => { const memo = new Map<string, number>(); const walk = (id: string): number => { if (memo.has(id)) return memo.get(id)!; const it = byId.get(id); const n = it?.kind === "folder" ? items.filter((c) => c.parent === id).reduce((a, c) => a + walk(c.id), 0) : (it?.size ?? 0); memo.set(id, n); return n; }; return walk; }, [byId, items]); const used = items.filter((i) => i.kind !== "folder").reduce((a, i) => a + (i.size ?? 0), 0); const parentOf = (i: FileItem) => i.parent ?? ROOT; const q = query.trim().toLowerCase(); const shown = (q ? items.filter((i) => i.name.toLowerCase().includes(q)) : items.filter((i) => parentOf(i) === folder)).sort( (a, b) => Number(b.kind === "folder") - Number(a.kind === "folder") || a.name.localeCompare(b.name), ); const trail: { id: string; label: string }[] = []; for (let f = byId.get(folder); f; f = f.parent ? byId.get(f.parent) : undefined) trail.unshift({ id: f.id, label: f.name }); trail.unshift({ id: ROOT, label: rootLabel }); const tree = useMemo(() => { const build = (pid: string): TreeViewNode[] => items .filter((i) => i.kind === "folder" && (i.parent ?? ROOT) === pid) .sort((a, b) => a.name.localeCompare(b.name)) .map((f) => { const children = build(f.id); return { id: f.id, label: f.name, icon: <FileKindIcon kind="folder" />, children: children.length ? children : undefined }; }); return [{ id: ROOT, label: rootLabel, icon: <FileKindIcon kind="folder" />, children: build(ROOT) }]; }, [items, rootLabel]); const go = (id: string) => { setFolder(id); setSel([]); setQuery(""); // Open every folder on the way, so the tree shows where you are. const open = new Set(expanded); for (let f = byId.get(id); f; f = f.parent ? byId.get(f.parent) : undefined) open.add(f.parent ?? ROOT); setExpanded([...open]); }; const toggle = (id: string) => setSel((s) => (s.includes(id) ? s.filter((x) => x !== id) : [...s, id])); const remove = () => { const gone = new Set(sel); // Deleting a folder takes everything inside it. let grew = true; while (grew) { grew = false; for (const i of items) if (i.parent && gone.has(i.parent) && !gone.has(i.id)) { gone.add(i.id); grew = true; } } setItems((l) => l.filter((i) => !gone.has(i.id))); onDelete?.([...gone]); setSel([]); }; const allStarred = sel.length > 0 && sel.every((id) => byId.get(id)?.starred); const star = () => setItems((l) => l.map((i) => (sel.includes(i.id) ? { ...i, starred: !allStarred } : i))); const meta = (i: FileItem) => (i.kind === "folder" ? `${items.filter((c) => c.parent === i.id).length} items · ${formatBytes(sizeOf(i.id))}` : [i.modified, i.size ? formatBytes(i.size) : null].filter(Boolean).join(" · ")); return ( <div className={cx("@container w-full overflow-hidden rounded-[14px] bg-paper text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]", className)}> <style href="asta-file-manager" precedence="asta">{KEYFRAMES}</style> <div className="flex min-h-[520px] @min-[640px]:grid @min-[640px]:grid-cols-[220px_1fr]"> {/* Sidebar */} <aside className="hidden flex-col gap-4 bg-paper-2/60 p-3 @min-[640px]:flex"> <TreeView nodes={tree} label="Folders" selected={folder} onSelect={(id) => go(id)} expanded={expanded} onExpandedChange={setExpanded} /> {quota && ( <div className="mt-auto rounded-[10px] bg-paper p-3 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_8%,transparent)]"> <Meter label="Storage" value={used} max={quota} format={formatBytes} size="sm" /> </div> )} </aside> {/* Main */} <section aria-label={trail[trail.length - 1].label} className="relative flex min-w-0 flex-1 flex-col"> <div className="flex flex-col gap-3 p-3 pb-2 @min-[640px]:p-4 @min-[640px]:pb-2"> <div className="flex flex-wrap items-center gap-2"> <div className="min-w-0 flex-1"> {q ? ( <p className="text-[13.5px] text-mute"> {shown.length} result{shown.length === 1 ? "" : "s"} for “<span className="text-ink">{query}</span>” </p> ) : ( <Breadcrumb items={trail.map((t, i) => (i === trail.length - 1 ? { label: t.label } : { label: t.label, onClick: () => go(t.id) }))} /> )} </div> {actions} </div> <div className="flex items-center gap-2"> <label className="flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-paper-2 px-2.5 text-mute focus-within:shadow-[inset_0_0_0_1px_var(--color-brand)]"> <svg viewBox="0 0 24 24" className="h-3.5 w-3.5 shrink-0" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <circle cx="10.5" cy="10.5" r="6" /> <path d="m15 15 5 5" /> </svg> <input type="search" name="q" autoComplete="off" value={query} onChange={(e) => { setQuery(e.target.value); setSel([]); }} placeholder="Search all files…" aria-label="Search all files" className="h-full min-w-0 flex-1 bg-transparent text-[16px] sm:text-[13px] text-ink outline-none placeholder:text-mute [&::-webkit-search-cancel-button]:hidden" /> </label> <SegmentedControl size="sm" label="View" value={view} onChange={(v) => setView(v as "grid" | "list")} segments={[ { value: "grid", label: <span className="sr-only">Grid</span>, icon: ( <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <rect x="4" y="4" width="6.5" height="6.5" rx="1.5" /> <rect x="13.5" y="4" width="6.5" height="6.5" rx="1.5" /> <rect x="4" y="13.5" width="6.5" height="6.5" rx="1.5" /> <rect x="13.5" y="13.5" width="6.5" height="6.5" rx="1.5" /> </svg> ), }, { value: "list", label: <span className="sr-only">List</span>, icon: ( <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="M9 6.5h11" /> <path d="M9 12h11" /> <path d="M9 17.5h11" /> <path d="M4.5 6.5h.01" /> <path d="M4.5 12h.01" /> <path d="M4.5 17.5h.01" /> </svg> ), }, ]} /> </div> </div> <div key={folder + view + (q ? "q" : "")} className="asta-fm-a min-h-0 flex-1 animate-[asta-fm-in_.35s_cubic-bezier(.16,1,.3,1)_both] overflow-y-auto px-3 pb-16 pt-1 @min-[640px]:px-4"> {shown.length === 0 ? ( <div className="flex h-full min-h-[240px] flex-col items-center justify-center gap-1 text-center"> <p className="text-[14px] font-medium">{q ? "No files match" : "This folder is empty"}</p> <p className="text-[12.5px] text-mute">{q ? "Try another name." : "Drop files here or use Upload."}</p> </div> ) : ( <ul className={cx(view === "grid" ? "grid grid-cols-2 gap-3 @min-[520px]:grid-cols-3 @min-[860px]:grid-cols-4" : "flex flex-col gap-0.5")}> {shown.map((i) => ( <li key={i.id}> <FileCard view={view} title={i.name} meta={meta(i)} icon={<FileKindIcon kind={i.kind} />} thumbnail={i.kind === "folder" ? <FolderThumb count={items.filter((c) => c.parent === i.id).length} /> : (i.thumbnail ?? <KindThumb kind={i.kind} />)} selected={sel.includes(i.id)} starred={!!i.starred} onStarChange={(on) => setItems((l) => l.map((x) => (x.id === i.id ? { ...x, starred: on } : x)))} onOpen={() => { if (i.kind === "folder") return go(i.id); toggle(i.id); onOpenFile?.(i); }} /> </li> ))} </ul> )} </div> {sel.length > 0 && ( <div role="toolbar" aria-label="Selection" className="asta-fm-a absolute inset-x-3 bottom-3 flex animate-[asta-fm-bar_.35s_cubic-bezier(.16,1,.3,1)_both] items-center gap-2 rounded-[10px] bg-ink py-1.5 pl-3.5 pr-1.5 text-[12.5px] text-paper shadow-[0_12px_28px_-12px_rgb(0_0_0/0.5)] @min-[640px]:inset-x-4"> <span className="mr-auto truncate tabular-nums"> {sel.length} selected · {formatBytes(sel.reduce((a, id) => a + sizeOf(id), 0))} </span> <button type="button" onClick={star} className="h-7 rounded-md px-2.5 font-medium outline-none transition-colors hover:bg-paper/15 focus-visible:ring-2 focus-visible:ring-paper/60"> {allStarred ? "Unstar" : "Star"} </button> <Button size="xs" variant="soft" onClick={remove} className="!bg-paper !text-ink"> Delete </Button> <button type="button" aria-label="Clear selection" onClick={() => setSel([])} className="grid h-7 w-7 place-items-center rounded-md outline-none transition-colors hover:bg-paper/15 focus-visible:ring-2 focus-visible:ring-paper/60"> <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m6 6 12 12" /> <path d="M18 6 6 18" /> </svg> </button> </div> )} {quota && ( <div className="px-3 pb-3 @min-[640px]:hidden"> <Meter label="Storage" value={used} max={quota} format={formatBytes} size="sm" /> </div> )} </section> </div> </div> ); } function FolderThumb({ count }: { count: number }) { return ( <span className="absolute inset-0 grid place-items-center bg-[color-mix(in_srgb,var(--color-brand)_7%,var(--color-paper-2))] text-brand"> <FileKindIcon kind="folder" className="h-9 w-9" /> <span className="absolute bottom-2 right-2.5 font-mono text-[10.5px] text-mute">{count}</span> </span> ); } function KindThumb({ kind }: { kind: FileItem["kind"] }) { return ( <span className="absolute inset-0 grid place-items-center text-mute"> <FileKindIcon kind={kind} className="h-8 w-8" /> </span> ); } export default FileManager;"use client"; import { useMemo, useState, type ReactNode } from "react"; import { Breadcrumb } from "@/components/kit/breadcrumb"; import { Button } from "@/components/kit/base/button"; import { FileCard } from "@/components/kit/file-card"; import { Meter } from "@/components/kit/meter"; import { SegmentedControl } from "@/components/kit/base/segmented-control"; import { TreeView, type TreeViewNode } from "@/components/kit/tree-view"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const KEYFRAMES = `@keyframes asta-fm-in { from { opacity: 0; transform: translateY(6px) } } @keyframes asta-fm-bar { from { opacity: 0; transform: translateY(8px) } } @media (prefers-reduced-motion: reduce) { .asta-fm-a { animation: none !important } }`; export interface FileItem { id: string; name: string; kind: "folder" | "image" | "doc" | "sheet" | "video" | "archive"; /** The folder it sits in. Omit for the root. */ parent?: string; /** Bytes. Folders add up their contents. */ size?: number; /** Already formatted, e.g. "Edited 2 h ago". */ modified?: string; /** Image URL for the preview. */ thumbnail?: string; starred?: boolean; } export interface FileManagerProps { items: FileItem[]; /** Name of the root folder. */ rootLabel?: string; /** Storage limit in bytes. Shows a meter in the sidebar. */ quota?: number; defaultView?: "grid" | "list"; /** Called with the ids that were deleted. */ onDelete?: (ids: string[]) => void; onOpenFile?: (item: FileItem) => void; /** Extra buttons in the toolbar, e.g. Upload. */ actions?: ReactNode; className?: string; } const ROOT = "__root"; export function formatBytes(n: number) { if (n < 1024) return `${n} B`; const u = ["KB", "MB", "GB", "TB"]; let i = -1; do { n /= 1024; i++; } while (n >= 1024 && i < u.length - 1); return `${n >= 100 ? Math.round(n) : n.toFixed(1)} ${u[i]}`; } const PATHS: Record<FileItem["kind"], string> = { folder: "M3.5 7A1.5 1.5 0 0 1 5 5.5h4.5l2 2.5H19a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 19 19H5a1.5 1.5 0 0 1-1.5-1.5Z", image: "M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM7.25 9.5a1.75 1.75 0 1 0 3.5 0a1.75 1.75 0 1 0-3.5 0M4 17l5-5 4 4 2.5-2.5 4.5 4.5", doc: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M9 13h6M9 16.5h4", sheet: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M8.5 12h7v6h-7ZM8.5 15h7M12 12v6", video: "M5 6h8.5a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8.5a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2ZM15.5 10.5l5.5-3.5v10l-5.5-3.5", archive: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M9.5 5.5h2M11.5 8h2M9.5 10.5h2M10.5 13h2a1 1 0 0 1 1 1v2.5a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2.5a1 1 0 0 1 1-1Z", }; export const FileKindIcon = ({ kind, className = "h-4 w-4" }: { kind: FileItem["kind"]; className?: string }) => ( <svg viewBox="0 0 24 24" className={className} fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d={PATHS[kind]} /> </svg> ); /** * A file browser: folders in a tree on the left, the open folder as a grid or a list, a breadcrumb, search and a * storage meter. Folders open on click; files select on click, and the selection bar can star or delete them, * which the storage meter follows. Under 640px of container width the tree folds away and the breadcrumb leads. */ export function FileManager({ items: initial, rootLabel = "My files", quota, defaultView = "grid", onDelete, onOpenFile, actions, className }: FileManagerProps) { const [items, setItems] = useState(initial); const [folder, setFolder] = useState<string>(ROOT); const [view, setView] = useState<"grid" | "list">(defaultView); const [query, setQuery] = useState(""); const [sel, setSel] = useState<string[]>([]); const [expanded, setExpanded] = useState<string[]>([ROOT]); const byId = useMemo(() => new Map(items.map((i) => [i.id, i])), [items]); const sizeOf = useMemo(() => { const memo = new Map<string, number>(); const walk = (id: string): number => { if (memo.has(id)) return memo.get(id)!; const it = byId.get(id); const n = it?.kind === "folder" ? items.filter((c) => c.parent === id).reduce((a, c) => a + walk(c.id), 0) : (it?.size ?? 0); memo.set(id, n); return n; }; return walk; }, [byId, items]); const used = items.filter((i) => i.kind !== "folder").reduce((a, i) => a + (i.size ?? 0), 0); const parentOf = (i: FileItem) => i.parent ?? ROOT; const q = query.trim().toLowerCase(); const shown = (q ? items.filter((i) => i.name.toLowerCase().includes(q)) : items.filter((i) => parentOf(i) === folder)).sort( (a, b) => Number(b.kind === "folder") - Number(a.kind === "folder") || a.name.localeCompare(b.name), ); const trail: { id: string; label: string }[] = []; for (let f = byId.get(folder); f; f = f.parent ? byId.get(f.parent) : undefined) trail.unshift({ id: f.id, label: f.name }); trail.unshift({ id: ROOT, label: rootLabel }); const tree = useMemo(() => { const build = (pid: string): TreeViewNode[] => items .filter((i) => i.kind === "folder" && (i.parent ?? ROOT) === pid) .sort((a, b) => a.name.localeCompare(b.name)) .map((f) => { const children = build(f.id); return { id: f.id, label: f.name, icon: <FileKindIcon kind="folder" />, children: children.length ? children : undefined }; }); return [{ id: ROOT, label: rootLabel, icon: <FileKindIcon kind="folder" />, children: build(ROOT) }]; }, [items, rootLabel]); const go = (id: string) => { setFolder(id); setSel([]); setQuery(""); // Open every folder on the way, so the tree shows where you are. const open = new Set(expanded); for (let f = byId.get(id); f; f = f.parent ? byId.get(f.parent) : undefined) open.add(f.parent ?? ROOT); setExpanded([...open]); }; const toggle = (id: string) => setSel((s) => (s.includes(id) ? s.filter((x) => x !== id) : [...s, id])); const remove = () => { const gone = new Set(sel); // Deleting a folder takes everything inside it. let grew = true; while (grew) { grew = false; for (const i of items) if (i.parent && gone.has(i.parent) && !gone.has(i.id)) { gone.add(i.id); grew = true; } } setItems((l) => l.filter((i) => !gone.has(i.id))); onDelete?.([...gone]); setSel([]); }; const allStarred = sel.length > 0 && sel.every((id) => byId.get(id)?.starred); const star = () => setItems((l) => l.map((i) => (sel.includes(i.id) ? { ...i, starred: !allStarred } : i))); const meta = (i: FileItem) => (i.kind === "folder" ? `${items.filter((c) => c.parent === i.id).length} items · ${formatBytes(sizeOf(i.id))}` : [i.modified, i.size ? formatBytes(i.size) : null].filter(Boolean).join(" · ")); return ( <div className={cx("@container w-full overflow-hidden rounded-[14px] bg-paper text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]", className)}> <style href="asta-file-manager" precedence="asta">{KEYFRAMES}</style> <div className="flex min-h-[520px] @min-[640px]:grid @min-[640px]:grid-cols-[220px_1fr]"> {/* Sidebar */} <aside className="hidden flex-col gap-4 bg-paper-2/60 p-3 @min-[640px]:flex"> <TreeView nodes={tree} label="Folders" selected={folder} onSelect={(id) => go(id)} expanded={expanded} onExpandedChange={setExpanded} /> {quota && ( <div className="mt-auto rounded-[10px] bg-paper p-3 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_8%,transparent)]"> <Meter label="Storage" value={used} max={quota} format={formatBytes} size="sm" /> </div> )} </aside> {/* Main */} <section aria-label={trail[trail.length - 1].label} className="relative flex min-w-0 flex-1 flex-col"> <div className="flex flex-col gap-3 p-3 pb-2 @min-[640px]:p-4 @min-[640px]:pb-2"> <div className="flex flex-wrap items-center gap-2"> <div className="min-w-0 flex-1"> {q ? ( <p className="text-[13.5px] text-mute"> {shown.length} result{shown.length === 1 ? "" : "s"} for “<span className="text-ink">{query}</span>” </p> ) : ( <Breadcrumb items={trail.map((t, i) => (i === trail.length - 1 ? { label: t.label } : { label: t.label, onClick: () => go(t.id) }))} /> )} </div> {actions} </div> <div className="flex items-center gap-2"> <label className="flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-paper-2 px-2.5 text-mute focus-within:shadow-[inset_0_0_0_1px_var(--color-brand)]"> <svg viewBox="0 0 24 24" className="h-3.5 w-3.5 shrink-0" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <circle cx="10.5" cy="10.5" r="6" /> <path d="m15 15 5 5" /> </svg> <input type="search" name="q" autoComplete="off" value={query} onChange={(e) => { setQuery(e.target.value); setSel([]); }} placeholder="Search all files…" aria-label="Search all files" className="h-full min-w-0 flex-1 bg-transparent text-[16px] sm:text-[13px] text-ink outline-none placeholder:text-mute [&::-webkit-search-cancel-button]:hidden" /> </label> <SegmentedControl size="sm" label="View" value={view} onChange={(v) => setView(v as "grid" | "list")} segments={[ { value: "grid", label: <span className="sr-only">Grid</span>, icon: ( <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <rect x="4" y="4" width="6.5" height="6.5" rx="1.5" /> <rect x="13.5" y="4" width="6.5" height="6.5" rx="1.5" /> <rect x="4" y="13.5" width="6.5" height="6.5" rx="1.5" /> <rect x="13.5" y="13.5" width="6.5" height="6.5" rx="1.5" /> </svg> ), }, { value: "list", label: <span className="sr-only">List</span>, icon: ( <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="M9 6.5h11" /> <path d="M9 12h11" /> <path d="M9 17.5h11" /> <path d="M4.5 6.5h.01" /> <path d="M4.5 12h.01" /> <path d="M4.5 17.5h.01" /> </svg> ), }, ]} /> </div> </div> <div key={folder + view + (q ? "q" : "")} className="asta-fm-a min-h-0 flex-1 animate-[asta-fm-in_.35s_cubic-bezier(.16,1,.3,1)_both] overflow-y-auto px-3 pb-16 pt-1 @min-[640px]:px-4"> {shown.length === 0 ? ( <div className="flex h-full min-h-[240px] flex-col items-center justify-center gap-1 text-center"> <p className="text-[14px] font-medium">{q ? "No files match" : "This folder is empty"}</p> <p className="text-[12.5px] text-mute">{q ? "Try another name." : "Drop files here or use Upload."}</p> </div> ) : ( <ul className={cx(view === "grid" ? "grid grid-cols-2 gap-3 @min-[520px]:grid-cols-3 @min-[860px]:grid-cols-4" : "flex flex-col gap-0.5")}> {shown.map((i) => ( <li key={i.id}> <FileCard view={view} title={i.name} meta={meta(i)} icon={<FileKindIcon kind={i.kind} />} thumbnail={i.kind === "folder" ? <FolderThumb count={items.filter((c) => c.parent === i.id).length} /> : (i.thumbnail ?? <KindThumb kind={i.kind} />)} selected={sel.includes(i.id)} starred={!!i.starred} onStarChange={(on) => setItems((l) => l.map((x) => (x.id === i.id ? { ...x, starred: on } : x)))} onOpen={() => { if (i.kind === "folder") return go(i.id); toggle(i.id); onOpenFile?.(i); }} /> </li> ))} </ul> )} </div> {sel.length > 0 && ( <div role="toolbar" aria-label="Selection" className="asta-fm-a absolute inset-x-3 bottom-3 flex animate-[asta-fm-bar_.35s_cubic-bezier(.16,1,.3,1)_both] items-center gap-2 rounded-[10px] bg-ink py-1.5 pl-3.5 pr-1.5 text-[12.5px] text-paper shadow-[0_12px_28px_-12px_rgb(0_0_0/0.5)] @min-[640px]:inset-x-4"> <span className="mr-auto truncate tabular-nums"> {sel.length} selected · {formatBytes(sel.reduce((a, id) => a + sizeOf(id), 0))} </span> <button type="button" onClick={star} className="h-7 rounded-md px-2.5 font-medium outline-none transition-colors hover:bg-paper/15 focus-visible:ring-2 focus-visible:ring-paper/60"> {allStarred ? "Unstar" : "Star"} </button> <Button size="xs" variant="soft" onClick={remove} className="!bg-paper !text-ink"> Delete </Button> <button type="button" aria-label="Clear selection" onClick={() => setSel([])} className="grid h-7 w-7 place-items-center rounded-md outline-none transition-colors hover:bg-paper/15 focus-visible:ring-2 focus-visible:ring-paper/60"> <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m6 6 12 12" /> <path d="M18 6 6 18" /> </svg> </button> </div> )} {quota && ( <div className="px-3 pb-3 @min-[640px]:hidden"> <Meter label="Storage" value={used} max={quota} format={formatBytes} size="sm" /> </div> )} </section> </div> </div> ); } function FolderThumb({ count }: { count: number }) { return ( <span className="absolute inset-0 grid place-items-center bg-[color-mix(in_srgb,var(--color-brand)_7%,var(--color-paper-2))] text-brand"> <FileKindIcon kind="folder" className="h-9 w-9" /> <span className="absolute bottom-2 right-2.5 font-mono text-[10.5px] text-mute">{count}</span> </span> ); } function KindThumb({ kind }: { kind: FileItem["kind"] }) { return ( <span className="absolute inset-0 grid place-items-center text-mute"> <FileKindIcon kind={kind} className="h-8 w-8" /> </span> ); } export default FileManager;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI File manager component to my project. Folders, files and storage. It includes: tree, breadcrumbs, grid/list, search, selection, storage meter. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add file-manager --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/file-manager.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Button } from "@/components/astabyte/button"; import { FileManager, type FileItem } from "@/components/astabyte/file-manager"; ``` Usage example and props: https://ui.astabyte.com/file-manager Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI File manager component to my project. Folders, files and storage. It includes: tree, breadcrumbs, grid/list, search, selection, storage meter. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add file-manager ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/file-manager.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Button } from "@/components/astabyte/button"; import { FileManager, type FileItem } from "@/components/astabyte/file-manager"; ``` Usage example and props: https://ui.astabyte.com/file-manager Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<!-- Built from asta-tree-view, asta-breadcrumb, asta-file-card, asta-segmented and asta-meter. Swap the folder with htmx. --> <div class="asta-files" style="max-width:980px"> <div class="asta-files-inner"> <aside class="asta-files-side"><ul role="tree" class="asta-tree-view" data-asta-tree aria-label="Folders"><li role="treeitem" class="asta-tree-item" data-id="root" tabindex="-1" aria-level="1" aria-setsize="1" aria-posinset="1" aria-expanded="true" aria-selected="false" style="--i:0"><div class="asta-tree-row" data-asta-tree-row data-open><span class="asta-tree-chevron" data-asta-tree-chevron aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-tree-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M2 4.5a1 1 0 0 1 1-1h3L7.5 5H13a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7.5Z"/></svg></span><span class="asta-tree-label">Astabyte Drive</span></div><ul role="group" class="asta-tree-group"><li role="treeitem" class="asta-tree-item" data-id="brand" tabindex="-1" aria-level="2" aria-setsize="3" aria-posinset="1" aria-expanded="false" aria-selected="false" style="--i:1"><div class="asta-tree-row" data-asta-tree-row><span class="asta-tree-chevron" data-asta-tree-chevron aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m6 4 4 4-4 4"/></svg></span><span class="asta-tree-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M2 4.5a1 1 0 0 1 1-1h3L7.5 5H13a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7.5Z"/></svg></span><span class="asta-tree-label">Brand</span></div></li><li role="treeitem" class="asta-tree-item" data-id="campaign" tabindex="0" aria-level="2" aria-setsize="3" aria-posinset="2" aria-selected="true" style="--i:1"><div class="asta-tree-row" data-asta-tree-row><span class="asta-tree-chevron" aria-hidden="true"></span><span class="asta-tree-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M2 4.5a1 1 0 0 1 1-1h3L7.5 5H13a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7.5Z"/></svg></span><span class="asta-tree-label">Spring campaign</span></div></li><li role="treeitem" class="asta-tree-item" data-id="finance" tabindex="-1" aria-level="2" aria-setsize="3" aria-posinset="3" aria-selected="false" style="--i:1"><div class="asta-tree-row" data-asta-tree-row><span class="asta-tree-chevron" aria-hidden="true"></span><span class="asta-tree-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M2 4.5a1 1 0 0 1 1-1h3L7.5 5H13a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7.5Z"/></svg></span><span class="asta-tree-label">Finance</span></div></li></ul></li></ul> <div class="asta-files-storage"><div class="asta-meter asta-meter-sm" role="meter" aria-label="Storage" aria-valuenow="277" aria-valuemin="0" aria-valuemax="512"><div class="asta-meter-head"><span class="asta-meter-label">Storage</span></div><div class="asta-meter-track"><span class="asta-meter-fill" style="--value:.54"></span></div><div class="asta-meter-foot"><span><b>277 MB</b> of 512 MB</span></div></div></div> </aside> <section class="asta-files-main" aria-label="Spring campaign"> <div class="asta-files-toolbar"><nav class="asta-breadcrumb" aria-label="Breadcrumb"><ol class="asta-breadcrumb-list"><li class="asta-breadcrumb-item"><a class="asta-breadcrumb-link" href="#"><span class="asta-breadcrumb-label">Astabyte Drive</span></a><span class="asta-breadcrumb-sep" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 3.5 4.5 4.5L6 12.5"/></svg></span></li><li class="asta-breadcrumb-item"><span class="asta-breadcrumb-page" aria-current="page"><span class="asta-breadcrumb-label">Spring campaign</span></span></li></ol></nav><button type="button" class="asta-btn asta-btn-accent asta-btn-sm"><span class="asta-btn-label">Upload</span></button></div> <div class="asta-files-toolbar"><input class="asta-files-search" type="search" name="q" autocomplete="off" placeholder="Search all files…" aria-label="Search all files"><div role="radiogroup" data-asta-segmented aria-label="View" class="asta-segmented asta-segmented-sm"><label class="asta-segmented-item"><input type="radio" name="fm-view" value="grid" checked> <span aria-hidden="true" data-asta-ind class="asta-segmented-pill"></span> <span class="asta-segmented-label">Grid</span></label><label class="asta-segmented-item"><input type="radio" name="fm-view" value="list"> <span aria-hidden="true" data-asta-ind class="asta-segmented-pill"></span> <span class="asta-segmented-label">List</span></label></div></div> <ul class="asta-files-grid"> <li><div class="asta-file-card"><a href="#" class="asta-file-card-open" aria-label="Open Poppies hero.webp"></a><div class="asta-file-card-media"><img class="asta-file-card-img" src="/lab/art/poppies.webp" alt="" width="640" height="400" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover"><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star aria-label="Star Poppies hero.webp" aria-pressed="true"><svg class="asta-file-star" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round" aria-hidden="true"><path d="m12 3.6 2.6 5.3 5.8.8-4.2 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.2-4.1 5.8-.8z"/></svg></button></span></div><div class="asta-file-card-body"><span class="asta-file-card-text"><span class="asta-file-card-title">Poppies hero.webp</span><span class="asta-file-card-meta">Edited 2 h ago · 4.2 MB</span></span></div></div></li> <li><div class="asta-file-card asta-file-card-selected"><a href="#" class="asta-file-card-open" aria-label="Open Parasol banner.webp"></a><div class="asta-file-card-media"><img class="asta-file-card-img" src="/lab/art/parasol.webp" alt="" width="640" height="400" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover"><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star aria-label="Star Parasol banner.webp" aria-pressed="false"><svg class="asta-file-star" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round" aria-hidden="true"><path d="m12 3.6 2.6 5.3 5.8.8-4.2 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.2-4.1 5.8-.8z"/></svg></button></span></div><div class="asta-file-card-body"><span class="asta-file-card-text"><span class="asta-file-card-title">Parasol banner.webp</span><span class="asta-file-card-meta">Yesterday · 3.1 MB</span></span></div></div></li> <li><div class="asta-file-card"><a href="#" class="asta-file-card-open" aria-label="Open Wheat field.webp"></a><div class="asta-file-card-media"><img class="asta-file-card-img" src="/lab/art/wheat.webp" alt="" width="640" height="400" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover"><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star aria-label="Star Wheat field.webp" aria-pressed="false"><svg class="asta-file-star" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round" aria-hidden="true"><path d="m12 3.6 2.6 5.3 5.8.8-4.2 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.2-4.1 5.8-.8z"/></svg></button></span></div><div class="asta-file-card-body"><span class="asta-file-card-text"><span class="asta-file-card-title">Wheat field.webp</span><span class="asta-file-card-meta">Nov 18 · 5.6 MB</span></span></div></div></li> <li><div class="asta-file-card"><a href="#" class="asta-file-card-open" aria-label="Open Launch brief.docx"></a><div class="asta-file-card-media"><span class="asta-file-card-initial">L</span><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star aria-label="Star Launch brief.docx" aria-pressed="false"><svg class="asta-file-star" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round" aria-hidden="true"><path d="m12 3.6 2.6 5.3 5.8.8-4.2 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.2-4.1 5.8-.8z"/></svg></button></span></div><div class="asta-file-card-body"><span class="asta-file-card-text"><span class="asta-file-card-title">Launch brief.docx</span><span class="asta-file-card-meta">Nov 12 · 410 KB</span></span></div></div></li> </ul> <div class="asta-files-bar" role="toolbar" aria-label="Selection"><span>1 selected · 3.1 MB</span><button type="button" class="asta-btn asta-btn-ghost asta-btn-sm" style="color:inherit"><span class="asta-btn-label">Star</span></button><button type="button" class="asta-btn asta-btn-sm" style="background:var(--paper);color:var(--ink)"><span class="asta-btn-label">Delete</span></button></div> </section> </div> </div>
Usage
The demo above, as code.
"use client";
import { Button } from "@/components/astabyte/button";
import { FileManager, type FileItem } from "@/components/astabyte/file-manager";
const MB = 1024 * 1024;
const ITEMS: FileItem[] = [
{ id: "brand", name: "Brand", kind: "folder" },
{ id: "campaign", name: "Spring campaign", kind: "folder" },
{ id: "finance", name: "Finance", kind: "folder" },
{ id: "logos", name: "Logos", kind: "folder", parent: "brand" },
{ id: "f1", name: "Poppies hero.webp", kind: "image", parent: "campaign", size: 4.2 * MB, modified: "Edited 2 h ago", thumbnail: "/lab/art/poppies.webp", starred: true },
{ id: "f2", name: "Parasol banner.webp", kind: "image", parent: "campaign", size: 3.1 * MB, modified: "Edited yesterday", thumbnail: "/lab/art/parasol.webp" },
{ id: "f3", name: "Wheat field.webp", kind: "image", parent: "campaign", size: 5.6 * MB, modified: "Nov 18", thumbnail: "/lab/art/wheat.webp" },
{ id: "f4", name: "Riverbank.webp", kind: "image", parent: "campaign", size: 6.8 * MB, modified: "Nov 16", thumbnail: "/lab/art/bathers.webp" },
{ id: "f5", name: "Launch brief.docx", kind: "doc", parent: "campaign", size: 0.4 * MB, modified: "Nov 12" },
{ id: "f6", name: "Teaser cut.mp4", kind: "video", parent: "campaign", size: 182 * MB, modified: "Nov 10" },
{ id: "f7", name: "Island picnic.webp", kind: "image", parent: "brand", size: 7.3 * MB, modified: "Oct 30", thumbnail: "/lab/art/grande-jatte.webp" },
{ id: "f8", name: "Brand guide.pdf", kind: "doc", parent: "brand", size: 12.5 * MB, modified: "Oct 22", starred: true },
{ id: "f9", name: "Wordmark.svg", kind: "image", parent: "logos", size: 0.02 * MB, modified: "Oct 2" },
{ id: "f10", name: "Logo pack.zip", kind: "archive", parent: "logos", size: 48 * MB, modified: "Oct 2" },
{ id: "f11", name: "Q4 budget.xlsx", kind: "sheet", parent: "finance", size: 0.9 * MB, modified: "Nov 19" },
{ id: "f12", name: "Invoices 2026.xlsx", kind: "sheet", parent: "finance", size: 1.6 * MB, modified: "Nov 15" },
{ id: "f13", name: "Frost morning.webp", kind: "image", size: 3.9 * MB, modified: "Nov 20", thumbnail: "/lab/art/hoarfrost.webp" },
{ id: "f14", name: "Studio notes.docx", kind: "doc", size: 0.2 * MB, modified: "Nov 21" },
];
export default function FileManagerDemo() {
return (
<div className="flex min-h-[640px] w-full items-center justify-center p-3 sm:p-6">
<FileManager
className="max-w-[980px]"
items={ITEMS}
rootLabel="Astabyte Drive"
quota={512 * MB}
actions={
<Button size="sm" variant="accent">
Upload
</Button>
}
/>
</div>
);
}