UNPKG

@canard/schema-form

Version:

React-based component library that renders forms based on JSON Schema with plugin system support for validators and UI components

31 lines (30 loc) 1.95 kB
import { type PropsWithChildren } from 'react'; import type { Fn } from '../../@aileron/declare'; import type { FormProps } from '../../components/Form'; import { type SchemaNode, ValidationMode } from '../../core'; import type { AllowedValue, JsonSchema } from '../../types'; interface RootNodeContextProviderProps<Schema extends JsonSchema = JsonSchema, Value extends AllowedValue = any> { /** JSON Schema to use within this SchemaForm */ jsonSchema: FormProps<Schema, Value>['jsonSchema']; /** Default value for this SchemaForm */ defaultValue?: FormProps<Schema, Value>['defaultValue']; /** Initial validation errors, defaults to undefined */ errors?: FormProps<Schema, Value>['errors']; /** Function called when the value of this SchemaForm changes */ onChange: NonNullable<FormProps<Schema, Value>['onChange']>; /** Function called when this SchemaForm is validated */ onValidate: NonNullable<FormProps<Schema, Value>['onValidate']>; /** Function called when the root node of this SchemaForm is ready */ onReady: Fn<[rootNode: SchemaNode]>; /** * Execute Validation Mode (default: ValidationMode.OnChange | ValidationMode.OnRequest) * - `ValidationMode.None`: Disable validation * - `ValidationMode.OnChange`: Validate when value changes * - `ValidationMode.OnRequest`: Validate on request */ validationMode?: ValidationMode; /** ValidatorFactory declared externally, creates internally if not provided */ validatorFactory?: FormProps<Schema, Value>['validatorFactory']; } export declare const RootNodeContextProvider: <Value extends AllowedValue, Schema extends JsonSchema>({ jsonSchema, defaultValue, errors, onChange, onValidate, onReady, validationMode: inputValidationMode, validatorFactory: inputValidatorFactory, children, }: PropsWithChildren<RootNodeContextProviderProps<Schema, Value>>) => import("react/jsx-runtime").JSX.Element; export {};