<!-- generated by scripts/gen-docs.mjs from docs/system/file-tile.md. Edit the source and rerun. -->
# FileTile

## Description

Shows one file as one tile, with its kind, its name and one line about it, so a person can tell which file it is, download it once it is there, and see how its upload is going.

`import { FileTile, fileTileLabels } from "@/components/cobalt/ui/file-tile"`, source `registry/cobalt/ui/file-tile.tsx`, status `ready`.
Foundation: `hand-rolled`, over the system `FileTypeIcon`, `Tooltip` and `Button`. Traps checked: `trap/link-as-button`, `trap/link-wraps-button`, `trap/button-icon-name`, `trap/focus-ring-shape`, `trap/touch-hover-flash`, `trap/loading-layout-shift`, `trap/loading-label-swap`, `trap/live-region-double`, `trap/color-only-status`, `trap/numbers-shift`, `trap/tooltip-essential`, `trap/disabled-drops-focus`, `trap/illustration-announced`, `trap/surface-matches-parent`, `trap/reduced-motion-ignored`, `trap/toast-errors`, `trap/demo-on-timers` (n/a: the uploading and failed examples stand in for a server's progress events, and no example steps through its own animation on a timer).

Where each trap is answered. `trap/link-as-button` in States: a done tile with `href` is a plain link that downloads, with no button look. `trap/link-wraps-button` in Foundation: the link's `::after` covers the tile and the end button sits beside it, above it, never inside it. `trap/button-icon-name` in ARIA: Retry, Remove and Dismiss are named after the file. `trap/focus-ring-shape` in States: the link draws one ring, around the whole tile on the tile's own corner, the 12px one or a bubble's, from the tile through `has-[[data-tile-link]:focus-visible]`. `trap/touch-hover-flash` in Tokens: the hover fill sits behind the guarded `hover` variant. `trap/loading-layout-shift` in States: one 56px box in every state, with the name at the same x. `trap/loading-label-swap` n/a: the tile has no action label; the upload's words are on the line under the name, which is one line in every state. `trap/live-region-double` in ARIA: one status line per tile, which the tile drops when a host passes `detail` and speaks for itself. `trap/color-only-status` in States: every state has words on the line, and a failure has the retry arrow. `trap/numbers-shift` in Tokens: the line uses tabular figures. `trap/tooltip-essential` in ARIA: the whole name is read from a visually hidden copy, and the tooltip only repeats it on screen when the name is cut. `trap/disabled-drops-focus` in Keyboard: a button that leaves with the state it changed, such as Retry, hands focus to the end button or to the tile. `trap/illustration-announced` in ARIA: the glyph is hidden unless it is the progress bar. `trap/surface-matches-parent` in `rule/file-tile-muted-on-card`. `trap/reduced-motion-ignored` in Motion. `trap/toast-errors` in States: a failure and a refusal stay on the tile.

### Foundation

Not applicable: hand-rolled.

| Given by the foundation                                                                                                                                                  | Added by the team                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `FileTypeIcon`, which picks the kind from the MIME type or the extension and draws an upload on its sheet; `splitFileName`, `fitFileName` and `Upload` from `@/lib/cobalt/messages`; `bytes()` from `@/lib/cobalt/format`, the formatter FileDrop's own line uses; a canvas's `measureText` for the name's width; the system `Tooltip` and `Button` | One tile, 56px tall and 288px wide by default, or with `compact` 48px tall and as wide as its name and line, up to 16rem, so a short name sits beside its Remove with no gap and a long one is cut only past 16rem (measured in the composer: "Fjord walk.jpg" 168px, "Rooming list.csv" 184px, "Q3 holdings review, final.pdf" 249px, all whole, where every tile was 240px); the name's whole text sits unseen in the same cell and gives the tile its width, and the cut is measured against the room the tile has, scaled to the page's own width for the whole name so a name that fits is never cut; a picture as its own thumbnail through `src`, grey with its colour rising from the bottom as the share grows, as the glyph does; the name cut in the middle to fit, measured in its own font before paint and again as its box or the fonts change, so the start of the name, an ellipsis, its last short word and the extension read as one word, "Form ADV Part 2A bro…2026.pdf", or its last character when the word would leave fewer than 4 characters of the start, "Fjordst…e.pdf", with no gap and never "….pdf" (`fitFileName`; measured on file-tile, message, thread, file-drop and composer at 390 and 1440: 35 names, none with a gap, a fourth dot or a CSS overflow), read whole from a visually hidden copy, with the whole name in a tooltip only when it is cut; one line under the name: the kind and size, such as "XLSX, 812 KB", "Uploading, 42%" with the share rounded down, "Upload failed" or the reason a file was `refused`; a failed upload's glyph as the Retry button when `onRetry` is passed; the end button, named "Remove {name}" or "Dismiss {name}"; `href`, which makes the whole tile one download link through the link's `::after`, with the download glyph held invisible until then, so the name is cut at the same place in every state; `detail` and `action` for a host that says more; focus kept in the tile, on the end button or on the tile itself, when a button pressed in it leaves; one status line; `fileTileLabels` for every string it speaks |

## Examples

The documents filed with a fund's annual report. Each tile shows its kind's glyph, or a picture as its own thumbnail, its name with the extension in view, and its kind and size; a press downloads it.

Real uses, 0 call sites (`rg -n "<FileTile\b" app registry --glob '!registry/cobalt/ui/*'`): no showcase page draws one outside its examples yet, and the examples folder does not count.

Uses inside the registry, outside the count since they share its folder:

- FileDrop draws each file's row as a `FileTile` with `variant` left at `card`, its own state words in `detail`, `onRetry` after a failure, so the glyph is its Retry, `onRemove` unless the list is disabled, and `w-full` (`registry/cobalt/ui/file-drop.tsx:298-311`).
- The composer's attachments are compact `FileTile`s, a picture with its own `src`, each as wide as its name up to 16rem, in a row that scrolls sideways with the chip row's edge fade, seen on the composer's grey in light and dark (`registry/cobalt/ui/composer.tsx:1295-1260`).
- MessageFile is a `FileTile` in the `bubble` or `bubble-mine` variant for its side, with the run's corners (`registry/cobalt/ui/message-attachment.tsx:110-113`).

So every file tile in the system is this one, and every size is written by `bytes()`, "812 KB"; the `fileSize()` that wrote "812 kB" is gone.

### Example files

| File                                           | Covers               | Caption                                                                                                                                                                                       |
| ---------------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `docs/system/examples/file-tile/default.tsx`   | default              | The documents filed with a fund's annual report, each with its kind's glyph or a picture as its own thumbnail, its name with the extension in view, and its kind and size; a press downloads it |
| `docs/system/examples/file-tile/default.tsx`   | variant=card         | The default fill, on the page                                                                                                                                                                 |
| `docs/system/examples/file-tile/in-message.tsx` | variant=bubble | Theirs at the start in the bubble's grey fill, as MessageFile draws it |
| `docs/system/examples/file-tile/in-message.tsx` | variant=bubble-mine | Yours at the end in the ink fill |
| `docs/system/examples/file-tile/in-card.tsx`   | variant=muted        | On a white card the tiles take the grey fill                                                                                                                                                  |
| `docs/system/examples/file-tile/compact.tsx`   | compact=true         | The 48px tiles of a message composer, in a row above what is being written: ready, on its way up, or failed with its glyph as Retry, each with Remove                                         |
| `docs/system/examples/file-tile/uploading.tsx` | state:uploading      | Two files on their way up. The glyph, or the picture, is grey and its colour rises from the bottom as the share grows                                                                         |
| `docs/system/examples/file-tile/failed.tsx`    | state:failed         | An upload that did not finish. The glyph stays grey with the retry arrow and becomes the Retry button                                                                                         |
| `docs/system/examples/file-tile/refused.tsx`   | state:refused        | A file the list does not take stays where it would have been, with the reason in red, until it is dismissed                                                                                   |
| `docs/system/examples/file-tile/in-card.tsx`   | composition:Card     | A filing's documents on its record card, two to a row from 640px up                                                                                                                          |

Example: The documents filed with a fund's annual report, each with its kind's glyph or a picture as its own thumbnail, its name with the extension in view, and its kind and size; a press downloads it (`docs/system/examples/file-tile/default.tsx`)

```tsx
import { FileTile } from "@/components/cobalt/ui/file-tile";

export default function Example() {
  return (
    <ul aria-label="Documents" className="flex w-full max-w-md flex-col gap-2">
      <li>
        <FileTile name="Form ADV Part 2A brochure, March 2026.pdf" size={2_410_000} href="#brochure" className="w-full" />
      </li>
      <li>
        <FileTile name="Schedule of investments.xlsx" size={812_000} href="#schedule" className="w-full" />
      </li>
      <li>
        <FileTile
          name="Annual meeting, main hall.webp"
          size={346_000}
          src="/photos/assembly.jpg"
          href="/photos/assembly.jpg"
          className="w-full"
        />
      </li>
    </ul>
  );
}
```

Example: A filing's documents on its record card, two to a row from 640px up (`docs/system/examples/file-tile/in-card.tsx`)

```tsx
import { Card, CardContent, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { FileTile } from "@/components/cobalt/ui/file-tile";

const documents = [
  { name: "Form ADV Part 2A brochure.pdf", size: 2_410_000 },
  { name: "Audited financial statements 2025.pdf", size: 5_820_000 },
  { name: "Schedule of investments.xlsx", size: 812_000 },
  { name: "Code of ethics.docx", size: 148_000 },
];

export default function Example() {
  return (
    <Card className="w-full max-w-2xl">
      <CardHeader>
        <CardTitle>Documents filed</CardTitle>
      </CardHeader>
      <CardContent>
        <ul aria-label="Documents filed" className="grid grid-cols-1 gap-2 sm:grid-cols-2">
          {documents.map((doc) => (
            <li key={doc.name}>
              <FileTile variant="muted" name={doc.name} size={doc.size} href={`#${doc.size}`} className="w-full" />
            </li>
          ))}
        </ul>
      </CardContent>
    </Card>
  );
}
```

## Variants

### variant

- `card`: the default, the card fill on the page (the muted fill in dark), for a tile on the page, in a composer or in a drop list. Used at 0 call sites; FileDrop's rows use it inside the registry.
- `muted`: the grey fill, for a tile on a white card, so its edge shows. Used at 0 call sites.
- `bubble`: a file in someone else's message: the bubble's grey fill, `--bubble` with `--bubble-foreground`, on the `--r-bubble` corner, the line under the name in that ink at 70 percent, and the glyph's Retry press the ink at 8 percent on the bubble's inner corner. Used at 0 call sites; MessageFile uses it inside the registry, with the run's corners on `rounded-[inherit]`.
- `bubble-mine`: the same in your own message, in `--bubble-mine` with `--bubble-mine-foreground`. Used at 0 call sites; MessageFile uses it for your side.

Example: The default fill, on the page (`docs/system/examples/file-tile/default.tsx`)

```tsx
import { FileTile } from "@/components/cobalt/ui/file-tile";

