Make your AI a shadcn expert

Shadcn Attachment

React attachment for files in a composer or thread. Built with TypeScript and Tailwind CSS for Next.js using Base UI — upload states, sizes, and a full-card trigger.

An attachment is a file card: media, name, size, and actions. Use it in a composer, a message thread, or an upload list. It does not upload — you map your own machine onto state.

Scroll to load preview...

Usage

import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
} from "@/components/ui/attachment"
<Attachment>
  <AttachmentMedia>
    <FileTextIcon />
  </AttachmentMedia>
  <AttachmentContent>
    <AttachmentTitle>kit-readme.pdf</AttachmentTitle>
    <AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
  </AttachmentContent>
  <AttachmentActions>
    <AttachmentAction aria-label="Remove kit-readme.pdf">
      <XIcon />
    </AttachmentAction>
  </AttachmentActions>
</Attachment>

state is idle, uploading, processing, error, or done. Idle is the dashed drop target.

Composition

AttachmentMedia
AttachmentTitle
AttachmentDescription
AttachmentTrigger

AttachmentGroup is a scroll row of Attachments.

Image

variant="image" on AttachmentMedia plus an <img>. orientation="vertical" stacks the photo above the name.

Scroll to load preview...

States

uploading and processing shimmer the title. error is the red treatment — keep the reason in the description.

Scroll to load preview...

Sizes

default in a composer, sm in a thread, xs in a dense list.

Scroll to load preview...

Group

AttachmentGroup is a horizontal snap-scroll with an edge fade. Ten files stay one row tall.

Scroll to load preview...

Trigger

AttachmentTrigger fills the card behind the actions. Wrap it in a Dialog trigger or a render={<a />} link.

Scroll to load preview...

API

Prop

Type

AttachmentMedia

Prop

Type

AttachmentTrigger

Prop

Type

AttachmentAction is a Button. Default size is icon-xs.

Notes

Name every icon button

aria-label="Remove kit-readme.pdf" — not a bare X. Color is not the error message; put the reason in AttachmentDescription.

This component does not upload. You own fetch, XHR, or the signed URL.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.