Copy Button
FreeCopies text, swaps to a check, and announces the result.
Installation
pnpm dlx shadcn@latest add @viewport/copy-button
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
import { CopyButton } from "@/components/viewport/copy-button";
const command = "npx shadcn@latest add @viewport/copy-button";
export default function CopyButtonDemo() {
return (
<div className="flex w-full max-w-md items-center gap-2 rounded-xl border border-border bg-card py-1.5 pl-4 pr-1.5 font-mono text-[13px]">
<span className="min-w-0 flex-1 truncate">{command}</span>
<CopyButton value={command} label="Copy install command" />
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| value* | stringText written to the clipboard. | — |
| label | stringAccessible name. | "Copy" |
| onCopied | () => voidCalled after a successful copy. | — |
Accessibility
- Announces “Copied” through a polite live region.
- Has an accessible name through the `label` prop.
- Fails silently if clipboard access is denied.