Asks an agent's clarifying questions one at a time inside a chat and collects the answers.
Asks an agent's clarifying questions one at a time inside a chat and collects the answers.
import { ApprovalCard } from 'heroui-native-pro' ;
< ApprovalCard questions ={questions}>
< ApprovalCard.Header >
< ApprovalCard.Title />
< ApprovalCard.Dismiss />
</ ApprovalCard.Header >
< ApprovalCard.Content >
< ApprovalCard.Options >
{(option) => < ApprovalCard.Option value ={option.id} />}
</ ApprovalCard.Options >
< ApprovalCard.CustomInput />
</ ApprovalCard.Content >
< ApprovalCard.Footer >
< ApprovalCard.Steps >
{({ question }) => < ApprovalCard.Step id ={question.id} />}
</ ApprovalCard.Steps >
< ApprovalCard.StepCount />
< ApprovalCard.SkippedCount />
< ApprovalCard.Actions >
< ApprovalCard.Skip />
< ApprovalCard.Continue />
</ ApprovalCard.Actions >
</ ApprovalCard.Footer >
</ ApprovalCard >
ApprovalCard : heroui-native Card that owns the questions, the answers, and the shown question. Without children it renders the layout above. It leaves out the dismiss button without onDismiss, and the steps and step count for a single question. Its height springs to each new question.
ApprovalCard.Header : Row that holds the title and the dismiss button.
ApprovalCard.Title : Text of the shown question, announced as a header.
ApprovalCard.Dismiss : Ghost heroui-native CloseButton in the top-end corner. It calls onDismiss.
ApprovalCard.Content : Column that holds the options and the custom input. It fades and rises in when the question changes.
ApprovalCard.Options : Option rows of the shown question. Every option is shown; the list does not scroll. Renders nothing when the question has no options.
ApprovalCard.Option : Pressable row with the label, the description, and a leading Radio (single selection) or Checkbox (multiple selection). The whole row is one touch target and one screen reader radio or checkbox.
ApprovalCard.CustomInput : heroui-native Input for an answer that isn't listed. Renders only when the question sets allowCustom. The return key moves on.
ApprovalCard.Footer : Row that holds the progress and the actions. It wraps the actions to a second line when they don't fit.
ApprovalCard.Steps : Row of progress dots, announced as a tab list.
ApprovalCard.Step : Dot of one question. The shown question's dot grows into a pill. Pressing a dot shows that question.
ApprovalCard.StepCount : Visible N/M, announced as "Question N of M" when the question changes.
ApprovalCard.SkippedCount : "N skipped". Shows on the last question when another question has no answer.
ApprovalCard.Actions : Row at the trailing edge that holds Skip and Continue.
ApprovalCard.Skip : Ghost button that skips the question. On the last question it submits.
ApprovalCard.Continue : Primary button that answers the question and moves on. On the last question it reads "Send" and submits.
Pass questions and handle onSubmit. A question picks one option by default. Set selectionMode: 'multiple' to pick several, and allowCustom to add a text field.
const questions: ApprovalCardQuestion [] = [
{
id: 'method' ,
title: 'How should users sign in?' ,
options: [
{ id: 'passkeys' , label: 'Passkeys' , description: 'Face ID or Touch ID, no passwords' },
{ id: 'magic-link' , label: 'Magic link' , description: 'A one-time link sent to their inbox' },
],
},
{
id: 'pages' ,
title: 'Which pages need sign-in?' ,
selectionMode: 'multiple' ,
options: [
{ id: 'dashboard' , label: 'Dashboard' },
{ id: 'settings' , label: 'Settings' },
],
},
{
id: 'sessions' ,
title: 'Where do sessions live?' ,
allowCustom: true ,
options: [{ id: 'database' , label: 'Database' }],
},
];
< ApprovalCard
questions ={questions}
onSubmit ={({ answers, skipped }) => sendToolOutput ({ answers, skipped })}
onDismiss ={cancelToolCall}
/>;
onSubmit receives the answered questions, with typed answers trimmed, and the ids of the questions without an answer.
{
answers: {
method: { selected: [ 'passkeys' ] },
sessions: { selected: [], custom: 'Redis' },
},
skipped: [ 'pages' ],
}
A question without options or allowCustom is a confirmation. Continue answers it with { selected: [] }. Skip declines it. Rename the buttons through their children.
< ApprovalCard
questions ={[{ id: 'migrate' , title: 'Run the database migration on production?' }]}
onSubmit ={({ answers }) => ( 'migrate' in answers ? runMigration () : cancel ())}
>
< ApprovalCard.Header >
< ApprovalCard.Title />
</ ApprovalCard.Header >
< ApprovalCard.Content className = "px-2 pb-2" >...</ ApprovalCard.Content >
< ApprovalCard.Footer >
< ApprovalCard.Actions >
< ApprovalCard.Skip >Decline</ ApprovalCard.Skip >
< ApprovalCard.Continue >Approve</ ApprovalCard.Continue >
</ ApprovalCard.Actions >
</ ApprovalCard.Footer >
</ ApprovalCard >
The default labels are English. Every part takes its own text, including the screen reader labels.
< ApprovalCard.Dismiss aria-label ={ t `Dismiss` } />
< ApprovalCard.CustomInput accessibilityLabel ={ t `Other answer` } placeholder ={ t `Something else…` } />
< ApprovalCard.Steps accessibilityLabel ={ t `Questions` }>
{({ index, isAnswered, question }) => (
< ApprovalCard.Step
id ={question.id}
accessibilityLabel ={isAnswered ? t `Question ${ index + 1 } , answered` : t `Question ${ index + 1 } , not answered` }
/>
)}
</ ApprovalCard.Steps >
< ApprovalCard.StepCount >{({ current, total }) => t `Question ${ current } of ${ total } ` }</ ApprovalCard.StepCount >
< ApprovalCard.SkippedCount >{({ count }) => t ` ${ count } skipped` }</ ApprovalCard.SkippedCount >
< ApprovalCard.Skip >{ t `Skip` }</ ApprovalCard.Skip >
< ApprovalCard.Continue >{({ isLastStep }) => (isLastStep ? t `Send` : t `Continue` )}</ ApprovalCard.Continue >
A function that returns text keeps Continue as wide as its longer label, so the button doesn't resize on the last question.
Control the answers with value and onChange, and the shown question with currentStep and onStepChange. This keeps the state when a chat list recycles the cell.
const [value, setValue] = useState < ApprovalCardValue >({});
const [step, setStep] = useState ( 0 );
< ApprovalCard
questions ={questions}
value ={value}
onChange ={setValue}
currentStep ={step}
onStepChange ={setStep}
onSubmit ={submit}
/>;
Past maxVisible questions, the dots scroll with the shown question. The dots at the edges shrink.
< ApprovalCard.Steps maxVisible ={ 5 } />
Every part is optional. For a custom approval, ask one confirmation question and put your content in Header, Content, and Footer.
< ApprovalCard questions ={[{ id: 'book' , title: 'Book Casa Lago' }]} onSubmit ={handleBooking}>
< ApprovalCard.Header className = "items-center" >
< Avatar alt = "Casa Lago" size = "lg" >...</ Avatar >
< View className = "flex-1 gap-1" >
< ApprovalCard.Title />
< Text className = "text-sm text-muted" >Bellagio, Lake Como</ Text >
</ View >
</ ApprovalCard.Header >
< ApprovalCard.Content className = "gap-6 px-2 pt-4 pb-3" >...</ ApprovalCard.Content >
< ApprovalCard.Footer >
< ControlField isSelected ={alwaysAllow} onSelectedChange ={setAlwaysAllow}>
...
</ ControlField >
< ApprovalCard.Actions >
< ApprovalCard.Skip variant = "tertiary" >Decline</ ApprovalCard.Skip >
< ApprovalCard.Continue >Book</ ApprovalCard.Continue >
</ ApprovalCard.Actions >
</ ApprovalCard.Footer >
</ ApprovalCard >
To build a custom part, read the card state with useApprovalCard.
The card height springs between questions. Give content below the card the same transition so it moves in sync. Inside a virtualized ChatConversation.Content row the card resizes at once, because the list can't follow an animated height.
< Animated.View layout ={ApprovalCardLayoutTransition}>...</ Animated.View >
Show the card for an ask_user tool call that waits for input. Send the result back as the tool output.
if (part.state === 'input-available' ) {
return (
< ApprovalCard
key ={part.toolCallId}
questions ={ toQuestions (part.input)}
onSubmit ={(output) => addToolOutput ({ tool: 'ask_user' , toolCallId: part.toolCallId, output })}
onDismiss ={() =>
addToolOutput ({
tool: 'ask_user' ,
toolCallId: part.toolCallId,
state: 'output-error' ,
errorText: 'The user dismissed the questions.' ,
})
}
/>
);
}
import type { ApprovalCardQuestion } from 'heroui-native-pro' ;
import { ApprovalCard, ChatMessage } from 'heroui-native-pro' ;
import { useState } from 'react' ;
import { Text } from 'react-native' ;
const QUESTIONS: ApprovalCardQuestion [] = [
{
id: 'flight' ,
title: 'Which flight works best?' ,
options: [
{ id: 'nonstop' , label: '11:05 AM nonstop' , description: 'Lands Saturday 3:20 PM, $1,240' },
{ id: 'one-stop' , label: '8:40 AM one-stop' , description: 'Lands Saturday 6:55 PM, $860' },
{ id: 'red-eye' , label: '11:50 PM red-eye' , description: 'Lands Sunday 5:30 AM, $790' },
],
},
{
id: 'extras' ,
title: 'Anything to add?' ,
selectionMode: 'multiple' ,
allowCustom: true ,
options: [
{ id: 'bag' , label: 'Checked bag' , description: '23 kg, $75 each way' },
{ id: 'legroom' , label: 'Extra legroom' , description: 'Aisle seat in row 14, $120' },
{ id: 'pickup' , label: 'Airport pickup' , description: 'A driver waiting at arrivals, $95' },
],
},
];
export default function ApprovalCardExample () {
const [result, setResult] = useState < string | null >( null );
return (
< ChatMessage.Assistant >
< ChatMessage.Avatar alt = "Assistant" fallback = "AI" />
< ChatMessage.Body >
< ChatMessage.Content >I found three flights. A couple of questions first:</ ChatMessage.Content >
{result ? (
< Text className = "text-sm text-muted" >{result}</ Text >
) : (
< ApprovalCard
questions ={QUESTIONS}
onDismiss ={() => setResult ( 'Dismissed' )}
onSubmit ={({ answers }) =>
setResult ( `Answered ${ Object. keys (answers). length } of ${ QUESTIONS. length } questions` )
}
/>
)}
</ ChatMessage.Body >
</ ChatMessage.Assistant >
);
}
prop type default description childrenReactNode- Card parts. Defaults to the full layout questionsApprovalCardQuestion[]- Questions asked one at a time (required) variant'default' | 'secondary' | 'tertiary' | 'transparent''default'heroui-native Card surface valueApprovalCardValue- Answers when controlled defaultValueApprovalCardValue{}Initial answers when uncontrolled currentStepnumber- Index of the shown question when controlled defaultStepnumber0Index of the first shown question when uncontrolled classNamestring- Additional CSS classes for the card onChange(value: ApprovalCardValue) => void- Called on every answer change onStepChange(step: number) => void- Called when the shown question changes onSkip(questionId: string) => void- Called with the id of a skipped question onSubmit(result: ApprovalCardSubmitResult) => void- Called by Send on the last question, or by Skip there onDismiss() => void- Called by the dismiss button animationApprovalCardRootAnimation- Height and question-change animations ...CardPropsCardRootProps- heroui-native Card props, including background
prop type default description idstring- Unique id. Answers are keyed by it titlestring- Question text optionsApprovalCardOptionItem[]- Options in order. Without options or allowCustom, a confirmation selectionMode'single' | 'multiple''single'Pick one option or several allowCustombooleanfalseShows a text field for an unlisted answer allowSkipbooleantrueShows Skip for this question
prop type default description idstring- Unique id within the question labelstring- Option label descriptionstring- Muted second line under the label
prop type description selectedstring[]Picked option ids customstringTyped answer from the custom input
ApprovalCardValue is Record<string, ApprovalCardAnswer>, keyed by question id.
prop type description answersApprovalCardValueAnswered questions only, with typed answers trimmed skippedstring[]Ids of the questions without an answer, in order
prop type default description state'disabled' | 'disable-all' | boolean- Disable animations while customizing properties layout.valueLayoutTransitionLinearTransition.springify().damping(140).stiffness(1600).mass(4)Height animation of the card, header, content, footer, and actions swap.valueEntryOrExitLayoutTypeFade in while rising 4px, 200ms Entering of the title and content after the question changes labelSwap.valueEntryOrExitLayoutTypeFadeIn.duration(200)Entering of the Continue label and skipped count after a change
false or 'disabled' changes the question and height at once. 'disable-all' also turns off the dots and the press feedback of every option and button. The animations don't play on the first render. The layout transition is exported as ApprovalCardLayoutTransition.
prop type default description childrenReactNode- Title, dismiss button, or custom content classNamestring- Additional CSS classes ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNodeThe question title Replaces the question title classNamestring- Additional CSS classes ...TextPropsTextProps- All standard React Native Text props are supported
prop type default description variantButtonVariant'ghost'Button variant. Ghost has no fill until pressed aria-labelstring'Dismiss'Screen reader label classNamestring- Additional CSS classes onPress(event) => void- Called before onDismiss ...CloseButtonPropsCloseButtonProps- heroui-native CloseButton props
prop type default description childrenReactNode- Options, custom input, or custom content classNamestring- Additional CSS classes ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode | ((option: ApprovalCardOptionItem) => ReactNode)One per option Option elements, or a function called for each option classNamestring- Additional CSS classes ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Replaces the label valuestring- Id of an option of the shown question (required) isDisabledbooleanfalseWhether the option can't be picked classNamestring- Additional CSS classes for the row classNamesElementSlots<OptionSlots>- Additional CSS classes for the slots stylesOptionStyles- Styles for the slots onPress(event: GestureResponderEvent) => void- Called before the option is picked animationApprovalCardOptionAnimation- Press highlight and scale ...PressableFeedbackPropsPressableFeedbackProps- heroui-native PressableFeedback props
slot description containerPressable row contentColumn that holds the label and description labelLabel text descriptionDescription text controlLeading view that holds the radio or checkbox
slot type description containerViewStylePressable row contentViewStyleLabel column labelTextStyleLabel text descriptionTextStyleDescription text controlViewStyleRadio / checkbox view
prop type default description state'disabled' | 'disable-all' | boolean- Disable animations while customizing scalePressableFeedbackScaleAnimationOff Press scale of the row highlightPressableFeedbackHighlightAnimationOpacity [0, 0.05] Highlight overlay while pressed
prop type default description variant'primary' | 'secondary''secondary'heroui-native Input variant placeholderstring'Something else…'Placeholder text accessibilityLabelstring'Other answer'Screen reader label returnKeyTypeReturnKeyTypeOptions'next' / 'send''send' on the last questionclassNamestring- Additional CSS classes onChangeText(text: string) => void- Called before the typed answer is stored onSubmitEditing(event) => void- Called before the card moves on ...InputPropsInputProps- heroui-native Input props, except value and defaultValue
With single selection, typing an answer clears the picked option.
prop type default description childrenReactNode- Progress, actions, or custom content classNamestring- Additional CSS classes ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode | ((props: ApprovalCardStepRenderProps) => ReactNode)One per question Step elements, or a function called for each question maxVisiblenumber7Dots shown at once. Past it, the dots scroll accessibilityLabelstring'Questions'Screen reader label of the tab list classNamestring- Additional CSS classes ...ViewPropsViewProps- All standard React Native View props are supported
prop type description indexnumber0-based position of the question isAnsweredbooleanWhether the question has an answer questionApprovalCardQuestionThe question
prop type default description idstring- Id of the question (required) accessibilityLabelstring'Question N, (not) answered'Screen reader label of the tab classNamestring- Additional CSS classes for the hit area classNamesElementSlots<StepSlots>- Additional CSS classes for the slots stylesPartial<Record<StepSlots, ViewStyle>>- Styles for the slots onPress(event: GestureResponderEvent) => void- Called before the question is shown animationApprovalCardStepAnimation- Dot size animation isAnimatedStyleActivebooleantrueWhether the animated dot size is applied ...PressablePropsPressableProps- All standard React Native Pressable props are supported
The hit area is 24px tall. hitSlop extends it to 44pt.
slot description containerPressable hit area dotPainted dot. Its width and height are animated
prop type default description state'disabled' | boolean- Disable animations while customizing size.timingConfigWithTimingConfig{ duration: 200, easing: Easing.bezier(0.76, 0, 0.24, 1) }Timing of the dot width and height
prop type default description childrenstring | ((props: ApprovalCardStepCountRenderProps) => string)'Question N of M'Replaces the announced text. The visible N/M stays classNamestring- Additional CSS classes classNamesElementSlots<StepCountSlots>- Additional CSS classes for the slots stylesPartial<Record<StepCountSlots, TextStyle>>- Styles for the slots ...TextPropsTextProps- All standard React Native Text props are supported
slot description containerN/M textcurrentNested current number
prop type description currentnumber1-based position of the shown question totalnumberNumber of questions
prop type default description childrenReactNode | ((props: ApprovalCardSkippedCountRenderProps) => ReactNode)'N skipped'Replaces the default text classNamestring- Additional CSS classes ...TextPropsTextProps- All standard React Native Text props are supported
prop type description countnumberQuestions, other than the shown one, without an answer
prop type default description childrenReactNode- Skip, Continue, or custom buttons classNamestring- Additional CSS classes ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode'Skip'Button label sizeButtonSize'sm'Button size variantButtonVariant'ghost'Button variant onPress(event) => void- Called before the question is skipped ...ButtonPropsButtonRootProps- heroui-native Button props
Renders nothing when the question sets allowSkip: false.
prop type default description childrenReactNode | ((props: ApprovalCardContinueRenderProps) => ReactNode)'Continue' / 'Send'Replaces both labels sizeButtonSize'sm'Button size variantButtonVariant'primary'Button variant isDisabledboolean- Disables the button. It is also disabled until the question can continue onPress(event) => void- Called before the question is answered ...ButtonPropsButtonRootProps- heroui-native Button props, except children
prop type description isLastStepbooleanWhether the shown question is the last one
Reads the card state inside an ApprovalCard.
property type description questionsApprovalCardQuestion[]All questions questionApprovalCardQuestion | undefinedShown question currentStepnumber0-based index of the shown question isLastStepbooleanWhether the shown question is the last one valueApprovalCardValueAll answers answerApprovalCardAnswerAnswer of the shown question canContinuebooleanWhether the shown question can continue skippedCountnumberQuestions, other than the shown one, without an answer pick(optionId: string) => voidPicks an option. Toggles it with multiple selection setCustom(text: string) => voidSets the typed answer goTo(step: number) => voidShows the question at step next() => voidAnswers the shown question and moves on, or submits skip() => voidSkips the shown question and moves on, or submits onDismiss(() => void) | undefinedRoot onDismiss
It also returns the values the parts use for their animations: hasSwapped, layoutTransition, swapEntering, and labelSwapEntering.