import React, { useCallback, useRef, useState } from "react"; type ChatMessageInputProps = { placeholder: string; onSend?: (message: string) => void; onStartStop?: () => void; }; export const ChatMessageInput = ({ placeholder, onSend, onStartStop }: ChatMessageInputProps) => { const [message, setMessage] = useState(""); const [isRecording, setIsRecording] = useState(false); const inputRef = useRef(null); const handleSend = useCallback(() => { if (!onSend) { return; } if (message === "") { return; } onSend(message); setMessage(""); }, [onSend, message]); const handleStartStop = useCallback(() => { if (!onStartStop) { return; } setIsRecording(!isRecording); onStartStop(); }, [isRecording, onStartStop]); return (
0 ? 12 : 24, caretShape: "block", }} placeholder={placeholder} value={message} onChange={(e: React.ChangeEvent) => { e.target?.value && setMessage(e.target.value); }} onKeyDown={(e: React.KeyboardEvent) => { if (e.key === "Enter") { handleSend(); } }} />
); };