Prompt input
FreeThe 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.
npx shadcn@latest add https://pixilui.com/r/prompt-input.jsonPreview
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>
);
}When to use
Use it when
- A chat that only sends and stops: a support widget, an inline ask box.
Use something else when
- Models, tools, a folder or permissions to choose, or a queue while the agent works: use the composer field.
Installation
npx shadcn@latest add https://pixilui.com/r/prompt-input.jsonAdds prompt-input.tsx with button.tsx, chip.tsx, dropdown-menu.tsx, text-shimmer.tsx, kbd.tsx, tooltip.tsx, meter.tsx, usage-meter.tsx and composer-field.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.
"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} />;
});
It uses Button, Chip, Dropdown menu, Text shimmer, Kbd, Tooltip, Meter, Usage meter and Composer field: add them the same way. Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
import { PromptInput } from "@/components/pixilui/prompt-input";
<PromptInput
icons={icons}
onChange={onChange}
onSubmit={onSubmit}
/>Fills its container.
API reference
iconsRequiredComposerIcons–The icons it draws (composerIcons in composer-field's examples).statusComposerStatus–The chat's status: submitted or streaming shows Stop.defaultValuestring–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.placeholderstring–The placeholder ("Ask anything").maxLengthnumber–The longest message: from 90% a count shows; over it, send is off.quotestring–Words quoted from a reply, over the box.onQuoteRemove() => void–Runs when the quote's cross is pressed.filesComposerFile[]–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.noticeComposerNotice | null–A notice in the box.onNoticeActionComposerFieldProps["onNoticeAction"]–A notice's button.wordsPartial<ComposerWords>–Every word it says.Also takes every native <div> attribute except onSubmit, onChange, defaultValue, and a ref.
Keyboard
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.