/** * CopyablePath - Path display with copy-to-clipboard on hover. * Click anywhere on the path row to copy the full absolute path. * A small icon appears on hover as visual affordance. */ import React, { useCallback, useState } from 'react'; import { Check, Copy } from 'lucide-react'; interface CopyablePathProps { /** Shortened path for display */ displayText: string; /** Full absolute path for clipboard */ copyText: string; /** CSS classes for the text span */ className?: string; /** Inline style for the text span */ style?: React.CSSProperties; } export const CopyablePath = ({ displayText, copyText, className = '', style, }: Readonly): React.ReactElement => { const [copied, setCopied] = useState(false); const handleCopy = useCallback( async (e: React.MouseEvent) => { e.stopPropagation(); e.preventDefault(); try { await navigator.clipboard.writeText(copyText); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch { // Clipboard API may not be available in all contexts } }, [copyText] ); return (
{ if (e.key === 'Enter' || e.key === ' ') void handleCopy(e as unknown as React.MouseEvent); }} > {displayText}
); };