"use client";; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { cn } from "@/lib/utils"; import { useTextareaResize } from "@/hooks/use-textarea-resize"; import { ArrowUpIcon } from "lucide-react"; import { createContext, useContext } from "react"; const ChatInputContext = createContext({}); function ChatInput({ children, className, variant = "default", value, onChange, onSubmit, loading, onStop, rows = 1 }) { const contextValue = { value, onChange, onSubmit, loading, onStop, variant, rows, }; return ( (
{children}
) ); } ChatInput.displayName = "ChatInput"; function ChatInputTextArea({ onSubmit: onSubmitProp, value: valueProp, onChange: onChangeProp, className, variant: variantProp, ...props }) { const context = useContext(ChatInputContext); const value = valueProp ?? context.value ?? ""; const onChange = onChangeProp ?? context.onChange; const onSubmit = onSubmitProp ?? context.onSubmit; const rows = context.rows ?? 1; // Convert parent variant to textarea variant unless explicitly overridden const variant = variantProp ?? (context.variant === "default" ? "unstyled" : "default"); const textareaRef = useTextareaResize(value, rows); const handleKeyDown = (e) => { if (!onSubmit) { return; } if (e.key === "Enter" && !e.shiftKey) { if (typeof value !== "string" || value.trim().length === 0) { return; } e.preventDefault(); onSubmit(); } }; return ( (