Skip to main content
Our new developer certification is live!

CopyButton

Client-side component for copying text to the clipboard with visual feedback.

Props

PropTypeRequiredDefaultDescription
codestringYes-The text content to copy
classNamestringNo-Additional CSS classes

Usage

import { CopyButton } from '@/components/atoms/CopyButton';

<CopyButton code={codeToCopy} />

Features

  • Clipboard API: Uses modern navigator.clipboard API
  • Fallback support: Falls back to document.execCommand for older browsers
  • Visual feedback: Shows "Copied!" message for 2 seconds
  • Accessible: Includes proper ARIA labels
  • Design system: Uses shared Button component with consistent styling

Styling

The button uses:

  • variant="ghost" with custom dark overlay background
  • size="sm" for compact size
  • Positioned absolutely in top-right corner
  • Subtle hover effects

Notes

  • This is a client component ("use client") due to clipboard API usage
  • The button is typically positioned absolutely within a relative container
  • Copy feedback timeout is 2000ms (2 seconds)
  • Uses the shared Button component for consistency