Skip to content
Hazine

Copy Button

Button that writes a string to the clipboard, confirms with a check icon for two seconds and announces the result. It also reports a rejected clipboard write.

How it differs. The smallest copy primitive: one icon or icon plus label button with idle, copied and failed states, a stable name and feedback through a status region.

Install

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

Adds 1 file, 1 shadcn primitive (button), 1 package (lucide-react), and the success token.

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props6

valuerequired
string
Text written to the clipboard.
timeout
number = 2000
Milliseconds the result stays visible before the button returns to rest.
copyLabel
string = "Copy to clipboard"
Accessible name of the icon-only button. It does not change with the result.
copiedLabel
string = "Copied"
Announced after a successful copy.
failedLabel
string = "Copy failed. Select the text manually."
Announced when the browser rejects the clipboard write.
onValueCopy
(value: string) => void

Also accepts every prop of Omit<React.ComponentProps<typeof Button>, "value">.

Accessibility

Keyboard
Keyboard support for Copy Button
KeyEffect
Enter or SpaceCopies the value and announces the result
Screen reader

A native button whose accessible name stays the same in every state. The result is announced by a status region next to the button.

  • Announces: Copied
  • Announces: Copy failed. Select the text manually.
Reduced motion
No motion. The icon swaps without a transition.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies2

  • button
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped2

  • --success
  • --success-foreground

Added to your stylesheet in light and dark, unless you already define them.

More in Buttons and Actions