import { useState } from 'react'; import { Copy, Check } from 'lucide-react'; interface CopyButtonProps { value: string; className?: string; size?: 'sm' | 'md'; title?: string; } export default function CopyButton({ value, className = '', size = 'sm', title = 'In Zwischenablage kopieren' }: CopyButtonProps) { const [copied, setCopied] = useState(false); const handleCopy = async (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); try { await navigator.clipboard.writeText(value); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch (err) { console.error('Failed to copy:', err); } }; const iconSize = size === 'sm' ? 'w-3.5 h-3.5' : 'w-4 h-4'; return ( ); } // Wrapper component for displaying a value with copy button interface CopyableValueProps { value: string | number | null | undefined; label?: string; className?: string; multiline?: boolean; } export function CopyableValue({ value, label, className = '', multiline = false }: CopyableValueProps) { if (value === null || value === undefined || value === '') return null; const stringValue = String(value); return (
{label &&
{label}
}
{stringValue}
); } // For copying multiple values at once (e.g., full address) interface CopyableBlockProps { values: (string | number | null | undefined)[]; separator?: string; children: React.ReactNode; className?: string; } export function CopyableBlock({ values, separator = '\n', children, className = '' }: CopyableBlockProps) { const combinedValue = values .filter(v => v !== null && v !== undefined && v !== '') .map(String) .join(separator); if (!combinedValue) return <>{children}; return (
{children}
); }