diff --git a/components/ui/CopyButton.tsx b/components/ui/CopyButton.tsx new file mode 100644 index 0000000..79b3eec --- /dev/null +++ b/components/ui/CopyButton.tsx @@ -0,0 +1,57 @@ +"use client"; + +import { useState, type ReactNode } from "react"; + +type CopyButtonProps = { + value: string; + label: string; + copiedLabel?: string; + className?: string; + children: ReactNode; +}; + +export default function CopyButton({ + value, + label, + copiedLabel = "Copied!", + className = "rounded-md p-1 text-neutral-600 transition-colors duration-200 hover:text-neutral-200", + children, +}: CopyButtonProps) { + const [copied, setCopied] = useState(false); + + const handleCopy = async (e: React.MouseEvent) => { + e.currentTarget.blur(); + try { + await navigator.clipboard.writeText(value); + setCopied(true); + window.setTimeout(() => setCopied(false), 1500); + } catch { + // clipboard unavailable — silently ignore + } + }; + + return ( + + + + {copied ? copiedLabel : label} + + + ); +}