import React, { useRef, KeyboardEvent } from 'react'; import './style.scss'; export interface ConversationInputProps { value: string; onChange: (value: string) => void; onSend: () => void; onStop?: () => void; isStreaming?: boolean; disabled?: boolean; placeholder?: string; maxLength?: number; showCharCount?: boolean; autoResize?: boolean; className?: string; inputClassName?: string; buttonClassName?: string; } export const ConversationInput: React.FC = ({ value, onChange, onSend, onStop, isStreaming = false, disabled = false, placeholder = 'Type your message...', maxLength = 4000, showCharCount = true, autoResize = true, className = '', inputClassName = '', buttonClassName = '' }) => { const textareaRef = useRef(null); const handleSend = () => { const trimmed = value.trim(); if (trimmed && !isStreaming && !disabled) { onSend(); } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; const handleInputChange = (e: React.ChangeEvent) => { const newValue = e.target.value; if (newValue.length <= maxLength) { onChange(newValue); // Auto-resize textarea if (autoResize && textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`; } } }; const handleStop = () => { if (onStop) { onStop(); } }; const isDisabled = disabled || (!value.trim() && !isStreaming); return (