2023-06-13 23:58:59 +04:00
|
|
|
'use client'
|
|
|
|
|
|
2023-06-16 21:52:01 +04:00
|
|
|
import { type Message } from 'ai-connector'
|
|
|
|
|
|
2023-06-13 23:58:59 +04:00
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
import { IconCheck, IconCopy } from '@/components/ui/icons'
|
|
|
|
|
import { useCopyToClipboard } from '@/lib/hooks/use-copy-to-clipboard'
|
|
|
|
|
import { cn } from '@/lib/utils'
|
|
|
|
|
|
|
|
|
|
interface ChatMessageActionsProps extends React.ComponentProps<'div'> {
|
|
|
|
|
message: Message
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ChatMessageActions({
|
|
|
|
|
message,
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: ChatMessageActionsProps) {
|
|
|
|
|
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 })
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
2023-06-15 11:31:03 +04:00
|
|
|
'flex items-center justify-end transition-opacity group-hover:opacity-100 md:absolute md:-right-10 md:-top-2 md:opacity-0',
|
2023-06-13 23:58:59 +04:00
|
|
|
className
|
|
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={() => copyToClipboard(message.content)}
|
|
|
|
|
>
|
|
|
|
|
{isCopied ? <IconCheck /> : <IconCopy />}
|
|
|
|
|
<span className="sr-only">Copy message</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|