Copy button
One-click clipboard copy action with checkmark icon morph, label crossfade, and self-reverting timer.
Used forCode blocksShare links & invite codesAPI keys & secrets
Install with the shadcn CLI
Where it’s used
Code blocks
Top-right copy button in syntax-highlighted code specimens.
Share links & invite codes
One-tap copy for URLs and referral tokens.
API keys & secrets
Fast copying of sensitive tokens with visual confirmation.
What it handles for you
Copying to clipboard is a standard action that often gives weak or delayed feedback. This button gives immediate tactile response with icon morphing and seamless revert.
Checkmark morph
The copy icon crossfades smoothly into a green checkmark on successful copy.
Optional label crossfade
Supports both compact icon-only mode and text-labeled mode ("Copy" → "Copied!").
Self-reverting timer
Automatically resets back to idle after a configurable timeout (default 2000ms).
Accessible announcement
Screen readers hear "Copied!" via an aria-live polite status region.
Overview
A micro-action button engineered for copying code snippets, markdown blocks, URLs, and API keys. On click, the copy icon smoothly morphs into an animated checkmark, optional labels crossfade without layout jumps, and an accessible screen-reader announcement is dispatched.
States
- idle
- Copy icon with title tooltip.
- copied
- Emerald checkmark morph with "Copied!" feedback and status announcement.
Usage
Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.
Props
| Prop | Type | Description |
|---|---|---|
| text | string | The string to copy to the user’s clipboard. |
| label | stringdefault "Copy" | Text shown when idle. |
| copiedLabel | stringdefault "Copied!" | Text shown when successfully copied. |
| showLabel | booleandefault false | Whether to show the text label beside the icon. |
| timeoutMs | numberdefault 2000 | Duration in milliseconds before reverting back to idle. |
| variant | "secondary" | "outline" | "ghost"default "ghost" | Visual appearance. |
| size | "xs" | "sm" | "md"default "sm" | Height and icon scale. |
Accessibility and motion
- Uses navigator.clipboard with fallback for older browsers or non-secure contexts.
- Screen readers announce "Copied!" automatically via aria-live.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
The CLI also installs ui-interaction-motion.
Source
Registry item: /r/copy-button.json