Copy Button

Copies text and swaps its icon in a quick blur crossfade.

copy-button.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/copy-button.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/copy-button.json

3

Turn on the motion

npx @prequelui/cli@latest animate copy-button

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

copy-button.tsx
import { Check, Copy } from "lucide-react";
import { CopyButton, CopyButtonIcon } from "@/components/prequelui/copy-button";

export default function Demo() {
  return (
    <CopyButton content="npx shadcn@latest add button">
      <CopyButtonIcon icon={<Copy />} copiedIcon={<Check />} />
      Copy command
    </CopyButton>
  );
}
import { CopyButton } from "@/components/prequelui/copy-button";

export function Variant() {
  return (
    <CopyButton tempo={1.2}>
      …
    </CopyButton>
  );
}

Animation

Copying swaps one glyph for another in place. The leaving icon shrinks to half, blurs by two pixels and fades in 150 ms while the check takes its place on the same curve; the state returns after three seconds.

  • Icon swap: 150 ms, scale 0.5 → 1, blur 2 px → 0.
  • The button itself keeps the shared press spring.
  • The reset timer is cleared if the button is clicked again.
  • Reduced motion keeps the crossfade and removes scale and blur.
swap 150 msscale 0.5blur 2 pxreset 3 s

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

CopyButton

PropTypeDefault
contentstring—
delaynumber3000
copiedboolean—
defaultCopiedbooleanfalse
onCopiedChange(copied: boolean) => void—

CopyButtonIcon

PropTypeDefault
iconReactNode—
copiedIconReactNode—
transitionTransitioncomponent spring or tween

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026