@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
43 lines (42 loc) • 1.57 kB
TypeScript
import { type ReactNode } from 'react';
import type { StandardSchemaV1 } from '@tanstack/react-form';
import type { ScopeHandle } from '../FieldScope/index.js';
import type { RegistryEntry } from '../internal/registry.js';
import type { HeadingLevel } from '../internal/types.js';
export type StepStatus = 'complete' | 'current' | 'upcoming' | 'error';
/** What `useFormSteps()` returns — for custom step chrome. */
export interface StepsApi {
steps: readonly {
value: string;
title: ReactNode;
status: StepStatus;
}[];
current: string;
index: number;
count: number;
isFirst: boolean;
isLast: boolean;
/** Validates the current step; advances if valid (on the last step: submits the form). */
next(): Promise<boolean>;
back(): void;
/** Goes to a step. With `linear`, going forward validates every step in between. */
goTo(step: string): Promise<boolean>;
}
export interface StepEntry extends RegistryEntry {
value: string;
title: ReactNode;
scope: ScopeHandle;
schema: StandardSchemaV1 | undefined;
/** Visible errors in the step right now. */
errors: number;
heading(): HTMLElement | null;
}
export interface FormStepsContextValue {
api: StepsApi;
current: string | undefined;
headingLevel: HeadingLevel;
register: (entry: StepEntry) => () => void;
/** Shows a step without validating (focus handling's `reveal()`). */
reveal: (step: string) => void;
}
export declare const FormStepsContext: import("react").Context<FormStepsContextValue | null>;