UNPKG

@payfit/unity-components

Version:

47 lines (46 loc) • 2.18 kB
import { ComponentPropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react'; import { AIStructuredInputStepProps } from './parts/AIStructuredInputStep.js'; /** * Data for one dynamically rendered structured-input step. * @property id Stable, explicit identity shared by the rendered step and its answer draft. */ export type AIStructuredInputItem = { id: string; }; /** Receives a navigation request for the next active step. */ export type AIStructuredInputActiveStepChangeHandler = (activeStepId: string) => void; /** * Props for a static or data-driven structured question sequence. * @typeParam TItem - Data type used by the `items` render-function API. */ export type AIStructuredInputProps<TItem extends AIStructuredInputItem = AIStructuredInputItem> = Omit<ComponentPropsWithoutRef<'div'>, 'children' | 'className'> & { /** * Renders identified steps directly, or renders each item when `items` is * supplied. Every step must have an explicit stable ID. */ children: ReactNode | ((item: TItem, index: number) => ReactElement<AIStructuredInputStepProps>); /** * Controls the active step. Pair with `onActiveStepChange` to control * navigation from the consumer. */ activeStepId?: string; /** * Sets the initially active step for uncontrolled navigation. Defaults to * the first step. */ defaultActiveStepId?: string; /** Receives navigation requests when the active step changes. */ onActiveStepChange?: AIStructuredInputActiveStepChangeHandler; /** Adds a banner above the questions and lets the root manage their layout. */ header?: ReactNode; /** * Supplies ordered question data for the render-function API. New items may * be appended while the sequence is active. */ items?: readonly TItem[]; /** Adds styles to the structured-input surface. */ className?: string; }; type StructuredInputComponent = <TItem extends AIStructuredInputItem = AIStructuredInputItem>(props: AIStructuredInputProps<TItem> & RefAttributes<HTMLDivElement>) => ReactElement | null; export declare const AIStructuredInput: StructuredInputComponent; export {};