# Copy button

An icon or a chip that copies a value, then shows a check.

Section: Components / Actions
Page: https://ui.heyramzi.com/components/copy-button
Import path: `@heyramzi/ui/components/copy`

## Import

```ts
import { CopyButton } from "@heyramzi/ui/components/copy";
```

## Demo

```svelte
<script lang="ts">
	import { CopyButton } from "@heyramzi/ui/components/copy";
</script>

<div class="flex items-center gap-4">
	<CopyButton value="pnpm add @heyramzi/ui" label="Copy install command" />
	<CopyButton value="acme-4821" text="acme-4821" label="Copy id" />
</div>

<p class="mt-6 text-sm">
	Codes in running text, such as
	<CopyButton
		value="26011200"
		text="26011200"
		label="Copy CN code 26011200"
		copiedLabel="CN code 26011200 copied"
		variant="inline"
		announce="name"
	/>, copy on click.
</p>
```

## API

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `value` | `string \| (() => string \| Promise<string>)` |  | 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. |
| `label` | `string` | `"Copy"` | Names the thing being copied, for a screen reader and the tooltip. |
| `copiedLabel` | `string` | `"Copied"` | Announced when the write lands; see `announce`. |
| `text` | `string` |  | The chip's visible text. Its presence is what makes this a chip. |
| `agent` | `boolean` | `false` | Marks the payload as an instruction for an AI rather than a raw string. |
| `size` | `"default" \| "md" \| "sm"` | `"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"` | `"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"` | `"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. |
| `class` | `string` |  |  |

Every prop of `HTMLButtonAttributes` from `svelte/elements`, except `children, onclick, value`.
