Proxy viewer extraction: response viewers into packages/ui (#754)

This commit is contained in:
Gregory Schier authored and GitHub committed 2026-10-14 21:32:19 -07:00
1 parent b5508e6bb1
commit b6c1f700f1
137 files changed
+3498 -2890

No files matched your search

@@ -0,0 +1,29 @@
import { useTimedBoolean } from "../hooks/useTimedBoolean";
import { IconButton, type IconButtonProps } from "./IconButton";
export interface CopyIconButtonProps extends Omit<IconButtonProps, "onClick" | "icon"> {
text: string | (() => Promise<string | null>);
copy: (text: string) => void;
/** Called when `text` resolves to nothing */
onCopyFailed?: () => void;
}
export function CopyIconButton({ text, copy, onCopyFailed, ...props }: CopyIconButtonProps) {
const [copied, setCopied] = useTimedBoolean();
return (
<IconButton
{...props}
icon={copied ? "check" : "copy"}
showConfirm
onClick={async () => {
const content = typeof text === "function" ? await text() : text;
if (content == null) {
onCopyFailed?.();
} else {
copy(content);
setCopied();
}
}}
/>
);
}