Collapsible tool-call cards for inputs, outputs, errors, approvals, and grouped tool activity.
Collapsible tool-call cards for inputs, outputs, errors, approvals, and grouped tool activity.
import { ChatTool, ChatToolGroup } from 'heroui-native-pro' ;
< ChatTool state = "output-available" >
< ChatTool.Trigger >
< ChatTool.StatusIcon />
...
< ChatTool.Duration >...</ ChatTool.Duration >
</ ChatTool.Trigger >
< ChatTool.Content >
< ChatTool.Args />
< ChatTool.Result />
< ChatTool.Error />
< ChatTool.Meta />
</ ChatTool.Content >
< ChatTool.Approval >
< ChatTool.ApprovalActions >
< ChatTool.Reject />
< ChatTool.Approve />
</ ChatTool.ApprovalActions >
</ ChatTool.Approval >
</ ChatTool >
< ChatToolGroup >
< ChatToolGroup.Trigger >...</ ChatToolGroup.Trigger >
< ChatToolGroup.Content >
< ChatTool />
</ ChatToolGroup.Content >
</ ChatToolGroup >
ChatTool : Bordered card and disclosure root. Its border and status icon follow state. Without children it renders a preset from its props.
ChatTool.Trigger : Full-width pressable row with a chevron. Text children form one label that shimmers while the tool is active. A trigger of a card that cannot expand has no chevron and no button role.
ChatTool.StatusIcon : State glyph: wrench while streaming or running, then check, cross, or exclamation mark.
ChatTool.Duration : Trailing muted duration or timestamp with tabular digits.
ChatTool.Content : Collapsible body. Renders nothing when the card cannot expand.
ChatTool.Args / ChatTool.Result : Tool input and output as JSON CodeBlocks, collapsed past maxLines. Result renders nothing in the output-error state.
ChatTool.Error : Selectable error details in the danger color. Renders nothing without errorText or children.
ChatTool.Approval : Footer shown only in the requires-action state. Place it after ChatTool.Content, outside the collapsible body, so the actions stay visible on a collapsed card.
ChatTool.ApprovalActions : Trailing row of approval buttons.
ChatTool.Approve / ChatTool.Reject : Small heroui-native Buttons, primary and secondary.
ChatTool.Meta : Selectable tool call id footer in a monospace font.
ChatToolGroup : Card grouping consecutive tool calls.
ChatToolGroup.Trigger : Same row as ChatTool.Trigger, shimmering while the group isActive.
ChatToolGroup.Content : Collapsible column of ChatTools.
Pass the tool data to ChatTool to render the preset card. The card expands when it has args, a result, an error, or a tool call id.
< ChatTool
state = "output-available"
toolName = "getWeather"
triggerPrefix = "Used tool: "
duration = "0.8s"
input ={{ city: 'Paris' }}
output ={{ summary: '18°C, partly cloudy' }}
/>
Pass the raw partial JSON through argsText while the model generates the input. The label shimmers while the tool is input-streaming or input-available. Override it with isActive.
< ChatTool
defaultExpanded
state = "input-streaming"
toolName = "searchDocs"
triggerPrefix = "Running tool: "
argsText = '{"query":"HeroUI Pro'
/>
output-error tints the border and icon with the danger color and hides the result.
< ChatTool
state = "output-error"
toolName = "fetchPage"
triggerPrefix = "Failed tool: "
argsText = '{"url":"https://example.com"}'
errorText = "Request timed out after 30s"
/>
output-denied shows a muted cross on the neutral card. deniedLabel replaces the duration and defaults to "Declined".
< ChatTool
state = "output-denied"
toolName = "sendEmail"
triggerPrefix = "Rejected: "
argsText = '{"to":"team@acme.com"}'
deniedLabel = "Declined"
/>
In requires-action, the approval footer renders below the trigger when onApprove or onReject is set. Labels default to "Approve" / "Reject". Pass approveLabel / rejectLabel to localize them.
An uncontrolled card expands when it enters requires-action, so the user sees what they approve. It stays open after they answer. Pass defaultExpanded={false} to keep it collapsed. Measure a duration from the approval, not from the start of the call.
< ChatTool
state = "requires-action"
toolName = "sendEmail"
triggerPrefix = "Approval needed: "
argsText = '{"to":"team@acme.com"}'
approveLabel = "Send"
rejectLabel = "Cancel"
onApprove ={approve}
onReject ={reject}
/>
Args and results collapse past maxLines (default 12, 0 shows everything) behind a "Show more" toggle. Long lines scroll sideways, so JSON keeps its indentation. Set isCodeWrapped to wrap them instead. With onCopy, each code block shows a copy button. onTriggerLongPress fires on the preset trigger, for example to open a context menu.
import * as Clipboard from 'expo-clipboard' ;
< ChatTool
state = "output-available"
toolName = "searchWeb"
output ={results}
maxLines ={ 8 }
onCopy ={Clipboard.setStringAsync}
onTriggerLongPress ={openToolMenu}
/>;
markdownTextProps is forwarded to the highlighted renderer of the args and result code blocks (see CodeBlock.Code). Use contextMenuItems to act on a selected part of a tool result.
< ChatTool
state = "output-available"
toolName = "searchWeb"
output ={results}
markdownTextProps ={{
contextMenuItems: [
{ text: 'Ask about this' , icon: 'sparkles' , onPress : ({ text }) => ask (text) },
],
}}
/>
Compose the card from the parts. Consecutive strings, numbers, and React Native Text elements in the trigger form one label. Other nodes render as row items.
< ChatTool state = "output-available" >
< ChatTool.Trigger onLongPress ={openToolMenu}>
< ChatTool.StatusIcon />
Used tool: < Text className = "font-medium" >getWeather</ Text >
< ChatTool.Duration >0.8s</ ChatTool.Duration >
</ ChatTool.Trigger >
< ChatTool.Content >
< ChatTool.Args label = "Parameters" input ={{ city: 'Paris' }} />
< ChatTool.Result label = "Result" value ={{ summary: '18°C' }} />
< ChatTool.Meta toolCallId = "call_8f2c1a9e" />
</ ChatTool.Content >
</ ChatTool >
ChatToolGroup collapses consecutive tool calls into one card. Set isActive to shimmer its label while a grouped tool runs. isToolRunning returns true for input-streaming and input-available.
import { ChatTool, ChatToolGroup, isToolRunning } from 'heroui-native-pro' ;
< ChatToolGroup isActive ={parts. some ((part) => isToolRunning (part.state))}>
< ChatToolGroup.Trigger >{parts.length} tool calls</ ChatToolGroup.Trigger >
< ChatToolGroup.Content >
{parts. map ((part) => (
< ChatTool key ={part.toolCallId} state ={part.state} toolName ={part.toolName} />
))}
</ ChatToolGroup.Content >
</ ChatToolGroup >;
In ChatConversation.Content, the card changes height in a single commit and fades its body in, so the messages below move with it. The card keeps its expanded state with the message under its stateKey (default: toolCallId), so it survives scrolling away. Give a ChatToolGroup its own stateKey.
In your own list, give content laid out after the card the same layout transition, ChatToolLayoutTransition. Keep the expanded state in your message store with isExpanded / onExpandedChange.
import Animated from 'react-native-reanimated' ;
import { ChatTool, ChatToolLayoutTransition } from 'heroui-native-pro' ;
< ChatTool
state ={part.state}
toolName ={part.toolName}
isExpanded ={part.isExpanded}
onExpandedChange ={(isExpanded) => updatePart (part.toolCallId, { isExpanded })}
/>
< Animated.View layout ={ChatToolLayoutTransition}>...</ Animated.View >
import type { ChatToolState } from 'heroui-native-pro' ;
import { ChatMessage, ChatTool } from 'heroui-native-pro' ;
import { useEffect, useState } from 'react' ;
import { View } from 'react-native' ;
const EMAIL_ARGS = '{"to":"team@acme.com","subject":"Launch update"}' ;
const TRIGGER_PREFIX: Record < ChatToolState , string > = {
'input-streaming' : 'Running tool: ' ,
'input-available' : 'Running tool: ' ,
'output-available' : 'Used tool: ' ,
'output-error' : 'Failed tool: ' ,
'output-denied' : 'Rejected: ' ,
'requires-action' : 'Approval needed: ' ,
};
export default function ChatToolExample () {
const [state, setState] = useState < ChatToolState >( 'requires-action' );
useEffect (() => {
if (state !== 'input-available' ) return undefined ;
const timeout = setTimeout (() => setState ( 'output-available' ), 1200 );
return () => clearTimeout (timeout);
}, [state]);
return (
< View className = "flex-1 justify-center px-5" >
< ChatMessage.Assistant >
< ChatMessage.Avatar alt = "Assistant" fallback = "AI" />
< ChatMessage.Body >
< ChatMessage.Content >
I drafted the launch update. Should I send it to the team?
</ ChatMessage.Content >
< ChatTool
state ={state}
toolName = "sendEmail"
triggerPrefix ={TRIGGER_PREFIX[state]}
argsText ={EMAIL_ARGS}
output ={state === 'output-available' ? { status: 'sent' } : undefined }
approveLabel = "Send"
rejectLabel = "Cancel"
onApprove ={() => setState ( 'input-available' )}
onReject ={() => setState ( 'output-denied' )}
/>
</ ChatMessage.Body >
</ ChatMessage.Assistant >
</ View >
);
}
prop type default description childrenReactNode- Custom parts. When set, every preset prop that renders content is ignored stateChatToolState- Lifecycle state of the tool call. Required isExpandedboolean- Controlled expanded state defaultExpandedbooleantrue in requires-action, else falseExpanded state on mount. When unset, the card also expands on entering requires-action isDisabledbooleanfalseDisables the trigger. The content keeps its current state isActivebooleantrue while input-streaming or input-availableWhether the trigger label shimmers isExpandablebooleantrue with children, else whether the preset has a bodyWhether the card can expand stateKeystringtoolCallIdKeeps the expanded state across row remounts in ChatConversation.Content classNamestring- Additional CSS classes for the card toolNamestring- Preset: tool name, rendered after triggerPrefix in medium weight triggerPrefixReactNode- Preset: label before toolName durationReactNode- Preset: trailing duration or timestamp deniedLabelReactNode'Declined'Preset: trailing label in the output-denied state, shown instead of duration inputunknown- Preset: tool input. Strings render as-is; other values render as formatted JSON argsTextstring- Preset: preformatted input, used instead of input outputunknown- Preset: tool output, rendered like input. Hidden in the output-error state errorTextstring- Preset: error details toolCallIdstring- Preset: tool call id footer maxLinesnumber12Lines the args and result show before "Show more". 0 shows every line isCodeWrappedbooleanfalseWraps long lines in the args and result instead of scrolling them sideways approveLabelReactNode'Approve'Preset: approve button label rejectLabelReactNode'Reject'Preset: reject button label markdownTextPropsCodeBlockMarkdownTextProps- Props of the args and result highlighted renderer, such as contextMenuItems onApprove() => void- Preset: called when the user approves. The approval footer renders when this or onReject is set onReject() => void- Preset: called when the user rejects onTriggerLongPress(event: GestureResponderEvent) => void- Preset: called when the trigger is long-pressed onCopy(text: string) => unknown- Writes text to the clipboard. When set, the args and result show a copy button onExpandedChange(isExpanded: boolean) => void- Called when the expanded state changes animationChatToolRootAnimation- Animation configuration ...ViewPropsViewProps- All React Native View props are supported
value description input-streamingThe model is generating the input. Wrench icon and shimmering label. Use argsText for partial JSON input-availableThe input is complete and the tool runs. Wrench icon and shimmering label output-availableThe tool returned a result. Success check output-errorThe tool failed. Danger cross and border; the result is hidden output-deniedThe user rejected the call. Muted cross on the neutral card; deniedLabel replaces the duration requires-actionThe tool waits for approval. Warning icon and border; the approval footer renders
Animation configuration for the ChatTool and ChatToolGroup roots. Can be:
false or "disabled": Disable only the layout transition
"disable-all": Disable all animations including the chevron, the panel fade, the shimmer, and the copy buttons
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | 'disable-all' | boolean- Disable animations while customizing properties layout.valueLayoutTransitionLinearTransition.springify().damping(140).stiffness(1600).mass(4)Layout transition of the card, the panel, and the approval footer. Exported as ChatToolLayoutTransition
prop type default description childrenReactNode- Trigger content. Text runs form one label; other nodes are row items classNamestring- Additional CSS classes for the container classNamesElementSlots<TriggerSlots>- Additional CSS classes for the slots styleViewStyle- Inline style of the container stylesChatToolTriggerStyles- Inline styles for the slots iconPropsChatToolTriggerIconProps- Props of the default chevron onPress(event: GestureResponderEvent) => void- Called when the trigger is pressed, before the content toggles onLongPress(event: GestureResponderEvent) => void- Called when the trigger is long-pressed. Works on non-expandable triggers too animationChatToolTriggerAnimation- Chevron rotation configuration isAnimatedStyleActivebooleantrueWhen false, the animated rotation is not applied to the indicator slot ...PressablePropsPressableProps- All React Native Pressable props except children and style
prop type description containerstringThe Pressable row contentstringRow hosting the status icon, the label, and the duration labelstringText grouping the text childrenshimmerContainerstringContainer of the TextShimmer label while the tool is active indicatorstringView hosting the chevron
prop type description contentViewStyleStyles for the content row labelTextStyleStyles for the label Text indicatorViewStyleStyles for the chevron view
prop type default description sizenumber14Size of the chevron, in pixels colorstringtheme muted Color of the chevron
Animation configuration for the chevron. Can be:
false or "disabled": The chevron snaps between its two rotations
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | boolean- Disable animations while customizing properties rotation.value[number, number][0, -180]Rotation values [collapsed, expanded], in degrees rotation.springConfigWithSpringConfig{ damping: 140, stiffness: 1000, mass: 4 }Spring configuration of the rotation
prop type default description childrenReactNode- Custom glyph replacing the state default classNamestring- Additional CSS classes for the wrapper iconPropsChatToolStatusIconIconProps- Props of the default glyphs ...ViewPropsViewProps- All React Native View props are supported
prop type default description sizenumber14Size of the glyph, in pixels colorstringsuccess when complete, danger on error, warning awaiting approval, otherwise mutedColor of the glyph
prop type default description childrenReactNode- Duration or timestamp. Strings and numbers render as muted tabular text classNamestring- Additional CSS classes. Applied to the Text for text children, else the View ...ViewPropsViewProps- All React Native View props are supported
prop type default description childrenReactNode- Expanded content, usually the args, result, and error classNamestring- Additional CSS classes for the container classNamesElementSlots<ContentSlots>- Additional CSS classes for the slots stylesPartial<Record<ContentSlots, ViewStyle>>- Inline styles for the slots animationChatToolContentAnimation- Panel fade configuration ...ViewPropsViewProps- All React Native View props are supported
prop type description containerstringAlways-mounted clipping wrapper whose height animates bodystringPadded column, mounted only while expanded
prop type description containerViewStyleStyles for the clipping wrapper bodyViewStyleStyles for the body
Animation configuration for the panel. Can be:
false or "disabled": The panel appears and disappears instantly
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(200).easing(Easing.bezier(0, 0, 0.2, 1))Entering animation of the panel exiting.valueEntryOrExitLayoutTypeFadeOut.duration(200).easing(Easing.in(Easing.ease))Exiting animation of the panel
prop type default description childrenReactNode- Custom content replacing the code block inputunknown- Tool input, rendered as formatted JSON argsTextstring- Preformatted input, used instead of input labelReactNode- Section label. Strings and numbers render as a small uppercase label languagestring'json'Language of the code block maxLinesnumberroot maxLines Lines shown before "Show more". 0 shows every line isCodeWrappedbooleanroot isCodeWrapped Wraps long lines instead of scrolling them sideways classNamestring- Additional CSS classes for the section column classNamesElementSlots<SectionSlots>- Additional CSS classes for the slots stylesChatToolSectionStyles- Inline styles for the slots showMoreLabelstring'Show more'Label of the "Show more" toggle showLessLabelstring'Show less'Label of the "Show less" toggle copyAccessibilityLabelstring'Copy code'Accessibility label of the copy button markdownTextPropsCodeBlockMarkdownTextPropsroot markdownTextProps Props of the highlighted renderer onCopy(text: string) => unknownroot onCopy Writes the code to the clipboard. The copy button renders only when set ...ViewPropsViewProps- All React Native View props are supported
prop type description containerstringSection column labelstringSection label Text codestringThe section's CodeBlock codeContentstringThe section's CodeBlock.Code
prop type description containerViewStyleStyles for the section column labelTextStyleStyles for the label Text codeViewStyleStyles for the CodeBlock codeContentViewStyleStyles for the CodeBlock.Code
Takes the same props as ChatTool.Args, with value instead of input and argsText.
prop type default description childrenReactNode- Custom content replacing the code block valueunknown- Tool output, rendered as formatted JSON labelReactNode- Section label. Strings and numbers render as a small uppercase label languagestring'json'Language of the code block maxLinesnumberroot maxLines Lines shown before "Show more". 0 shows every line isCodeWrappedbooleanroot isCodeWrapped Wraps long lines instead of scrolling them sideways classNamestring- Additional CSS classes for the section column classNamesElementSlots<SectionSlots>- Additional CSS classes for the slots stylesChatToolSectionStyles- Inline styles for the slots showMoreLabelstring'Show more'Label of the "Show more" toggle showLessLabelstring'Show less'Label of the "Show less" toggle copyAccessibilityLabelstring'Copy code'Accessibility label of the copy button markdownTextPropsCodeBlockMarkdownTextPropsroot markdownTextProps Props of the highlighted renderer onCopy(text: string) => unknownroot onCopy Writes the code to the clipboard. The copy button renders only when set ...ViewPropsViewProps- All React Native View props are supported
prop type default description childrenReactNode- Custom error content. Strings and numbers render in the danger color errorTextstring- Error message labelReactNode- Section label. Strings and numbers render as a small uppercase label classNamestring- Additional CSS classes for the section column classNamesElementSlots<Exclude<SectionSlots, 'code'>>- Additional CSS classes for the container and label slots stylesOmit<ChatToolSectionStyles, 'code'>- Inline styles for the container and label slots ...ViewPropsViewProps- All React Native View props are supported
Renders only in the requires-action state.
prop type default description childrenReactNode- Footer content, usually ChatTool.ApprovalActions classNamestring- Additional CSS classes for the footer ...ViewPropsViewProps- All React Native View props are supported
prop type default description childrenReactNode- Buttons, usually ChatTool.Reject and ChatTool.Approve classNamestring- Additional CSS classes for the row ...ViewPropsViewProps- All React Native View props are supported
prop type default description childrenReactNode'Approve' / 'Reject'Button label. Strings and numbers render in Button.Label sizeButtonSize'sm'Size of the button variantButtonVariant'primary' / 'secondary'Visual variant of the button ...ButtonRootPropsButtonRootProps- All heroui-native Button props are supported
prop type default description toolCallIdstring- Tool call id. Required classNamestring- Additional CSS classes for the container classNamesElementSlots<MetaSlots>- Additional CSS classes for the slots styles{ container?: ViewStyle; text?: TextStyle }- Inline styles for the slots ...ViewPropsViewProps- All React Native View props are supported
prop type description containerstringFooter row textstringTool call id Text
prop type default description childrenReactNode- Usually ChatToolGroup.Trigger followed by ChatToolGroup.Content isExpandedboolean- Controlled expanded state defaultExpandedbooleanfalseExpanded state on mount, for uncontrolled usage isDisabledbooleanfalseDisables the trigger. The content keeps its current state isActivebooleanfalseWhether the trigger label shimmers stateKeystring- Keeps the expanded state across row remounts in ChatConversation.Content classNamestring- Additional CSS classes for the card onExpandedChange(isExpanded: boolean) => void- Called when the expanded state changes animationChatToolRootAnimation- Animation configuration. Same as the ChatTool root ...ViewPropsViewProps- All React Native View props are supported
Takes the same props as ChatTool.Trigger.
prop type default description childrenReactNode- Grouped ChatTools classNamestring- Additional CSS classes for the container classNamesElementSlots<GroupContentSlots>- Additional CSS classes for the slots stylesPartial<Record<GroupContentSlots, ViewStyle>>- Inline styles for the slots animationChatToolContentAnimation- Panel fade configuration ...ViewPropsViewProps- All React Native View props are supported
prop type description containerstringAlways-mounted clipping wrapper whose height animates bodystringColumn of tools, mounted only while expanded
Returns the state of the enclosing ChatTool, for custom parts.
property type description stateChatToolStateLifecycle state of the tool call visualStateChatToolVisualStateVisual state derived from state with mapToolStateToVisual isActivebooleanWhether the trigger label shimmers isExpandablebooleanWhether the card can expand isExpandedbooleanWhether the content is expanded isDisabledbooleanWhether the trigger is disabled maxLinesnumberLine clamp of the args and result isCodeWrappedbooleanWhether long lines in the args and result wrap onCopy((text: string) => unknown) | undefinedClipboard writer shared with the args and result markdownTextPropsCodeBlockMarkdownTextProps | undefinedHighlighted-renderer props shared with the args and result setIsExpanded(isExpanded: boolean) => voidExpands or collapses the content
Returns the state of the enclosing ChatToolGroup.
property type description isActivebooleanWhether the trigger label shimmers isExpandedbooleanWhether the content is expanded isDisabledbooleanWhether the trigger is disabled setIsExpanded(isExpanded: boolean) => voidExpands or collapses the content