# PromptInput

The composer for sending a prompt, with attachments, a toolbar and a way to stop.

- **Use it for**: The composer for prompts, with attachments, toolbar, submit and cancel.
- **Not for**: Plain form fields. Try [Textarea](https://unseenui.com/components/textarea/), [Chat](https://unseenui.com/components/chat/).

## Installation

```bash
npm install @stackunseen/ui
```

## Parts

One form with the text box in the middle. The slots around it hold your own controls; the text, attachments and whether sending is allowed stay with your app.

1. **Command list**: Opens above the text when someone types "/" or "@". Choosing an item calls you back with it. Props: `commands`, `onCommand`, `mentions`, `onMention`, `onMentionQueryChange`.
2. **Attachments**: Your attachment chips above the text, for example a row of Attachment. Built from Attachment. Props: `attachments`.
3. **Text box**: Grows with the text. Enter sends and Shift + Enter adds a line; typing with an input method never sends early. Props: `value`, `onValueChange`, `placeholder`, `disabled`, `disabledReason`, `textareaRef`, `selection`, `onSelectionChange`.
4. **Toolbar**: Your own controls beside the send button, such as a model picker. Props: `toolbar`.
5. **Send button**: Sends the trimmed text. While a reply runs and you pass `onCancel`, it becomes Stop response. Built from IconButton, Button. Props: `onSubmit`, `busy`, `onCancel`, `submitDisabled`, `submitDisabledReason`, `allowEmptySubmit`.
6. **Hint**: A line under the box: your hint, or the reason sending is unavailable. Without either it is read to screen readers only. Props: `hint`.

## Usage

```tsx
import { PromptInput } from '@stackunseen/ui';
import '@stackunseen/ui/styles.css';

<PromptInput variant="standard" value={draft} onValueChange={setDraft} onSubmit={send} />
```

## Props

- `value` (`string`): The controlled draft. Clear it when your application is ready to do so.
- `onValueChange` (`(value: string) => void`): Update value with the edited draft.
- `onSubmit` (`(text: string) => void`): Receives the trimmed draft. Send it through your application and track the result there.
- `busy` (`boolean (optional)`): Prevents another send while a response is in progress.
- `submitDisabled` (`boolean (optional)`): Disables sending while keeping the draft editable.
- `submitDisabledReason` (`string (optional)`): The explanation shown when submitDisabled is true.
- `attachments` (`ReactNode (optional)`): Content above the draft, such as attachment previews. Handle uploads separately.

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `allowEmptySubmit` | `boolean` | Opt in for a host-validated attachment-only message. |
| `assist` | `ReactNode` | Extra actions beside the variables, such as an "Enhance prompt" button. |
| `attachments` | `ReactNode` | Composition slots; uploads, validation and authoritative state remain with the host. |
| `busy` | `boolean` |  |
| `commands` | `readonly CommandOption[]` | Offered when the message starts with "/". |
| `disabled` | `boolean` |  |
| `disabledReason` | `string` |  |
| `hint` | `string` | A line shown under the box, such as a notice. |
| `limit` | `number` | A character limit shown as "86 / 500" under the box; sending stops past it. |
| `mentions` | `readonly CommandOption[]` | Offered after "@" (at the start or after a space). |
| `onCancel` | `(() => void)` |  |
| `onCommand` | `((command: CommandOption, value: string) => void)` |  |
| `onInsertVariable` | `((variable: PromptVariable) => void)` |  |
| `onMention` | `((item: CommandOption) => void)` |  |
| `onMentionQueryChange` | `((query: string \| null) => void)` | The text after "@" while the mention list is open, or null when it closes. |
| `onSelectionChange` | `((selection: TextRange) => void)` |  |
| `onSubmit` (required) | `(text: string) => void` |  |
| `onValueChange` (required) | `(value: string) => void` |  |
| `placeholder` | `string` |  |
| `selection` | `TextRange` | UTF-16 selection against value, with an exclusive end. |
| `submitDisabled` | `boolean` |  |
| `submitDisabledReason` | `string` |  |
| `textareaRef` | `Ref<HTMLTextAreaElement>` | The host can focus/measure the textarea without querying the DOM. |
| `toolbar` | `ReactNode` |  |
| `value` (required) | `string` |  |
| `variables` | `readonly PromptVariable[]` | Placeholders the message can carry, such as the selected text or a saved voice. |
| `variant` | `"compact" \| "standard" \| "inline"` |  |

## Keyboard

Enter sends a ready draft; Shift+Enter adds a line break. Enter does not send while composing with an IME. Tab reaches the toolbar and send or stop controls.

## Works with

[Chat](https://unseenui.com/components/chat/), [Message](https://unseenui.com/components/message/), [StreamingResponse](https://unseenui.com/components/streaming-response/), [MessageActions](https://unseenui.com/components/message-actions/), [Suggestions](https://unseenui.com/components/suggestions/), [Attachment](https://unseenui.com/components/attachment/), [AttachmentTray](https://unseenui.com/components/attachment-tray/), [FileDropzone](https://unseenui.com/components/file-dropzone/), [ModelSelector](https://unseenui.com/components/model-selector/), [FeedbackCapture](https://unseenui.com/components/feedback-capture/), [Reasoning](https://unseenui.com/components/reasoning/), [SuggestTextarea](https://unseenui.com/components/suggest-textarea/)

Page: https://unseenui.com/components/prompt-input/
