forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageCopyButton.tsx
More file actions
27 lines (25 loc) · 852 Bytes
/
Copy pathMessageCopyButton.tsx
File metadata and controls
27 lines (25 loc) · 852 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
import { memo } from "react";
import { CopyIcon, CheckIcon } from "lucide-react";
import { Button } from "../ui/button";
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
export const MessageCopyButton = memo(function MessageCopyButton({
text,
label = "Copy message",
}: {
text: string | (() => string);
label?: string;
}) {
const { copyToClipboard, isCopied } = useCopyToClipboard();
return (
<Button
type="button"
size="xs"
variant="outline"
onClick={() => copyToClipboard(typeof text === "function" ? text() : text)}
title={isCopied ? label.replace(/^Copy\s+/i, "Copied ") : label}
aria-label={isCopied ? label.replace(/^Copy\s+/i, "Copied ") : label}
>
{isCopied ? <CheckIcon className="size-3 text-success" /> : <CopyIcon className="size-3" />}
</Button>
);
});