# Attachment chip

> A file on its way into a prompt: uploading, being read, ready or failed.

Shows a file’s whole journey in one small chip, on one line that never swaps out. A ring fills around the icon while "Uploading 42%" rolls; the ring fades as the line morphs to "Reading" under a sweep of light; then it morphs again into type and size. Images show a thumbnail, failures blur the icon into an alert and say why, with Retry opening in beside it, and the remove button appears on hover or focus (always on touch screens).

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/attachment-chip.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/attachment-chip
- Registry item (source): https://hairlineui.com/r/attachment-chip.json

## Usage

```tsx
import { AttachmentChip } from "@/components/attachment-chip";

<AttachmentChip name="q3-sales.pdf" type="application/pdf" size={2_400_000} status="uploading" progress={0.42} onRemove={remove} />
```

## With the AI SDK

```tsx
import type { UIMessage } from "ai";
import { AttachmentChip } from "@/components/attachment-chip";

// Files a user sent arrive as "file" parts on their message.
function SentFiles({ message }: { message: UIMessage }) {
  return message.parts.map((part, i) =>
    part.type === "file" ? (
      <AttachmentChip
        key={i}
        name={part.filename ?? "Attachment"}
        type={part.mediaType}
        previewUrl={part.mediaType.startsWith("image/") ? part.url : undefined}
      />
    ) : null
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `name / size / type` | `string / number / string` | – | File name, size in bytes and MIME type (picks the icon). |
| `previewUrl` | `string` | – | Thumbnail for images, e.g. URL.createObjectURL(file). |
| `status` | `"uploading" \| "processing" \| "ready" \| "error"` | `"ready"` | Where the file is. |
| `progress` | `number` | – | Upload progress from 0 to 1. |
| `error / onRetry` | `string / () => void` | – | Why it failed, and a Retry link. |
| `onRemove` | `() => void` | – | Shows the remove button. |

## States

- **uploading**: A progress ring fills around the icon and "Uploading 42%" rolls with it.
- **processing**: The ring fades (360ms), the percent folds away and the line morphs to "Reading" under a 1.4s sweep of light.
- **ready**: The line morphs into type and size, e.g. "PDF · 2.4 MB"; a thumbnail brightens to full.
- **error**: A red border, the icon blurs into an alert, the line morphs to the reason and Retry opens in.

## What it handles

An upload usually shows a bar and then a file name. A file going into an AI prompt has one more step, being read, and a failure that should say why. The chip carries the whole journey in one small line.

- **Upload progress**: A ring fills round the icon while “Uploading 42%” rolls with it.
- **A step for being read**: When the upload is done the line morphs to “Reading” under a sweep of light.
- **Ready at a glance**: The line settles into the type and size, such as “PDF · 2.4 MB”.
- **Thumbnails for images**: Pass a preview URL and the image shows, brightening to full when ready.
- **Failures say why**: The icon becomes an alert, the line shows the reason and Retry opens in beside it.
- **Easy to remove, easy to hear**: A remove button named after the file, and each step announced politely, never every percent.

## Replaces

an upload progress bar, file type icons, image thumbnails, an error row with Retry, a remove button

## Where it fits

- **AI prompt boxes**: Show a file the person dropped into the prompt while it uploads and is read.
- **Email and message composers**: Attachments on a message that is still being written.
- **Forms with uploads**: Documents for job applications, claims and verification.
- **Knowledge bases**: Files added for an assistant or a search index to read.

## Notes

- Each step is announced politely ("Uploading q3-sales.pdf", "q3-sales.pdf is ready"), but never every percent.
- Installs Number roll and Text morph. With reduced motion, states change in place.
- The remove button is labelled with the file name, e.g. "Remove q3-sales.pdf".
- Long names truncate; the chip never grows past 260px.

License: MIT (https://hairlineui.com/license#components)