export default function Example() {
  return (
    <ul aria-label="Documents" className="flex w-full max-w-md flex-col gap-2">
      <li>
        <FileTile name="Form ADV Part 2A brochure, March 2026.pdf" size={2_410_000} href="#brochure" className="w-full" />
      </li>
      <li>
        <FileTile name="Schedule of investments.xlsx" size={812_000} href="#schedule" className="w-full" />
      </li>
      <li>
        <FileTile
          name="Annual meeting, main hall.webp"
          size={346_000}
          src="/photos/assembly.jpg"
          href="/photos/assembly.jpg"
          className="w-full"
        />
      </li>
    </ul>
  );
}
```

Example: Theirs at the start in the bubble's grey fill, as MessageFile draws it (`docs/system/examples/file-tile/in-message.tsx`)

```tsx
import { FileTile } from "@/components/cobalt/ui/file-tile";

export default function Example() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <FileTile
        variant="bubble"
        name="Harbour suite, house guide.pdf"
        size={1_840_000}
        href="#guide"
      />
      <FileTile
        variant="bubble-mine"
        name="Passport scan, Ada Park.jpg"
        mime="image/jpeg"
        size={412_000}
        href="#scan"
        className="self-end"
      />
    </div>
  );
}
```

Example: Yours at the end in the ink fill (`docs/system/examples/file-tile/in-message.tsx`)

```tsx
import { FileTile } from "@/components/cobalt/ui/file-tile";

