diff --git a/components/chat-input.tsx b/components/chat-input.tsx new file mode 100644 index 0000000..f764b6b --- /dev/null +++ b/components/chat-input.tsx @@ -0,0 +1,71 @@ +"use client" + +import React, { useCallback, useRef, useEffect } from "react" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { Loader2, Send } from "lucide-react" + +interface ChatInputProps { + input: string + isLoading: boolean + onSubmit: (e: React.FormEvent) => void + onChange: (e: React.ChangeEvent) => void +} + +export function ChatInput({ input, isLoading, onSubmit, onChange }: ChatInputProps) { + const textareaRef = useRef(null) + + // Auto-resize textarea based on content + const adjustTextareaHeight = useCallback(() => { + const textarea = textareaRef.current + if (textarea) { + textarea.style.height = "auto" + textarea.style.height = `${Math.min(textarea.scrollHeight, 200)}px` + } + }, []) + + useEffect(() => { + adjustTextareaHeight() + }, [input, adjustTextareaHeight]) + + // Handle keyboard shortcuts + const handleKeyDown = (e: React.KeyboardEvent) => { + if ((e.metaKey || e.ctrlKey) && e.key === "Enter") { + e.preventDefault() + const form = e.currentTarget.closest("form") + if (form && input.trim() && !isLoading) { + form.requestSubmit() + } + } + } + + return ( +
+