Attachment for Astro
Astro attachment parts for file and image previews with upload state and actions.
Installation
bunx --bun shadcn@latest add @gnostic/attachmentnpx shadcn@latest add @gnostic/attachmentpnpm dlx shadcn@latest add @gnostic/attachmentCopy the files
src/components/ui/attachment/attachment-action.astrosrc/components/ui/attachment/attachment-actions.astrosrc/components/ui/attachment/attachment-content.astrosrc/components/ui/attachment/attachment-description.astrosrc/components/ui/attachment/attachment-group.astrosrc/components/ui/attachment/attachment-media.astrosrc/components/ui/attachment/attachment-title.astrosrc/components/ui/attachment/attachment-trigger.astrosrc/components/ui/attachment/attachment-variants.tssrc/components/ui/attachment/attachment.astrosrc/components/ui/attachment/index.tssrc/components/ui/attachment/types.ts
The Attachment parts display a file or image attachment, its media, name, and metadata, with optional actions and upload state. Use them for files and images in chat composers, message threads, and upload lists.
Usage
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentDescription,
AttachmentMedia,
AttachmentTitle,
} from "@/components/ui/attachment"
---
import FileText from "@lucide/astro/icons/file-text"
import X from "@lucide/astro/icons/x"
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentDescription,
AttachmentMedia,
AttachmentTitle,
} from "@/components/ui/attachment"
---
<Attachment>
<AttachmentMedia>
<FileText />
</AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>sales-dashboard.pdf</AttachmentTitle>
<AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
</AttachmentContent>
<AttachmentActions>
<AttachmentAction aria-label="Remove sales-dashboard.pdf">
<X />
</AttachmentAction>
</AttachmentActions>
</Attachment>
Composition
Attachment
├── AttachmentMedia
├── AttachmentContent
│ ├── AttachmentTitle
│ └── AttachmentDescription
├── AttachmentActions
│ └── AttachmentAction
└── AttachmentTrigger
Use AttachmentGroup to lay out multiple attachments in a scrollable row:
AttachmentGroup
├── Attachment
└── Attachment
Image
Set variant="image" on AttachmentMedia and render an <img> or Image inside it. Use orientation="vertical" to stack the media above the content.
States
Set state on Attachment to reflect the upload lifecycle. uploading and processing shimmer the title, and error switches to a destructive treatment. Keep the failure reason in AttachmentDescription so the state is not conveyed by color alone.
Sizes
Use size to switch between default, sm, and xs.
Group
Wrap attachments in AttachmentGroup to lay them out in a horizontally scrollable, snapping row with an edge fade.
Trigger
Add an AttachmentTrigger to make the whole card open a link or dialog. It fills the card behind the actions, so the actions stay clickable. Give icon-only actions and the trigger an aria-label that names the file and the action.
For a dialog or lightbox, put the attachment inside its root and set
data-slot="dialog-trigger" on AttachmentTrigger. The dialog controller binds
the trigger within that root. No ID lookup or custom click handler is needed.
<Dialog>
<Attachment>
<!-- media, content, actions -->
<AttachmentTrigger
data-slot="dialog-trigger"
aria-label="Preview research-summary.pdf"
/>
</Attachment>
<DialogContent>{/* ... */}</DialogContent>
</Dialog>
API Reference
AttachmentProps
state?AttachmentState
Upload state. Drives border treatment and title shimmer while in progress.
AttachmentStatedonesize?'default' | 'sm' | 'xs'
Attachment density.
'default' | 'sm' | 'xs'defaultorientation?'horizontal' | 'vertical'
Lay media beside or above the text content.
'horizontal' | 'vertical'horizontalAttachmentMediaProps
variant?'icon' | 'image'
Whether the slot holds an icon or an image preview.
'icon' | 'image'iconAttachmentActionProps
size?ButtonProps['size']
Button size for the icon action.
ButtonProps['size']icon-xsRead the installed source for the complete prop types.
Theme and layout
Attachment uses shared component recipes and semantic colors. Choose the size and orientation that fit the surrounding form or file list. Keep file names readable and actions distinct from the preview. Use Field for input labels and messages; the attachment view does not perform an upload.


