Join the Discord!
Buttons

Copy Button

Animated copy button with visual feedback and state management. Perfect for React applications requiring clipboard functionality with Next.js integration and TypeScript support.

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/copy-button.json
npx shadcn@latest add https://www.shadcn.io/registry/copy-button.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/copy-button.json
bunx shadcn@latest add https://www.shadcn.io/registry/copy-button.json

Features

  • Animated state transitions with smooth scale effects using Motion (Framer Motion)
  • Visual feedback showing copy success with animated icon swap
  • Multiple variants including default, ghost, outline, secondary, muted, and destructive
  • Four size options from small to large with proportional icon scaling
  • TypeScript support with complete type definitions for all props
  • Controlled and uncontrolled modes for flexible state management

Examples

Variants

Loading component...

Display different button styles for various UI contexts and design systems.

Sizes

Loading component...

Scale the button and icon appropriately for different interface densities.

Use Cases

This free open source React component works well for:

  • Code snippets - Copy code examples in documentation built with Next.js
  • Share functionality - Copy URLs or share links using TypeScript and Tailwind CSS
  • Form fields - Quick copy for API keys, tokens, or configuration values
  • Data tables - Copy cell values or row data with shadcn/ui integration
  • Command palettes - Copy commands or shortcuts in developer tools

API Reference

CopyButton

PropTypeDefaultDescription
contentstring-The text content to copy to clipboard
variant"default" | "ghost" | "outline" | "secondary" | "muted" | "destructive""default"Visual style variant
size"sm" | "default" | "md" | "lg""default"Button and icon size
delaynumber3000Duration in ms before resetting to copy state
onCopy(content: string) => void-Callback when content is copied
isCopiedboolean-Controlled copy state
onCopyChange(isCopied: boolean) => void-Callback when copy state changes
classNamestring-Additional CSS classes

Size Specifications

  • sm - 24x24px button, 12x12px icon
  • default - 32x32px button, 16x16px icon
  • md - 40x40px button, 20x20px icon
  • lg - 48x48px button, 24x24px icon

Implementation Notes

  • Uses native Clipboard API (navigator.clipboard.writeText)
  • Automatically handles copy state with configurable reset delay
  • Supports both controlled and uncontrolled usage patterns
  • Icon animation provides clear visual feedback
  • Falls back gracefully if clipboard access fails
  • Compatible with shadcn/ui design system tokens