Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Copy Button

Free

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

copy-button-demo.tsx
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

PropTypeDefault
value*string

Text written to the clipboard.

—
labelstring

Accessible name.

"Copy"
onCopied() => void

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