Attachment
A file or image chip with media, metadata, upload state, and actions.
Overview
Attachment shows a file or image with optional actions and upload state. Use AttachmentMedia for an icon or image, AttachmentContent for the name and metadata, and AttachmentActions for remove or cancel. Long names truncate; keep remove and cancel controls named.
Preview
Customize
Installation
Add the component with the CLI. It copies the files in and installs anything they depend on.
npx vinyaas add attachmentUsage
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentDescription,
AttachmentMedia,
AttachmentTitle,
} from "@/components/ui/attachment";
function FileCodeIcon() {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z" />
<path d="M14 2v6h6" />
<path d="m10 13-2 2 2 2" />
<path d="m14 17 2-2-2-2" />
</svg>
);
}
function XIcon() {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</svg>
);
}
export function FileAttachment() {
return (
<Attachment className="w-full max-w-sm">
<AttachmentMedia>
<FileCodeIcon />
</AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>message-renderer.tsx</AttachmentTitle>
<AttachmentDescription>TypeScript · 12 KB</AttachmentDescription>
</AttachmentContent>
<AttachmentActions>
<AttachmentAction aria-label="Remove message-renderer.tsx">
<XIcon />
</AttachmentAction>
</AttachmentActions>
</Attachment>
);
}Examples
Images
Vertical attachments in a group show image previews with truncated names.
Uploading
An uploading row uses Spinner in the media slot and a cancel action.
Error
Failed uploads keep the reason in the description, not color alone.
File
A horizontal file chip with an icon and remove action.
In practice
A chat composer stacks image previews, an uploading file, and a finished attachment.
API
Other attributes for the underlying element are passed through.
| Name | Type | Default | Description |
|---|---|---|---|
state | "idle" | "uploading" | "processing" | "error" | "done" | "done" | Drives border treatment and title pulse while uploading. |
size | "default" | "sm" | "xs" | "default" | Overall density for media and padding. |
orientation | "horizontal" | "vertical" | "horizontal" | Lay media beside or above the content. |
variant | "icon" | "image" | "icon" | On AttachmentMedia, choose an icon slot or an image preview. |
className | string | — | Merged onto any Attachment part with cn. |
Accessibility
- Icon-only AttachmentAction needs an aria-label that names the file or action.
- AttachmentTrigger needs an aria-label for what activating it does.
- Keep failure reasons in AttachmentDescription so error is not color alone.