'use client'; import { cn } from '@/lib/utils'; import { Check } from 'lucide-react'; import { useState } from 'react'; import { toast } from 'sonner'; import { CopyIcon } from './animated-icons/copy'; import { Button } from './button'; interface CopyProps { value: string; /** * Optional display text. If not provided, will display the value */ displayText?: string; /** * Optional success message. Defaults to "Copied to clipboard!" */ successMessage?: string; /** * Optional className for the container */ className?: string; } export function CopyToClipboard({ value, displayText = '', successMessage = 'Copied to clipboard!', className }: CopyProps) { const [hasCopied, setHasCopied] = useState(false); const handleCopy = async () => { await navigator.clipboard.writeText(value); setHasCopied(true); toast.success(successMessage); // Reset copy icon after 2 seconds setTimeout(() => { setHasCopied(false); }, 2000); }; return (
{displayText ?? value}
); }