GitHub

Copy Button

An icon button that copies a value, with copied and failed feedback.

Loading example…

Installation

pnpm dlx shadcn@latest add @sui/copy-button

Install 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.

Loading example…

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

PropTypeDefault / behavior
valuestringRequired text to copy.
labelsClipboardLabelsEnglish labels.
renderReactElementRenders another button, such as <InputGroupButton />.
disabled, resetDelay, onCopy, onCopyErrorClipboard optionsAs in CopyText.
variant, sizeButton props"ghost", "icon-sm".
feedbackFeedbackOptionFollows 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.