Copy button
An icon or a chip that copies a value, then shows a check.
Installation
pnpm add @heyramzi/uiUsage
import { CopyButton } from "@heyramzi/ui/components/copy";Keyboard and accessibility
| Key | Does |
|---|---|
| Space Enter | Copies the value. |
- The button's name comes from label, and it's "Copy" by default. Say what gets copied, like "Copy invite link".
- When the copy lands, a polite live region reads out copiedLabel.
- In a long list of these, announce="name" swaps the button's name to copiedLabel and skips the live region.
- Inside a clickable row or card, the press copies and doesn't open the row.
API reference
valuerequiredstring | (() => string | Promise<string>)- What lands on the clipboard. A function runs on the click, so a long list doesn't build every prompt up front. It may return a promise.
labelstring- Default
"Copy" - Names the thing being copied, for a screen reader and the tooltip.
copiedLabelstring- Default
"Copied" - Announced when the write lands; see `announce`.
textstring- The chip's visible text. Its presence is what makes this a chip.
agentboolean- Default
false - Marks the payload as an instruction for an AI rather than a raw string.
size"default" | "md" | "sm"- Default
"default" - `sm` matches `OpenIn`, for the icon row inside a calendar chip. `md` is the 28px icon `Button`, for a toolbar that sits beside other icon buttons.
variant"ghost" | "outline" | "inline"- Default
"ghost" - Ghost unless it sits beside an outline button; `inline` is for the chip, taking the surrounding text's font and colour.
announce"region" | "name"- Default
"region" - `region` announces `copiedLabel` in a live region; `name` swaps the button's name to it (write it in full), for a page rendering hundreds of these.
onCopied() => void- Runs after a write that landed, for a toast the call site owns.
classstring...rest- Every prop of
HTMLButtonAttributesfromsvelte/elementsexceptchildren, onclick, value
| Prop | Type | Default |
|---|---|---|
value required What lands on the clipboard. A function runs on the click, so a long list doesn't build every prompt up front. It may return a promise. | string | (() => string | Promise<string>) | |
label Names the thing being copied, for a screen reader and the tooltip. | string | "Copy" |
copiedLabel Announced when the write lands; see `announce`. | string | "Copied" |
text The chip's visible text. Its presence is what makes this a chip. | string | |
agent Marks the payload as an instruction for an AI rather than a raw string. | boolean | false |
size `sm` matches `OpenIn`, for the icon row inside a calendar chip. `md` is the 28px icon `Button`, for a toolbar that sits beside other icon buttons. | "default" | "md" | "sm" | "default" |
variant Ghost unless it sits beside an outline button; `inline` is for the chip, taking the surrounding text's font and colour. | "ghost" | "outline" | "inline" | "ghost" |
announce `region` announces `copiedLabel` in a live region; `name` swaps the button's name to it (write it in full), for a page rendering hundreds of these. | "region" | "name" | "region" |
onCopied Runs after a write that landed, for a toast the call site owns. | () => void | |
class | string | |
...rest | Every prop of HTMLButtonAttributes from svelte/elements except children, onclick, value | |