Skip to content
Ballpoint

Copy Button

Copies a value; its label swaps for a pen-drawn tick and "Copied" without changing width.

Only in Ballpoint
npx shadcn@latest add @ballpoint/copy-button

Installation

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

Usage

tsx
import { CopyButton } from "@/components/ui/copy-button"

<CopyButton value="hello@example.com">Copy email</CopyButton>

Examples

Variants and sizes

Any button variant, a custom copied label, and the icon size.

Read at click time

Pass a function and the value is read when it's clicked.

Beside a command

An icon button at the end of a line of code.

$ pnpm dlx shadcn@latest add @ballpoint/card

Beside a field

A read-only link with a labelled copy button next to it.

Anyone with it can join. It stops working in a week.

API reference

value
string | (() => string)

What to copy, or a function that returns it when clicked.

children
default "Copy"
ReactNode

The label. Icon sizes show the copy icon instead and use this as the button's accessible name.

copiedLabel
default "Copied"
ReactNode

Shown, after a drawn tick, once it's copied.

timeout
default 1600
number

ms before it goes back to the label.

onCopy
(value: string) => void

Called once the value is on the clipboard.

variant, size
default "outline"
Button's

Any Button variant and size; icon sizes swap the copy icon for the tick.

Pen settings

The drawing also takes draw, roughness, passes, radius, corners, fill, shadow, weight and speed, as props or from the nearest InkProvider. What each one does.