# Copy button

Copies a value to the clipboard; the icon turns into a check and a status says it was copied.

- Family: action
- Import: `import { CopyButton } from "@senvenli/react/action";`
- Page: https://design.senvenli.com/docs/components/copy-button
- JSON: https://design.senvenli.com/docs/components/copy-button.json

## Example: Beside a value

Icon-only, named by what it copies; the icon turns into a check.

```tsx
import { CopyButton } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-100">
      <Text isNumeric>INV-2026-0318</Text>
      <CopyButton value="INV-2026-0318" aria-label="Copy the invoice number" />
    </Stack>
  );
}
```

## Examples

### With a label

A visible label for a value people copy often, such as an install command.

```tsx
import { CopyButton } from "@senvenli/react/action";

export default function Example() {
  return (
    <CopyButton value="npm i @senvenli/react" variant="default" size="medium">
      Copy install command
    </CopyButton>
  );
}
```

## Guidelines

### When to use it

- A value people paste elsewhere: an ID, an API key, a link, a command.

### Use something else when

- [description-list](https://design.senvenli.com/docs/components/description-list.md): The value is a field of a record, which DescriptionList can copy on its own.

### Do and avoid

- Icon-only, name what is copied: "Copy the invoice number".

## Accessibility

Built in:

- Says "Copied" (or that it could not copy) in a polite status, again on every press.
- The check shows for two seconds.

You provide:

- An aria-label naming the value when it is icon-only.

## API reference

### CopyButton

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| value | `string \| (() => string \| Promise<string>)` |  | yes | The text to copy, or a function that returns it (or a promise of it) at the moment of the press. |
| children | `React.ReactNode` |  | no | Shown as the label; left out, the button is icon-only and named by `aria-label` (default "Copy"). |
| aria-label | `string` |  | no | The name of an icon-only button: "Copy the invoice number". Default "Copy". |
| variant | `ButtonVariant` | `"subtle"` | no |  |
| size | `ButtonSize` | `"small"` | no |  |
| radius | `ComponentRadius` |  | no |  |
| onCopy | `(text: string) => void` |  | no | Runs after a successful copy (to show a toast, log, …). |

### Tokens it reads

`--ds-background-brand-bold`, `--ds-background-brand-bold-hovered`, `--ds-background-brand-bold-pressed`, `--ds-background-danger`, `--ds-background-danger-bold`, `--ds-background-danger-bold-hovered`, `--ds-background-disabled`, `--ds-background-neutral`, `--ds-background-neutral-hovered`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-background-selected`, `--ds-background-selected-hovered`, `--ds-background-selected-pressed`, `--ds-border`, `--ds-border-bold`, `--ds-border-focused`, `--ds-border-selected`, `--ds-easing-standard`, `--ds-link`, `--ds-link-pressed`, `--ds-radius-control-medium`, `--ds-radius-full`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-size-control-large`, `--ds-size-icon`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-on-danger`, `--ds-text-subtle`

## Related

- [button](https://design.senvenli.com/docs/components/button.md)
- [description-list](https://design.senvenli.com/docs/components/description-list.md)
