UNPKG

@plteam/chat-ui

Version:

CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript

25 lines (24 loc) 1.36 kB
import * as React from 'react'; import Box from '@mui/material/Box'; import { useChatSlots } from '../core/ChatSlotsContext'; import { useChatContext } from '../core/ChatGlobalContext'; import { motion } from '../../utils/materialDesign/motion'; import { ChatViewConstants } from '../../views/ChatViewConstants'; const SendMessageButton = ({ onSendMessage, isTyping, disabled }) => { const { slots, slotProps } = useChatSlots(); const { handleStopMessageStreaming } = useChatContext(); const onClick = () => { if (isTyping) { handleStopMessageStreaming?.(); } else { onSendMessage(); } }; return (React.createElement(Box, { width: ChatViewConstants.INPUT_BUTTON_SIZE, height: ChatViewConstants.INPUT_BUTTON_SIZE }, React.createElement(slots.sendMessageButton, { ...slotProps.sendMessageButton, disabled: disabled || (!handleStopMessageStreaming && !!isTyping), sx: { transition: (theme) => theme.transitions.create('color', { duration: motion.duration.short4 }), ...slotProps.sendMessageButton?.sx, }, onClick: onClick }, (!!isTyping && !!handleStopMessageStreaming) ? React.createElement(slots.stopStreamIcon, null) : React.createElement(slots.sendMessageIcon, null)))); }; export default SendMessageButton;