File card
A file with a thumbnail, name and star.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add file-cardOr install the package
Don’t want the file? Import from
asta-ui/file-cardand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { } from "asta-ui/file-card";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useState, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const KEYFRAMES = `@keyframes asta-file-star { 0% { transform: scale(.6) } 55% { transform: scale(1.25) } 100% { transform: scale(1) } } @media (prefers-reduced-motion: reduce) { .asta-file-star { animation: none !important } }`; export interface FileCardProps { title: string; /** A short line under the title, e.g. "Edited 2 h ago". */ meta?: ReactNode; /** An image URL, or any node (a rendered preview, an illustration). */ thumbnail?: string | ReactNode; /** Small icon in front of the title that says what kind of file it is. */ icon?: ReactNode; /** Makes the card a link. Use `onOpen` instead for client-side routing. */ href?: string; onOpen?: () => void; starred?: boolean; defaultStarred?: boolean; /** Shows the star button. Omit it to hide starring. */ onStarChange?: (starred: boolean) => void; /** A menu or buttons shown on the right of the footer (grid) or the row (list), e.g. a dropdown trigger. */ actions?: ReactNode; /** Grid card or a compact list row. */ view?: "grid" | "list"; selected?: boolean; className?: string; } function Star({ on }: { on: boolean }) { return ( <svg viewBox="0 0 24 24" className={cx("h-4 w-4", on && "asta-file-star animate-[asta-file-star_.42s_cubic-bezier(.16,1,.3,1)]")} fill={on ? "currentColor" : "none"} stroke="currentColor" strokeWidth={1.7} strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m12 3.8 2.5 5.1 5.6.8-4 4 .9 5.6-5-2.7-5 2.7.9-5.6-4-4 5.6-.8Z" /> </svg> ); } function Thumb({ thumbnail, title }: { thumbnail: FileCardProps["thumbnail"]; title: string }) { if (typeof thumbnail === "string") return ( <img src={thumbnail} alt="" width={640} height={400} loading="lazy" decoding="async" className="absolute inset-0 h-full w-full object-cover transition-transform duration-500 ease-[cubic-bezier(.16,1,.3,1)] group-hover/file:scale-[1.03]" /> ); if (thumbnail) return <div className="absolute inset-0 transition-transform duration-500 ease-[cubic-bezier(.16,1,.3,1)] group-hover/file:scale-[1.03]">{thumbnail}</div>; return <span className="absolute inset-0 grid place-items-center text-[28px] font-semibold tracking-[-0.04em] text-mute">{title.slice(0, 1).toUpperCase()}</span>; } /** * A file in a file browser: a big thumbnail with the name, a kind icon and when it was last edited. The preview * zooms a little on hover, the star pops when you star it, and the same data renders as a compact list row. */ export function FileCard({ title, meta, thumbnail, icon, href, onOpen, starred, defaultStarred = false, onStarChange, actions, view = "grid", selected, className }: FileCardProps) { const [innerStar, setInnerStar] = useState(defaultStarred); const on = starred ?? innerStar; const toggle = () => { if (starred === undefined) setInnerStar(!on); onStarChange?.(!on); }; // One link covers the card. Buttons sit above it so they stay clickable and focusable on their own. const open = href ? ( <a href={href} className="absolute inset-0 z-[1] rounded-[inherit] outline-none" aria-label={`Open ${title}`} /> ) : onOpen ? ( <button type="button" onClick={onOpen} className="absolute inset-0 z-[1] cursor-pointer rounded-[inherit] outline-none" aria-label={`Open ${title}`} /> ) : null; const star = onStarChange && ( <button type="button" aria-label={on ? `Unstar ${title}` : `Star ${title}`} aria-pressed={on} onClick={toggle} className={cx( "relative z-[2] grid h-7 w-7 cursor-pointer place-items-center rounded-[7px] outline-none transition-[opacity,color,background-color] duration-150", "focus-visible:opacity-100 focus-visible:shadow-[0_0_0_2px_var(--color-brand)]", on ? "text-brand opacity-100" : "text-ink-2 opacity-0 hover:text-ink group-hover/file:opacity-100", view === "grid" && "bg-paper shadow-[0_1px_3px_rgb(0_0_0/0.12)]", )} > <Star on={on} /> </button> ); const ring = selected ? "shadow-[inset_0_0_0_2px_var(--color-brand)]" : "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)] hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_22%,transparent)] has-[:focus-visible]:shadow-[inset_0_0_0_2px_var(--color-brand)]"; const style = <style href="asta-file-card" precedence="asta">{KEYFRAMES}</style>; if (view === "list") return ( <div className={cx("group/file relative flex h-14 items-center gap-3 rounded-[10px] px-2 transition-[box-shadow,background-color] duration-150 hover:bg-[color-mix(in_srgb,var(--color-ink)_4%,transparent)]", selected && "bg-[color-mix(in_srgb,var(--color-brand)_8%,transparent)]", className)}> {style} {open} <span className="relative h-10 w-16 shrink-0 overflow-hidden rounded-[6px] bg-paper-2 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_8%,transparent)]"> <Thumb thumbnail={thumbnail} title={title} /> </span> {icon && <span className="h-4 w-4 shrink-0 text-mute [&>svg]:h-full [&>svg]:w-full">{icon}</span>} <span className="min-w-0 flex-1 truncate text-[13.5px] font-medium text-ink">{title}</span> {meta && <span className="hidden shrink-0 text-[12.5px] text-mute sm:block">{meta}</span>} <span className="relative z-[2] flex shrink-0 items-center gap-1"> {star} {actions} </span> </div> ); return ( <div className={cx("group/file relative overflow-hidden rounded-[12px] bg-paper transition-shadow duration-150", ring, className)}> {style} {open} <div className="relative aspect-[16/10] overflow-hidden bg-paper-2"> <Thumb thumbnail={thumbnail} title={title} /> {star && <span className="absolute right-2.5 top-2.5 z-[2]">{star}</span>} </div> <div className="flex items-center gap-2.5 px-3.5 py-3"> {icon && <span className="h-4 w-4 shrink-0 text-mute [&>svg]:h-full [&>svg]:w-full">{icon}</span>} <span className="min-w-0 flex-1"> <span className="block truncate text-[13.5px] font-medium text-ink">{title}</span> {meta && <span className="mt-0.5 block truncate text-[12px] text-mute">{meta}</span>} </span> {actions && <span className="relative z-[2] shrink-0">{actions}</span>} </div> </div> ); }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 card component to my project. A file with a thumbnail, name and star. It includes: grid, list, thumbnail, star, actions, link or button, selected. Install it: ```sh pnpm dlx asta-ui@latest add file-card --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/file-card.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 { FileCard } from "@/components/astabyte/file-card"; import { SegmentedControl } from "@/components/astabyte/segmented-control"; ``` Usage example and props: https://ui.astabyte.com/file-card 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. - 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.<!-- asta.js toggles the star (aria-pressed); persisting it needs a server endpoint. --> <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px"> <div class="asta-file-card"><a href="#" class="asta-file-card-open" aria-label="Open Brand guide.pdf"></a><div class="asta-file-card-media"><div class="asta-file-card-thumb" style="background:linear-gradient(135deg,color-mix(in srgb,var(--brand) 30%,var(--paper)),var(--paper-2))"></div><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star name="starred" value="true" aria-label="Star Brand guide.pdf" 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">Brand guide.pdf</span><span class="asta-file-card-meta">PDF · 4.2 MB</span></span></div></div> <div class="asta-file-card asta-file-card-selected"><a href="#" class="asta-file-card-open" aria-label="Open Homepage hero.png"></a><div class="asta-file-card-media"><div class="asta-file-card-thumb" style="background:linear-gradient(135deg,color-mix(in srgb,var(--ink) 18%,var(--paper)),var(--paper-2))"></div><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star name="starred" value="false" aria-label="Star Homepage hero.png" 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">Homepage hero.png</span><span class="asta-file-card-meta">PNG · 1.8 MB</span></span></div></div> <div class="asta-file-card"><div class="asta-file-card-media"><span class="asta-file-card-initial">Q</span><span class="asta-file-card-corner"><button type="button" class="asta-file-card-star" data-asta-file-star name="starred" value="false" aria-label="Star Q4 report.xlsx" 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">Q4 report.xlsx</span><span class="asta-file-card-meta">Sheet · 310 KB</span></span></div></div> </div><div style="margin-top:16px;max-width:640px"> <div class="asta-file-row"><span class="asta-file-row-thumb"><div class="asta-file-card-thumb" style="background:linear-gradient(135deg,color-mix(in srgb,var(--brand) 22%,var(--paper)),var(--paper-2))"></div></span><span class="asta-file-row-title">Pitch deck.key</span><span class="asta-file-row-meta">Keynote · 12 MB · Edited 2h ago</span><span class="asta-file-row-actions"><button type="button" class="asta-file-card-star" data-asta-file-star name="starred" value="false" aria-label="Star Pitch deck.key" 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-row asta-file-row-selected"><span class="asta-file-row-thumb"><span class="asta-file-card-initial">C</span></span><span class="asta-file-row-title">Contract draft.docx</span><span class="asta-file-row-meta">Doc · 88 KB · Edited yesterday</span><span class="asta-file-row-actions"><button type="button" class="asta-file-card-star" data-asta-file-star name="starred" value="true" aria-label="Star Contract draft.docx" 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>
Usage
The demo above, as code.
"use client";
import { useState, type ReactNode } from "react";
import { FileCard } from "@/components/astabyte/file-card";
import { SegmentedControl } from "@/components/astabyte/segmented-control";
const FileIcon = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.7} strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d="M4.5 9h15" />
<path d="M4.5 15h15" />
<path d="M10 4 8.5 20" />
<path d="M15.5 4 14 20" />
</svg>
);
const VideoIcon = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.7} strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<rect x="3" y="6" width="12.5" height="12" rx="2" />
<path d="m15.5 10.5 5.5-3.5v10l-5.5-3.5" />
</svg>
);
/** Little artboards drawn with tokens, standing in for real canvas thumbnails. */
const board = (children: ReactNode) => <div className="absolute inset-0 flex items-center justify-center gap-2 bg-paper-2 p-5">{children}</div>;
const FILES: { id: string; title: string; meta: string; video?: boolean; thumb: ReactNode; star?: boolean }[] = [
{
id: "a",
title: "Summer launch kit",
meta: "Edited 18 min ago",
star: true,
thumb: board(
<>
<span className="h-[70%] w-[30%] rounded-[3px] bg-brand" />
<span className="flex h-[70%] w-[18%] items-end rounded-[3px] bg-ink p-1.5"><span className="h-1 w-3/4 rounded-full bg-paper/70" /></span>
<span className="h-[40%] w-[34%] rounded-[3px] bg-paper shadow-[0_4px_12px_-6px_rgb(0_0_0/0.3)]" />
</>,
),
},
{ id: "b", title: "Product teaser", meta: "Edited 2 h ago", video: true, thumb: board(<span className="relative h-[72%] w-[80%] rounded-[3px] bg-ink"><span className="absolute bottom-2 left-2 right-2 h-1 rounded-full bg-paper/25"><span className="block h-full w-2/5 rounded-full bg-brand" /></span></span>) },
{ id: "c", title: "Story templates", meta: "Edited yesterday", thumb: board([0, 1, 2, 3].map((i) => <span key={i} className={`h-[78%] w-[16%] rounded-[3px] ${i === 1 ? "bg-brand" : "bg-paper shadow-[0_4px_12px_-6px_rgb(0_0_0/0.3)]"}`} />)) },
{ id: "d", title: "Newsletter header", meta: "Edited 3 d ago", thumb: board(<span className="flex h-[46%] w-[86%] items-center gap-2 rounded-[3px] bg-paper px-3 shadow-[0_4px_12px_-6px_rgb(0_0_0/0.3)]"><span className="h-6 w-6 rounded-full bg-brand" /><span className="h-1.5 w-1/2 rounded-full bg-ink/70" /></span>) },
{ id: "e", title: "Event recap reel", meta: "Edited 1 w ago", video: true, thumb: board([0, 1, 2].map((i) => <span key={i} className={`h-[50%] w-[24%] rounded-[3px] ${i === 2 ? "bg-brand" : "bg-ink/80"}`} />)) },
{ id: "f", title: "Pitch cover", meta: "Edited 2 w ago", thumb: board(<span className="flex h-[66%] w-[66%] flex-col justify-end gap-1 rounded-[3px] bg-brand p-2"><span className="h-1.5 w-2/3 rounded-full bg-paper" /><span className="h-1 w-1/3 rounded-full bg-paper/60" /></span>) },
];
export default function FileCardDemo() {
const [view, setView] = useState("grid");
const [stars, setStars] = useState(() => new Set(FILES.filter((f) => f.star).map((f) => f.id)));
const [opened, setOpened] = useState<string | null>(null);
return (
<div className="flex min-h-[520px] w-full justify-center p-6 sm:p-10">
<div className="w-full max-w-4xl">
<div className="flex items-center justify-between gap-4">
<p className="text-[13px] text-mute">{opened ? `Opening “${opened}”` : `${FILES.length} files · ${stars.size} starred`}</p>
<SegmentedControl size="sm" value={view} onChange={setView} segments={[{ value: "grid", label: "Grid" }, { value: "list", label: "List" }]} />
</div>
<div className={view === "grid" ? "mt-5 grid gap-4 sm:grid-cols-2 lg:grid-cols-3" : "mt-4 space-y-0.5"}>
{FILES.map((f) => (
<FileCard
key={f.id}
view={view as "grid" | "list"}
title={f.title}
meta={f.meta}
icon={f.video ? <VideoIcon /> : <FileIcon />}
thumbnail={f.thumb}
starred={stars.has(f.id)}
onStarChange={(on) => setStars((s) => { const n = new Set(s); if (on) n.add(f.id); else n.delete(f.id); return n; })}
onOpen={() => setOpened(f.title)}
/>
))}
</div>
</div>
</div>
);
}