@lifesg/web-frontend-engine 1.0.0-alpha.2 → 1.0.0-alpha.4
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 +21 -27
- package/cjs/index.js +88 -84
- package/cjs/index.js.map +1 -1
- package/components/custom/filter/filter/filter.d.ts +2 -0
- package/components/custom/filter/filter/types.d.ts +14 -0
- package/components/custom/filter/filter-checkbox/filter-checkbox.d.ts +3 -0
- package/components/custom/filter/filter-checkbox/types.d.ts +12 -0
- package/components/custom/filter/filter-item/filter-item.d.ts +3 -0
- package/components/custom/filter/filter-item/types.d.ts +8 -0
- package/components/custom/filter/index.d.ts +3 -0
- package/components/custom/index.d.ts +1 -0
- package/components/elements/alert/alert.d.ts +1 -2
- package/components/elements/section/index.d.ts +2 -0
- package/components/elements/section/section.d.ts +2 -0
- package/components/elements/section/types.d.ts +10 -0
- package/components/elements/sections/index.d.ts +2 -0
- package/components/elements/sections/sections.d.ts +14 -0
- package/components/elements/sections/types.d.ts +5 -0
- package/components/elements/text/data.d.ts +12 -12
- package/components/elements/text/text.d.ts +1 -2
- package/components/elements/wrapper/conditional-renderer.d.ts +5 -1
- package/components/elements/wrapper/types.d.ts +11 -2
- package/components/elements/wrapper/wrapper.d.ts +2 -11
- package/components/fields/checkbox-group/checkbox-group.d.ts +1 -2
- package/components/fields/checkbox-group/checkbox-group.styles.d.ts +2 -1
- package/components/fields/checkbox-group/types.d.ts +13 -1
- package/components/fields/chips/chips.d.ts +1 -2
- package/components/fields/chips/types.d.ts +1 -0
- package/components/fields/contact-field/contact-field.d.ts +3 -0
- package/components/fields/contact-field/data.d.ts +5 -0
- package/components/fields/contact-field/index.d.ts +2 -0
- package/components/fields/contact-field/types.d.ts +30 -0
- package/components/fields/date-field/date-field.d.ts +3 -0
- package/components/fields/date-field/index.d.ts +2 -0
- package/components/fields/{date-input → date-field}/types.d.ts +2 -2
- package/components/fields/index.d.ts +6 -4
- package/components/fields/multi-select/multi-select.d.ts +1 -2
- package/components/fields/radio-button/radio-button.d.ts +1 -2
- package/components/fields/radio-button/radio-button.styles.d.ts +1 -0
- package/components/fields/radio-button/types.d.ts +9 -0
- package/components/fields/reset-button/index.d.ts +2 -0
- package/components/fields/reset-button/reset-button.d.ts +3 -0
- package/components/fields/reset-button/types.d.ts +5 -0
- package/components/fields/select/select.d.ts +1 -2
- package/components/fields/submit-button/submit-button.d.ts +1 -2
- package/components/fields/text-field/index.d.ts +2 -0
- package/components/fields/text-field/text-field.d.ts +3 -0
- package/components/fields/text-field/types.d.ts +8 -0
- package/components/fields/textarea/textarea.d.ts +1 -2
- package/components/fields/time-field/index.d.ts +2 -0
- package/components/fields/time-field/time-field.d.ts +3 -0
- package/components/fields/{time-picker → time-field}/types.d.ts +1 -1
- package/components/fields/unit-number-field/index.d.ts +2 -0
- package/components/fields/unit-number-field/types.d.ts +7 -0
- package/components/fields/unit-number-field/unit-number-field.d.ts +3 -0
- package/components/frontend-engine/frontend-engine.d.ts +2 -8
- package/components/frontend-engine/types.d.ts +76 -20
- package/components/frontend-engine/yup/context-provider.d.ts +1 -1
- package/components/shared/chip/chip.d.ts +1 -1
- package/components/shared/error-messages.d.ts +3 -0
- package/components/shared/sanitize/sanitize.d.ts +1 -1
- package/index.js +95 -91
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/components/fields/contact-number/contact-number.d.ts +0 -4
- package/components/fields/contact-number/data.d.ts +0 -215
- package/components/fields/contact-number/index.d.ts +0 -2
- package/components/fields/contact-number/types.d.ts +0 -29
- package/components/fields/date-input/date-input.d.ts +0 -4
- package/components/fields/date-input/index.d.ts +0 -2
- package/components/fields/textfield/index.d.ts +0 -2
- package/components/fields/textfield/textfield.d.ts +0 -4
- package/components/fields/textfield/types.d.ts +0 -8
- package/components/fields/time-picker/index.d.ts +0 -2
- package/components/fields/time-picker/time-picker.d.ts +0 -4
- /package/components/fields/{contact-number → contact-field}/utils.d.ts +0 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { ControllerFieldState, ControllerRenderProps, UseFormSetValue, ValidationMode } from "react-hook-form";
|
|
1
|
+
import { ControllerFieldState, ControllerRenderProps, UseFormReset, UseFormSetValue, ValidationMode } from "react-hook-form";
|
|
2
|
+
import { IFilterSchema } from "../custom/filter/filter/types";
|
|
2
3
|
import { IAlertSchema, ITextSchema } from "../elements";
|
|
4
|
+
import { ISectionSchema } from "../elements/section";
|
|
3
5
|
import { IWrapperSchema } from "../elements/wrapper";
|
|
4
|
-
import { ICheckboxGroupSchema, IChipsSchema,
|
|
6
|
+
import { ICheckboxGroupSchema, IChipsSchema, IContactFieldSchema, IDateFieldSchema, IEmailFieldSchema, IMultiSelectSchema, INumericFieldSchema, IRadioButtonGroupSchema, IResetButtonSchema, ISelectSchema, ISubmitButtonSchema, ITextFieldSchema, ITextareaSchema, ITimeFieldSchema, IUnitNumberFieldSchema } from "../fields";
|
|
5
7
|
import { IYupValidationRule, TRenderRules, TYupSchemaType } from "./yup";
|
|
6
8
|
export type { IYupValidationRule } from "./yup";
|
|
7
9
|
export interface IFrontendEngineProps<V = undefined> {
|
|
8
10
|
/** HTML class attribute that is applied on the `<form>` element */
|
|
9
11
|
className?: string;
|
|
10
|
-
/** JSON configuration to define the
|
|
12
|
+
/** JSON configuration to define the components and functionalities of the form */
|
|
11
13
|
data?: IFrontendEngineData<V> | undefined;
|
|
12
14
|
/** Fires every time a value changes in any fields */
|
|
13
15
|
onChange?: ((values: TFrontendEngineValues, isValid?: boolean | undefined) => unknown) | undefined;
|
|
@@ -19,8 +21,14 @@ export interface IFrontendEngineData<V = undefined> {
|
|
|
19
21
|
className?: string | undefined;
|
|
20
22
|
/** Fields' initial values on mount. The key of each field needs to match the id used in the field */
|
|
21
23
|
defaultValues?: TFrontendEngineValues | undefined;
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Specifies the components to be rendered
|
|
26
|
+
*
|
|
27
|
+
* All components within the form are in key-value format, key refers to the id of the components while value refers to its JSON schema
|
|
28
|
+
*
|
|
29
|
+
* Note: sections accept only section `uiType`, the subsequent children accepts uiType other than section
|
|
30
|
+
* */
|
|
31
|
+
sections: Record<string, ISectionSchema<V>>;
|
|
24
32
|
/** Unique HTML id attribute that is applied on the `<form>` element */
|
|
25
33
|
id?: string | undefined;
|
|
26
34
|
/** Validation strategy when inputs with errors get re-validated after a user submits the form (onSubmit event) */
|
|
@@ -28,7 +36,7 @@ export interface IFrontendEngineData<V = undefined> {
|
|
|
28
36
|
/** Validation strategy before a user submits the form (onSubmit event) */
|
|
29
37
|
validationMode?: TValidationMode | undefined;
|
|
30
38
|
}
|
|
31
|
-
export type TFrontendEngineFieldSchema<V = undefined> = ITextareaSchema<V> |
|
|
39
|
+
export type TFrontendEngineFieldSchema<V = undefined> = ITextareaSchema<V> | ITextFieldSchema<V> | IEmailFieldSchema<V> | INumericFieldSchema<V> | ISubmitButtonSchema | ISelectSchema<V> | IMultiSelectSchema<V> | ICheckboxGroupSchema<V> | IDateFieldSchema<V> | IWrapperSchema | IContactFieldSchema<V> | IRadioButtonGroupSchema<V> | ITimeFieldSchema<V> | IChipsSchema<V> | IUnitNumberFieldSchema<V> | IAlertSchema | ITextSchema | IResetButtonSchema | IFilterSchema | ICustomComponentJsonSchema<V>;
|
|
32
40
|
export type TFrontendEngineValues<T = any> = Record<keyof T, T[keyof T]>;
|
|
33
41
|
export type TRevalidationMode = Exclude<keyof ValidationMode, "onTouched" | "all">;
|
|
34
42
|
export type TValidationMode = keyof ValidationMode;
|
|
@@ -37,19 +45,22 @@ export type TErrorPayload = Record<string, TErrorMessage>;
|
|
|
37
45
|
export interface IFrontendEngineRef extends HTMLFormElement {
|
|
38
46
|
/** gets form values */
|
|
39
47
|
getValues: () => TFrontendEngineValues;
|
|
40
|
-
/**
|
|
48
|
+
/** sets field value by id */
|
|
41
49
|
setValue: UseFormSetValue<TFrontendEngineValues>;
|
|
42
|
-
/**
|
|
50
|
+
/** checks if form is valid */
|
|
43
51
|
isValid: () => boolean;
|
|
44
52
|
/** triggers form submission */
|
|
45
53
|
submit: () => void;
|
|
54
|
+
/** adds custom validation rule */
|
|
46
55
|
addCustomValidation: (type: TYupSchemaType | "mixed", name: string, fn: (value: unknown, arg: unknown) => boolean) => void;
|
|
47
|
-
/**
|
|
56
|
+
/** allows setting of custom errors thrown by endpoints */
|
|
48
57
|
setErrors: (errors: TErrorPayload) => void;
|
|
58
|
+
/** resets the form to the default state */
|
|
59
|
+
reset: UseFormReset<TFrontendEngineValues>;
|
|
49
60
|
}
|
|
50
61
|
export interface IFrontendEngineBaseFieldJsonSchema<T, V = undefined, U = undefined> {
|
|
51
|
-
/** defines what kind of
|
|
52
|
-
|
|
62
|
+
/** defines what kind of component to be rendered */
|
|
63
|
+
uiType: T;
|
|
53
64
|
/** caption for the field */
|
|
54
65
|
label: string;
|
|
55
66
|
/** render conditions
|
|
@@ -58,32 +69,62 @@ export interface IFrontendEngineBaseFieldJsonSchema<T, V = undefined, U = undefi
|
|
|
58
69
|
showIf?: TRenderRules[] | undefined;
|
|
59
70
|
/** validation config, can be customised by passing generics */
|
|
60
71
|
validation?: (V | U | IYupValidationRule)[];
|
|
72
|
+
/** escape hatch for other form / frontend engines to have unsupported attributes */
|
|
73
|
+
customOptions?: Record<string, unknown> | undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* to support custom components from other form / frontend engines
|
|
77
|
+
*/
|
|
78
|
+
export interface ICustomComponentJsonSchema<T> {
|
|
79
|
+
referenceKey: T;
|
|
80
|
+
uiType?: never | undefined;
|
|
81
|
+
}
|
|
82
|
+
export interface ICustomFieldJsonSchema<T, V = undefined, U = undefined> extends ICustomComponentJsonSchema<T> {
|
|
83
|
+
validation?: (V | U | IYupValidationRule)[];
|
|
84
|
+
/** render conditions
|
|
85
|
+
* - need to fulfil at least 1 object in array (OR condition)
|
|
86
|
+
* - in order for an object to be valid, need to fulfil all conditions in that object (AND condition) */
|
|
87
|
+
showIf?: TRenderRules[] | undefined;
|
|
61
88
|
}
|
|
62
89
|
/**
|
|
63
90
|
* JSON keys to omit from field schema when extending from other interfaces
|
|
64
91
|
* - keys already defined in `IFrontendEngineBaseFieldJsonSchema` to prevent collision
|
|
65
92
|
* - some inherited HTML attributes
|
|
66
93
|
*/
|
|
67
|
-
export type TFrontendEngineFieldJsonSchemaOmitKeys = "id" | "label" | "validation" | "
|
|
94
|
+
export type TFrontendEngineFieldJsonSchemaOmitKeys = "id" | "label" | "validation" | "uiType" | "showIf" | "children" | "value";
|
|
68
95
|
export interface IFrontendEngineElementJsonSchema<T> extends Omit<IFrontendEngineBaseFieldJsonSchema<T>, "label" | "validation"> {
|
|
69
96
|
}
|
|
70
97
|
type UnionOptionalKeys<T = undefined> = T extends string | number | symbol ? TFrontendEngineFieldJsonSchemaOmitKeys | T : TFrontendEngineFieldJsonSchemaOmitKeys;
|
|
98
|
+
/**
|
|
99
|
+
* Omits clashing keys between native props and frontend engine
|
|
100
|
+
*/
|
|
71
101
|
export type TComponentOmitProps<T, V = undefined> = Omit<T, UnionOptionalKeys<V>>;
|
|
102
|
+
/**
|
|
103
|
+
* Field types
|
|
104
|
+
* - components that can contain values that can get submitted
|
|
105
|
+
*/
|
|
72
106
|
export declare enum EFieldType {
|
|
73
107
|
TEXTAREA = "Textarea",
|
|
74
|
-
TEXT = "TextField",
|
|
75
|
-
NUMERIC = "TextField",
|
|
76
|
-
EMAIL = "TextField",
|
|
108
|
+
"TEXT-FIELD" = "TextField",
|
|
109
|
+
"NUMERIC-FIELD" = "TextField",
|
|
110
|
+
"EMAIL-FIELD" = "TextField",
|
|
77
111
|
SUBMIT = "SubmitButton",
|
|
78
112
|
SELECT = "Select",
|
|
79
113
|
"MULTI-SELECT" = "MultiSelect",
|
|
80
|
-
DATE = "
|
|
114
|
+
"DATE-FIELD" = "DateField",
|
|
81
115
|
CHECKBOX = "CheckboxGroup",
|
|
82
|
-
CONTACT = "
|
|
116
|
+
"CONTACT-FIELD" = "ContactField",
|
|
83
117
|
RADIO = "RadioButtonGroup",
|
|
84
|
-
TIME = "
|
|
85
|
-
CHIPS = "Chips"
|
|
118
|
+
"TIME-FIELD" = "TimeField",
|
|
119
|
+
CHIPS = "Chips",
|
|
120
|
+
RESET = "ResetButton",
|
|
121
|
+
"UNIT-NUMBER-FIELD" = "UnitNumberField"
|
|
86
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Non-field types
|
|
125
|
+
* - components that do not have values
|
|
126
|
+
* - typically used for layouts and messages
|
|
127
|
+
*/
|
|
87
128
|
export declare enum EElementType {
|
|
88
129
|
ALERT = "Alert",
|
|
89
130
|
"TEXT-D1" = "Text",
|
|
@@ -100,7 +141,6 @@ export declare enum EElementType {
|
|
|
100
141
|
"TEXT-XSMALL" = "Text",
|
|
101
142
|
DIV = "Wrapper",
|
|
102
143
|
SPAN = "Wrapper",
|
|
103
|
-
SECTION = "Wrapper",
|
|
104
144
|
HEADER = "Wrapper",
|
|
105
145
|
FOOTER = "Wrapper",
|
|
106
146
|
H1 = "Wrapper",
|
|
@@ -111,7 +151,23 @@ export declare enum EElementType {
|
|
|
111
151
|
H6 = "Wrapper",
|
|
112
152
|
P = "Wrapper"
|
|
113
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Custom element types
|
|
156
|
+
* - components that do not have uiType and have specific schema to render
|
|
157
|
+
*/
|
|
158
|
+
export declare enum ECustomElementType {
|
|
159
|
+
FILTER = "Filter",
|
|
160
|
+
"FILTER-ITEM" = "FilterItem"
|
|
161
|
+
}
|
|
162
|
+
export declare enum ECustomFieldType {
|
|
163
|
+
"FILTER-CHECKBOX" = "FilterCheckbox"
|
|
164
|
+
}
|
|
114
165
|
export interface IGenericFieldProps<T = TFrontendEngineFieldSchema> extends Partial<ControllerFieldState>, Partial<ControllerRenderProps> {
|
|
115
166
|
id: string;
|
|
116
167
|
schema: T;
|
|
117
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* prevents inferrence
|
|
171
|
+
* https://stackoverflow.com/questions/56687668/a-way-to-disable-type-argument-inference-in-generics
|
|
172
|
+
*/
|
|
173
|
+
export type TNoInfer<T, U> = [T][T extends U ? 0 : never];
|
|
@@ -8,5 +8,5 @@ interface IProps {
|
|
|
8
8
|
children: ReactElement;
|
|
9
9
|
}
|
|
10
10
|
export declare const YupContext: React.Context<IYupContext>;
|
|
11
|
-
export declare const YupProvider: ({ children }: IProps) => JSX.Element;
|
|
11
|
+
export declare const YupProvider: ({ children }: IProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
export {};
|
|
@@ -2,5 +2,5 @@ import React from "react";
|
|
|
2
2
|
import { IChipButtonProps } from "./types";
|
|
3
3
|
interface IProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, IChipButtonProps {
|
|
4
4
|
}
|
|
5
|
-
export declare const Chip: ({ children, ...otherProps }: IProps) => JSX.Element;
|
|
5
|
+
export declare const Chip: ({ children, ...otherProps }: IProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export {};
|