import { ClipboardCheckIcon, ClipboardIcon } from "lucide-react"; import { useState } from "react"; import { SimpleTooltip } from "~/components/primitives/Tooltip"; import { useCopy } from "~/hooks/useCopy"; import { cn } from "~/utils/cn"; import { Button } from "./Buttons"; export function CopyableText({ value, copyValue, className, asChild, variant, }: { value: string; copyValue?: string; className?: string; asChild?: boolean; variant?: "icon-right" | "text-below"; }) { const [isHovered, setIsHovered] = useState(false); const { copy, copied } = useCopy(copyValue ?? value); const resolvedVariant = variant ?? "icon-right"; if (resolvedVariant === "icon-right") { return ( setIsHovered(false)} > setIsHovered(true)}>{value} e.stopPropagation()} className={cn( "absolute -right-6 top-0 z-10 size-6 font-sans", isHovered ? "flex" : "hidden" )} > {copied ? ( ) : ( )} } content={copied ? "Copied!" : "Copy"} className="font-sans" disableHoverableContent asChild={asChild} /> ); } if (resolvedVariant === "text-below") { return ( { e.stopPropagation(); copy(); }} className={cn( "cursor-pointer bg-transparent px-1 py-0 text-left text-text-dimmed transition-colors hover:bg-transparent", className )} > {value} } content={copied ? "Copied" : "Copy"} className="px-2 py-1 font-sans" disableHoverableContent open={isHovered || copied} onOpenChange={setIsHovered} asChild /> ); } return null; }