Components / AI Chat Interfaces
AI Chat Input Bar
A modern chat input bar with send button, attachment support, and auto-resize textarea for AI conversation interfaces.
Components / AI Chat Interfaces
A modern chat input bar with send button, attachment support, and auto-resize textarea for AI conversation interfaces.
"use client";
import React, { useState, useRef } from "react";
import { Send, Paperclip, Mic } from "lucide-react";
interface AIChatInputProps {
onSend?: (message: string) => void;
placeholder?: string;
disabled?: boolean;
}
export default function AIChatInput({ onSend, placeholder = "Ask anything...", disabled = false }: AIChatInputProps) {
const [value, setValue] = useState("");
const textareaRef = useRef<HTMLTextAreaElement>(null);
const handleSend = () => {
if (!value.trim() || disabled) return;
onSend?.(value.trim());
setValue("");
if (textareaRef.current) textareaRef.current.style.height = "auto";
};
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
handleSend();
}
};
const handleInput = () => {
const el = textareaRef.current;
if (el) {
el.style.height = "auto";
el.style.height = Math.min(el.scrollHeight, 160) + "px";
}
};
return (
<div className="flex items-end gap-2 rounded-2xl border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 p-3 shadow-sm">
<button className="p-2 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300 transition-colors rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800">
<Paperclip className="h-5 w-5" />
</button>
<textarea
ref={textareaRef}
value={value}
onChange={(e) => setValue(e.target.value)}
onKeyDown={handleKeyDown}
onInput={handleInput}
placeholder={placeholder}
disabled={disabled}
rows={1}
className="flex-1 resize-none bg-transparent text-sm text-zinc-900 dark:text-zinc-100 placeholder:text-zinc-400 focus:outline-none max-h-40"
/>
<button className="p-2 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300 transition-colors rounded-lg hover:bg-zinc-100 dark:hover:bg-zinc-800">
<Mic className="h-5 w-5" />
</button>
<button
onClick={handleSend}
disabled={!value.trim() || disabled}
className="p-2 rounded-xl bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
>
<Send className="h-5 w-5" />
</button>
</div>
);
}react lucide-react npm install react lucide-react