# Copy Button

> Icon button that copies a value and confirms with a checkmark.

- Install: `npx shadcn@latest add @0xui/copy-button`
- Registry JSON: https://0xui.io/r/copy-button.json
- Source: https://github.com/fimbul-lab/0xui/blob/main/registry/default/components/copy-button.tsx

Copies a value to the clipboard. The icon turns into a checkmark for two seconds, and "Copied" is announced to screen readers.

## Installation

```bash
npx shadcn@latest add @0xui/copy-button
```

## Usage

```tsx
import { CopyButton } from "@/components/copy-button";

<CopyButton value={address} label="Copy address" />;
```

Always pass a specific `label`. It is the button's only accessible name.

## Examples

### Other button styles

Accepts every shadcn `Button` prop, including `variant` and `size`.

```tsx
<CopyButton value={hash} label="Copy transaction hash" variant="outline" size="icon" />
```

## States

| State | What the user sees |
| --- | --- |
| Idle | Copy icon. |
| Copied | Checkmark for `timeout` ms, "Copied" announced. `data-copied` is set on the button. |
| Clipboard blocked | Nothing changes and `onCopy` is not called. |

## Props

Also accepts all shadcn `Button` props except `onClick` and `children`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | — | Text to copy. |
| `label` | `string` | `"Copy"` | Accessible label and tooltip. |
| `timeout` | `number` | `2000` | How long the copied state lasts, in ms. |
| `onCopy` | `(value: string) => void` | — | Called after a successful copy. |
| `copyIcon` | `ComponentType \| false` | `CopyIcon` | Custom icon, or `false` to hide it. |
| `copiedIcon` | `ComponentType \| false` | `CheckIcon` | Custom icon, or `false` to hide it. |
