mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-20 15:31:37 +01:00
Proxy viewer extraction: response viewers into packages/ui (#754)
This commit is contained in:
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();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user