UNPKG

react-multistep-forms

Version:

Flexible and customizable multi-step form context for React with native React Hook Form integration.

46 lines 2.19 kB
import React from "react"; import type { ReactNode } from "react"; type StepKey = string; type MultistepFormContextType = { /** The index of the current step in the multistep form. */ currentStepIndex: number; /** The key of the current step in the multistep form. */ currentStepKey: StepKey; /** A mapping of step keys to their associated field names. */ stepFields: Record<StepKey, string[]>; /** A function to update the mapping of step keys to field names. */ setStepFields: React.Dispatch<React.SetStateAction<Record<StepKey, string[]>>>; /** Advances to the next step in the multistep form. */ nextStep: () => void; /** Moves to the previous step in the multistep form. */ prevStep: () => void; /** Submits the multistep form. */ submit: () => void; /** An array of step keys derived from the `stepFields` mapping. */ steps: StepKey[]; }; /** * A React context for managing the state and behavior of a multistep form. * Provides the current step, navigation functions, and step field mappings. */ export declare const MultistepFormContext: React.Context<MultistepFormContextType | undefined>; /** * A provider component for the `MultistepFormContext`. * * - Manages the state of the multistep form, including the current step and step fields. * - Provides functions for navigating between steps and submitting the form. * * @param {Object} props - The props for the `MultistepFormProvider` component. * @param {Record<StepKey, string[]>} props.stepFieldsMap - A mapping of step keys to their associated field names. * @param {() => void} [props.onSubmit] - An optional callback function to execute on form submission. * @param {ReactNode} props.children - The child elements to render within the provider. * * @returns {React.ReactElement} The `MultistepFormContext.Provider` wrapping the provided children. */ export declare function MultistepFormProvider({ stepFieldsMap, onSubmit, children, }: { stepFieldsMap: Record<StepKey, string[]>; onSubmit?: () => void; children: ReactNode; }): import("react/jsx-runtime").JSX.Element; export {}; //# sourceMappingURL=MultistepFormContext.d.ts.map