Copy Button
An icon button that copies a value, with copied and failed feedback.
Installation
pnpm dlx shadcn@latest add @sui/copy-buttonInstall with the shadcn CLI or use the shared @workspace/ui package. Follow the installation guide to configure the registry, load styles, and choose import aliases.
import { CopyButton } from "@workspace/ui/components/copy-button";Usage
<CopyButton value={command} />The icon morphs to a check mark after the clipboard write succeeds, or to a cross when it fails, and the tooltip and a polite live region say the same. The button is disabled while a write is pending. It is a Tooltip Button, so variant, size, disabled and className pass through; it defaults to a small ghost icon button. Code Viewer, Diff Viewer and the Code Editor copy() plugin use it.
Copy field
A read-only copy field is an Input Group composition, as in shadcn: render turns the button into an InputGroupButton.
Labels
labels overrides copy, pending, copied and copyFailed. Pass clipboardLabelsZhCN from @workspace/ui/hooks/use-clipboard for Chinese. CopyText shares the same labels.
API reference
| Prop | Type | Default / behavior |
|---|---|---|
value | string | Required text to copy. |
labels | ClipboardLabels | English labels. |
render | ReactElement | Renders another button, such as <InputGroupButton />. |
disabled, resetDelay, onCopy, onCopyError | Clipboard options | As in CopyText. |
variant, size | Button props | "ghost", "icon-sm". |
feedback | FeedbackOption | Follows FeedbackProvider; haptics when a copy succeeds or fails. |
The module exports CopyButtonProps. The button carries data-copy-status (idle, pending, copied or error) for data-[copy-status=copied]: styles.