-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMessageCopyButton.tsx
More file actions
32 lines (30 loc) · 857 Bytes
/
MessageCopyButton.tsx
File metadata and controls
32 lines (30 loc) · 857 Bytes
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
import { memo } from "react";
import { CopyIcon, CheckIcon } from "lucide-react";
import { Button } from "../ui/button";
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
import { cn } from "~/lib/utils";
export const MessageCopyButton = memo(function MessageCopyButton({
text,
label = "message",
className,
}: {
text: string;
label?: string;
className?: string;
}) {
const { copyToClipboard, isCopied } = useCopyToClipboard();
const title = isCopied ? "Copied" : `Copy ${label}`;
return (
<Button
type="button"
size="xs"
variant="outline"
className={cn("gap-1.5", className)}
onClick={() => copyToClipboard(text)}
title={title}
aria-label={title}
>
{isCopied ? <CheckIcon className="size-3 text-success" /> : <CopyIcon className="size-3" />}
</Button>
);
});