Files
paperclip/ui/src/components/CopyText.tsx
Forgotten ef7a7ecee8 UI: Identity component, LiveRunWidget, issue identifiers, and UX improvements
Add Identity component (avatar + name) used across agent/issue displays. Add
LiveRunWidget for real-time streaming of active heartbeat runs on issue detail
pages via WebSocket. Display issue identifiers (PAP-42) instead of UUID
fragments throughout Issues, Inbox, CommandPalette, and detail pages.
Enhance CommentThread with re-open checkbox, Cmd+Enter submit, sorted display,
and run linking. Improve Activity page with richer formatting and filtering.
Update Dashboard with live metrics. Add reports-to agent link in AgentProperties.
Various small fixes: StatusIcon centering, CopyText ref init, agent detail
run-issue cross-links.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 09:10:07 -06:00

49 lines
1.5 KiB
TypeScript

import { useCallback, useRef, useState } from "react";
import { cn } from "@/lib/utils";
interface CopyTextProps {
text: string;
/** What to display. Defaults to `text`. */
children?: React.ReactNode;
className?: string;
/** Tooltip message shown after copying. Default: "Copied!" */
copiedLabel?: string;
}
export function CopyText({ text, children, className, copiedLabel = "Copied!" }: CopyTextProps) {
const [visible, setVisible] = useState(false);
const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
const triggerRef = useRef<HTMLButtonElement>(null);
const handleClick = useCallback(() => {
navigator.clipboard.writeText(text);
clearTimeout(timerRef.current);
setVisible(true);
timerRef.current = setTimeout(() => setVisible(false), 1500);
}, [text]);
return (
<span className="relative inline-flex">
<button
ref={triggerRef}
type="button"
className={cn(
"cursor-copy hover:text-foreground transition-colors",
className,
)}
onClick={handleClick}
>
{children ?? text}
</button>
<span
className={cn(
"pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1.5 rounded-md bg-foreground text-background px-2 py-1 text-xs whitespace-nowrap transition-opacity duration-300",
visible ? "opacity-100" : "opacity-0",
)}
>
{copiedLabel}
</span>
</span>
);
}