# Prompt input

The locked composer's box alone: it grows with the words to six lines, sends on Enter, and send becomes Stop while the model answers. Files, a quote and notices still fit in it.

Tier: free. Type: component. Category: ai. Tags: chat, streaming, keyboard, motion.

## Install

```bash
npx shadcn@latest add https://pixilui.com/r/prompt-input.json
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json"
  }
}
```

Files: `components/pixilui/prompt-input.tsx`.

## Preview

Live preview: https://pixilui.com/components/prompt-input

Knobs:

- `status`: `ready`, `streaming`

Signature: Press Enter and the sheen crosses send as the arrow turns into the stop square.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop. Standalone files: lively https://pixilui.com/r/standalone/prompt-input.tsx, quiet https://pixilui.com/r/standalone/prompt-input.quiet.tsx.

## Code

`components/pixilui/prompt-input.tsx`

```tsx
"use client";

/*
  The prompt input: the locked composer's box alone (design/explorations/components/locked/composer, H2), with no tray and no
  menus, for a chat that only sends and stops. It is ComposerField with its tray off (the lock's tray: false) and no sources,
  tools or models: it grows with the words to six lines, sends on Enter (never mid-composition), and send becomes Stop while
  the model answers. The look and motion are the composer's (foundation.css section 8).
*/

import { forwardRef } from "react";
import type { ComponentPropsWithoutRef } from "react";
import { ComposerField, type ComposerFieldProps, type ComposerFile, type ComposerIcons, type ComposerMessageDraft, type ComposerNotice, type ComposerStatus, type ComposerWords } from "./composer-field";

export type PromptInputProps = Omit<ComponentPropsWithoutRef<"div">, "onSubmit" | "onChange" | "defaultValue"> & {
  /** The chat's status: submitted or streaming shows Stop. */
  status?: ComposerStatus;
  /** Words in the box at first. */
  defaultValue?: string;
  /** Runs as the words change. */
  onChange?: (text: string) => void;
  /** Runs on Enter or Send with what to send; the box then clears. Return false to keep the words. */
  onSubmit?: (draft: ComposerMessageDraft) => void | boolean | Promise<void>;
  /** Runs on Stop (or Escape) while the model answers. */
  onStop?: () => void;
  /** The placeholder ("Ask anything"). */
  placeholder?: string;
  /** The longest message: from 90% a count shows; over it, send is off. */
  maxLength?: number;
  /** Words quoted from a reply, over the box. */
  quote?: string;
  /** Runs when the quote's cross is pressed. */
  onQuoteRemove?: () => void;
  /** File tiles in the box. */
  files?: ComposerFile[];
  /** Runs when a tile's cross is pressed. */
  onRemoveFile?: (id: string) => void;
  /** Files dropped on the box. */
  onFiles?: (files: File[]) => void;
  /** A notice in the box. */
  notice?: ComposerNotice | null;
  /** A notice's button. */
  onNoticeAction?: ComposerFieldProps["onNoticeAction"];
  /** The icons it draws (composerIcons in composer-field's examples). */
  icons: ComposerIcons;
  /** Every word it says. */
  words?: Partial<ComposerWords>;
};

/** The chat box alone: it grows with the words, sends on Enter, and send becomes Stop while the model answers. */
export const PromptInput = forwardRef<HTMLDivElement, PromptInputProps>(function PromptInput(props, ref) {
  return <ComposerField ref={ref} {...props} tray={false} />;
});
```

## Usage

When to use:

- A chat that only sends and stops: a support widget, an inline ask box.

When not to use:

- Models, tools, a folder or permissions to choose, or a queue while the agent works: use the composer field.

```tsx
import { useState } from "react";
import { composerIcons } from "@/components/pixilui/composer-field.examples";
import type { ComposerStatus } from "@/components/pixilui/composer-field";
import { PromptInput } from "@/components/pixilui/prompt-input";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  status: ["ready", "streaming"],
} as const;

/** Type and press Enter: send becomes Stop for the answer's length, then Send again. */
export default function PromptInputDemo({ status: start = "ready" }: KnobValues<typeof knobs>) {
  const [status, setStatus] = useState<ComposerStatus>(start);
  return (
    <div className="w-full max-w-xl">
      <PromptInput
        icons={composerIcons}
        status={status}
        onSubmit={() => {
          setStatus("streaming");
          setTimeout(() => setStatus("ready"), 2400);
        }}
        onStop={() => setStatus("ready")}
      />
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `status` | `ComposerStatus` |  | The chat's status: submitted or streaming shows Stop. |
| `defaultValue` | `string` |  | Words in the box at first. |
| `onChange` | `(text: string) => void` |  | Runs as the words change. |
| `onSubmit` | `(draft: ComposerMessageDraft) => void \| boolean \| Promise<void>` |  | Runs on Enter or Send with what to send; the box then clears. Return false to keep the words. |
| `onStop` | `() => void` |  | Runs on Stop (or Escape) while the model answers. |
| `placeholder` | `string` |  | The placeholder ("Ask anything"). |
| `maxLength` | `number` |  | The longest message: from 90% a count shows; over it, send is off. |
| `quote` | `string` |  | Words quoted from a reply, over the box. |
| `onQuoteRemove` | `() => void` |  | Runs when the quote's cross is pressed. |
| `files` | `ComposerFile[]` |  | File tiles in the box. |
| `onRemoveFile` | `(id: string) => void` |  | Runs when a tile's cross is pressed. |
| `onFiles` | `(files: File[]) => void` |  | Files dropped on the box. |
| `notice` | `ComposerNotice \| null` |  | A notice in the box. |
| `onNoticeAction` | `ComposerFieldProps["onNoticeAction"]` |  | A notice's button. |
| `icons` (required) | `ComposerIcons` |  | The icons it draws (composerIcons in composer-field's examples). |
| `words` | `Partial<ComposerWords>` |  | Every word it says. |

Also accepts every native `<div>` attribute except `onSubmit`, `onChange`, `defaultValue`, and a ref to it.

## Keyboard

- `Enter`: Sends, never while event.nativeEvent.isComposing (Japanese and Chinese input).
- `Shift` + `Enter`: Adds a line.
- `Escape`: Stops the answer.

## Accessibility

- The field is a textbox (aria-multiline); send stays focusable when it can't send, its reason as the tooltip.

## Motion

- The field grows and glides with the words; the send sweep as a message leaves; the arrow turns into the stop square while the model answers. Reduced motion: at once.

## Responsive

- Fills its container.

## Performance

- The composer's CSS (foundation section 8).

## Notes for AI

- <PromptInput status={status} onSubmit={(d) => sendMessage(d.text)} onStop={stop} icons={icons} />: status is the AI SDK's (submitted, streaming, ready, error).
- It is ComposerField with no tray and no menus; every word is in words, every icon in icons (composerIcons in composer-field's examples).
- Per-style rule: none of its own; quiet is the composer's quiet box.

## Related

- [Composer field](https://pixilui.com/components/composer-field/markdown): The chat box of an AI agent: files, your words, tools, the model with its effort, dictation and send, with folder, branch and permission below. Messages sent while it works wait in order.
- [Textarea](https://pixilui.com/components/textarea/markdown): A text area that opens at three lines and grows to eight as you write, with a counter that turns orange near its limit; its reason kind is where saying no to an agent comes with a why.
