This page as markdown: /attachment.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

Attachment

Status: stable

A file or image attached to a message: media or icon lead, name and metadata, upload and error states, an actions slot, and a full-card trigger that keeps those actions separately clickable.

Keywords: attachment, file, upload, image preview, chat file, document, drag and drop, file card

Usage

The card a file takes in a conversation — in the composer while it uploads, and in the transcript once it has. It renders all four states an attachment actually moves through (queued, uploading, failed, delivered) rather than only the delivered one, because the other three are the states that are hard to get right and would otherwise fall back on every caller.

Best practices

Anatomy

Part Required Description
Media yes Thumbnail crop or file glyph. Fills the tile in media, a lead square in card.
Label yes Name and metadata. A row beside the media in card; a scrim strip over the picture in media, shown only when there is something to say.
Actions no Remove / retry / download controls, stacked above the stretched trigger so they stay separately clickable.
Progress no A hairline bar along the bottom edge while status="uploading"; determinate with progress, indeterminate without.

Props

Name Type Default Description
name string — File name. Truncated rather than wrapped — the stem truncates and a short extension stays visible — and used as the default label for the stretched trigger and the media tile's alt text.
meta ReactNode — Size, type, upload progress, or the failure reason — the quiet second line.
thumbnail string — Image preview URL. Present means the card shows a crop of the file instead of a glyph.
icon string "file" Semantic icon name for a non-image file (resolved through IconProvider). Defaults to "image-stack" when a thumbnail is set.
variant "card" | "media" "card" card is a name-led horizontal row for documents; media is a square tile that is mostly picture.
status "idle" | "uploading" | "error" "idle" Transfer state. uploading adds a progress bar; error re-colors the card without changing its shape.
progress number — Percentage 0–100 while uploading. Omit for an indeterminate bar.
actions ReactNode — Remove / retry / download controls. Stay clickable when onOpen makes the card a trigger. On a media tile they float on the top-end corner over the picture, so pass variant="floating" buttons there.
onOpen () => void — Makes the whole card activate, via a stretched button rendered beneath the actions rather than by wrapping the card.
openLabel string Open ${name} Accessible label for that stretched trigger.
uploadingLabel string Uploading ${name} Accessible name of the progress bar while status is "uploading".
...div props Omit<ComponentPropsWithRef<"div">, "onClick"> — Spread onto the card. Use onOpen rather than onClick — a click handler on a div is not a control.

Variants

Tokens used

card, border, border-strong, muted, muted-foreground, foreground, destructive, overlay, overlay-foreground, ring, destructive-mark

Motion

Accessibility

Related

Examples

Document with a remove action

import { Attachment, Button, Icon } from "@sableui/react"

<Attachment name="proposal.pdf" meta="2.4 MB · PDF" onOpen={() => open(file)} actions={<Button variant="ghost" size="icon-xs" aria-label="Remove"><Icon name="xmark" /></Button>} />

Image tile, uploading

import { Attachment } from "@sableui/react"

<Attachment variant="media" name="cover.png" thumbnail={previewUrl} status="uploading" progress={62} meta="Uploading… 62%" />

Failed upload with a retry

import { Attachment, Button } from "@sableui/react"

<Attachment name="recording.mov" meta="Upload failed — file is over the 50 MB limit" status="error" icon="warning" actions={<Button variant="ghost" size="xs" onClick={retry}>Retry</Button>} />

Attachments as a message payload

import { Attachment, Message, RelativeTime } from "@sableui/react"

<Message messageId="m7" align="end" footer={<RelativeTime date={sentAt} />}>
	<div className="flex flex-wrap gap-2">
		{files.map((f) => (<Attachment key={f.id} variant="media" name={f.name} thumbnail={f.url} onOpen={() => open(f)} />))}
	</div>
</Message>