

<Demo name="attachment/demos/attachment" />

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/attachment
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/attachment
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/attachment
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/attachment
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

```tsx
import {
  Attachment,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
} from "@/ui/attachment"
```

```tsx
<Attachment>
  <AttachmentMedia>
    <FileTextIcon />
  </AttachmentMedia>
  <AttachmentContent>
    <AttachmentTitle>quarterly-report.pdf</AttachmentTitle>
    <AttachmentDescription>1.2 MB · PDF</AttachmentDescription>
  </AttachmentContent>
</Attachment>
```

## Anatomy [#anatomy]

`Attachment` is the card; its `state` walks the upload lifecycle — `idle`
renders a dashed outline, `uploading` and `processing` pulse the title, and
`error` switches to the danger treatment. `AttachmentMedia` holds a file-type
icon or an image thumbnail, `AttachmentActions` holds icon buttons that stay
pressable even when an `AttachmentTrigger` stretches a click target over the
whole card. A scrolling row of attachments goes in an `AttachmentGroup`.

```tsx
import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentGroup,
  AttachmentTrigger,
} from "@/ui/attachment"
```

```tsx
<AttachmentGroup>
  <Attachment state="uploading">
    {/* media, content… */}
    <AttachmentActions>
      <AttachmentAction aria-label="Cancel upload">
        <XIcon />
      </AttachmentAction>
    </AttachmentActions>
    <AttachmentTrigger aria-label="Open file" onClick={openFile} />
  </Attachment>
</AttachmentGroup>
```

## Examples [#examples]

<Examples className="md:grid-cols-2">
  <Example name="attachment/demos/states" title="States" />

  <Example name="attachment/demos/sizes" title="Sizes" />

  <Example name="attachment/demos/vertical" title="Vertical" />

  <Example name="attachment/demos/group" title="Group" />
</Examples>

## API Reference [#api-reference]

### Attachment [#attachment]

<Reference name="attachment" />

### AttachmentMedia [#attachmentmedia]

<Reference name="attachment-media" />

### AttachmentContent [#attachmentcontent]

<Reference name="attachment-content" />

### AttachmentTitle [#attachmenttitle]

<Reference name="attachment-title" />

### AttachmentDescription [#attachmentdescription]

<Reference name="attachment-description" />

### AttachmentActions [#attachmentactions]

<Reference name="attachment-actions" />

### AttachmentAction [#attachmentaction]

<Reference name="attachment-action" />

### AttachmentTrigger [#attachmenttrigger]

<Reference name="attachment-trigger" />

### AttachmentGroup [#attachmentgroup]

<Reference name="attachment-group" />
