ComponentsPrompt Composer

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:

Can you help me plan a landing page?

Sure — here's a quick plan:

  1. Hero with a one-line promise and a primary CTA
  2. Three features with icons and short copy
  3. Pricing with a free tier

Want me to generate the code?

Sure — here's a quick plan: 1. **Hero** with a one-line promise and a primary CTA 2. **Three features** with icons and short copy 3. **Pricing** with a free tier Want me to generate the code?

Installation

  1. 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

PropTypeDefaultDescription
valuestring—Controlled text.
defaultValuestring—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.
errorMessageReactNode—Inline message that slides down under the bar when status is "error".
maxLengthnumber—Character limit. Submits are blocked (and the counter shakes) above it.

Composer.Input

PropTypeDefaultDescription
placeholderstring"Ask anything…"
maxRowsnumber8Grows from 1 line up to this many, then scrolls.
aria-labelstring"Message"

Composer.AttachButton

PropTypeDefaultDescription
acceptstring—Accepted file types, e.g. "image/*,.pdf".
multiplebooleantrueAllow several files.

Composer.ModelChip

PropTypeDefaultDescription
models*{ id, label, description?, icon? }[]—Options in the popover.
valuestring—Controlled selected id.
defaultValuestringthe first modelUncontrolled initial id.
onChange(id: string) => void—Called with the new id.

Composer.Counter

PropTypeDefaultDescription
showAtnumber0.8Fraction of maxLength after which the counter appears.

Composer.Suggestions

PropTypeDefaultDescription
items*(string | { label, value?, icon? })[]—Pills shown while the input is empty.
onSelect(value: string) => void—Called after the typewriter fill finishes.
typeSpeednumber8ms per character for the fill.

Composer.Attachments, Composer.Toolbar, Composer.Spacer and Composer.Submit take a className and read everything else from context.

Keyboard

KeyAction
EnterSend (never while an IME is composing — safe for Hindi, Japanese, Chinese input)
Shift + EnterNew line
⌘ / Ctrl + EnterSend
EscStop 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.