# Chat Composer — BIU UI > Auto-growing AI prompt input with file attachments, drag-and-drop, model & approval pickers, voice dictation, and streaming stop controls. - **Documentation**: https://ui.biu.dev/docs/components/chat-composer - **Category**: AI Agents - **Edition**: Open Source (MIT) - **Architecture**: Zero-Tailwind React 19 + Base UI 1.9 + 4-layer `@layer` CSS ## Installation ```bash # shadcn Registry pnpm dlx shadcn add @biudev/chat-composer # BIU CLI npx @biudev/cli add chat-composer --registry https://ui.biu.dev/r/0.1.0 # npm package pnpm add @biudev/ui @base-ui/react ``` Public source URL: https://ui.biu.dev/docs/source/chat-composer ## Usage ```tsx import { ChatComposer } from "@/components/ui/biu/chat-composer"; export function Example() { return ( console.log("send", payload)} /> ); } ``` ## API Reference ### ChatComposerStatus Also accepts properties from `'ready' & 'submitted' & 'streaming'`. `'ready' | 'submitted' | 'streaming'` ### ChatComposerModel | Property | Type | Default | Description | | --- | --- | --- | --- | | `id` * | `string` | `—` | Unique identifier for this element or item. | | `name` * | `string` | `—` | Form field name or display name. | | `description` | `string` | `—` | Secondary supporting description text. | | `badge` | `string` | `—` | Optional badge value or count displayed beside the label. | | `icon` | `ReactNode` | `—` | Leading icon element. | ### ChatComposerApprovalMode | Property | Type | Default | Description | | --- | --- | --- | --- | | `id` * | `string` | `—` | Unique identifier for this element or item. | | `label` * | `string` | `—` | Visible text label or accessible name. | | `description` | `string` | `—` | Secondary supporting description text. | | `tone` | `'neutral' \| 'info' \| 'warning' \| 'danger'` | `—` | Semantic color tone (neutral, info, success, warning, danger, or purple). | ### ChatComposerAttachment | Property | Type | Default | Description | | --- | --- | --- | --- | | `id` * | `string` | `—` | Unique identifier for this element or item. | | `name` * | `string` | `—` | Form field name or display name. | | `size` | `number` | `—` | Size tier controlling height, padding, and typography. | | `mimeType` | `string` | `—` | MIME type of the attached file. | | `previewUrl` | `string` | `—` | Caller-owned preview URL. The composer generates its own temporary previews for image files without one. | | `file` | `File` | `—` | Underlying browser File object when attached from disk. | ### ChatComposerSuggestion | Property | Type | Default | Description | | --- | --- | --- | --- | | `id` * | `string` | `—` | Unique identifier for this element or item. | | `label` * | `string` | `—` | Visible text label or accessible name. | | `prompt` * | `string` | `—` | Submitted prompt text. | | `icon` | `ReactNode` | `—` | Leading icon element. | ### ChatComposerCommand | Property | Type | Default | Description | | --- | --- | --- | --- | | `value` * | `string` | `—` | Command slug without the leading slash (e.g. `'review'`, `'fix'`). | | `label` * | `string` | `—` | Human-readable command title shown in the slash menu. | | `description` | `string` | `—` | Optional short explanation shown beside or beneath the label. | | `icon` | `ReactNode` | `—` | Optional leading icon. | | `shortcut` | `string` | `—` | Optional trailing keyboard hint or badge. | ### ChatComposerAction | Property | Type | Default | Description | | --- | --- | --- | --- | | `value` * | `string` | `—` | Action identifier passed to `onAction`. | | `label` * | `string` | `—` | Action label rendered inside the `+` menu. | | `description` | `string` | `—` | Optional supporting description. | | `icon` | `ReactNode` | `—` | Optional leading icon. | ### ChatComposerSubmitPayload | Property | Type | Default | Description | | --- | --- | --- | --- | | `text` * | `string` | `—` | Plain text content for the item or status. | | `attachments` * | `ChatComposerAttachment[]` | `—` | Attached files included with the prompt. | | `modelId` | `string` | `—` | Selected model identifier. | | `approvalModeId` | `string` | `—` | Selected agent approval policy identifier. | ### ChatComposerLabels | Property | Type | Default | Description | | --- | --- | --- | --- | | `placeholder` * | `string` | `—` | Placeholder text displayed when the input is empty. | | `send` * | `string` | `—` | Accessible label for the send prompt button. | | `stop` * | `string` | `—` | Accessible label for stopping an active generation. | | `submitting` * | `string` | `—` | Indicates an asynchronous submission is in progress. | | `attach` * | `string` | `—` | Accessible label for the attach-files button. | | `removeAttachment` * | `(name: string) => string` | `—` | Accessible label for removing an attachment chip. | | `selectModel` * | `string` | `—` | Accessible label for the model selector menu. | | `selectApproval` * | `string` | `—` | Accessible label for the approval mode selector menu. | | `voiceStart` * | `string` | `—` | Accessible label for starting voice dictation. | | `voiceStop` * | `string` | `—` | Accessible label for stopping voice dictation. | | `dropHint` * | `string` | `—` | Prompt shown when dragging files over the composer. | | `voiceUnavailable` | `string` | `—` | Notice shown when browser speech recognition is unavailable. | | `dictationSample` * | `string` | `—` | Fallback demo phrase inserted when voice API is unavailable. | ### ChatComposerProps | Property | Type | Default | Description | | --- | --- | --- | --- | | `value` | `string` | `—` | Controlled text value. | | `defaultValue` | `string` | `''` | Uncontrolled initial text value. | | `onValueChange` | `(value: string) => void` | `—` | Fired whenever the prompt text changes. | | `onSubmit` | `(payload: ChatComposerSubmitPayload) => void` | `—` | Fired when the user submits via Enter or the send button. | | `onStop` | `() => void` | `—` | Fired when the user clicks Stop during `'streaming'` status. | | `status` | `ChatComposerStatus` | `'ready'` | Current submission / streaming lifecycle state. Defaults to `'ready'`. | | `placeholder` | `string` | `—` | Placeholder copy inside the auto-growing textarea. | | `disabled` | `boolean` | `false` | Disables typing, attachments, and submission. | | `autoFocus` | `boolean` | `false` | Auto-focus the textarea on mount. | | `maxHeight` | `number` | `200` | Maximum textarea height in pixels before scrolling. Defaults to `200`. | | `models` | `readonly ChatComposerModel[]` | `DEFAULT_CHAT_MODELS` | Available models shown in the bottom-left model picker. Pass `[]` to hide. | | `model` | `string` | `—` | Controlled selected model id. | | `defaultModel` | `string` | `—` | Uncontrolled initial model id. | | `onModelChange` | `(modelId: string) => void` | `—` | Fired when the user selects a different model. | | `approvalModes` | `readonly ChatComposerApprovalMode[]` | `—` | Optional human-in-the-loop approval modes (e.g. Always ask / Approve edits / Full access). | | `approvalMode` | `string` | `—` | Controlled selected approval mode id. | | `defaultApprovalMode` | `string` | `—` | Uncontrolled initial approval mode id. | | `onApprovalModeChange` | `(modeId: string) => void` | `—` | Fired when the user switches approval mode. | | `attachments` | `readonly ChatComposerAttachment[]` | `—` | Controlled attachment list. | | `defaultAttachments` | `readonly ChatComposerAttachment[]` | `[]` | Uncontrolled initial attachments. | | `onAttachmentsChange` | `(attachments: ChatComposerAttachment[]) => void` | `—` | Fired whenever attachments are added or removed. | | `allowAttachments` | `boolean` | `true` | Enables file attach button, paste, and drag-and-drop. Defaults to `true`. | | `accept` | `string` | `—` | Accepted MIME types / extensions for the file picker, paste, and drop. | | `maxAttachments` | `number` | `8` | Maximum number of attached files. Defaults to `8`. | | `voice` | `boolean` | `true` | Shows the voice dictation trigger with animated waveform feedback. Defaults to `true`. | | `onVoiceChange` | `(listening: boolean) => void` | `—` | Optional custom handler when toggling voice input; if omitted, uses Web Speech API with graceful fallback. | | `suggestions` | `readonly ChatComposerSuggestion[]` | `—` | Optional starter prompt chips displayed beneath the composer card. | | `submitOnSuggestion` | `boolean` | `false` | If `true`, clicking a suggestion submits immediately instead of filling the textarea. Defaults to `false`. | | `commands` | `readonly ChatComposerCommand[]` | `—` | Optional `/` slash commands surfaced in a floating menu when typing `/` in the prompt. | | `onCommand` | `(command: ChatComposerCommand) => void` | `—` | Fired when the user selects a `/` slash command. | | `actions` | `readonly ChatComposerAction[]` | `—` | Optional quick actions rendered in a `+` dropdown menu alongside file upload. | | `onAction` | `(actionValue: string) => void` | `—` | Fired when the user picks an item from the `+` quick actions menu. | | `header` | `ReactNode` | `—` | Optional banner or context slot rendered at the top of the composer card (e.g. reply quote or approval notice). | | `leadingActions` | `ReactNode` | `—` | Optional custom controls rendered on the left side of the bottom toolbar after built-in pickers. | | `trailingActions` | `ReactNode` | `—` | Optional custom controls rendered on the right side of the bottom toolbar before voice/send. | | `footerHint` | `ReactNode` | `—` | Optional hint text rendered beneath the composer (e.g. keyboard shortcut or disclaimer). | | `labels` | `Partial` | `—` | Localized labels and aria strings. | | `className` | `string` | `—` | Additional CSS class name applied to the root element. | | `style` | `CSSProperties` | `—` | Inline CSS styles applied to the root element. |