import type { ReactNode } from 'react'; import type { output, ZodObject } from 'zod'; import type { FormProcessor, ZodFormRegistry } from '@zod-to-form/core'; import type { RuntimeComponentConfig, ZodFormComponents } from './FieldRenderer.js'; import type { input } from 'zod'; export type { ZodFormComponents }; type ZodFormProps = { schema: TSchema; onSubmit?: (data: output) => unknown; onInvalid?: (errors: Record) => void; /** * Fires on every field change (and programmatic `form.reset()`). The first * arg is `output` when `meta.isValid` is true, `input` * otherwise (raw/partial values mid-edit). See `useZodForm` for details. */ onValueChange?: (data: output | input, meta: { isValid: boolean; }) => void; mode?: 'onSubmit' | 'onChange' | 'onBlur'; /** Forwarded to `useZodForm`/`FieldRenderer`. See `UseZodFormOptions.errorDisplay`. */ errorDisplay?: 'always' | 'afterTouched'; defaultValues?: Partial>; components?: ZodFormComponents; componentConfig?: RuntimeComponentConfig; formRegistry?: ZodFormRegistry; processors?: Record; className?: string; children?: ReactNode; }; /** * Runtime React component that renders a type-safe form from a Zod v4 schema. * * Walks `schema` to produce `FormField[]`, wires React Hook Form with a * `zodResolver`, and renders each field using the matched component from * `components` (defaults to `defaultComponentMap`). Sections defined in * `componentConfig.fields` are rendered as grouped fieldsets. * * @param props - Schema, event handlers, and optional component/config overrides. * @returns A ``-wrapped form element. * * @example * ```tsx * import { ZodForm } from '@zod-to-form/react'; * import { z } from 'zod'; * * const loginSchema = z.object({ * email: z.string().email(), * password: z.string().min(8), * }); * * console.log(data)} /> * ``` * * @useWhen * - You need form rendering in storybook, playgrounds, or low-traffic admin UIs — where bundle overhead is acceptable and a build step would add friction * - You are prototyping before committing to CLI codegen — `` and the CLI share the same walkSchema output so the migration is mechanical * * @avoidWhen * - Bundle size is critical — use CLI codegen (`@zod-to-form/cli`) instead; runtime schema walking includes the full Zod type graph traversal, which does not tree-shake * - You need forms for complex schemas with cyclic references — the walker does not handle cycles and hits the max-depth guard silently with no error * * @never * - NEVER pass `componentConfig` without a matching `components` map that covers * the component names referenced — missing components are silently dropped at * render time with no console error; add each name to `components` or use * `defaultComponentMap` as the base * - NEVER expect controlled component prop expressions (e.g. `field.value`) to * work without a `propMap` in `componentConfig` — uncontrolled mode is the * default; add `propMap: { value: 'value', onChange: 'onChange' }` in field * config to opt in to controlled mode * * @category Components */ export declare function ZodForm(props: ZodFormProps): ReactNode; //# sourceMappingURL=ZodForm.d.ts.map