import { SyntheticEvent } from "react"; import BaseFormControl from "../form/form-controls/BaseFormControl"; import BaseFormGroup from "../form/form-group/BaseFormGroup"; import BaseFormStepper from "../form/form-stepper/BaseFormStepper"; import { IDisplayProps, IEvent, IField, IFieldError, IFormConfig, IFormatterType, IIconConfig, IOption, IRest, IFormConfigExtended, IUISchema, IValidation, IconConfig, TParam, TParamType } from "./model-interfaces"; import { TChangeMode, TFormType, TNextCondition, TNextResponseMode, TOperator, TSectionLayout, TValue } from "./types"; import BaseFormWizard from "../form/form-wizard/BaseFormWizard"; export interface IBasicFormControl { date: () => Element; text: () => Element; radio: () => Element; select: () => Element; } export interface IElementTypes { [key: string]: JSX.Element; } export interface IFormData { [key: string]: string | number | boolean | IFormData | Array; } export interface IError { hasError: boolean; errorMsg: string; } export interface IRestConfig { type?: string; url?: string; queryParams?: Array; responseKey?: string; } export interface IRequestBody { [key: string]: TValue | IRequestBody; } export interface IApiConfig { requestType?: string; requestBody?: IRequestBody; requestBodyParams?: Array; requestHeaders?: Record; queryParams?: Array; url?: string; urlType?: string; labelKey?: string; valueKey?: string; responseKey?: string; } export interface IFieldConfig extends IApiConfig { type?: string; loadOn?: string | Array; lazy?: boolean; multiple?: boolean; inputFormat?: string; views?: Array; openTo?: Array; autocomplete?: any; accept?: string; blob?: boolean; template?: string; } export interface IFormField { prop?: string | null; className?: string; config?: IFieldConfig | Record; events?: IEvent; error: IError; display: boolean; displayName?: string; displayProps?: IDisplayProps; htmlProps?: Record; displayType?: string; type?: string; value: Exclude; placeholder?: string; isDisabled?: boolean; isReadonly?: boolean; options?: Array; file?: File; files?: Array; validation?: IValidation; /** @deprecated */ icons?: IIconConfig; iconName?: string; icon?: IconConfig; isArray?: boolean; } export interface IFnTypes { [key: string]: (arg: TValue, ref?: IOption, formField?: IFormField) => TValue | IOption[]; } export interface IRenderField extends IField { section: string; form: IFormField; sync: () => void; } export interface IFormSection { [key: string]: IFormField; } export interface IForm { [key: string]: IFormSection; } export interface IFieldChange { section: string; field: string; value: TValue; } export interface IControlProps { field: IFormField; form: IForm; } export declare type TFormResponse = Promise | Promise | void; export interface IEventPayload { payload: string | number | IFieldChange; } export interface IFooterProps { page: number; isGrouped: boolean; previousBtn: JSX.Element; nextBtn: JSX.Element; submitBtn: JSX.Element; } export interface IFormRenderer extends IUISchema, IFormConfig { baseFormControl?: typeof BaseFormControl; baseFormGroup?: typeof BaseFormGroup; baseFormStepper?: typeof BaseFormStepper; baseFormWizard?: typeof BaseFormWizard; loader?: JSX.Element; /** * Basic inputs params */ /** Form class */ className?: string; /** Input form data in key, value object format */ data?: IFormData; /** Form class */ type?: TFormType; /** Section layout */ sectionLayout?: TSectionLayout; /** Field layout - row | column (default) */ fieldLayout?: "row" | "column" | string; /** Spacing around the field */ spacing?: string; /** theme configuration input params */ themeConfig?: IFormConfigExtended; /** * Customization params */ buttons?: IElementTypes; controls?: IElementTypes; components?: Record>; fns?: IFnTypes; footer?: React.FunctionComponent; formatter?: IFormatterType; icons?: IElementTypes; lastPageNumber?: number; name?: string; nextResponseMode?: TNextResponseMode; /** */ changeResponseMode?: TChangeMode; pageNumber?: number; /** * REST API configruation params in the form */ rest?: IRest; /** * Event handling params */ onChange?: (change: IFieldChange, formData?: IFormData) => void; onCustom?: (formData: IFormData, e: SyntheticEvent) => TFormResponse; onError?: (errorResponse: any) => TFormResponse; onPopupClose?: (params: Array) => void; onPrevious?: (formData: IFormData, pageNumber: number) => TFormResponse; onNext?: (formData: IFormData, pageNumber: number, setErrors: (errors: IFieldError | Array) => void) => TFormResponse; onSubmit: (formData: IFormData, pageNumber: number, setErrors: (errors: IFieldError | Array) => void) => TFormResponse; onSubmitError?: (params: IEventPayload) => void; setLoading?: (isLoading: boolean) => void; } export declare type TComponent = (props: T) => JSX.Element; export interface ISectionError { hasError: boolean; section: string; } export interface IOperand { ref: string; section?: string; } export declare type TCondition = [IOperand, TOperator, IOperand | TValue, TNextCondition?]; export declare const TVALUE_MAP_TYPE_REF: { fieldValue: string; fieldProp: string; }; export interface IValueMapRef { type?: "fieldValue" | "fieldProp"; ref: string; section?: string; propName?: string; } export interface IDepdendencyItem extends IApiConfig { ref?: string; section: string; type: string; condition?: Array; changeType: string; defaultValue?: string; value: string; responseKey: string; labelKey: string; valueFn?: string; valueKey: string; valueMap: Record | IValueMapRef>; queryParams: Array; pathParams: Array; field: string; url: string; urlType: string; currentValue: TValue; resetValue: TValue; pattern: string; propValue: TValue; propName: string; } export interface IMetaForm { formConfig: IFormConfig; form: IForm; } export interface IFieldRef { ref?: string; } export declare type TFieldRef = string | IFieldRef; export declare type TErrorCallback = (error: Error, section: string, field: string) => void; interface IEventDetail { eventType: string; } export declare class MetaformEvent extends Event { detail: IEventDetail; } export interface IErrorDetails { hasErrors: boolean; errors: Array<{ id: string; errorMsg: string; }>; } export interface IFormErrorDetails { id: string; errorMsg: string; } export {};