A composable AI prompt composer with attachments, toolbar actions, and send states.
import { PromptInput } from 'heroui-native-pro' ;
< PromptInput value ={value} onValueChange ={setValue} onSubmit ={send}>
< PromptInput.SlashMenu >
< PromptInput.SlashMenuItem command = "..." >
< PromptInput.SlashMenuItemIcon >...</ PromptInput.SlashMenuItemIcon >
< PromptInput.SlashMenuItemContent >
< PromptInput.SlashMenuItemLabel />
< PromptInput.SlashMenuItemDescription />
</ PromptInput.SlashMenuItemContent >
</ PromptInput.SlashMenuItem >
</ PromptInput.SlashMenu >
< PromptInput.Shell >
< PromptInput.Background />
< PromptInput.Content >
< PromptInput.Attachments >...</ PromptInput.Attachments >
< PromptInput.TextArea />
</ PromptInput.Content >
< PromptInput.Toolbar >
< PromptInput.ToolbarStart >
< PromptInput.Action >...</ PromptInput.Action >
</ PromptInput.ToolbarStart >
< PromptInput.ToolbarEnd >
< PromptInput.Send >
< PromptInput.SendIcon />
</ PromptInput.Send >
</ PromptInput.ToolbarEnd >
</ PromptInput.Toolbar >
</ PromptInput.Shell >
< PromptInput.Footer >...</ PromptInput.Footer >
</ PromptInput >
PromptInput : Root column. Owns the text, the status, and the layout.
PromptInput.Shell : Bordered field surface. Pressing it outside its buttons focuses the field.
PromptInput.Background : Theme background layer of the shell, such as the glass frosted layer. The shell renders it by default; replace it through the shell's background prop.
PromptInput.Content : Column of attachments and the field.
PromptInput.Attachments : Row of attachments, for example a horizontal ChatAttachmentGroup. It expands the compact and inline layouts while it has children. Presses on the row do not focus the field, so scrolling a strip of attachments leaves the keyboard as it is.
PromptInput.TextArea : Multiline field. It starts at one line, grows to maxHeight, then scrolls.
PromptInput.Toolbar : Action row. In the stacked layout it sits under the field. In the compact and inline rows, its ToolbarStart and ToolbarEnd groups flank the field.
PromptInput.ToolbarStart : Leading group of the toolbar, such as attach and tool buttons.
PromptInput.ToolbarEnd : Trailing group of the toolbar, such as the send button.
PromptInput.Action : Round icon button (heroui-native Button, tertiary by default).
PromptInput.Send : Round send button reflecting the status. Renders SendIcon by default.
PromptInput.SendIcon : Status glyph of the send button: an up arrow, a spinner, a stop square, or an x mark. Colored like the button's label.
PromptInput.Footer : Muted note under the shell.
PromptInput.SlashMenu : Commands panel (menu role) shown above the shell while the text starts with /.
PromptInput.SlashMenuItem : One command row (menuitem role).
PromptInput.SlashMenuItemIcon : Leading icon box of a row, hidden from screen readers.
PromptInput.SlashMenuItemContent : Text column of a row.
PromptInput.SlashMenuItemLabel : Label of a row. Renders the item's label by default.
PromptInput.SlashMenuItemDescription : Secondary text of a row. Renders the item's description by default.
onSubmit receives the text; clear the value there. Return inserts a new line, and Send sends. The field starts at one line and grows to maxHeight.
const [value, setValue] = useState ( '' );
< PromptInput
value ={value}
onValueChange ={setValue}
onSubmit ={(text) => {
send (text);
setValue ( '' );
}}
>
< PromptInput.Shell >
< PromptInput.Content >
< PromptInput.TextArea placeholder = "Chat with AI" />
</ PromptInput.Content >
< PromptInput.Toolbar >
< PromptInput.ToolbarStart >
< PromptInput.Action accessibilityLabel = "Add to chat" onPress ={openAttachSheet}>
< PaperClipIcon />
</ PromptInput.Action >
</ PromptInput.ToolbarStart >
< PromptInput.ToolbarEnd >
< PromptInput.Send />
</ PromptInput.ToolbarEnd >
</ PromptInput.Toolbar >
</ PromptInput.Shell >
< PromptInput.Footer >AI can make mistakes. Check important info.</ PromptInput.Footer >
</ PromptInput >;
layout sets how the field and the toolbar sit together. Layouts switch instantly.
"stacked" (default): the field above a toolbar row.
"compact": a single-line pill with the toolbar groups flanking the field. It switches to the stacked layout once the text needs a second line or attachments are shown. It switches back once the text is cleared and no attachments remain.
"inline": always a single row. The field grows in place between the toolbar groups, which stay by its last line. The corners go from pill to card once it grows.
< PromptInput layout = "compact" value ={value} onValueChange ={setValue} onSubmit ={send}>
...
</ PromptInput >
variant sets the shell surface. "primary" uses the field surface, and "secondary" uses the default fill.
< PromptInput variant = "secondary" value ={value} onValueChange ={setValue} onSubmit ={send}>
...
</ PromptInput >
status follows your chat runtime: "ready", "submitted" (spinner), "streaming" (stop button), or "error" (danger fill). While a reply generates, nothing can be sent. With onStop, Send becomes a Stop button; without it, Send is disabled. The field is read-only meanwhile unless lockInputOnRun={false}.
< PromptInput value ={value} status ={status} onValueChange ={setValue} onSubmit ={send} onStop ={stop}>
...
</ PromptInput >
Render a horizontal ChatAttachmentGroup in PromptInput.Attachments. Render nothing when there are no attachments, so the compact and inline layouts can shrink back. The attach button is a regular PromptInput.Action: open your own sheet or picker from it, and call Keyboard.dismiss() first.
< PromptInput.Content >
< PromptInput.Attachments >
{files.length > 0 ? (
< ChatAttachmentGroup orientation = "horizontal" >
{files. map ((file) => (
< ChatAttachment key ={file.id} {...file}>
< ChatAttachment.Preview />
< ChatAttachment.Info />
< ChatAttachment.Remove onPress ={() => remove (file.id)} />
</ ChatAttachment >
))}
</ ChatAttachmentGroup >
) : null }
</ PromptInput.Attachments >
< PromptInput.TextArea />
</ PromptInput.Content >
While PromptInput.Attachments shows attachments, Send enables with an empty field and onSubmit receives "", so a photo can be sent without a caption. Pass canSubmit to decide yourself when there is something to send. Pass isSubmitDisabled to block sending while files upload. The field stays editable, and Stop still works.
< PromptInput
value ={value}
onValueChange ={setValue}
isSubmitDisabled ={files. some ((file) => file.isUploading)}
onSubmit ={(text) => send ({ text, files })}
>
...
</ PromptInput >
PromptInput.SlashMenu opens above the shell while the text starts with / and has no space yet. The text after the slash filters the items by command (prefix), label, and keywords. Selecting an item replaces the text with /{command} , ready for its argument, then calls onSelect. Without matches, the panel hides, or shows emptyContent. Items must be direct children of the menu, since the menu filters them by their props.
< PromptInput value ={value} onValueChange ={setValue} onSubmit ={send}>
< PromptInput.SlashMenu emptyContent ={< Text >No matching commands</ Text >}>
< PromptInput.SlashMenuItem command = "summarize" description = "Condense the conversation" icon ={< ListIcon />} />
< PromptInput.SlashMenuItem command = "image" description = "Generate an image" keywords ={[ 'picture' ]} />
</ PromptInput.SlashMenu >
< PromptInput.Shell >...</ PromptInput.Shell >
</ PromptInput >
Compose the row parts to restyle a row. They read the item's icon, label, and description, so keep those props on the item for filtering and the screen reader label.
< PromptInput.SlashMenuItem command = "translate" description = "Translate the next message into another language" >
< PromptInput.SlashMenuItemIcon className = "size-8 rounded-full bg-accent-soft" >
< LanguageIcon />
</ PromptInput.SlashMenuItemIcon >
< PromptInput.SlashMenuItemContent >
< PromptInput.SlashMenuItemLabel className = "text-accent" />
< PromptInput.SlashMenuItemDescription numberOfLines ={ 2 } />
</ PromptInput.SlashMenuItemContent >
</ PromptInput.SlashMenuItem >
Every part takes className. The field, toolbar, and attachments row set their side padding with logical properties (paddingStart / paddingEnd). Override it with ps-* / pe-*, not px-*.
< PromptInput.Shell className = "rounded-[28px] bg-surface" >
< PromptInput.Content >
< PromptInput.TextArea className = "ps-3 pe-3 font-medium" />
</ PromptInput.Content >
< PromptInput.Toolbar className = "ps-3 pe-3 pb-3" >...</ PromptInput.Toolbar >
</ PromptInput.Shell >
PromptInput.Send is a heroui-native Button, so variant and className restyle it. Its default PromptInput.SendIcon takes the label color of the button's variant, so the glyph stays legible. Pass PromptInput.SendIcon yourself to change its size or color.
< PromptInput.Send variant = "secondary" className = "bg-foreground" >
< PromptInput.SendIcon size ={ 18 } color ={themeColorBackground} />
</ PromptInput.Send >
Pass a function as children for content that changes with the status. It receives { status, action, isError, isDisabled }, where action is "send", "stop", or "none". For a labeled button, pass isIconOnly={false} and widen it with className. Custom components inside PromptInput.Send read the same state with usePromptInputSend().
< PromptInput.Send isIconOnly ={ false } className = "w-auto px-4" >
{({ action }) => (
< Button.Label >{action === 'stop' ? 'Stop' : 'Send' }</ Button.Label >
)}
</ PromptInput.Send >
Place the composer in ChatConversation.Composer, which floats it over the list and moves it with the keyboard. The composer tells the conversation just before it calls onSubmit, so the list holds still while the keyboard closes and the sent message flies up. The composer also passes its status to the conversation, so the list knows when a reply is generating.
< ChatConversation >
< ChatConversation.Content
data ={messages}
itemEntrance ={(message) => (message.role === 'user' ? 'send' : 'reply' )}
renderItem ={renderMessage}
/>
< ChatConversation.ScrollButton />
< ChatConversation.Composer className = "pb-safe-offset-3" >
< PromptInput value ={value} status ={status} onValueChange ={setValue} onSubmit ={send} onStop ={stop}>
...
</ PromptInput >
</ ChatConversation.Composer >
</ ChatConversation >
Send text that does not come from the field, such as a tapped suggestion, with submit(text) from usePromptInput(). It runs the same checks as Send, prepares the conversation for the send, then calls onSubmit(text). Nothing is sent while a reply generates or while isSubmitDisabled is set. Render the suggestions inside PromptInput, above PromptInput.Shell, so they can reach it.
const Suggestions = () => {
const { submit } = usePromptInput ();
return (
< PromptSuggestion variant = "card" >
< PromptSuggestion.Items orientation = "horizontal" >
{suggestions. map ((suggestion) => (
< PromptSuggestion.Item key ={suggestion.id} onPress ={() => submit (suggestion.prompt)}>
< PromptSuggestion.ItemTitle >{suggestion.title}</ PromptSuggestion.ItemTitle >
</ PromptSuggestion.Item >
))}
</ PromptSuggestion.Items >
</ PromptSuggestion >
);
};
< PromptInput value ={value} status ={status} onValueChange ={setValue} onSubmit ={send}>
{messages.length === 0 ? < Suggestions /> : null }
< PromptInput.Shell >...</ PromptInput.Shell >
</ PromptInput >;
import { useThemeColor } from 'heroui-native' ;
import {
ChatAttachment,
ChatAttachmentGroup,
PromptInput,
} from 'heroui-native-pro' ;
import { useState } from 'react' ;
import { Keyboard } from 'react-native' ;
import { PaperClipIcon } from './icons/paper-clip' ;
const PHOTO_URL =
'https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/demo1.jpg' ;
const DEMO_ATTACHMENTS = [
{ id: 'photo' , name: 'desk.jpg' , mimeType: 'image/jpeg' , src: PHOTO_URL },
{
id: 'brief' ,
name: 'final-v2-annual-financial-summary-report.pdf' ,
mimeType: 'application/pdf' ,
size: 824_120 ,
},
{ id: 'sheet' , name: 'quarterly-report.xlsx' , size: 98_400 },
{
id: 'memo' ,
name: 'voice-memo.m4a' ,
mimeType: 'audio/mp4' ,
size: 1_802_240 ,
},
];
export default function Composer () {
const themeColorField = useThemeColor ( 'field' );
const [attachments, setAttachments] = useState (DEMO_ATTACHMENTS);
const [value, setValue] = useState ( '' );
return (
< PromptInput
value ={value}
onValueChange ={setValue}
onSubmit ={() => {
setValue ( '' );
setAttachments ([]);
}}
>
< PromptInput.Shell >
< PromptInput.Content >
< PromptInput.Attachments className = "ps-0 pe-0" >
{attachments.length > 0 ? (
< ChatAttachmentGroup
orientation = "horizontal"
scrollShadowProps ={{ color: themeColorField }}
classNames ={{ content: 'px-2' }}
>
{attachments. map ((attachment) => (
< ChatAttachment
key ={attachment.id}
name ={attachment.name}
mimeType ={attachment.mimeType}
size ={attachment.size}
src ={attachment.src}
>
< ChatAttachment.Preview />
< ChatAttachment.Info />
< ChatAttachment.Remove
accessibilityLabel = "Remove attachment"
onPress ={() =>
setAttachments ((current) =>
current. filter ((item) => item.id !== attachment.id)
)
}
/>
</ ChatAttachment >
))}
</ ChatAttachmentGroup >
) : null }
</ PromptInput.Attachments >
< PromptInput.TextArea placeholder = "Ask about your files" />
</ PromptInput.Content >
< PromptInput.Toolbar >
< PromptInput.ToolbarStart >
< PromptInput.Action
accessibilityLabel = "Add to chat"
onPress ={() => {
Keyboard. dismiss ();
setAttachments (DEMO_ATTACHMENTS);
}}
>
< PaperClipIcon size ={ 16 } colorClassName = "accent-foreground" />
</ PromptInput.Action >
</ PromptInput.ToolbarStart >
< PromptInput.ToolbarEnd >
< PromptInput.Send />
</ PromptInput.ToolbarEnd >
</ PromptInput.Toolbar >
</ PromptInput.Shell >
< PromptInput.Footer >
AI can make mistakes. Check important info.
</ PromptInput.Footer >
</ PromptInput >
);
}
prop type default description childrenReactNode- SlashMenu, Shell, and Footerlayout'stacked' | 'compact' | 'inline''stacked'Layout of the composer maxHeightnumber160Maximum field height in pixels before the text scrolls variant'primary' | 'secondary''primary'Shell surface: field surface or default fill valuestring- Text (controlled) defaultValuestring''Initial text (uncontrolled) status'ready' | 'submitted' | 'streaming' | 'error''ready'Lifecycle status isDisabledbooleanfalseDisables the composer canSubmitbooleantrue while attachments showSomething to send besides the text; Send enables with an empty field isSubmitDisabledbooleanfalseBlocks sending, such as during uploads. The field and Stop keep working lockInputOnRunbooleantrueMakes the field read-only while a reply generates classNamestring- Additional CSS classes for the root onSubmit(value: string) => void- Called with the text when Send is pressed. Empty with canSubmit onStop() => void- Called when Stop is pressed. Without it, Send is disabled while generating onValueChange(value: string) => void- Called when the text changes animationPromptInputRootAnimation- Animation configuration for the composer ...ViewPropsViewProps- All standard React Native View props are supported
Animation configuration for the root. Layouts always switch instantly. Can be:
'disable-all': Disable all animations, including the slash menu and the button press feedback
undefined: Use default animations
prop type default description childrenReactNode- Content and ToolbarclassNamestring- Additional CSS classes for the shell styleStyleProp<ViewStyle>- Inline style of the shell backgroundReactNodetheme default Background layer. A node replaces it, and null removes it onPress(event: GestureResponderEvent) => void- Called on a press, before the field focuses ...PressablePropsPressableProps- React Native Pressable props, without children and style
prop type default description classNamestring- Additional CSS classes fallbackColorThemeColor'field' (primary) or 'default' (secondary)Opaque fallback color of the theme layer forceFallbackColorbooleanfalsePaints the fallback color on every platform ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Attachments and TextAreaclassNamestring- Additional CSS classes for the column ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Attachments. The row renders nothing without children classNamestring- Additional CSS classes for the row ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description placeholderstring'What do you want to know?'Placeholder text placeholderTextColorColorValuefield-placeholder colorPlaceholder color editablebooleanfalse while disabled or lockedWhether the field is editable classNamestring- Additional CSS classes for the field accessibilityLabelstring'Message input'Screen reader label. Pass a translated label to localize it ...TextInputPropsTextInputProps- React Native TextInput props, without value, defaultValue, and multiline
prop type default description childrenReactNode- ToolbarStart and ToolbarEndclassNamestring- Additional CSS classes for the row ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Leading actions classNamestring- Additional CSS classes for the group ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Trailing actions classNamestring- Additional CSS classes for the group ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Icon sizeButtonSize'sm'heroui-native Button size. sm is 32px hitSlopInsets6 on each sideExtends the touch target to 44pt variantButtonVariant'tertiary'heroui-native Button variant isIconOnlybooleantrueRound icon-only button isDisabledboolean- Disables the button. It is also disabled with the composer, and while a reply generates when lockInputOnRun is on classNamestring- Additional CSS classes accessibilityLabelstring- Screen reader label. Set it, since the button shows only an icon ...ButtonRootPropsButtonRootProps- heroui-native Button props
prop type default description childrenReactNode | ((state: PromptInputSendState) => ReactNode)<PromptInput.SendIcon />Button content. A function receives the send state sizeButtonSize'sm'heroui-native Button size. sm is 32px hitSlopInsets6 on each sideExtends the touch target to 44pt isIconOnlybooleantrueRound icon-only button. Pass false for a labeled button statusChatStatusroot status Status override isDisabledbooleanfrom the status and the text Overrides the computed disabled state classNamestring- Additional CSS classes accessibilityLabelstring'Send message' or 'Stop'Screen reader label. Pass a translated label to localize it onPress(event: GestureResponderEvent) => void- Called before the message is sent or the reply stopped onStop() => voidroot onStop Stop handler override ...ButtonRootPropsButtonRootProps- heroui-native Button props
prop type description statusChatStatusStatus the button reflects action'send' | 'stop' | 'none'What a press does. 'none' means the button is disabled isErrorbooleanWhether the status is 'error'. The button takes the danger fill isDisabledbooleanWhether the button is disabled
Render it inside PromptInput.Send. It shows an up arrow when ready, a spinner when submitted, a stop square while streaming, and an x mark on error.
prop type default description sizenumber16Size of the glyph. The spinner keeps its sm size colorstringlabel color of the button variant Color of the glyph. danger-foreground on error statusChatStatusstatus of the Send Status override
prop type default description childrenReactNode- Note text classNamestring- Additional CSS classes ...TextPropsTextProps- All standard React Native Text props are supported
prop type default description childrenReactNode- SlashMenuItem elements, as direct childrenemptyContentReactNode- Shown when nothing matches. Without it, the panel hides classNamestring- Additional CSS classes for the panel classNamesElementSlots<SlashMenuSlots>- Additional CSS classes for the slots stylesPartial<Record<SlashMenuSlots, ViewStyle>>- Styles for the slots onSelect(command: string) => void- Called after an item replaces the text animationPromptInputSlashMenuAnimation- Show and hide animation of the panel ...ViewPropsViewProps- All standard React Native View props are supported
prop type description containerstringPanel above the shell backgroundstringGlass frosted layer behind the panel scrollstringScrolling list of commands, up to 240px tall emptystringWrapper of emptyContent
prop type description containerViewStylePanel above the shell backgroundViewStyleGlass frosted layer behind the panel scrollViewStyleScrolling list of commands emptyViewStyleWrapper of emptyContent
Animation configuration for the slash menu. Can be:
false or 'disabled': No entering or exiting animation
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | boolean- Disable animations while customizing properties entering.valueEntryOrExitLayoutTypeFadeIn.duration(150).easing(Easing.out(Easing.ease))Entering animation of the panel exiting.valueEntryOrExitLayoutTypeFadeOut.duration(120).easing(Easing.in(Easing.ease))Exiting animation of the panel
prop type default description childrenReactNodeicon, label, and description parts Row content commandstring- Command name, without the slash (required) labelstring/{command}Row label descriptionstring- Secondary text iconReactNode- Leading icon keywordsstring[]- Extra search terms classNamestring- Additional CSS classes for the row accessibilityLabelstring'{label}, {description}'Screen reader label onPress(event: GestureResponderEvent) => void- Called before the item replaces the text ...PressableFeedbackPropsPressableFeedbackProps- heroui-native PressableFeedback props
prop type default description childrenReactNodeitem icon Icon. The box renders nothing without an icon classNamestring- Additional CSS classes for the icon box ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- SlashMenuItemLabel and SlashMenuItemDescriptionclassNamestring- Additional CSS classes for the column ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNodeitem label Label text numberOfLinesnumber1Maximum number of lines classNamestring- Additional CSS classes ...TextPropsTextProps- All standard React Native Text props are supported
prop type default description childrenReactNodeitem description Description text. Renders nothing without one numberOfLinesnumber1Maximum number of lines classNamestring- Additional CSS classes ...TextPropsTextProps- All standard React Native Text props are supported
Reads the composer state inside a PromptInput, for custom parts.
property type description valuestringText of the message setValue(value: string) => voidUpdates the text statusChatStatusLifecycle status isGeneratingbooleanWhether a reply is generating ('submitted' or 'streaming') isDisabledbooleanWhether the composer is disabled lockInputOnRunbooleanWhether the field is read-only while a reply generates layoutPromptInputLayoutLayout of the composer isExpandedbooleanAlways true when stacked. In compact and inline, true once the text wraps or attachments show isRowLayoutbooleanWhether the toolbar groups flank the field in a single row isFocusedbooleanWhether the field is focused variantPromptInputVariantShell surface maxHeightnumberMaximum height of the field slashQuerystring | nullText after the leading slash while the slash menu is open, else null canSubmitbooleanWhether there is something to send besides the text isSubmitDisabledbooleanWhether sending is blocked submit(text?: string) => voidSends the field, or text when given, through the same checks as Send onStop(() => void) | undefinedStop handler focus() => voidFocuses the field inputRefRefObject<TextInputRef | null>Ref of the field
Reads the send state inside a PromptInput.Send. It returns PromptInputSendState.
property type description statusChatStatusStatus the button reflects action'send' | 'stop' | 'none'What a press does isErrorbooleanWhether the status is 'error' isDisabledbooleanWhether the button is disabled
Reads the row state inside a PromptInput.SlashMenuItem.
property type description commandstringCommand name, without the slash labelstringRow label (label, else /{command}) descriptionstring | undefinedSecondary text iconReactNodeLeading icon
function returns description isPromptInputGenerating(status)booleantrue while 'submitted' or 'streaming'getSlashQuery(value)string | nullText after a leading / while it has no whitespace, otherwise null matchesSlashQuery(query, command, label?, keywords?)booleanWhether a command matches the query: command prefix, or label or keyword contains it