Prompt input
FreeA message box with attachments, suggestions, commands and a stop button.
pnpm dlx shadcn@latest add https://caliperui.site/r/prompt-input.jsonWhen to use #
Use it for
- The user writes to an assistant.
- You need slash commands, mentions or file attachments.
Skip it when
- It is a short single-line reply; use the thread composer.
Installation #
terminal
pnpm dlx shadcn@latest add https://caliperui.site/r/prompt-input.json
Adds its 3 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage #
This is the code behind the preview above.
example.tsx
import { useEffect, useRef, useState } from "react" import { PromptInput } from "@/components/ui/prompt-input" type Turn = { id: string; role: "user" | "assistant"; text: string; status?: "pending" | "complete" }; const answers = [ "Here is a short answer. Start with the smallest change, check it with the keyboard, then add polish.", "Good question. I would keep one source of truth and let the components stay controlled.", "That depends on the screen. If you tell me where it lives, I can be more specific.", ]; function useScriptedChat(initial: Turn[]) { const [turns, setTurns] = useState(initial); const n = useRef(0); const timers = useRef<ReturnType<typeof setTimeout>[]>([]); useEffect(() => () => timers.current.forEach(clearTimeout), []); const send = (text: string) => { const id = n.current++; setTurns((t) => [...t, { id: `u${id}-${t.length}`, role: "user", text }, { id: `a${id}-${t.length}`, role: "assistant", text: "", status: "pending" }]); timers.current.push( setTimeout(() => setTurns((t) => t.map((x, i) => (i === t.length - 1 && x.status === "pending" ? { ...x, text: answers[id % answers.length], status: "complete" } : x))), 1100), ); }; return [turns, send, setTurns] as const; } export function PromptInputDemo() { const [, send] = useScriptedChat([{ id: "s0", role: "assistant", text: "Ask me about your projects, like which one needs attention first.", status: "complete" }]); return ( <PromptInput allowFiles={false} placeholder="Ask about this workspace" onSubmit={({ text }) => send(text)} /> ); }
API reference #
PromptInput
component
PropTypeDefaultDescription
labelstring"Message"
placeholderstring"Ask anything"
onSubmit *(message: { text: string; files: File[]; }) => void—
onStop(() => void)—Called by the Stop button, and by Escape while streaming.
streamingboolean—While true the send button becomes Stop and Enter does not send.
disabledboolean—
maxLengthnumber—
suggestionsreadonly string[]—Starter prompts shown while the input is empty.
controlsReactNode—Extra controls on the left of the toolbar, such as a model select.
acceptstring—
maxFilesnumber4
maxFileSizenumber5 * 1024 * 1024
allowFilesbooleantrue
classNamestring—
Accessibility #
It exposes group and alert semantics, with aria-label, aria-hidden, aria-describedby and aria-live kept in step with state. Changes that matter are announced through a live region.
KeyBehaviour
EnterActivates the focused control.
EscapeCloses or cancels, then returns focus to where it came from.
↑Moves to the previous item or value.
↓Moves to the next item or value.
Motion #
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.