UNPKG

zod-auto-form

Version:

Auto-generate typed React forms from Zod schemas

95 lines (94 loc) 3.25 kB
import type { ZodError } from "zod"; type WithDefault<T> = { id: string; value: T; label: string; disabled: boolean; placeholder: string; isError: boolean; errorMessages: ZodError[]; title: string; description: string; onChange: (value: T) => void; onBlur: () => void; }; export type TextInputType = WithDefault<string>; export type SelectType = WithDefault<string> & { selectOptions?: string[]; }; export type MultiSelectType = WithDefault<string[]> & { selectOptions?: string[]; }; export type RadioGroupType = WithDefault<string> & { selectOptions?: string[]; }; export type NumberInputType = WithDefault<number>; export type CheckboxType = WithDefault<boolean>; export type SwitchType = WithDefault<boolean>; export type TextAreaType = WithDefault<string>; export type DateTimePickerType = WithDefault<Date>; export type ObjectWrapperType = { children: React.ReactNode[]; title?: string; description?: string; label?: string; required?: boolean; }; export type ArrayWrapperType = { children: React.ReactNode[]; label?: string; title?: string; description?: string; onAddField: () => void; onRemoveField: (index: number) => void; }; export type FormComponentType = { children: React.ReactNode; formId?: string; onSubmit: (e: React.FormEvent<HTMLFormElement>) => void; }; export type SubmitButtonType = { children: React.ReactNode; formId?: string; isLoading?: boolean; onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void; }; export type GroupedFieldsWrapperType = { children: React.ReactNode[]; groupName: string; }; export type ArrayInputFieldWrapperType = { children: React.ReactNode[]; label?: string; title?: string; description?: string; onAddField: () => void; onRemoveField: (index: number) => void; }; export type ArrayStringType = WithDefault<string>; export type ArrayNumberType = WithDefault<number>; export type ArrayBooleanType = WithDefault<boolean>; export type ArrayDateType = WithDefault<Date>; export type ComponentContextType = { Input: React.ComponentType<TextInputType>; Select: React.ComponentType<SelectType>; MultiSelect: React.ComponentType<MultiSelectType>; RadioGroup: React.ComponentType<RadioGroupType>; NumberInput: React.ComponentType<NumberInputType>; Checkbox: React.ComponentType<CheckboxType>; Switch: React.ComponentType<SwitchType>; TextArea: React.ComponentType<TextAreaType>; DateTimePicker: React.ComponentType<DateTimePickerType>; ObjectWrapper: React.ComponentType<ObjectWrapperType>; ArrayWrapper: React.ComponentType<ArrayWrapperType>; Form: React.ComponentType<FormComponentType>; SubmitButton: React.ComponentType<SubmitButtonType>; GroupedFieldsWrapper: React.ComponentType<GroupedFieldsWrapperType>; ArrayInputFieldWrapper: React.ComponentType<ArrayInputFieldWrapperType>; arrayString: React.ComponentType<ArrayStringType>; arrayNumber: React.ComponentType<ArrayNumberType>; arrayBoolean: React.ComponentType<ArrayBooleanType>; arrayDate: React.ComponentType<ArrayDateType>; }; export type ComponentContextTypeKeys = keyof ComponentContextType; export {};