Message composer with attachments, toolbar and stop
import {PromptInput} from "@peakui-pro/react" ;
import {PromptInput} from "@peakui-pro/react" ;
export default () => (
< PromptInput value = {value} layout = "stacked" onSubmit = {send} onStop = {stop} onValueChange = {setValue}>
{ /* Queued follow-ups, above the shell. */ }
< PromptInput.Queue >
< PromptInput.Queue.List >
< PromptInput.Queue.Item >
{ /* Presentational grip: rows do not reorder by drag. */ }
< PromptInput.Queue.Item.Handle />
< PromptInput.Queue.Item.Body >
< PromptInput.Queue.Item.Icon />
< PromptInput.Queue.Item.Content >Queued prompt text</ PromptInput.Queue.Item.Content >
</ PromptInput.Queue.Item.Body >
< PromptInput.Queue.Item.Actions >
< PromptInput.Queue.Item.Remove />
< PromptInput.Queue.Item.More />
</ PromptInput.Queue.Item.Actions >
</ PromptInput.Queue.Item >
</ PromptInput.Queue.List >
</ PromptInput.Queue >
< PromptInput.Shell >
< PromptInput.Content >
{ /* ChatAttachment children; their remove buttons come before the text in the tab order. */ }
< PromptInput.Attachments />
{ /* Enter submits, Shift+Enter adds a line. */ }
< PromptInput.TextArea placeholder = "What do you want to know?" />
</ PromptInput.Content >
< PromptInput.Toolbar >
< PromptInput.ToolbarStart >
< PromptInput.Action aria-label = "Attach file" >...</ PromptInput.Action >
</ PromptInput.ToolbarStart >
< PromptInput.ToolbarEnd >
{ /* Send, or Stop while submitted or streaming. */ }
< PromptInput.Send />
</ PromptInput.ToolbarEnd >
</ PromptInput.Toolbar >
</ PromptInput.Shell >
< PromptInput.Footer >AI can make mistakes. Check important info.</ PromptInput.Footer >
</ PromptInput >
);
status turns send into stop while submitted or streaming; the text area goes read-only.
variant="secondary" for a composer that sits on a surface.
layout="inline" keeps the toolbars and the growing text on one row.
layout="compact" starts as a pill and stacks once the text wraps or a file is attached.
Render PromptInput.Shell through ChatAttachmentInput.Dropzone to make it the drop target.
< PromptInput className = "[--prompt-input-radius:1.5rem] [--prompt-input-bg:var(--color-surface-secondary)]" >
< PromptInput.Shell >
< PromptInput.TextArea />
</ PromptInput.Shell >
</ PromptInput >
@layer components {
.prompt-input {
--prompt-input-radius : 1.5 rem ;
--prompt-input-inset : 0.5 rem ;
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The PromptInput component uses these CSS classes (view source styles ):
.prompt-input - Root state wrapper
.prompt-input--sm
.prompt-input--md - Default, empty: the base class carries it
.prompt-input--lg
.prompt-input__shell--stacked - Default
.prompt-input__shell--inline
.prompt-input__shell--compact
.prompt-input__shell--primary - Default
.prompt-input__shell--secondary
.prompt-input__shell - Composer surface
.prompt-input__content - Attachments and text area
.prompt-input__attachments - Attachment row, hidden while empty
.prompt-input__textarea - Text area, beside the core .textarea
.prompt-input__toolbar - Toolbar row
.prompt-input__toolbar-start - Leading toolbar actions
.prompt-input__toolbar-end - Trailing toolbar actions
.prompt-input__action - Toolbar action, beside the core .button
.prompt-input__send - Send and stop button
.prompt-input__footer - Disclaimer
.prompt-input__queue - Queued prompts card
.prompt-input__queue-list - Scrolling list, beside the core .scroll-shadow
.prompt-input__queue-list-items - The ul of queued rows
.prompt-input__queue-item - Queued row
.prompt-input__queue-item-handle - Grip, presentational
.prompt-input__queue-item-body - Icon and text
.prompt-input__queue-item-icon - Leading icon
.prompt-input__queue-item-content - Prompt text, clamped to two lines
.prompt-input__queue-item-description - Secondary text
.prompt-input__queue-item-attachments - Attachment previews in a row
.prompt-input__queue-item-attachments-overflow - Hidden attachment count
.prompt-input__queue-item-actions - Row actions
.prompt-input__queue-item-remove - Remove button
.prompt-input__queue-item-more - More button
.prompt-input__queue-item-action - Any other row action
[data-slot="prompt-input"]
[data-slot="prompt-input-shell"]
[data-slot="prompt-input-content"]
[data-slot="prompt-input-attachments"]
[data-slot="prompt-input-textarea"]
[data-slot="prompt-input-toolbar"]
[data-slot="prompt-input-toolbar-start"]
[data-slot="prompt-input-toolbar-end"]
[data-slot="prompt-input-action"]
[data-slot="prompt-input-send"]
[data-slot="prompt-input-footer"]
[data-slot="prompt-input-queue"]
[data-slot="prompt-input-queue-list"] - on the ul; the scrolling root keeps the core's scroll-shadow
[data-slot="prompt-input-queue-item"]
[data-slot="prompt-input-queue-item-handle"]
[data-slot="prompt-input-queue-item-body"]
[data-slot="prompt-input-queue-item-icon"]
[data-slot="prompt-input-queue-item-content"]
[data-slot="prompt-input-queue-item-description"]
[data-slot="prompt-input-queue-item-attachments"]
[data-slot="prompt-input-queue-item-attachments-overflow"]
[data-slot="prompt-input-queue-item-actions"]
[data-slot="prompt-input-queue-item-remove"]
[data-slot="prompt-input-queue-item-more"]
[data-slot="prompt-input-queue-item-action"]
Variable Purpose --prompt-input-radiusShell and queue corner; defaults to var(--radius-2xl) --prompt-input-pill-radiusCorner of the inline and compact shell; defaults to 1.5rem --prompt-input-bgShell and queue fill; defaults to var(--color-surface), var(--color-default) for secondary --prompt-input-insetToolbar and attachment inset; defaults to 0.75rem --prompt-input-gapSpace between queue, shell and footer; defaults to 0.5rem --prompt-input-min-heightText area height at rest; defaults to 3.5rem --prompt-input-pill-heightHeight of the inline and compact row; defaults to 3rem --prompt-input-toolbar-heightToolbar row height; follows the control size --prompt-input-max-heightTallest text area before it scrolls; set from maxHeight --prompt-input-queue-max-heightTallest queue list before it scrolls; defaults to 10rem
Status : [data-status="ready" | "submitted" | "streaming" | "error"] on the root and on .prompt-input__send
Running : [data-pending="true"] on the root while submitted or streaming
Expanded : [data-expanded="true"] on a compact root once it stacks
Disabled : [data-disabled="true"] on the root
Focus : the shell draws the focus ring while its text area has focus
Drop target : [data-drop-target] on a shell rendered through ChatAttachmentInput.Dropzone, with its dashed outline
Read-only : [readonly] on the text area while a response runs
Queue actions : [data-actions-visibility="hover"] hides row actions until hover or keyboard focus in the row
Forced colors : the shell and the queue keep a ButtonBorder boundary
Prop Type Default Description valuestringinternal Controlled text onValueChange(value: string) => void- Called when the text changes onSubmit(value: string) => void- Called with the text when it is submitted; an uncontrolled composer then clears itself onStop() => void- Called by the send button while submitted or streaming; without it the button is disabled then status'ready' | 'submitted' | 'streaming' | 'error''ready'Run state isDisabledbooleanfalseDisables the text area and every control lockInputOnRunbooleantrueMakes the text area read-only while submitted or streaming; focus stays in it maxHeightnumber | string240Tallest text area, in pixels or any CSS length; also --prompt-input-max-height size'sm' | 'md' | 'lg''md'Composer size variant'primary' | 'secondary''primary'Shell surface layout'stacked' | 'compact' | 'inline''stacked'Arrangement of the text and the toolbars renderDOMRenderFunction<E, undefined>- Replaces the rendered element; E defaults to 'div' ...restComponentProps<'div'>- Native attributes
Prop Type Default Description disableAutosizebooleanfalseLeaves the height to CSS instead of growing with the text allowSubmitWhileRunningbooleanfalseLets Enter submit while a response runs, to queue follow-ups; pair with lockInputOnRun={false} aria-labelstring'Message input'Accessible name placeholderstring'What do you want to know?'Text shown while empty ...restComponentProps<typeof TextArea>- Every core TextArea prop except value and defaultValue, which the root owns
Prop Type Default Description tooltipReactNode- Tooltip on the button; still one tab stop ...restButtonProps- Core Button props; icon-only, tertiary and the composer's control size by default
Prop Type Default Description aria-labelstring'Send message' or 'Stop'Named for what it does in the current status childrenReactNodesend, spinner, stop or error glyph Custom glyph ...restButtonProps- Core Button props; disabled while there is nothing to send or nothing to stop
Prop Type Default Description renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> ...restComponentProps<'div'>- Native attributes
Prop Type Default Description renderDOMRenderFunction<'p', undefined>- Replaces the rendered <p> ...restComponentProps<'p'>- Native attributes
Prop Type Default Description actionsVisibility'always' | 'hover''hover'When row actions show; hover also shows them on keyboard focus in the row, and always on touch ...restComponentProps<'div'>- Native attributes
Prop Type Default Description ...restComponentProps<typeof ScrollShadow>- Core ScrollShadow props
Prop Type Default Description renderDOMRenderFunction<'li', undefined>- Replaces the rendered <li> ...restComponentProps<'li'>- Native attributes
Prop Type Default Description childrenReactNodegrip for Handle Slot content; Handle and Icon are hidden from assistive technology ...restComponentProps<'div' | 'span' | 'p'>- Native attributes of the slot's element
Prop Type Default Description hiddenCountnumber- Attachments not shown, rendered as +2 files nounstring'files'Noun after the count
Prop Type Default Description aria-labelstring'Remove queued prompt', 'More queue actions'Default names of Remove and More childrenReactNodetrash, ellipsis Custom glyph ...restButtonProps- Core Button props; small, ghost, icon-only