export default function Example() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <FileTile
        variant="bubble"
        name="Harbour suite, house guide.pdf"
        size={1_840_000}
        href="#guide"
      />
      <FileTile
        variant="bubble-mine"
        name="Passport scan, Ada Park.jpg"
        mime="image/jpeg"
        size={412_000}
        href="#scan"
        className="self-end"
      />
    </div>
  );
}
```

Example: On a white card the tiles take the grey fill (`docs/system/examples/file-tile/in-card.tsx`)

```tsx
import { Card, CardContent, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { FileTile } from "@/components/cobalt/ui/file-tile";

const documents = [
  { name: "Form ADV Part 2A brochure.pdf", size: 2_410_000 },
  { name: "Audited financial statements 2025.pdf", size: 5_820_000 },
  { name: "Schedule of investments.xlsx", size: 812_000 },
  { name: "Code of ethics.docx", size: 148_000 },
];

export default function Example() {
  return (
    <Card className="w-full max-w-2xl">
      <CardHeader>
        <CardTitle>Documents filed</CardTitle>
      </CardHeader>
      <CardContent>
        <ul aria-label="Documents filed" className="grid grid-cols-1 gap-2 sm:grid-cols-2">
          {documents.map((doc) => (
            <li key={doc.name}>
              <FileTile variant="muted" name={doc.name} size={doc.size} href={`#${doc.size}`} className="w-full" />
            </li>
          ))}
        </ul>
      </CardContent>
    </Card>
  );
}
```

Example: The 48px tiles of a message composer, in a row above what is being written: ready, on its way up, or failed with its glyph as Retry, each with Remove (`docs/system/examples/file-tile/compact.tsx`)

```tsx
import { useRef, useState } from "react";

import { scrollRowFade, useScrollRow } from "@/components/cobalt/ui/chip-row";

import { FileTile } from "@/components/cobalt/ui/file-tile";
import { Textarea } from "@/components/cobalt/ui/textarea";
import type { Upload } from "@/lib/cobalt/messages";
import { cn } from "@/lib/cobalt/utils";

type Attached = { id: string; name: string; size: number; src?: string; upload?: Upload };

export default function Example() {
  const [files, setFiles] = useState<Attached[]>([
    { id: "c", name: "Office.jpg", size: 1_400_000, src: "/photos/city-london.webp", upload: { status: "failed" } },
    { id: "b", name: "Cap table.xlsx", size: 96_000, upload: { status: "uploading", progress: 55 } },
    { id: "a", name: "Term sheet draft.docx", size: 182_000 },
  ]);
  const row = useRef<HTMLUListElement>(null);
  const scrollRow = useScrollRow(row, [files.length]);
  return (
    <div className="flex w-full max-w-lg flex-col gap-2 rounded-3xl bg-input/50 p-1.5">
      <ul
        ref={row}
        aria-label="Attached files"
        {...scrollRow}
        className={cn(
          "flex scroll-px-8 gap-1.5 overflow-x-auto",
          scrollRowFade,
        )}
      >
        {files.map((file) => (
          <li key={file.id} className="shrink-0">
            <FileTile
              compact
              name={file.name}
              size={file.size}
              {...(file.src ? { src: file.src } : {})}
              {...(file.upload ? { upload: file.upload } : {})}
              onRetry={() =>
                setFiles((list) => list.map((f) => (f.id === file.id ? { ...f, upload: { status: "done" } } : f)))
              }
              onRemove={() => setFiles((list) => list.filter((f) => f.id !== file.id))}
            />
          </li>
        ))}
      </ul>
      <Textarea aria-label="Message" placeholder="Add a note for the deal team" className="bg-transparent" />
    </div>
  );
}
```

## States

| State          | Trigger                                                        | What the user can do                                                 | Shown by, besides color                                                                                                                                                                                                            | Checked by        |
| -------------- | -------------------------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| done           | no `upload`, or one that is done, and no `refused`             | read it; remove it when `onRemove` is passed                         | the kind's glyph or the picture; the name with its extension; the kind and size on the line, such as "XLSX, 812 KB", or the size alone for a name with no extension (measured 56px tall, 288px wide; 48px and 240px compact)    | test              |
| link           | done, with `href`                                              | press anywhere on the tile to download the file                      | the download glyph at the end; the whole tile is the link (measured: presses at the glyph, the middle and the end all land on the link)                                                                                          | by hand           |
| hover          | the pointer over a link tile, under `(hover: hover)`           | press it                                                             | the fill steps to the muted hover fill; pointer only                                                                                                                                                                               | by hand           |
| focus-visible  | Tab onto the link                                              | press Enter to download                                              | one 2px ring around the whole tile on the tile's corner, drawn on the tile while its link has keyboard focus (measured: the link's own outline none, the ring's radius 12px); the name's tooltip when it is cut | by hand           |
| uploading      | `upload` with the status "uploading"                           | wait; remove it                                                      | the glyph or picture grey, its colour rising from the bottom by the share; "Uploading", or "Uploading, 42%" once the share is known, rounded down so a file still on its way never reads 100% (measured 99.6 as "Uploading, 99%"); with no share the grey breathes; the glyph is the progress bar                              | test              |
| failed         | `upload` with the status "failed"                              | press the glyph to try again when `onRetry` is passed; remove it    | the glyph grey with the retry arrow; "Upload failed" on the line; the glyph a button with the tooltip "Retry"                                                                                                                      | test              |
| refused        | `refused` holds a reason                                       | dismiss it                                                           | the kind's glyph at half opacity with no arrow, or the picture grey with no arrow; the reason on the line; the end button named "Dismiss {name}"                                                                              | test              |
| host line      | `detail` is passed                                             | what the host's line offers, such as FileDrop's Retry in `action`    | the host's line in place of the tile's, and no status line of the tile's own                                                                                                                                                       | by hand           |

Every state keeps one box: measured 56px tall with the name at the same x through failed, uploading and done after a Retry on /components/file-tile.

Example: Two files on their way up. The glyph, or the picture, is grey and its colour rises from the bottom as the share grows (`docs/system/examples/file-tile/uploading.tsx`)

```tsx
import { useEffect, useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { FileTile } from "@/components/cobalt/ui/file-tile";
import type { Upload } from "@/lib/cobalt/messages";

export default function Example() {
  const [run, setRun] = useState(0);
  const [share, setShare] = useState(0);
  // Stands in for the upload's progress events: 8 percent every 300ms, to the end.
  useEffect(() => {
    setShare(0);
    const timer = setInterval(() => setShare((now) => Math.min(100, now + 8)), 300);
    return () => clearInterval(timer);
  }, [run]);
  const upload = (offset: number): Upload =>
    share - offset >= 100 ? { status: "done" } : { status: "uploading", progress: Math.max(0, share - offset) };
  return (
    <div className="flex w-full max-w-72 flex-col items-start gap-3">
      <ul aria-label="Attachments" className="flex w-full flex-col gap-2">
        <li>
          <FileTile name="Quarterly holdings, Q3 2026.csv" size={1_200_000} upload={upload(0)} />
        </li>
        <li>
          <FileTile name="Site visit.jpg" size={2_900_000} src="/photos/hike.webp" upload={upload(24)} />
        </li>
      </ul>
      <Button variant="secondary" size="sm" onClick={() => setRun((n) => n + 1)}>
        Upload again
      </Button>
    </div>
  );
}
```

Example: An upload that did not finish. The glyph stays grey with the retry arrow and becomes the Retry button (`docs/system/examples/file-tile/failed.tsx`)

```tsx
import { useEffect, useState } from "react";

import { FileTile } from "@/components/cobalt/ui/file-tile";
import { nextUpload, type Upload } from "@/lib/cobalt/messages";

export default function Example() {
  const [upload, setUpload] = useState<Upload>({ status: "failed" });
  // Stands in for the retried upload: 20 percent every 250ms, then done.
  useEffect(() => {
    if (upload.status !== "uploading") return;
    const timer = setTimeout(() => {
      const progress = (upload.progress ?? 0) + 20;
      setUpload((now) => nextUpload(now, progress >= 100 ? { type: "finish" } : { type: "progress", progress }));
    }, 250);
    return () => clearTimeout(timer);
  }, [upload]);
  return (
    <FileTile
      name="Side letter, Harbour Capital.pdf"
      size={640_000}
      upload={upload}
      onRetry={() => setUpload((now) => nextUpload(now, { type: "retry" }))}
      onRemove={() => setUpload({ status: "failed" })}
    />
  );
}
```

Example: A file the list does not take stays where it would have been, with the reason in red, until it is dismissed (`docs/system/examples/file-tile/refused.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { FileTile } from "@/components/cobalt/ui/file-tile";

export default function Example() {
  const [shown, setShown] = useState(true);
  return (
    <div className="flex w-full max-w-72 flex-col items-start gap-3">
      {shown ? (
        <FileTile
          name="Board meeting recording.mov"
          size={1_480_000_000}
          refused="Over 100 MB"
          onRemove={() => setShown(false)}
        />
      ) : (
        <Button variant="secondary" size="sm" onClick={() => setShown(true)}>
          Show it again
        </Button>
      )}
    </div>
  );
}
```

### State precedence

- Refused and an upload: refused wins. The reason shows, and the glyph draws no upload.
- Uploading, failed and done: Not applicable: `upload` holds one status at a time.
- Link and an upload that is not done: the upload wins. The tile is no link until the upload is done, and the download glyph holds its place unseen.
- Host line and every state: the host line wins for the line under the name; the glyph still draws the upload.
- Hover and focus-visible on a link tile: both show. The hover fill under the rings.
- Failed and a picture: both show. The picture stays grey under the retry arrow.

### Motion

| Trigger                                        | Kind     | Preset                                                                | Properties                      | Reduced motion                                |
| ---------------------------------------------- | -------- | --------------------------------------------------------------------- | ------------------------------- | --------------------------------------------- |
| an upload's share grows, on a glyph            | announce | `duration-settle`, `--t-settle` 300ms, `ease-out` on `--curve`        | transform of `FileTypeIcon`'s clip | none: the share jumps to its new height      |
| an upload's share grows, on a picture          | announce | `duration-settle`, `--t-settle` 300ms, `ease-out` on `--curve`        | clip-path                       | none: the share jumps to its new height       |
| an upload with no share yet                    | announce | `animate-pulse`                                                       | opacity                         | none: the glyph stays grey and still          |
| the pointer over a link tile, or a press       | input    | `pressable`, `--t-press` 140ms on `--curve`                           | background-color, box-shadow    | the same fade                                 |
| the name's or Retry's tooltip opens or closes  | announce | `popup-motion` at `--t-press`                                         | opacity                         | the same fade                                 |

## Props

<!-- Props generated from registry/cobalt/ui/file-tile.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `name` | `string` |  | The file's name. |
| `action?` | `ReactNode` |  | One more control before the end button, such as a drop list's Retry. |
| `className?` | `string` |  | Placement only, such as `w-full` in a list, and a bubble's fill and corners. |
| `compact?` | `boolean` | `false` | 48px tall with a 32px glyph, as wide as its name up to 16rem, for a composer's row of attachments. |
| `detail?` | `ReactNode` |  | The line under the name, in place of the kind and size or the upload's words, for a host that says more, such as a drop list's state words. |
| `href?` | `string` |  | Where it downloads from, once it is there. |
| `labels?` | `Partial<{ progress: (percent: number) => string; uploading: (name: string) => string; uploaded: string; failed: string; retry: (name: string) => string; retryShort: string; remove: (name: string) => string; dismiss: (name: string) => string; kind: (extension: string) => string; }>` |  |  |
| `mime?` | `string` |  | Its MIME type, which says its kind before the extension does. |
| `onRemove?` | `() => void` |  | Takes the file off, or clears a refused one. |
| `onRetry?` | `() => void` |  | Tries a failed upload again. |
| `refused?` | `string` |  | Why it was not added, such as "Over 10 MB". |
| `size?` | `number` |  | In bytes. |
| `src?` | `string` |  | A picture's own preview, drawn in the glyph's place: an object URL while it uploads. |
| `upload?` | `Upload` |  | Its upload, from `nextUpload`: uploading with its share, failed, or done. |
| `variant?` | `"card" \| "muted" \| "bubble" \| "bubble-mine"` | `"card"` | `card` on the page, in a composer or a drop list; `muted` on a white card; `bubble` in someone else's message and `bubble-mine` in yours, in that bubble's fill, ink and corner, with the line under the name in the bubble's ink, faded. |

`name` is the file's name; cut, it is cut in the middle, so its end and its extension stay in view as one word, and the whole name shows in the tooltip. `mime` says the kind before the extension does. `size` is in bytes. `src` is a picture's own preview, an object URL while it uploads. `href` is where the file downloads from once it is there; the whole tile becomes that link. `upload` is the file's `Upload` from `nextUpload`: uploading with its share, failed, or done. `refused` is why the file was not added, such as "Over 10 MB". `onRetry` makes a failed glyph the Retry button. `onRemove` shows the end button. `detail` replaces the line under the name for a host that says more, and the host then announces its own changes. `action` is one more control before the end button. `variant` is `card` or `muted`. `compact` is the 48px tile that hugs its name up to 16rem. `labels` replaces any string from `fileTileLabels`. `className` is for placement, such as `w-full` in a list.

## Usage

### When to use

- A file attached to a record, a message or a filing, that a person reads by name and downloads.
- A file on its way up, in a list of attachments or a composer's row, while its upload runs or after it failed.

### When not to use

- A thing shown by its picture first, such as a venue or a listing, with its name under the photo. Use MediaTile instead.
- Photos sent in a message, meant to be looked at. Use MessageAttachment instead, whose `MessageImages` lays them out.
- A place to drop or choose files. Use FileDrop instead, which draws its rows with this tile.
- A table of many files with columns to sort, such as a document library. Use DataTable instead.

### Rules

- `rule/file-tile-grid-columns`: When tiles sit in a grid, give it explicit columns, such as `grid-cols-1 sm:grid-cols-2`, instead of the implicit column, because an implicit column grows to fit a name with no break, which widened every tile to 746px and the page to 786px at 390px, while `grid-cols-1` held the tile to 310px with the name cut and its extension in view. Evidence: measured on /stress/file-tile?data=worst at 390 with Playwright, before and after `grid-cols-1` was added to the page; measured 310px tiles in the 390px page since. Check: probe /stress/file-tile?data=worst at 390, the page's scroll width against its client width.
  - Don't: `<ul className="grid gap-2 sm:grid-cols-2">{files.map((f) => <li key={f.id}><FileTile {...f} className="w-full" /></li>)}</ul>`
  - Do: `<ul className="grid grid-cols-1 gap-2 sm:grid-cols-2">{files.map((f) => <li key={f.id}><FileTile {...f} className="w-full" /></li>)}</ul>`
- `rule/file-tile-muted-on-card`: When tiles sit on a white `Card`, pass `variant="muted"` instead of leaving the default `card`, because the default fill is the card's own white, so the tile would have no edge on it. Evidence: measured the `card` tile's fill at oklch(1 0 0) and the `muted` tile's at oklch(0.948 0.004 264) in light mode on /components/file-tile; person D11. Check: review of every `FileTile` inside a `Card`.
  - Don't: `<CardContent><FileTile name={doc.name} size={doc.size} href={doc.url} /></CardContent>`
  - Do: `<CardContent><FileTile variant="muted" name={doc.name} size={doc.size} href={doc.url} /></CardContent>`
- `rule/file-tile-host-line-speaks`: When a host passes `detail`, give the words that change a `role="status"` of their own instead of plain text, because the tile drops its own status line when `detail` is passed, so a host line with no live region changes in silence. Evidence: single use registry/cobalt/ui/file-drop.tsx:271, FileDrop's line holds its own status; principle wcag: 4.1.3 Status messages. Check: review of every `detail` passed to `FileTile`.
  - Don't: `<FileTile name={file.name} upload={upload} detail={<span>{word}</span>} />`
  - Do: `<FileTile name={file.name} upload={upload} detail={<span role="status">{word}</span>} />`

### Content

- `rule/file-tile-refusal-names-the-limit`: When a file is refused, write the limit it broke, such as "Over 100 MB" or "Not a file this list takes", in `refused`, instead of "Error" or "Invalid file", because the reason is the only line under the name and a person picks another file from it. Evidence: principle heuristic: help users recognize, diagnose and recover from errors; single use docs/system/examples/file-tile/refused.tsx:15. Check: review of every `refused` passed to `FileTile`.
  - Don't: `<FileTile name={file.name} size={file.size} refused="Invalid file" onRemove={dismiss} />`
  - Do: `<FileTile name={file.name} size={file.size} refused="Over 100 MB" onRemove={dismiss} />`

### Anti-slop

- `rule/file-tile-upload-on-the-glyph`: When a file uploads, pass `upload` with its share instead of a `Progress` bar or a `Spinner` beside the tile, because the tile draws the share on its glyph and keeps one box in every state, and a bar or spinner added beside it changes the tile's size as the upload goes. Evidence: measured 56px with the name at the same x through failed, uploading and done (Playwright on /components/file-tile); person D37. Check: review of every `Progress` or `Spinner` beside a `FileTile`.
  - Don't: `<FileTile name={f.name} size={f.size} /><Progress value={f.progress} />`
  - Do: `<FileTile name={f.name} size={f.size} upload={{ status: "uploading", progress: f.progress }} />`
- `rule/file-tile-not-a-hand-row`: When a screen shows a file, render `FileTile` instead of a `FileTypeIcon` beside a `truncate` name, because the tile cuts the name before its extension, names its buttons after the file and draws the upload on the glyph, where a hand-made row cuts the extension off. Evidence: single use registry/cobalt/ui/file-drop.tsx:298, FileDrop draws its rows with it; principle heuristic: consistency and standards, one file looks the same on every screen. Check: review of every `FileTypeIcon` outside `registry/cobalt/ui/`.
  - Don't: `<div className="flex gap-3"><FileTypeIcon name={name} /><span className="truncate">{name}</span></div>`
  - Do: `<FileTile name={name} size={size} href={url} />`

### Limits

- `rule/file-tile-refusal-length`: When a refusal reason runs past 26 characters, shorten it to the limit, such as "Over 100 MB", instead of a sentence, because the line under the name is one line, 180px in a 288px tile with its end button and at most 164px in a compact one, which hugs its words up to 16rem, and a longer reason is cut. Evidence: measured by setting the line's text on /components/file-tile with Playwright: "Not a file this list takes", 26 characters, whole in both lines, "Over 100 MB, choose a smaller file", 34 characters, needing 188px and cut in both, and the stress page's 59-character reason needing 317px; measured the longest whole run of a test sentence at 39 characters in the 180px line and 32 in the 148px one. Check: review of every `refused` passed to `FileTile`.
  - Don't: `refused="Bigger than the 100 MB this list takes, so it was not added"`
  - Do: `refused="Over 100 MB"`

## Accessibility

Rests on a native `a` with `download` for a done file, native `button` elements for Retry and the end button, and the system `Tooltip`. Screen reader pass with VoiceOver: NEEDS REVIEW.

### Keyboard

| Key            | Where focus is                     | Effect                                                                    | Focus after                                                                                                   | Checked by |
| -------------- | ---------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ---------- |
| Tab            | before a link tile                 | focuses the link and opens the name's tooltip when the name is cut       | the link                                                                                                      | by hand    |
| Enter          | the link                           | downloads the file                                                        | stays on the link                                                                                             | by hand    |
| Tab            | before a failed tile with `onRetry` | focuses the glyph and opens its "Retry" tooltip                          | the Retry glyph                                                                                               | by hand    |
| Enter or Space | the Retry glyph                    | calls `onRetry`                                                           | the end button, or the tile when there is none, since the glyph stops being a button once the upload restarts (measured "Remove Side letter, Harbour Capital.pdf") | by hand    |
| Enter or Space | the end button                     | calls `onRemove`, which takes the file off or clears a refused one       | where the host puts it; the tile usually leaves                                                              | by hand    |

### ARIA

| Part                      | Role                 | Accessible name from                                              | States and properties                                                  | Announced                                                                                                    | Checked by          |
| ------------------------- | -------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------- |
| link                      | link                 | a visually hidden copy of the whole name; the cut halves on screen are `aria-hidden` | `download` set to the name                                  | the whole name (measured "Form ADV Part 2A brochure, March 2026.pdf")                                       | snapshot            |
| glyph or picture, uploading | progressbar        | `aria-label` from `labels.uploading`, "Uploading {name}"          | `aria-valuemin` 0, `aria-valuemax` 100, `aria-valuenow` once known     | on request; the share is not read on every step                                                              | test                |
| glyph or picture, otherwise | none, `aria-hidden` | none                                                              | none                                                                   | nothing                                                                                                      | test                |
| Retry glyph               | button               | `aria-label` from `labels.retry`, "Retry uploading {name}"        | none                                                                   | the name and "button"; the tooltip repeats "Retry"                                                          | test                |
| end button                | button               | `aria-label`, "Remove {name}", or "Dismiss {name}" when refused  | none                                                                   | the name and "button"                                                                                        | test                |
| status line               | status               | its text                                                          | visually hidden; left out when `detail` is passed                     | "Uploading" when an upload starts, "Upload failed", and "Uploaded" when an upload ends; once each           | by hand             |
| tile                      | none                 | none                                                              | `tabIndex` -1, so it takes focus only from the code                    | nothing; it holds focus when a button pressed in it leaves and there is no end button                       | by hand             |
| name tooltip              | tooltip              | the whole name                                                    | opens only when the name is cut                                       | nothing new, the link or text already holds the name                                                        | by hand             |

## Tokens

| Part                      | State                       | Token                                                                 |
| ------------------------- | --------------------------- | --------------------------------------------------------------------- |
| tile                      | all                         | `--r-xl`                                                              |
| tile                      | `card`                      | `--card`, and `--muted` in dark                                       |
| tile                      | `muted`                     | `--muted`                                                             |
| tile                      | hover, link                 | `--muted-hover`                                                       |
| tile                      | press, link                 | `--hover`, through `pressable`                                        |
| line                      | done, uploading             | `--muted-foreground`, tabular figures                                 |
| line                      | failed, refused             | `--destructive`                                                       |
| glyph                     | all                         | `FileTypeIcon`'s kind fills, such as `--file-pdf`, with `--file-ink` and `--file-other` |
| picture                   | all                         | `--r-xs`, `--outline-image`, `--muted`                                |
| picture's retry arrow     | failed                      | `--on-photo` on black at 60 percent                                   |
| Retry glyph button        | hover                       | `--hover`, `--r-md`                                                   |
| download glyph            | link                        | `--muted-foreground`                                                  |
| focus ring                | focus-visible               | `--ring`, `--line-focus`, `--focus-offset`                            |
| fills and fades           | all                         | `--t-press`, `--t-settle`, `--curve`                                  |

## Related

- FileDrop: a place to drop or choose files, whose rows are FileTiles.
- FileTypeIcon: the kind's glyph alone, without the name or the line.
- MediaTile: a thing shown by its picture first, with its name under the photo.
- Composer: a message's composer, whose attachments do not yet use this tile.
- Progress: a share of work that is not a file.
