Copy button
Requires 2.0
CopyButton ships in @rtorcato/shadcn-ui 2.0.0 and later. On 1.x the
import fails with ERR_PACKAGE_PATH_NOT_EXPORTED.
A button that copies value to the clipboard. It is icon-only with a tooltip by
default, or labelled with showLabel. After each attempt it shows a copied or
failed state for timeout ms, then returns to idle. It wraps the
useCopy hook.
import { CopyButton, type CopyButtonProps } from '@rtorcato/shadcn-ui/components/ui-extended/copy-button'
Usage
<CopyButton value={command} />
<CopyButton value={apiKey} showLabel label="Copy key" />
// Inside a code block
<CopyButton value={command} variant="ghost" size="icon-sm" />
Props
Also accepts every Button prop except value, children, onClick and the DOM onCopy event, which onCopy below replaces.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Text written to the clipboard. |
label | string | 'Copy' | Idle label: the aria-label and tooltip (icon-only), or the visible text. |
copiedLabel | string | 'Copied' | Text shown after a successful copy. |
failedLabel | string | "Couldn't copy" | Text shown after a failed copy. |
showLabel | boolean | false | Show the label beside the icon instead of in a tooltip. |
timeout | number | 2000 | ms before returning to idle. |
onCopy | (ok: boolean) => void | — | Fires after each attempt with the result. |
variant | Button variant | 'outline' | Use 'ghost' inside code blocks. |
size | Button size | 'icon', or 'default' with showLabel |
Accessibility
- Icon-only, the
aria-labelstayslabelin every state. A politerole="status"region announces the copied or failed text, for both variants. - With
showLabel, the visible text is the accessible name and the button keeps its width as the text changes. - States are carried by icon shape and text, not colour.
- Icon-only buttons keep a 44px touch target at every icon size. Disabled buttons show no tooltip.