Components

Copy Button

new

Copies text to the clipboard and confirms it.

npx shadcn@latest add @blank/copy-button

Installation

npx shadcn@latest add @blank/copy-button

Usage

import { CopyButton } from "@/components/ui/copy-button"
<CopyButton value="npx shadcn@latest add @blank/button" />

A successful copy is confirmed three ways: the icon turns into a check, the tooltip says "Copied", and a polite live region announces it for screen readers. If the clipboard refuses, the button shows an error state instead of pretending. Pass onCopy to do the copying yourself — a rejected promise lands in the same error state.

Examples

With a label

Children render beside the icon. label still names the button in the tooltip.

Props

Every Button prop, plus:

PropTypeDefault
valuestring—
onCopy() => void | Promise<void>—
timeoutnumber2000
labelstring"Copy"
copiedLabelstring"Copied"
errorLabelstring"Copy failed"
tooltipbooleantrue