UNPKG

@undermuz/react-json-form

Version:
203 lines (198 loc) 7.51 kB
import { IErrors, UseFormConfig, IError, ITouched } from '@undermuz/use-form'; import { ForwardedRef, MutableRefObject, FC, PropsWithChildren, CSSProperties, Ref, ComponentClass, ReactNode, ForwardRefExoticComponent, RefAttributes } from 'react'; interface IChildFormRef { id: string; ref: IJsonFormRef | null; } interface IChildFormRefs { [s: string]: IJsonFormRef; } type IChildFormsSetRef = (ref: IChildFormRef) => void; declare const hasErrors: (errors?: IErrors | TypeErrorItem[] | null) => boolean; declare const useFlatRef: (id: string | number, ref: ForwardedRef<IJsonFormRef>, form: UseFormConfig, childFormsRef: MutableRefObject<IChildFormRefs>) => void; interface IInput { id?: string; name?: string; placeholder?: string; value?: any; isDisabled?: boolean; type: EnumSchemeItemType | string; hasError?: boolean; title: string; settings: TypeSchemeItemSettings; onFormsRef?: IChildFormsSetRef; onError?: CallableFunction; onChange?: (value: unknown) => void; onFocus?: () => void; onBlur?: () => void; } declare const Input: FC<PropsWithChildren & IInput>; declare enum EnumSchemeItemType { Input = "input", Text = "text", TextBlock = "text-block", TextEditor = "text-editor", Checkbox = "checkbox", Files = "files", Widget = "widget", Select = "select", GeoCoordinates = "geo", Date = "date", Submit = "submit" } type TypeSchemeItemSettings = Record<string, any> & { showToggle?: boolean; showLabel?: boolean; }; type FieldRuleSingleFunction = (v: any) => boolean; type FieldRuleGenericFunction<T extends Array<any> = any[]> = (...args: T) => FieldRuleSingleFunction; type FieldRuleFunction = FieldRuleSingleFunction | FieldRuleGenericFunction; type JsonFormFieldRule = [Array<FieldRuleFunction | string>, string?]; interface ISchemeItem { name: string; title: string; description?: string; placeholder?: string; type?: EnumSchemeItemType | string; def_value?: any; single?: boolean; multiple?: boolean; rules?: JsonFormFieldRule[] | undefined; settings?: TypeSchemeItemSettings; scheme?: ISchemeItem[]; } interface IFieldWidgetSettings { scheme: ISchemeItem[]; multiple: boolean; } interface IScheme { id: string; title: string; scheme: ISchemeItem[]; multiple?: boolean; } type TypeErrorItem = { id: number; value: IErrors | TypeErrorItem[]; }; type SubmitErrors = null | IErrors | TypeErrorItem[] | IErrors[]; type DefType = Record<string, any>; type TypeValueItem<T extends DefType = DefType> = T; type TypeValue<T extends DefType = DefType> = TypeValueItem<T> | TypeValueItem<T>[]; type FunctionOnChange<T extends DefType = DefType> = (value: TypeValue<T>) => void; type FieldTests = { [p: string]: FieldRuleFunction; }; interface JsonFormControls { [key: string]: FC<IInput>; FileInput: FC<IInput>; Input: FC<IInput>; TextBlock: FC<IInput>; CheckBox: FC<IInput>; Date: FC<IInput>; Select: FC<IInput>; } type IUiHeaderProps = Partial<Pick<IScheme, "id" | "title">> & { primary?: boolean; level: number; }; type IUiBodyProps = Partial<Pick<IScheme, "id" | "title">> & { primary?: boolean; multiple?: boolean; level: number; }; interface IUiTabProps { label?: string; active?: boolean; alt?: string; style?: CSSProperties | undefined; ref?: Ref<HTMLElement> | undefined; onSelect?: (...args: any[]) => any; } interface IField { id: string; title: string; description?: string; name: string; isLast: boolean; showToggle?: boolean; showLabel?: boolean; primary?: boolean; type: EnumSchemeItemType | string; errors: IError; } interface IItem { [k: string]: any; title: string; isLast: boolean; primary?: boolean; type: EnumSchemeItemType | string; isLoading?: boolean; } interface IUiArrayFormProps { style?: CSSProperties | undefined; } interface IUiArrayFormTrashContainerProps { isOver: boolean; label?: string; ref?: Ref<HTMLDivElement> | undefined; } interface JsonFormIcons { Tabs: { Remove: FC<any> | ComponentClass<any>; Add: FC<any> | ComponentClass<any>; }; } type JsonFormErrors = IErrors | TypeErrorItem[]; interface IJsonFormParams { isLoading?: boolean; value: TypeValue; primary?: boolean; header?: ReactNode; onChange: FunctionOnChange; onError?: (e: JsonFormErrors) => void; } interface IJsonFormRefObject<T extends DefType = DefType> { setTouched: (newTouched: ITouched | null, silent?: boolean, checkOnlyFilled?: boolean) => void; validate: (checkOnlyFilled?: boolean, level?: number) => null | IErrors | TypeErrorItem[]; values: () => TypeValue<T>; errors: () => IErrors | TypeErrorItem[]; } type IJsonFormRefArray<T extends DefType = DefType> = IJsonFormRefObject<T>[]; type IJsonFormRef<T extends DefType = DefType> = IJsonFormRefObject<T> | IJsonFormRefArray<T>; type IJsonFormProps = PropsWithChildren & IJsonFormParams & Partial<Pick<IScheme, "title">> & Pick<IScheme, "id" | "multiple" | "scheme"> & { tests?: FieldTests; viewType?: string; level?: number; fillArrayDefault?: boolean; }; interface JsonFormComponents { JsonForm: FC<PropsWithChildren<IJsonFormProps>>; } interface IUiArrayFormTabsProps { actions?: boolean; } interface IUiFlatFormProps { isShow: boolean; primary?: boolean; } interface JsonFormUi { Container: FC<PropsWithChildren<object>>; Header: FC<PropsWithChildren<IUiHeaderProps>>; Body: FC<PropsWithChildren<IUiBodyProps>>; FlatForm: FC<PropsWithChildren<IUiFlatFormProps>>; Field: FC<PropsWithChildren<IField>>; Item: FC<PropsWithChildren<IItem>>; ItemWrapper: FC<PropsWithChildren<IItem>>; ArrayForm: FC<PropsWithChildren<IUiArrayFormProps>> & { Header: FC<PropsWithChildren<object>>; Tabs: FC<PropsWithChildren<IUiArrayFormTabsProps>>; Body: FC<PropsWithChildren<object>>; TrashContainer: ForwardRefExoticComponent<Omit<PropsWithChildren<IUiArrayFormTrashContainerProps>, "ref"> & RefAttributes<HTMLDivElement>>; }; Tab: ForwardRefExoticComponent<Omit<PropsWithChildren<IUiTabProps>, "ref"> & RefAttributes<HTMLButtonElement>>; Components?: Partial<JsonFormComponents>; Controls: JsonFormControls; Icons: JsonFormIcons; } export { IUiArrayFormTabsProps as A, IUiFlatFormProps as B, JsonFormUi as C, DefType as D, EnumSchemeItemType as E, FieldTests as F, IChildFormsSetRef as G, IChildFormRef as H, IJsonFormParams as I, JsonFormFieldRule as J, IChildFormRefs as K, hasErrors as L, useFlatRef as M, Input as N, SubmitErrors as S, TypeValueItem as T, IScheme as a, TypeValue as b, TypeErrorItem as c, IJsonFormRef as d, IInput as e, TypeSchemeItemSettings as f, FieldRuleSingleFunction as g, FieldRuleGenericFunction as h, FieldRuleFunction as i, ISchemeItem as j, IFieldWidgetSettings as k, FunctionOnChange as l, JsonFormControls as m, IUiHeaderProps as n, IUiBodyProps as o, IUiTabProps as p, IField as q, IItem as r, IUiArrayFormProps as s, IUiArrayFormTrashContainerProps as t, JsonFormIcons as u, JsonFormErrors as v, IJsonFormRefObject as w, IJsonFormRefArray as x, IJsonFormProps as y, JsonFormComponents as z };