ai-input
dedevs-ui/ai-inputFreeComponent
AI chat input component with advanced features
See it running
Open the demo on dedevs-ui
ui.dedevs.com/components/ai-inputInstall it
npx shadcn@latest add https://ui.dedevs.com/r/ai-input.jsonSource
1'use client';23import { Loader2Icon, Send, SquareIcon, X } from 'lucide-react';4import type {5 ComponentProps,6 HTMLAttributes,7 KeyboardEventHandler,8} from 'react';9import { Children, useCallback, useEffect, useRef } from 'react';10import { Button } from '@repo/shadcn-ui/components/ui/button';11import {12 Select,13 SelectContent,14 SelectItem,15 SelectTrigger,16 SelectValue,17} from '@repo/shadcn-ui/components/ui/select';18import { Textarea } from '@repo/shadcn-ui/components/ui/textarea';19import { cn } from '@repo/shadcn-ui/lib/utils';2021type UseAutoResizeTextareaProps = {22 minHeight: number;23 maxHeight?: number;24};2526const useAutoResizeTextarea = ({27 minHeight,28 maxHeight,29}: UseAutoResizeTextareaProps) => {30 const textareaRef = useRef<HTMLTextAreaElement>(null);3132 const adjustHeight = useCallback(33 (reset?: boolean) => {34 const textarea = textareaRef.current;35 if (!textarea) {36 return;37 }3839 if (reset) {40 textarea.style.height = `${minHeight}px`;41 return;42 }4344 // Temporarily shrink to get the right scrollHeight45 textarea.style.height = `${minHeight}px`;4647 // Calculate new height48 const newHeight = Math.max(49 minHeight,50 Math.min(textarea.scrollHeight, maxHeight ?? Number.POSITIVE_INFINITY)51 );5253 textarea.style.height = `${newHeight}px`;54 },55 [minHeight, maxHeight]56 );5758 useEffect(() => {59 // Set initial height60 const textarea = textareaRef.current;61 if (textarea) {62 textarea.style.height = `${minHeight}px`;63 }64 }, [minHeight]);6566 // Adjust height on window resize67 useEffect(() => {68 const handleResize = () => adjustHeight();69 window.addEventListener('resize', handleResize);70 return () => window.removeEventListener('resize', handleResize);71 }, [adjustHeight]);7273 return { textareaRef, adjustHeight };74};7576export type AIInputProps = HTMLAttributes<HTMLFormElement>;7778export const AIInput = ({ className, ...props }: AIInputProps) => (79 <form80 className={cn(81 'w-full divide-y overflow-hidden rounded-xl border bg-background shadow-sm',82 className83 )}84 {...props}85 />86);8788export type AIInputTextareaProps = ComponentProps<typeof Textarea> & {89 minHeight?: number;90 maxHeight?: number;91};9293export const AIInputTextarea = ({94 onChange,95 className,96 placeholder = 'What would you like to know?',97 minHeight = 48,98 maxHeight = 164,99 ...props100}: AIInputTextareaProps) => {101// … truncated
Files it writes
More from dedevs-ui
All 30 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-branchai-branch | dedevs-ui | Components | Free | no deps | |
| ai-conversationai-conversation | dedevs-ui | Components | Free | no deps | |
| ai-messageai-message | dedevs-ui | Components | Free | no deps | |
| ai-reasoningai-reasoning | dedevs-ui | Components | Free | no deps | |
| ai-responseai-response | dedevs-ui | Components | Free | no deps | |
| ai-serverai-server | dedevs-ui | Components | Free | no deps | |
| ai-simpleai-simple | dedevs-ui | Components | Free | no deps | |
| ai-sourceai-source | dedevs-ui | Components | Free | no deps |
