diff --git a/frontend/src/components/CopyToClipboard.tsx b/frontend/src/components/CopyToClipboard.tsx new file mode 100644 index 00000000..cbeec3dc --- /dev/null +++ b/frontend/src/components/CopyToClipboard.tsx @@ -0,0 +1,48 @@ +import React, { useState } from 'react'; +import { AlertTriangle, Check, Copy } from 'lucide-react'; + +interface CopyToClipboardProps { + textToCopy: string; +} + +const CopyToClipboard: React.FC = ({ textToCopy }) => { + const [copyState, setCopyState] = useState<'idle' | 'copied' | 'error'>('idle'); + + const handleCopy = async (): Promise => { + if (!textToCopy) return; + try { + await navigator.clipboard.writeText(textToCopy); + setCopyState('copied'); + } catch (err) { + setCopyState('error'); + console.error('Failed to copy text: ', err); + } + setTimeout(() => setCopyState('idle'), 2000); + }; + + const buttonTone = { + idle: 'bg-black/30 border-white/10 text-silver hover:bg-white/5 hover:text-white', + copied: 'bg-green-900/30 border-green-500 text-green-400', + error: 'bg-red-900/30 border-red-500 text-red-300', + }[copyState]; + + const buttonContent = { + idle: { icon: