Copy Button

Copy-to-clipboard button with a blur-and-scale copy-to-check icon morph, optional rolling Copy/Copied label, execCommand fallback, error state, and screen reader announcements.

Preview

Copy Button preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/copy-button
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

value
string | (() => string | Promise<string>)

Text to copy, or a (possibly async) getter evaluated on click.

—
showLabel?
boolean

Show a text label next to the icon that swaps with the status.

false
labels?
Partial<CopyButtonLabels>

Label text per status. Also used for the accessible name and announcement.

—
timeout?
number

How long the copied/error state lingers before resetting, in ms.

1600
variant?
"primary" | "secondary" | "ghost" | "outline"
secondary
size?
"sm" | "md" | "icon"
—
icons?
Partial<Record<CopyButtonStatus, ReactNode>>

Override the idle / copied / error icons.

—
onCopy?
((text: string) => void)
—
onCopyError?
((error: unknown) => void)
—
onStatusChange?
((status: CopyButtonStatus) => void)
—
className?
string
—

Updated