-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Expand file tree
/
Copy pathCopyButton.tsx
More file actions
33 lines (30 loc) · 1.12 KB
/
CopyButton.tsx
File metadata and controls
33 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { CheckIcon, ClipboardIcon } from "@heroicons/react/24/outline";
import useCopy from "../../../hooks/useCopy";
import { ToolTip } from "../../gui/Tooltip";
import HoverItem from "../../mainInput/InputToolbar/HoverItem";
interface CopyButtonProps {
text: string;
}
export function CopyButton({ text }: CopyButtonProps) {
const { copyText, copied } = useCopy(text);
return (
<ToolTip place="top" content="Copy Code">
<HoverItem className="!p-0">
<div
role="button"
aria-label={copied ? "Code copied" : "Copy code block"}
className="text-lightgray flex cursor-pointer items-center border-none bg-transparent text-xs outline-none hover:brightness-125"
onClick={copyText}
>
<div className="flex items-center gap-1 transition-colors duration-200 hover:brightness-125">
{copied ? (
<CheckIcon className="h-3.5 w-3.5 text-green-500 hover:brightness-125" />
) : (
<ClipboardIcon className="h-3.5 w-3.5 hover:brightness-125" />
)}
</div>
</div>
</HoverItem>
</ToolTip>
);
}