Elffuss BraidHub

kikocis/continue public

4e3281ed77e4 · 1.0 KiBRawPermalink
1import { CheckIcon, ClipboardIcon } from "@heroicons/react/24/outline";
2import HeaderButtonWithToolTip from "./HeaderButtonWithToolTip";
3import useCopy from "../../hooks/useCopy";
4
5interface CopyIconButtonProps {
6 text: string | (() => string);
7 tabIndex?: number;
8 checkIconClassName?: string;
9 clipboardIconClassName?: string;
10 tooltipPlacement?: "top" | "bottom";
11}
12
13export function CopyIconButton({
14 text,
15 tabIndex,
16 checkIconClassName = "h-4 w-4 text-green-400",
17 clipboardIconClassName = "h-4 w-4 text-gray-400",
18 tooltipPlacement = "bottom",
19}: CopyIconButtonProps) {
20 const { copyText, copied } = useCopy(text);
21
22 return (
23 <>
24 <HeaderButtonWithToolTip
25 tooltipPlacement={tooltipPlacement}
26 tabIndex={tabIndex}
27 text={copied ? "Copied" : "Copy"}
28 onClick={copyText}
29 >
30 {copied ? (
31 <CheckIcon className={checkIconClassName} />
32 ) : (
33 <ClipboardIcon className={clipboardIconClassName} />
34 )}
35 </HeaderButtonWithToolTip>
36 </>
37 );
38}