Open History to see the last commit
1import { memo, useCallback, useState } from "react";
2import { CopyIcon, CheckIcon } from "lucide-react";
3import { Button } from "../ui/button";
4
5export const MessageCopyButton = memo(function MessageCopyButton({ text }: { text: string }) {
6 const [copied, setCopied] = useState(false);
7
8 const handleCopy = useCallback(() => {
9 void navigator.clipboard.writeText(text);
10 setCopied(true);
11 setTimeout(() => setCopied(false), 2000);
12 }, [text]);
13
14 return (
15 <Button type="button" size="xs" variant="outline" onClick={handleCopy} title="Copy message">
16 {copied ? <CheckIcon className="size-3 text-success" /> : <CopyIcon className="size-3" />}
17 </Button>
18 );
19});