Copy Button
Copy to clipboard with a drawn-on check.
npx shadcn@latest add @neonkit/copy-buttonInstallation
npx shadcn@latest add https://neonkit.heyaadi.com/r/copy-button.jsonUsage
import { CopyButton } from "@/components/ui/copy-button"
<CopyButton value="npx shadcn@latest add …" aria-label="Copy install command" />Examples
With a label
Children make it a text button. value can be a function, even an async one, for values fetched on demand.
Share link
side places the bubble where it has room.
Code block
Sizes
Square icon buttons by default; text buttons share Button's heights.
API reference
Also accepts native button attributes except value and the native onCopy. The ref points at the button.
| Prop | Type | Default |
|---|---|---|
value | stringText to copy, or a function that returns it when clicked. | None |
onCopy | (text: string) => voidCalled after the text reaches the clipboard. | None |
onCopyError | (error: unknown) => voidCalled when the clipboard refuses or value throws. | None |
timeout | numberMilliseconds the confirmation stays up. | 1600 |
copiedLabel | stringBubble text and announcement on success. | "Copied" |
errorLabel | stringBubble text and announcement on failure. | "Couldn't copy" |
side | "top"Where the bubble appears. | "top" |
bubble | booleanShow the bubble. The check and the announcement happen either way. | true |
variant | "ghost"Quiet icon button, or a neon-edged one. | "ghost" |
size | "sm"Square 32, 40 or 48px; with children, the same heights as Button. | "md" |
color | NeonColorPalette name or hex. Falls back to --neon-accent, then cyan. | inherited |
Accessibility
- Icon-only buttons are named "Copy" unless you pass aria-label. Say what gets copied: "Copy install command".
- The result is announced through a polite live region next to the button; the bubble itself is aria-hidden.
- Uses the async Clipboard API on secure pages and falls back to a hidden textarea elsewhere. Failures show the error label in red.
- The bubble is positioned inside the button, so an ancestor with overflow: hidden can clip it. Pick a side with room.