Copy button

Free

A button that copies a link, an ID or a snippet and says so: the icon swaps to a check that draws itself and the label to Copied, at a width that never moves.

npx shadcn@latest add @pixilui/copy-button

Preview

The copy icon swaps to a check that draws itself; the width holds.
Show

When to use

Use it when

  • Copying something a person pastes elsewhere: a share link, an API key's prefix, a run ID, a code block.
  • Icon-only beside a value in a table row or under a message, with an aria-label.

Use something else when

  • Copying a whole message among other message actions: use Message actions, which holds this copy with regenerate and feedback.
  • Secrets shown once: pair the copy with a clear warning on the page, not a toast.

Installation

Terminal
npx shadcn@latest add @pixilui/copy-button

Adds copy-button.tsx with button.tsx, and installs clsx and tailwind-merge. First PixilUI item in this app? Add the registry once, as in Installation.

Usage

example.tsx
import { CopyButton } from "@/components/pixilui/copy-button";

<CopyButton
  value={value}
  icon={icon}
  onCopied={onCopied}
  onCopyError={onCopyError}
/>

Never wider than its container. Icon-only sizes keep a 40px hit area on desktop and 44 on touch.

API reference

PropTypeDefault
valueRequiredstring | (() => string | Promise<string>)–What lands on the clipboard: a string, or a function that returns one when pressed.
iconRequiredReactNode–The copy icon (Lucide Copy, say). The check that replaces it is the button's own.
variantButtonVariant–Visual weight, as on Button. secondary (the glass) is the default; secondary-2 suits a row of message actions.
sizeButtonSize–Height, as on Button: xs 24, sm 28, md 32 (default), lg 36, xl 44.
labelstring–The label at rest. Leave it out for an icon-only button, and pass aria-label.
copiedLabelstring"Copied"The label while the copy shows.
resetAfternumberRESET_MSHow long Copied shows before the button returns, in ms.

Keyboard

TabMoves focus to the button.
EnterCopies the value; focus stays on the button while Copied shows.
SpaceCopies the value on release.

Accessibility

  • A native button. The label changes to Copied, so screen readers hear the result when they read the button again.
  • Icon-only needs aria-label ("Copy run ID"); it defaults to Copy.
  • The check is aria-hidden; the swapped label carries the meaning.
  • data-status is copied or idle, for styling and tests.

Motion

  • The copy icon swaps deep (scale .3 with a 3px blur) to a check that draws itself in 260ms.
  • The word swaps on the same curve; reserve holds the wider of Copy link and Copied, so the width never moves.
  • Copied returns to rest after 1600ms (resetAfter).
  • Reduced motion: the icon and the word change at once, with no draw.

PixilUI Pro opens Thu 10 Dec. The first 20 licenses are $99.