# Attachment

Displays a file or image attachment with media, metadata, upload state, and actions.

Section: Blocks / Chat
Page: https://ui.heyramzi.com/components/attachment
Import path: `@heyramzi/ui/shadcn/attachment`

## Import

```ts
import * as Attachment from "@heyramzi/ui/shadcn/attachment";
import { Spinner } from "@heyramzi/ui/shadcn/spinner";
```

## Usage

```svelte
<Attachment.Root>
  <Attachment.Media variant="image">
    <img src="/workspace.png" alt="Workspace" />
  </Attachment.Media>
  <Attachment.Content>
    <Attachment.Title>workspace.png</Attachment.Title>
    <Attachment.Description>PNG · 820 KB</Attachment.Description>
  </Attachment.Content>
  <Attachment.Actions>
    <Attachment.Action aria-label="Remove workspace.png">×</Attachment.Action>
  </Attachment.Actions>
</Attachment.Root>
```

## Demo

```svelte
<script lang="ts">
	import { FileCode, X } from "phosphor-svelte";
	import * as Attachment from "@heyramzi/ui/shadcn/attachment";
	import { Spinner } from "@heyramzi/ui/shadcn/spinner";

	const images = [
		{
			name: "workspace.png",
			meta: "PNG · 820 KB",
			src: "https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80",
			alt: "Workspace",
		},
		{
			name: "desk-reference.jpg",
			meta: "JPG · 1.1 MB",
			src: "https://images.unsplash.com/photo-1497215728101-856f4ea42174?w=900&auto=format&fit=crop&q=80",
			alt: "Desk",
		},
		{
			name: "office-reference.jpg",
			meta: "JPG · 940 KB",
			src: "https://images.unsplash.com/photo-1497366811353-6870744d04b2?w=900&auto=format&fit=crop&q=80",
			alt: "Office",
		},
	];
</script>

<div class="mx-auto flex w-full max-w-sm flex-col gap-3 py-12">
	<Attachment.Group>
		{#each images as image (image.name)}
			<Attachment.Root orientation="vertical">
				<Attachment.Media variant="image">
					<img src={image.src} alt={image.alt} />
				</Attachment.Media>
				<Attachment.Content>
					<Attachment.Title>{image.name}</Attachment.Title>
					<Attachment.Description>{image.meta}</Attachment.Description>
				</Attachment.Content>
				<Attachment.Trigger onclick={() => window.open(image.src, "_blank")} />
			</Attachment.Root>
		{/each}
	</Attachment.Group>
	<Attachment.Root state="uploading" class="w-full">
		<Attachment.Media>
			<Spinner />
		</Attachment.Media>
		<Attachment.Content>
			<Attachment.Title>sales-dashboard.pdf</Attachment.Title>
			<Attachment.Description>Uploading · 64%</Attachment.Description>
		</Attachment.Content>
		<Attachment.Actions>
			<Attachment.Action aria-label="Cancel upload">
				<X aria-hidden="true" />
			</Attachment.Action>
		</Attachment.Actions>
	</Attachment.Root>
	<Attachment.Root class="w-full">
		<Attachment.Media>
			<FileCode aria-hidden="true" />
		</Attachment.Media>
		<Attachment.Content>
			<Attachment.Title>message-renderer.tsx</Attachment.Title>
			<Attachment.Description>TypeScript · 12 KB</Attachment.Description>
		</Attachment.Content>
		<Attachment.Actions>
			<Attachment.Action>
				<X aria-hidden="true" />
			</Attachment.Action>
		</Attachment.Actions>
	</Attachment.Root>
</div>
```

## API

### Attachment.Root

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `state` | `"idle"` \| `"uploading"` \| `"processing"` \| `"error"` \| `"done"` | `"done"` |  |
| `size` | `"default"` \| `"sm"` \| `"xs"` | `"default"` |  |
| `orientation` | `"horizontal"` \| `"vertical"` | `"horizontal"` |  |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Attachment.Group

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Attachment.Media

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `variant` | `"icon"` \| `"image"` | `"icon"` |  |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Attachment.Content

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Attachment.Title

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLSpanElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `id` | `string` | `getAttachmentTitleId()` |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLSpanElement>` from `svelte/elements`.

### Attachment.Description

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLSpanElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLSpanElement>` from `svelte/elements`.

### Attachment.Trigger

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `child` | `Snippet<[{ props: Record<string, unknown> }]>` |  |  |
| `ref` | `HTMLButtonElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `type` | `"button" \| "submit" \| "reset"` | `"button"` |  |

Every prop of `HTMLButtonAttributes` from `svelte/elements`.

### Attachment.Actions

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Attachment.Action

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `variant` | `"default"` \| `"outline"` \| `"ghost"` \| `"destructive"` \| `"text"` \| `"dashed"` | `"ghost"` |  |
| `size` | `"sm"` \| `"default"` \| `"lg"` | `"sm"` |  |
| `icon` | `boolean` | `true` |  |
| `ref` | `HTMLButtonElement \| HTMLAnchorElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `aria-label` |  |  |  |

Every prop of `HTMLButtonAttributes` from `svelte/elements`.

Every prop of `HTMLAnchorAttributes` from `svelte/elements`.
