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.
Powered by
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
Display different button styles for various UI contexts and design systems.
Sizes
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
Prop | Type | Default | Description |
---|---|---|---|
content | string | - | 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 |
delay | number | 3000 | Duration in ms before resetting to copy state |
onCopy | (content: string) => void | - | Callback when content is copied |
isCopied | boolean | - | Controlled copy state |
onCopyChange | (isCopied: boolean) => void | - | Callback when copy state changes |
className | string | - | Additional CSS classes |
Size Specifications
sm
- 24x24px button, 12x12px icondefault
- 32x32px button, 16x16px iconmd
- 40x40px button, 20x20px iconlg
- 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
Wavy
Organic wave animations with simplex noise and customizable gradients. Perfect for React hero sections requiring fluid visual effects with Next.js integration and TypeScript support.
Flip Button
Animated flip button with customizable text and transitions. Perfect for React applications requiring interactive buttons with Next.js integration and TypeScript support.