nook
Browse the docs

Components

Prompt input

Built on Base UI

A growing message field with files, model selection, slash commands and send/stop actions.

See the prompt
0/2000

Enter to send · Shift+Enter for a new line · Drop files to attach

Installation

npx nook-ui@latest add prompt-input

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Prompt input" component to this project, exactly as Nook ships it.

A growing message field with files, model selection, slash commands and send/stop actions.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add prompt-input`. It writes `components/ui/prompt-input.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/prompt-input.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
"use client";
import * as React from "react";
import { PromptInput } from "@/components/ui/prompt-input";
export default function PromptDefault() {
  const [busy, setBusy] = React.useState(false);
  const [sent, setSent] = React.useState("");
  return (
    <div className="grid w-full max-w-xl gap-3 pt-32">
      <PromptInput
        busy={busy}
        onStop={() => setBusy(false)}
        onSend={({ text, files, model }) => {
          setSent(
            `${text || "Review attachments"} · ${files.length} files · ${model}`,
          );
          setBusy(true);
        }}
        models={[
          { value: "quick", label: "Quick" },
          { value: "reason", label: "Reason" },
          { value: "code", label: "Code" },
        ]}
        defaultModel="reason"
        commands={[
          {
            name: "review",
            description: "Review a change",
            prompt: "Review this change for bugs and accessibility: ",
          },
          {
            name: "explain",
            description: "Explain a code snippet",
            prompt: "Explain how this code works: ",
          },
          {
            name: "tests",
            description: "Suggest test cases",
            prompt: "Suggest tests for this behavior: ",
          },
        ]}
        limit={2000}
      />
      <p role="status" className="text-xs text-muted-foreground">
        {sent
          ? `Sent: ${sent}`
          : "Enter to send · Shift+Enter for a new line · Drop files to attach"}
      </p>
    </div>
  );
}
```

API
- `PromptInput`: An AI message form following ChatComposer patterns.
  - `onSend` (`({text, files, model}) => void`): Receives trimmed text, File objects and the model value.
  - `onStop` (`() => void`): Stops a busy response.
  - `busy / disabled` (`boolean`): Busy locks editing and offers Stop; disabled locks all controls.
  - `commands` (`PromptCommand[]`): name, description and inserted prompt.
  - `models` (`PromptModel[]`): value and label for Select.
  - `value / defaultValue / onValueChange` (`string / string / (value) => void`): Controlled or uncontrolled message.
  - `model / defaultModel / onModelChange` (`string / string / (model) => void`): Controlled or uncontrolled model.
  - `limit` (`number`): Character limit, default 4000.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Enter sends, Shift+Enter inserts a line, IME Enter is ignored. Arrows and Enter select slash commands; Escape closes them. File browsing works without drag and drop. Limit warnings are text.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

"use client";
import * as React from "react";
import { PromptInput } from "@/components/ui/prompt-input";
export default function PromptDefault() {
  const [busy, setBusy] = React.useState(false);
  const [sent, setSent] = React.useState("");
  return (
    <div className="grid w-full max-w-xl gap-3 pt-32">
      <PromptInput
        busy={busy}
        onStop={() => setBusy(false)}
        onSend={({ text, files, model }) => {
          setSent(
            `${text || "Review attachments"} · ${files.length} files · ${model}`,
          );
          setBusy(true);
        }}
        models={[
          { value: "quick", label: "Quick" },
          { value: "reason", label: "Reason" },
          { value: "code", label: "Code" },
        ]}
        defaultModel="reason"
        commands={[
          {
            name: "review",
            description: "Review a change",
            prompt: "Review this change for bugs and accessibility: ",
          },
          {
            name: "explain",
            description: "Explain a code snippet",
            prompt: "Explain how this code works: ",
          },
          {
            name: "tests",
            description: "Suggest test cases",
            prompt: "Suggest tests for this behavior: ",
          },
        ]}
        limit={2000}
      />
      <p role="status" className="text-xs text-muted-foreground">
        {sent
          ? `Sent: ${sent}`
          : "Enter to send · Shift+Enter for a new line · Drop files to attach"}
      </p>
    </div>
  );
}

Examples

While answering

37/4000

Models and commands

0/4000

Character limit

92/140

Disabled

0/4000

Props

PromptInput

An AI message form following ChatComposer patterns.

PropTypeDefaultDescription
onSend({text, files, model}) => void–Receives trimmed text, File objects and the model value.
onStop() => void–Stops a busy response.
busy / disabledboolean–Busy locks editing and offers Stop; disabled locks all controls.
commandsPromptCommand[]–name, description and inserted prompt.
modelsPromptModel[]–value and label for Select.
value / defaultValue / onValueChangestring / string / (value) => void–Controlled or uncontrolled message.
model / defaultModel / onModelChangestring / string / (model) => void–Controlled or uncontrolled model.
limitnumber–Character limit, default 4000.

Accessibility

Enter sends, Shift+Enter inserts a line, IME Enter is ignored. Arrows and Enter select slash commands; Escape closes them. File browsing works without drag and drop. Limit warnings are text.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.