Attachment
Displays a file or image attachment with media, metadata, upload state, and actions.
Installation
pnpm add @heyramzi/uiUsage
import * as Attachment from "@heyramzi/ui/shadcn/attachment";<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>Keyboard and accessibility
| Key | Does |
|---|---|
| Tab | Moves focus to the card's trigger, then to each action button. |
| Space Enter | Runs the focused trigger or action. |
- Attachment.Trigger is a button stretched over the whole card. With no aria-label, it's named by the card's Attachment.Title.
- An icon-only Attachment.Action with no aria-label reads "Remove", with the title as its description. Pass an aria-label for any other action.
- The card shows a ring while anything inside it has focus.
- Upload and error states are colour and shimmer only. Say the state in Attachment.Description so a screen reader hears it.
API reference
Attachment.Root
state"idle" | "uploading" | "processing" | "error" | "done"- Default
"done" size"default" | "sm" | "xs"- Default
"default" orientation"horizontal" | "vertical"- Default
"horizontal" refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
state | "idle" | "uploading" | "processing" | "error" | "done" | "done" |
size | "default" | "sm" | "xs" | "default" |
orientation | "horizontal" | "vertical" | "horizontal" |
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
Attachment.Group
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
Attachment.Media
variant"icon" | "image"- Default
"icon" refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
variant | "icon" | "image" | "icon" |
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
Attachment.Content
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
Attachment.Title
refbindableHTMLSpanElement | null- Default
null classstringidstring- Default
getAttachmentTitleId() childrenSnippet...rest- Every prop of
HTMLAttributes<HTMLSpanElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLSpanElement | null | null |
class | string | |
id | string | getAttachmentTitleId() |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLSpanElement> from svelte/elements | |
Attachment.Description
refbindableHTMLSpanElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLSpanElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLSpanElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLSpanElement> from svelte/elements | |
Attachment.Trigger
childSnippet<[{ props: Record<string, unknown> }]>refbindableHTMLButtonElement | null- Default
null classstringtype"button" | "submit" | "reset"- Default
"button" ...rest- Every prop of
HTMLButtonAttributesfromsvelte/elements
| Prop | Type | Default |
|---|---|---|
child | Snippet<[{ props: Record<string, unknown> }]> | |
ref bindable | HTMLButtonElement | null | null |
class | string | |
type | "button" | "submit" | "reset" | "button" |
...rest | Every prop of HTMLButtonAttributes from svelte/elements | |
Attachment.Actions
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
Attachment.Action
variant"default" | "outline" | "ghost" | "destructive" | "text" | "dashed"- Default
"ghost" size"sm" | "default" | "lg"- Default
"sm" iconboolean- Default
true refbindableHTMLButtonElement | HTMLAnchorElement | null- Default
null classstringaria-labelHTMLButtonAttributes...rest- Every prop of
HTMLButtonAttributesfromsvelte/elements ...rest- Every prop of
HTMLAnchorAttributesfromsvelte/elements
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "ghost" | "destructive" | "text" | "dashed" | "ghost" |
size | "sm" | "default" | "lg" | "sm" |
icon | boolean | true |
ref bindable | HTMLButtonElement | HTMLAnchorElement | null | null |
class | string | |
aria-label | HTMLButtonAttributes | |
...rest | Every prop of HTMLButtonAttributes from svelte/elements | |
...rest | Every prop of HTMLAnchorAttributes from svelte/elements | |