import { RequiredBy, PropTypes, JSX, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types'; import * as _zag_js_core from '@zag-js/core'; import { StateMachine, Machine } from '@zag-js/core'; interface FieldOptions { type?: string; validate?: ValidatorFn; } type ValiidatorResult = string | null | Promise; type ValidatorFn = (value: any, values: Record) => ValiidatorResult; type ValidateRules = Partial>>; interface FieldPublicContext extends DirectionProperty, CommonProperties { /** * The value of the field */ value?: any; /** * Validation rule for the field */ validate?: ValidatorFn; } type FieldUserDefinedContext = RequiredBy; type FieldComputedContext = Readonly<{}>; interface FieldPrivateContext { } interface FieldMachineContext extends FieldPublicContext, FieldPrivateContext, FieldComputedContext { } interface FieldMachineState { value: "idle" | "validating" | "valid" | "invalid"; } type FieldChangeEvent = { type: "CHANGE"; value: any; }; type FieldFocusEvent = { type: "FOCUS"; }; type FieldBlurEvent = { type: "BLUR"; }; type FieldValidateEvent = { type: "VALIDATE"; validator?: ValidatorFn; values?: Record; }; type FieldResetErrorEvent = { type: "RESET_ERROR"; }; type FieldMachineEvent = FieldFocusEvent | FieldBlurEvent | FieldChangeEvent | FieldValidateEvent | FieldResetErrorEvent; type FieldState = StateMachine.State; type FieldSend = StateMachine.Send; type FieldService = Machine; type ElementIds = Partial<{ form: string; field(name: K): string; }>; interface FormPublicContext extends DirectionProperty, CommonProperties { /** * The ids of the elements in the form. Useful for composition. */ ids?: ElementIds; /** * The default values of the fields in the form */ defaultValues: Record | (() => Record | Promise>); /** * Validation rules for the form */ validate?: ValidateRules; /** * When validation gets triggered * @default "all" */ validation: "change" | "submit" | "blur" | "all"; /** * Whether to focus on the first field with error after submitting * @default true */ focusOnError?: boolean; } type FormUserDefinedContext = RequiredBy, "id">; type FormComputedContext = Readonly<{}>; interface FormPrivateContext { } interface FormMachineContext extends FormPublicContext, FormPrivateContext, FormComputedContext { } interface FormMachineState { value: "loading" | "initialized" | "submitting" | "submitted"; } type FormInitializeEvent = { type: "INITIALIZE"; }; type FormInitializedEvent = { type: "INITIALIZED"; }; type FormFieldChangeEvent = { type: "FIELD.CHANGE"; name: K; value: any; }; type FormFieldFocusEvent = { type: "FIELD.FOCUS"; name: K; }; type FormFieldBlurEvent = { type: "FIELD.BLUR"; name: K; }; type FormSubmitEvent = { type: "SUBMIT"; cb: (values: Record) => void; }; type FormSubmittedEvent = { type: "SUBMITTED"; }; type FormSubmitAbortEvent = { type: "SUBMIT.ABORT"; }; type FormMachineEvent = FormInitializeEvent | FormInitializedEvent | FormFieldChangeEvent | FormFieldFocusEvent | FormFieldBlurEvent | FormSubmitEvent | FormSubmittedEvent | FormSubmitAbortEvent; type FormState = StateMachine.State, FormMachineState, FormMachineEvent>; type FormSend = StateMachine.Send>; type FormService = Machine, FormMachineState, FormMachineEvent>; interface FormMachineApi { /** * Whether the form is dirty */ dirty: boolean; /** * Whether the form is validating */ validating: boolean; /** * Errors in the form */ errors: Record; /** * Function to get Current values of the form */ getValues: () => Record; /** * Function to submit the form. */ onSubmit>(cb: (values: Record) => void): (event?: E) => void; getFieldProps(name: K, options?: FieldOptions): T["element"]; } declare function formConnect(state: FormState, send: FormSend, normalize: NormalizeProps): FormMachineApi; declare function createFormmachine(userContext: FormUserDefinedContext): _zag_js_core.Machine, FormMachineState, FormMachineEvent>; declare function createFieldMachine(userContext: FieldUserDefinedContext): _zag_js_core.Machine; declare const form: { connect: typeof formConnect; machine: typeof createFormmachine; }; declare const field: { machine: typeof createFieldMachine; }; export { type ElementIds, type FieldMachineContext, type FieldMachineEvent, type FieldMachineState, type FieldSend, type FieldService, type FieldState, type FieldUserDefinedContext, type FormMachineApi, type FormMachineContext, type FormMachineEvent, type FormMachineState, type FormSend, type FormService, type FormState, type FormUserDefinedContext, field, form };