Data
Copy button
Copy a value with instant confirmation.
API key
An icon-only copy button inside an input group. The icon swaps to a check with a small pop, a live region says “Copied”, and it reverts after 1.5 seconds.
Keep this key private. Rotate it from the dashboard if it is ever exposed.
When to use
- Anything people paste elsewhere: API keys, ids, commands, share links, error details.
- Beside the value, not instead of it: show the text so people can verify what they copied.
Labelled and icon-only
Add label for a text button; it keeps one width while “Copy” becomes “Copied”. Icon-only buttons need an aria-label. value may be a function, read at click time.
API
CopyButton
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | () => string | — | The text to copy. |
| label | ReactNode | — | Visible text. Omit for icon-only. |
| copiedLabel / errorLabel | ReactNode | 'Copied' / 'Copy failed' | Text for each state. |
| resetAfter | number | 1500 | Milliseconds before returning to idle. |
| onCopy / onCopyError | (text) => void / () => void | — | Callbacks. |
| variant, size, ...props | ButtonProps | — | Forwarded to Button (outline when labelled, ghost when icon-only; size sm). |
useCopy({ resetAfter, onCopy, onError }) returns { copy, copied, error, status, reset } for custom triggers. copyText(text) is the helper underneath: it uses the Clipboard API and falls back to a hidden textarea.
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Copies the value. |
Accessibility
- A native button. Its name stays “Copy”; a polite live region announces “Copied” or “Copy failed”.
- Success and error are shown by icon and text, not colour alone.
Motion
- The copy icon shrinks and blurs out as the check pops in (snappy spring). An error shakes the alert icon slightly.
- Reduced motion: the icons swap without movement.