Spaces:
Running
Running
File size: 1,110 Bytes
a8e1cb0 3ba9c0c a8e1cb0 3ba9c0c c69ef3e 052672d a8e1cb0 a86b547 3ba9c0c a86b547 3ba9c0c f80b091 3ba9c0c f80b091 3ba9c0c f80b091 3ba9c0c f80b091 3ba9c0c |
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 34 35 36 37 38 39 40 41 42 |
'use client';
import { type Message } from 'ai';
import { Button } from '@/components/ui/Button';
import { IconCheck, IconCopy } from '@/components/ui/Icons';
import { useCopyToClipboard } from '@/lib/hooks/useCopyToClipboard';
import { cn } from '@/lib/utils';
import { MessageBase } from '../../lib/types';
interface ChatMessageActionsProps extends React.ComponentProps<'div'> {
message: MessageBase;
}
export function ChatMessageActions({
message,
className,
...props
}: ChatMessageActionsProps) {
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });
const onCopy = () => {
if (isCopied) return;
copyToClipboard(message.content);
};
return (
<div
className={cn(
'flex items-center justify-end transition-opacity group-hover:opacity-100 md:absolute md:-right-10 md:-top-2 md:opacity-0',
className,
)}
{...props}
>
<Button variant="ghost" size="icon" onClick={onCopy}>
{isCopied ? <IconCheck /> : <IconCopy />}
<span className="sr-only">Copy message</span>
</Button>
</div>
);
}
|