'use client'; import { memo } from 'react'; import { Copy, Pencil, RefreshCw, Trash } from 'lucide-react'; import { cn } from '@djangocfg/ui-core/lib'; import { useChatDestructiveStyles } from '../styles'; import type { ChatRole } from '../types'; export interface MessageActionsProps { role: ChatRole; onCopy?: () => void; onRegenerate?: () => void; onEdit?: () => void; onDelete?: () => void; hideOn?: Array; className?: string; } /** * MessageActions — copy/regenerate/edit/delete buttons for a chat bubble. * * Memoised: re-renders only when `role`, `hideOn`, `className` or * any handler reference changes. Event handlers are compared by * reference — callers should stabilise them with useCallback. */ function MessageActionsRaw({ role, onCopy, onRegenerate, onEdit, onDelete, hideOn, className, }: MessageActionsProps) { if (hideOn?.includes(role)) return null; return (
{onCopy ? : null} {onRegenerate && role === 'assistant' ? ( ) : null} {onEdit && role === 'user' ? ( ) : null} {onDelete ? : null}
); } const ActionButton = memo(function ActionButton({ onClick, label, icon: Icon, destructive, }: { onClick: () => void; label: string; icon: typeof Copy; destructive?: boolean; }) { const styles = useChatDestructiveStyles(); return ( ); }); export const MessageActions = memo(MessageActionsRaw);