Black Friday is here 🔥 Get Wensity Pro for 20% less with

Copy Button

React copy to clipboard button whose icon morphs into a check as it turns green.

copy buttoncopy to clipboardclipboardbuttoncss animation
Copy Button component preview

Overview

Copy Button is a React and Tailwind CSS copy to clipboard button whose icon morphs into a check, in Next.js or any React app. On success the back sheet tucks away, a check draws itself, and a solid green layer spreads from the point you pressed. Pass value as a string or as a function that returns one, sync or async. A blocked clipboard shows a red cross and calls onCopyError rather than faking success. The label keeps its width as Copy becomes Copied, a polite live region announces the result, and reduced motion swaps icons with a quick fade.

Installation

Run the following command

~/your-project
pnpm dlx wensity@latest add copy-button

Usage

Import CopyButton from @/components/wensity/copy-button and render it anywhere in your React or Next.js app. The source lands in your own repo, so every prop, class and animation below is yours to edit.

app/example.tsx
import { CopyButton } from "@/components/wensity/copy-button";
export default function Example() {
return (
<div className="flex items-center gap-3">
<CopyButton value="npm install framer-motion" aria-label="Copy command" />
<CopyButton value="https://example.com/invite/42" variant="label" />
</div>
);
}

Props

PropTypeDefaultDescription
valuestring | (() => string | Promise<string>)-Text to copy, or a function that returns it, sync or async.
variant"icon" | "label""icon"Icon only, or icon with a label that rolls from Copy to Copied.
appearance"solid" | "ghost""solid"Solid is a raised button that fills with the tone. Ghost stays bare and only its icon and label take the tone.
size"sm" | "md" | "lg""md"28, 34 or 42 pixels tall.
tone"green" | "blue" | "violet" | "amber" | "mono""green"Colour the button turns once the copy lands.
timeoutnumber1600How long the check stays, in milliseconds.
sweepbooleantrueSpread the success fill from the point that was pressed.
labels{ copy?: string; copied?: string; failed?: string }-Words for the label, the aria-label and the screen reader announcement.
onCopied(text: string) => void-Called with the copied text.
onCopyError(error: unknown) => void-Called when the clipboard write fails. The button shows a red cross.
  • macOS Floating Dock component preview

    macOS Floating Dock

    A magnetic dock where icons inflate near the cursor and push their siblings aside.

  • Multi-Select Tag Input component preview

    Multi-Select Tag Input

    A tag input where pills pop in as you add them and slide out on remove, closing the gap without snapping the layout.

  • Shimmering Skeleton Wrapper component preview

    Shimmering Skeleton Wrapper

    One angled GPU sweep that travels across any placeholder geometry you wrap, never a separate shimmer stuttering per row.

  • Cool Button component preview

    Cool Button

    A dual-layer orbit glow that soft-spins around the edge of any button or link you wrap it around, at zero layout cost.