Prompt Composer
The chat input every AI app needs — auto-growing textarea, attachments, a model chip, suggestions and a Send button that morphs into Stop.
Preview
What can I help you build?
Drop files, paste images, or pick a starting point.
Pinned to the bottom of a chat:
Installation
- 1
Run the following command
npx shadcn@latest add https://localhostui.com/r/prompt-composer.json
Also copy parts.tsx and context.tsx from the same folder.
Usage
Basic
import PromptComposer from "@/components/lokalhost_io/micro-ai-components/prompt-composer/prompt-composer";
<PromptComposer onSubmit={(text) => send(text)} status={status} onStop={stop} />With attachments
Paste an image, drag files anywhere onto the composer, or use the paperclip. Pass onUpload to show progress rings and errors:
<Composer
onSubmit={(text, files) => send(text, files)}
onUpload={async (file, onProgress) => {
await uploadWithProgress(file, onProgress); // throw to show the error + Retry state
}}
>
<Composer.Attachments />
<Composer.Input />
<Composer.Toolbar>
<Composer.AttachButton accept="image/*,.pdf" />
<Composer.Spacer />
<Composer.Submit />
</Composer.Toolbar>
</Composer>With a model picker
const models = [
{ id: "fast", label: "Fast", description: "Quick answers" },
{ id: "smart", label: "Smart", description: "Balanced" },
{ id: "reasoning", label: "Reasoning", description: "Thinks longer" },
];
<Composer.ModelChip models={models} value={model} onChange={setModel} />Controlled
const [value, setValue] = useState("");
<Composer value={value} onValueChange={setValue} onSubmit={send}>
<Composer.Input />
<Composer.Toolbar>
<Composer.Spacer />
<Composer.Submit />
</Composer.Toolbar>
</Composer>Props
Composer
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Controlled text. |
defaultValue | string | — | Uncontrolled initial text. |
onValueChange | (value: string) => void | — | Called on every change. |
onSubmit | (value: string, attachments: ComposerAttachment[]) => void | — | Receives the trimmed text. The input clears and keeps focus. |
onStop | () => void | — | Called by the Stop button or Esc while streaming. |
status | "idle""submitting""streaming""error" | "idle" | streaming turns Send into Stop; error pulses the border once. |
errorMessage | ReactNode | — | Inline message that slides down under the bar when status is "error". |
maxLength | number | — | Character limit. Submits are blocked (and the counter shakes) above it. |
Composer.Input
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | "Ask anything…" | |
maxRows | number | 8 | Grows from 1 line up to this many, then scrolls. |
aria-label | string | "Message" |
Composer.AttachButton
| Prop | Type | Default | Description |
|---|---|---|---|
accept | string | — | Accepted file types, e.g. "image/*,.pdf". |
multiple | boolean | true | Allow several files. |
Composer.ModelChip
| Prop | Type | Default | Description |
|---|---|---|---|
models* | { id, label, description?, icon? }[] | — | Options in the popover. |
value | string | — | Controlled selected id. |
defaultValue | string | the first model | Uncontrolled initial id. |
onChange | (id: string) => void | — | Called with the new id. |
Composer.Counter
| Prop | Type | Default | Description |
|---|---|---|---|
showAt | number | 0.8 | Fraction of maxLength after which the counter appears. |
Composer.Suggestions
| Prop | Type | Default | Description |
|---|---|---|---|
items* | (string | { label, value?, icon? })[] | — | Pills shown while the input is empty. |
onSelect | (value: string) => void | — | Called after the typewriter fill finishes. |
typeSpeed | number | 8 | ms per character for the fill. |
Composer.Attachments, Composer.Toolbar, Composer.Spacer and Composer.Submit take a className and read everything else from context.
Keyboard
| Key | Action |
|---|---|
Enter | Send (never while an IME is composing — safe for Hindi, Japanese, Chinese input) |
Shift + Enter | New line |
⌘ / Ctrl + Enter | Send |
Esc | Stop generating while streaming |
↑ (empty input) | Recall the last sent message (needs history) |
↑ / ↓ | Move through models when the model popover is open |
Accessibility
- The textarea has an
aria-label; the submit button switches between “Send message” and “Stop generating”. - Attachments are a
role="list"; each remove button is labelled with the file name. - Dragging files over the composer is announced through a polite live region.
- With reduced motion the button morph, chip pops and typewriter fill become instant.