import { AnyComponentSchema } from '@open-formulieren/types'; import { z } from 'zod'; import { FormSettings } from '../context'; import { JSONObject } from '../types'; import { JSONObjectWithUndefined } from './utils'; type ErrorPrimitive = string | undefined; type ErrorValue = ErrorPrimitive | ErrorValue[] | Errors; export type Errors = { [k: string]: ErrorValue; }; /** * Props for a complete Formio form definition. * * A formio form configuration typically also has the keys `display` and possibly * `settings` - we don't support those. Only the list of components to render is used. */ export interface FormioFormProps { /** * The form components to render. Only the @open-formulieren/types components are * supported. */ components: AnyComponentSchema[]; /** * Initial values for the form. This is merged with and overrides default values * extracted from the component definitions. */ values?: JSONObject; /** * Initial validation errors to display. Note that these are cleared when the * client side validation runs. */ errors?: Errors; /** * Callback invoked when form values update. * * The form value changes can be triggered by user input or automatic calculated value * changes, e.g. client-side form logic such as `clearOnHide`. */ onChange?: (values: JSONObject) => void | Promise; /** * Callback when the form validates (client-side) to submit the entered values. * * It receives the entered field values object. * * Must be an async function to make the Formik state handling a bit more ergonomic. */ onSubmit: (values: JSONObject) => Promise; /** * HTML ID of the
element - required if you put the submit button outside of * tag. */ id?: string; /** * Any children passed to the form will be rendered after the form fields. */ children?: React.ReactNode; /** * Mark required fields with an asterisk. If asterisks are not used, then a suffix * is added to the label of optional fields to specify the field is not required. */ requiredFieldsWithAsterisk?: boolean; /** * Configuration necessary specific to certain Formio component types. */ componentParameters?: FormSettings['componentParameters']; /** * Callback that implements the actual async 'plugin validator' behaviour. */ validatePluginCallback?: FormSettings['validatePluginCallback']; } export type UpdateValues = JSONObjectWithUndefined; export interface FormStateRef { updateValues: (values: UpdateValues) => void; updateErrors: (errors: Errors) => void; } /** * Main component to render a Formio form definition. * * The form configration (list of components) is processed and default values are * extracted, which are merged with any provided existing submission values. The * requested form fields are rendered so the user can interact with them. * * You can pass a `ref` to get an imperative handle to set values and (validation) * errors from your parent component. * * @throws {Error} Throws an error when conditional logic cycles have been detected. * It's recommended to validate these in your downstream project and set up an error * boundary around the `FormioForm` component. */ declare const FormioForm: import('react').ForwardRefExoticComponent>; export type InnerFormioFormProps = Pick & { onValidationSchemaChange: (schema: z.ZodSchema) => void; validatePluginCallback: Required['validatePluginCallback']; }; export default FormioForm;