import { useState, useRef, useEffect, type KeyboardEvent } from "react"; import { Send, Square } from "lucide-react"; import { motion } from "motion/react"; interface ChatInputBarProps { onSendMessage: (message: string) => void; disabled?: boolean; } export function ChatInputBar({ onSendMessage, disabled = false }: ChatInputBarProps) { const [inputText, setInputText] = useState(""); const inputRef = useRef(null); const canSend = inputText.trim().length > 0 && !disabled; const handleSend = () => { if (!canSend) return; onSendMessage(inputText.trim()); setInputText(""); // Reset height after send and refocus setTimeout(() => { if (inputRef.current) { inputRef.current.style.height = "24px"; inputRef.current.focus(); } }, 0); }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key !== "Enter") { return; } // Keep Enter behavior as newline (same as Shift+Enter). // Sending is intentionally limited to the send button. }; // Auto-resize textarea based on content useEffect(() => { if (inputRef.current) { inputRef.current.style.height = "auto"; const scrollHeight = inputRef.current.scrollHeight; const maxHeight = 96; // max-h-24 = 6rem = 96px inputRef.current.style.height = `${Math.min(scrollHeight, maxHeight)}px`; } }, [inputText]); return (
{/* Text Input */}