Prompt Input
prompt-kit/prompt-inputFreeComponent
An input field designed for chat interfaces, allowing users to enter and submit text prompts to an AI model
Install it
npx shadcn@latest add https://raw.githubusercontent.com/agents-ui/agents-kit/main/public/c/prompt-input.jsonSource
1"use client"23import { Textarea } from "@/components/ui/textarea"4import {5 Tooltip,6 TooltipContent,7 TooltipProvider,8 TooltipTrigger,9} from "@/components/ui/tooltip"10import { cn } from "@/lib/utils"11import React, {12 createContext,13 useContext,14 useEffect,15 useRef,16 useState,17} from "react"1819type PromptInputContextType = {20 isLoading: boolean21 value: string22 setValue: (value: string) => void23 maxHeight: number | string24 onSubmit?: () => void25 disabled?: boolean26}2728const PromptInputContext = createContext<PromptInputContextType>({29 isLoading: false,30 value: "",31 setValue: () => {},32 maxHeight: 240,33 onSubmit: undefined,34 disabled: false,35})3637function usePromptInput() {38 const context = useContext(PromptInputContext)39 if (!context) {40 throw new Error("usePromptInput must be used within a PromptInput")41 }42 return context43}4445type PromptInputProps = {46 isLoading?: boolean47 value?: string48 onValueChange?: (value: string) => void49 maxHeight?: number | string50 onSubmit?: () => void51 children: React.ReactNode52 className?: string53}5455function PromptInput({56 className,57 isLoading = false,58 maxHeight = 240,59 value,60 onValueChange,61 onSubmit,62 children,63}: PromptInputProps) {64 const [internalValue, setInternalValue] = useState(value || "")6566 const handleChange = (newValue: string) => {67 setInternalValue(newValue)68 onValueChange?.(newValue)69 }7071 return (72 <TooltipProvider>73 <PromptInputContext.Provider74 value={{75 isLoading,76 value: value ?? internalValue,77 setValue: onValueChange ?? handleChange,78 maxHeight,79 onSubmit,80 }}81 >82 <div83 className={cn(84 "border-input bg-background rounded-3xl border p-2 shadow-xs",85 className86 )}87 >88 {children}89 </div>90 </PromptInputContext.Provider>91 </TooltipProvider>92 )93}9495export type PromptInputTextareaProps = {96 disableAutosize?: boolean97} & React.ComponentProps<typeof Textarea>9899function PromptInputTextarea({100 className,101 onKeyDown,102 disableAutosize = false,103 ...props104}: PromptInputTextareaProps) {105 const { value, setValue, maxHeight, onSubmit, disabled } = usePromptInput()106 const textareaRef = useRef<HTMLTextAreaElement>(null)107108 useEffect(() => {109 if (disableAutosize) return110111 if (!textareaRef.current) return112 textareaRef.current.style.height = "auto"113 textareaRef.current.style.height =114// … truncated
What it pulls in
Other registry items
Files it writes
More from prompt-kit
All 12 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Chat Containerchat-container | prompt-kit | Components | Free | 1 dep | |
| Code Blockcode-block | prompt-kit | Components | Free | 1 dep | |
| File Uploadfile-upload | prompt-kit | Components | Free | no deps | |
| Jsx Previewjsx-preview | prompt-kit | Components | Free | 1 dep | |
| Loaderloader | prompt-kit | Components | Free | no deps | |
| Markdownmarkdown | prompt-kit | Components | Free | 4 deps · 2 files | |
| Messagemessage | prompt-kit | Components | Free | 5 deps · 3 files | |
| Prompt Suggestionprompt-suggestion | prompt-kit | Components | Free | 2 deps |
