| 6 | import { cn } from '@/lib/utils' |
| 7 | |
| 8 | export function CopyButton({ |
| 9 | value, |
| 10 | className, |
| 11 | }: { |
| 12 | value: string |
| 13 | className?: string |
| 14 | }) { |
| 15 | const [copied, setCopied] = useState(false) |
| 16 | |
| 17 | const handleCopy = () => { |
| 18 | navigator.clipboard.writeText(value) |
| 19 | setCopied(true) |
| 20 | setTimeout(() => setCopied(false), 2000) |
| 21 | } |
| 22 | |
| 23 | return ( |
| 24 | <button |
| 25 | onClick={handleCopy} |
| 26 | className={cn( |
| 27 | 'p-1.5 rounded-md transition-colors hover:bg-white/10', |
| 28 | className, |
| 29 | )} |
| 30 | aria-label={`Copy: ${value}`} |
| 31 | > |
| 32 | {copied ? ( |
| 33 | <Check className="h-4 w-4 text-acid-matrix" /> |
| 34 | ) : ( |
| 35 | <Copy className="h-4 w-4 text-white/60" /> |
| 36 | )} |
| 37 | </button> |
| 38 | ) |
| 39 | } |