@bolttech/form-engine 3.0.1-beta.6 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +310 -96
- package/index.esm.js +2181 -1319
- package/package.json +11 -8
- package/src/components/AsFormField/AsFormField.type.d.ts +1 -1
- package/src/components/AsFormFieldBuilder/AsFormFieldBuilder.type.d.ts +8 -5
- package/src/components/AsFormFieldRepeater/AsFormFieldRepeater.d.ts +10 -0
- package/src/components/AsFormFieldRepeater/AsFormFieldRepeater.type.d.ts +49 -0
- package/src/components/FieldWrapper/FieldWrapper.d.ts +1 -1
- package/src/components/FieldWrapper/FieldWrapper.type.d.ts +7 -2
- package/src/components/Form/Form.d.ts +2 -2
- package/src/components/Form/Form.type.d.ts +8 -2
- package/src/components/index.d.ts +1 -0
- package/src/context/FormGroupContext.type.d.ts +35 -5
- package/src/generators/formBuilder.d.ts +8 -25
- package/src/helpers/helpers.d.ts +3 -3
- package/src/helpers/mapper.d.ts +2 -1
- package/src/hooks/useForm/useForm.d.ts +1 -2
- package/src/hooks/useForm/useForm.type.d.ts +7 -3
- package/src/hooks/useFormGroup/useFormGroup.d.ts +2 -6
- package/src/hooks/useFormGroup/useFormGroup.type.d.ts +17 -0
- package/src/types/index.d.ts +13 -13
- /package/{index.esm.d.ts → index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.0.1
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "A react adapter for bolttech form engine",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@bolttech/form-engine-core": "^1.0.1"
|
|
7
|
+
},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"react": "19.1.1",
|
|
10
|
+
"react-dom": "19.1.1",
|
|
11
|
+
"react-router-dom": "6.11.2"
|
|
12
|
+
},
|
|
5
13
|
"module": "./index.esm.js",
|
|
6
14
|
"type": "module",
|
|
7
15
|
"main": "./index.esm.js",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"react": "18.2.0",
|
|
11
|
-
"rxjs": "7.8.1"
|
|
12
|
-
},
|
|
13
|
-
"peerDependencies": {}
|
|
14
|
-
}
|
|
16
|
+
"types": "./index.d.ts"
|
|
17
|
+
}
|
|
@@ -3,7 +3,7 @@ import { ElementType, PropsWithChildren } from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* AsFormField props, inherits all schema field implementation except the children
|
|
5
5
|
* property and has mappers property to pass a custom component, that will be a ReactNode
|
|
6
|
-
* @see {@link
|
|
6
|
+
* @see {@link IComponentSchemaAsFormField}
|
|
7
7
|
*/
|
|
8
8
|
type TAsFormFieldProps = PropsWithChildren<Omit<IComponentSchemaAsFormField<ElementType>, 'children'>>;
|
|
9
9
|
export type { TAsFormFieldProps };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IComponentSchema, TFieldEvent, TMapper } from '@bolttech/form-engine-core';
|
|
1
|
+
import { IComponentSchema, TFieldEvent, TMapper, OneOf } from '@bolttech/form-engine-core';
|
|
2
2
|
import { ElementType, PropsWithChildren } from 'react';
|
|
3
3
|
import { TFieldWrapper } from '../../types';
|
|
4
4
|
/**
|
|
@@ -11,10 +11,13 @@ import { TFieldWrapper } from '../../types';
|
|
|
11
11
|
* @see {@link TMapper}
|
|
12
12
|
* @see {@link IComponentSchema}
|
|
13
13
|
* @see {@link TFieldWrapper}
|
|
14
|
+
* @interface
|
|
14
15
|
*/
|
|
15
|
-
type TAsFormFieldBuilderProps = PropsWithChildren<Omit<IComponentSchema, '
|
|
16
|
-
mapper: TMapper<ElementType>;
|
|
17
|
-
visibility?: boolean;
|
|
16
|
+
type TAsFormFieldBuilderProps = PropsWithChildren<Omit<IComponentSchema, 'component' | 'children' | 'name'> & Required<TFieldWrapper> & {
|
|
18
17
|
onSelected?: (data: TFieldEvent) => void;
|
|
19
|
-
|
|
18
|
+
formMounted?: boolean;
|
|
19
|
+
} & OneOf<{
|
|
20
|
+
mapper: TMapper<ElementType>;
|
|
21
|
+
component: string;
|
|
22
|
+
}>>;
|
|
20
23
|
export type { TAsFormFieldBuilderProps };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { TAsFormFieldRepeaterProps } from './AsFormFieldRepeater.type';
|
|
3
|
+
/**
|
|
4
|
+
* Adapter do manage repeated list elements on form
|
|
5
|
+
*
|
|
6
|
+
* @param {TAsFormFieldRepeaterProps} props Repeater properties to configure the elements repeater
|
|
7
|
+
* @returns {ReactElement}
|
|
8
|
+
*/
|
|
9
|
+
declare const AsFormFieldRepeater: ({ RepeaterComponent, addFieldName, removeFieldName, existingElements, initialElements, stateUpdater, formPrefix, RepeaterFooter, }: TAsFormFieldRepeaterProps) => ReactNode;
|
|
10
|
+
export default AsFormFieldRepeater;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TFormGroupOnDataEventPayload, OneOf } from '@bolttech/form-engine-core';
|
|
2
|
+
import { ElementType } from 'react';
|
|
3
|
+
type TRepeaterProps = {
|
|
4
|
+
formIndex: string;
|
|
5
|
+
index: number;
|
|
6
|
+
};
|
|
7
|
+
type TRepeaterFooterProps = Pick<TRepeaterProps, 'formIndex'>;
|
|
8
|
+
/**
|
|
9
|
+
* AsFormFieldRepeater props needed to build a repeater to build forms
|
|
10
|
+
* @property {ElementType<TRepeaterProps>} RepeaterComponent element to use as repeater
|
|
11
|
+
* @property {string} addFieldName field name button that will add an element on a position on a repeater
|
|
12
|
+
* @property {string} removeFieldName field name button that will remove an element on a position on a repeater
|
|
13
|
+
* @property {Record<string, unknown>[]} existingElements elements to restore a repeater list
|
|
14
|
+
* @property {number} initialElements elements to be pre-rendered when the form is presented
|
|
15
|
+
* @property {(payload: TFormGroupOnDataEventPayload<unknown>) => void} stateUpdater similar to onData for the group of form managed by the repeater
|
|
16
|
+
* @property {string} formPrefix prefix to use on the repeated forms ex: (person- will go person-1, person-2, ...)
|
|
17
|
+
* @property {ElementType<TRepeaterFooterProps>} RepeaterFooter component with a button that will add an element to the bottom of the list
|
|
18
|
+
* @see {@link TMapper}
|
|
19
|
+
* @see {@link IComponentSchema}
|
|
20
|
+
* @see {@link TFieldWrapper}
|
|
21
|
+
* @interface
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { AsFormFieldRepeater } from '@bolttech/form-engine';
|
|
25
|
+
*
|
|
26
|
+
* <AsFormFieldRepeater
|
|
27
|
+
* RepeaterComponent={FormElement}
|
|
28
|
+
* RepeaterFooter={FormElementFooter}
|
|
29
|
+
* addFieldName="addForm"
|
|
30
|
+
* removeFieldName="removeForm"
|
|
31
|
+
* formPrefix="insured"
|
|
32
|
+
* stateUpdater={(payload) => {
|
|
33
|
+
* console.log(payload);
|
|
34
|
+
* }}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type TAsFormFieldRepeaterProps = {
|
|
39
|
+
RepeaterComponent: ElementType<TRepeaterProps>;
|
|
40
|
+
addFieldName?: string;
|
|
41
|
+
removeFieldName?: string;
|
|
42
|
+
stateUpdater?: (payload: TFormGroupOnDataEventPayload<unknown>) => void;
|
|
43
|
+
formPrefix?: string;
|
|
44
|
+
RepeaterFooter: ElementType<TRepeaterFooterProps>;
|
|
45
|
+
} & OneOf<{
|
|
46
|
+
existingElements?: Record<string, unknown>[];
|
|
47
|
+
initialElements?: number;
|
|
48
|
+
}>;
|
|
49
|
+
export type { TAsFormFieldRepeaterProps, TRepeaterProps, TRepeaterFooterProps };
|
|
@@ -7,5 +7,5 @@ import { TFieldWrapperProps } from './FieldWrapper.type';
|
|
|
7
7
|
* @param {TFieldWrapperProps} param FieldWrapper params
|
|
8
8
|
* @returns {ReactElement}
|
|
9
9
|
*/
|
|
10
|
-
declare const FieldWrapper: ({ name, formIndex, children, props, context, }: TFieldWrapperProps) => ReactElement;
|
|
10
|
+
declare const FieldWrapper: ({ name, formIndex, children, props, context, mounted, mapper, visibility, component, }: TFieldWrapperProps) => ReactElement;
|
|
11
11
|
export default FieldWrapper;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
1
|
+
import { ElementType, PropsWithChildren } from 'react';
|
|
2
2
|
import { TFieldWrapper } from '../../types';
|
|
3
3
|
import { TFormContext } from '../../context/FormGroupContext';
|
|
4
|
-
import { FormField } from '@bolttech/form-engine-core';
|
|
4
|
+
import { FormField, TMapper } from '@bolttech/form-engine-core';
|
|
5
5
|
/**
|
|
6
6
|
* Represents the props for a field wrapper component, including children.
|
|
7
7
|
*
|
|
@@ -13,6 +13,10 @@ import { FormField } from '@bolttech/form-engine-core';
|
|
|
13
13
|
type TFieldWrapperProps = PropsWithChildren<TFieldWrapper & {
|
|
14
14
|
props?: Record<string, unknown>;
|
|
15
15
|
context?: TFormContext | null;
|
|
16
|
+
mounted?: boolean;
|
|
17
|
+
mapper?: TMapper<ElementType>;
|
|
18
|
+
component?: string;
|
|
19
|
+
visibility?: boolean;
|
|
16
20
|
}>;
|
|
17
21
|
/**
|
|
18
22
|
* Represents the props for rendering a field wrapper component, including children.
|
|
@@ -24,5 +28,6 @@ type TFieldWrapperProps = PropsWithChildren<TFieldWrapper & {
|
|
|
24
28
|
type TFieldWrapperComponentRenderProps = PropsWithChildren<{
|
|
25
29
|
props: Record<string, unknown>;
|
|
26
30
|
fieldInstance?: FormField;
|
|
31
|
+
mapper?: TMapper<ElementType>;
|
|
27
32
|
}>;
|
|
28
33
|
export type { TFieldWrapperProps, TFieldWrapperComponentRenderProps };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
1
|
+
import { PropsWithChildren, ReactElement } from 'react';
|
|
2
2
|
import { TFormProps } from './Form.type';
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
5
|
* @param {TFormProps} param form properties initializor
|
|
6
6
|
* @returns {ReactElement}
|
|
7
7
|
*/
|
|
8
|
-
declare function Form<T>({ schema, index, initialValues, iVars, action, method, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, children, }: TFormProps<T
|
|
8
|
+
declare function Form<T>({ schema, index, initialValues, iVars, action, method, config, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, stopEventsOnSubmit, children, }: PropsWithChildren<TFormProps<T>>): ReactElement;
|
|
9
9
|
export default Form;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { TFormEntry } from '@bolttech/form-engine-core';
|
|
2
|
-
import { PropsWithChildren } from 'react';
|
|
3
2
|
import { TEventsCallbackProps } from '../../types';
|
|
4
3
|
/**
|
|
5
4
|
* Form props, inherits the form instance constructor implementation except the mapper
|
|
6
5
|
* along with all event callback register props shared with other implementations
|
|
7
6
|
* @see {@link TFormEntry}
|
|
8
7
|
* @see {@link TEventsCallbackProps}
|
|
8
|
+
* @interface
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { Form } from '@bolttech/form-engine';
|
|
12
|
+
*
|
|
13
|
+
* <Form index={'foo'} schema={schema} onData={console.log} />
|
|
14
|
+
* ```
|
|
9
15
|
*/
|
|
10
|
-
type TFormProps<T> =
|
|
16
|
+
type TFormProps<T> = Omit<TFormEntry, 'mappers' | 'dataSubject$' | 'formValidSubject$' | 'submitSubject$'> & TEventsCallbackProps<T>;
|
|
11
17
|
export type { TFormProps };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { default as Form } from './Form/Form';
|
|
2
2
|
export { default as AsFormField } from './AsFormField/AsFormField';
|
|
3
3
|
export { default as AsFormFieldBuilder } from './AsFormFieldBuilder/AsFormFieldBuilder';
|
|
4
|
+
export { default as AsFormFieldRepeater } from './AsFormFieldRepeater/AsFormFieldRepeater';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormCore,
|
|
1
|
+
import { FormCore, TFormEntry, TFormGroup, TFormValues, TMapper, TSchemaFormConfig } from '@bolttech/form-engine-core';
|
|
2
2
|
import { ElementType } from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the context for managing forms within a form group.
|
|
@@ -12,13 +12,33 @@ import { ElementType } from 'react';
|
|
|
12
12
|
* @property {function(): void} printFormGroupInstance - Prints the form group instance.
|
|
13
13
|
* @property {function(string[]): TFormValues} submitMultipleFormsByIndex - Submits multiple forms by their indexes and returns the form values.
|
|
14
14
|
* @property {boolean} debugMode - Indicates if debug mode is active.
|
|
15
|
-
* @property {boolean} active - Indicates if the form context is active.
|
|
15
|
+
* @property {boolean} active - Indicates if the form context is active (if the context provider is defined above).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import React from 'react';
|
|
20
|
+
* import { useFormGroupContext } from '@bolttech/form-engine';
|
|
21
|
+
*
|
|
22
|
+
* const FormComponent = (): React.ReactElement => {
|
|
23
|
+
* const {
|
|
24
|
+
* addForm,
|
|
25
|
+
* removeForm,
|
|
26
|
+
* getForm,
|
|
27
|
+
* printFormGroupInstance,
|
|
28
|
+
* submitMultipleFormsByIndex,
|
|
29
|
+
* debugMode
|
|
30
|
+
* } = useFormGroupContext();
|
|
31
|
+
*
|
|
32
|
+
* // (...)
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
16
36
|
*/
|
|
17
37
|
type TFormContext = {
|
|
18
38
|
addFormWithIndex: (index: string) => void;
|
|
19
39
|
addForm: (payload: {
|
|
20
40
|
key: string;
|
|
21
|
-
|
|
41
|
+
params: TFormEntry;
|
|
22
42
|
}) => void;
|
|
23
43
|
getForm: (payload: {
|
|
24
44
|
key: string;
|
|
@@ -26,10 +46,10 @@ type TFormContext = {
|
|
|
26
46
|
removeForm: (payload: {
|
|
27
47
|
key: string;
|
|
28
48
|
}) => void;
|
|
29
|
-
formGroupInstance: TFormGroup
|
|
49
|
+
formGroupInstance: TFormGroup<ElementType>;
|
|
30
50
|
mappers?: TMapper<ElementType>[];
|
|
31
51
|
printFormGroupInstance: () => void;
|
|
32
|
-
submitMultipleFormsByIndex: (indexes: string[]) => void;
|
|
52
|
+
submitMultipleFormsByIndex: <T>(indexes: string[], callback?: (payload: TFormValues<T>) => void) => void;
|
|
33
53
|
debugMode: boolean;
|
|
34
54
|
active: boolean;
|
|
35
55
|
config?: TSchemaFormConfig;
|
|
@@ -39,6 +59,16 @@ type TFormContext = {
|
|
|
39
59
|
*
|
|
40
60
|
* @property {TMapper<ElementType>[]} [mappers] - Optional array of mappers for elements.
|
|
41
61
|
* @property {boolean} [debugMode] - Optional flag indicating if debug mode should be enabled.
|
|
62
|
+
* @property {TSchemaFormConfig} config - Optional config settings for debounce times and client logging
|
|
63
|
+
*
|
|
64
|
+
* * @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* import { FormGroupContextProvider } from '@bolttech/form-engine';
|
|
67
|
+
*
|
|
68
|
+
* <FormGroupContextProvider mappers={mappers} debugMode={true}>
|
|
69
|
+
* {children}
|
|
70
|
+
* </FormGroupContextProvider>
|
|
71
|
+
* ```
|
|
42
72
|
*/
|
|
43
73
|
type TFormContextProvider = {
|
|
44
74
|
mappers?: TMapper<ElementType>[];
|
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import { ElementType
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @param {Map<string,IFormField>} param.fields form instance field Map
|
|
8
|
-
* @param {string} param.prevPath previous field path to track the tree branch creation
|
|
9
|
-
* @param {string} param.formIndex form index to aid field identification onto the FieldWrapper
|
|
10
|
-
* @returns {ReactNode}
|
|
11
|
-
*/
|
|
12
|
-
declare const BuildTree: ({ fields, prevPath, formIndex, }: {
|
|
13
|
-
fields: Map<string, IFormField>;
|
|
14
|
-
prevPath?: string | undefined;
|
|
1
|
+
import { ElementType } from 'react';
|
|
2
|
+
import { TMapper, IComponentSchema } from '@bolttech/form-engine-core';
|
|
3
|
+
declare const BuildSchemaAsFields: ({ components, mappers, formIndex, mountedForm, }: {
|
|
4
|
+
components?: IComponentSchema[];
|
|
5
|
+
mappers?: TMapper<ElementType>[];
|
|
15
6
|
formIndex: string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @param param.children ReactNode children elements
|
|
21
|
-
* @returns {IComponentSchema[] | null | undefined}
|
|
22
|
-
*/
|
|
23
|
-
declare const BuildAsFormFieldTree: ({ children, }: {
|
|
24
|
-
children?: ReactNode;
|
|
25
|
-
}) => IComponentSchemaAsFormField<ElementType>[] | null | undefined;
|
|
26
|
-
export { BuildTree, BuildAsFormFieldTree };
|
|
7
|
+
mountedForm: boolean;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element[] | undefined;
|
|
9
|
+
export { BuildSchemaAsFields };
|
package/src/helpers/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TEvents } from '@bolttech/form-engine-core';
|
|
2
|
-
import { TEventProps } from '../types';
|
|
1
|
+
import { TEventProps, TEvents } from '@bolttech/form-engine-core';
|
|
3
2
|
/**
|
|
4
3
|
* events mapping to aid function callback binding
|
|
5
4
|
*/
|
|
6
5
|
declare const eventsMapping: Partial<Record<TEvents, TEventProps>>;
|
|
7
|
-
|
|
6
|
+
declare const uniqueIdGen: () => string;
|
|
7
|
+
export { eventsMapping, uniqueIdGen };
|
package/src/helpers/mapper.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { TValueChangeEvent } from '@bolttech/form-engine-core';
|
|
|
2
2
|
declare const defaultChangeEvent: TValueChangeEvent;
|
|
3
3
|
declare const checkedChangeEvent: TValueChangeEvent;
|
|
4
4
|
declare const valueChangeEvent: TValueChangeEvent;
|
|
5
|
+
declare const numberInputChangeEvent: TValueChangeEvent;
|
|
5
6
|
declare const datepickerChangeEvent: TValueChangeEvent;
|
|
6
7
|
declare const dropdownChangeEvent: TValueChangeEvent;
|
|
7
|
-
export { defaultChangeEvent, checkedChangeEvent, valueChangeEvent, datepickerChangeEvent, dropdownChangeEvent, };
|
|
8
|
+
export { defaultChangeEvent, checkedChangeEvent, valueChangeEvent, numberInputChangeEvent, datepickerChangeEvent, dropdownChangeEvent, };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { TUseFormProps } from './useForm.type';
|
|
3
2
|
/**
|
|
4
3
|
* Hook to register events callback functions
|
|
5
4
|
*/
|
|
6
|
-
declare function useForm<T>({ id, onData, onSubmit, onFormMount, onValid, ...rest }: TUseFormProps<T>, deps?: React.DependencyList): void;
|
|
5
|
+
declare function useForm<T>({ id, index, onData, onSubmit, onFormMount, onValid, iVars, initialValues, stopEventsOnSubmit, ...rest }: TUseFormProps<T>, deps?: React.DependencyList): void;
|
|
7
6
|
export default useForm;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { TFormEntry, OneOf } from '@bolttech/form-engine-core';
|
|
1
2
|
import { TEventsCallbackProps } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* Represents the properties for the useForm hook, including an ID and event callback properties.
|
|
4
5
|
*
|
|
5
|
-
* @property {string} id - The unique identifier for the form.
|
|
6
|
+
* @property {string} id - The unique identifier for the form. Deprecated, use 'index' instead
|
|
7
|
+
* @property {string} index - The unique identifier for the form.
|
|
6
8
|
*
|
|
7
9
|
* @see {@link TEventsCallbackProps}
|
|
10
|
+
* @interface
|
|
8
11
|
*/
|
|
9
|
-
type TUseFormProps<T> = {
|
|
12
|
+
type TUseFormProps<T> = Pick<TFormEntry, 'index' | 'initialValues' | 'iVars' | 'stopEventsOnSubmit'> & TEventsCallbackProps<T> & OneOf<{
|
|
10
13
|
id: string;
|
|
11
|
-
|
|
14
|
+
index: string;
|
|
15
|
+
}>;
|
|
12
16
|
export type { TUseFormProps };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare
|
|
3
|
-
ids: string[];
|
|
4
|
-
onData?: ((payload: TFormGroupOnDataEventPayload<Record<string, unknown>>) => void) | undefined;
|
|
5
|
-
onValid?: ((payload: TFormGroupOnValidEventPayload) => void) | undefined;
|
|
6
|
-
}, deps?: React.DependencyList) => void;
|
|
1
|
+
import { TUseFormGroup } from './useFormGroup.type';
|
|
2
|
+
declare function useFormGroup<T>({ ids, onData, onValid, onSubmit }: TUseFormGroup<T>, deps?: React.DependencyList): void;
|
|
7
3
|
export default useFormGroup;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload } from '@bolttech/form-engine-core';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the properties for the useFormGroup hook, including a list of ID's and event callback properties.
|
|
4
|
+
*
|
|
5
|
+
* @property {string} ids - The unique identifier for the forms.
|
|
6
|
+
* @property {payload: TFormGroupOnDataEventPayload<T>} onData - callback event occurring when a value is changing via input or logic.
|
|
7
|
+
* @property {payload: TFormGroupOnValidEventPayload} onData - callback event occurring when validation status changes on the form.
|
|
8
|
+
* @property {payload: TFormGroupOnSubmitEventPayload<T>} onData - event occurring when form submission is trigger.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
type TUseFormGroup<T> = {
|
|
12
|
+
ids: string[];
|
|
13
|
+
onData?: (payload: TFormGroupOnDataEventPayload<T>) => void;
|
|
14
|
+
onValid?: (payload: TFormGroupOnValidEventPayload) => void;
|
|
15
|
+
onSubmit?: (payload: TFormGroupOnSubmitEventPayload<T>) => void;
|
|
16
|
+
};
|
|
17
|
+
export type { TUseFormGroup };
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TFieldEvent, TFormValidationPayload, TFormValues } from '@bolttech/form-engine-core';
|
|
1
|
+
import { TEventProps, TFieldEvent, TFormValidationPayload, TFormValues, TEventDataProps } from '@bolttech/form-engine-core';
|
|
2
2
|
/**
|
|
3
3
|
* Represents a field wrapper containing the name of the field and its index in the form.
|
|
4
4
|
*
|
|
@@ -9,10 +9,6 @@ type TFieldWrapper = {
|
|
|
9
9
|
name: string;
|
|
10
10
|
formIndex: string;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* Represents the possible event properties for form fields callbacks.
|
|
14
|
-
*/
|
|
15
|
-
type TEventProps = 'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onMount' | 'onApiResponse' | 'onClick';
|
|
16
12
|
/**
|
|
17
13
|
* Represents the content inside onData payload action.
|
|
18
14
|
*/
|
|
@@ -21,12 +17,16 @@ type TFormData<T> = {
|
|
|
21
17
|
data: TFormValues<T>;
|
|
22
18
|
};
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* @property {(payload: TFormValues<T>) => void} onFormMount - triggered when form mounts
|
|
22
|
+
* @property {(payload: TFormValues<T>) => void} onData - triggered when any field change value
|
|
23
|
+
* @property {(payload: TFormValues<T>) => void} onSubmit - triggered when submit button is pressed
|
|
24
|
+
* @property {(payload: TFormValues<T>) => void} onValid - triggered when form valid status changes
|
|
25
|
+
* @interface
|
|
26
|
+
*
|
|
25
27
|
*/
|
|
26
|
-
type TEventsCallbackProps<T> = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
export { TFieldWrapper, TEventProps, TEventsCallbackProps, TFormData };
|
|
28
|
+
type TEventsCallbackProps<T> = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & Partial<Record<Extract<TEventDataProps, 'onFormMount' | 'onSubmit'>, (payload: TFormValues<T>) => void>> & Partial<Record<Extract<TEventDataProps, 'onData'>, (payload: {
|
|
29
|
+
field: string;
|
|
30
|
+
data: TFormValues<T>;
|
|
31
|
+
}) => void>> & Partial<Record<Extract<TEventDataProps, 'onValid'>, (payload: TFormValidationPayload) => void>>;
|
|
32
|
+
export { TFieldWrapper, TEventsCallbackProps, TFormData };
|
|
File without changes
|