dynamic-modal 1.1.1 → 1.1.7

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.
Files changed (52) hide show
  1. package/README-ES.md +217 -217
  2. package/README.md +216 -215
  3. package/dist/components/input-upload/input-upload.js +1 -1
  4. package/dist/components/make-button/make-button.js +7 -17
  5. package/dist/components/make-input/make-input.js +9 -19
  6. package/dist/components/make-select/make-select.js +9 -19
  7. package/dist/components/make-textarea/make-textarea.js +9 -19
  8. package/dist/components/make-toggle/make-toggle.js +9 -19
  9. package/dist/components/make-upload/make-upload.js +2 -2
  10. package/dist/components/portal/portal.js +7 -17
  11. package/dist/context/component/component-state.js +7 -17
  12. package/dist/hooks/field-render.js +1 -1
  13. package/dist/interfaces/field.d.ts +3 -2
  14. package/dist/interfaces/make-select.d.ts +2 -1
  15. package/dist/interfaces/modal.d.ts +2 -1
  16. package/dist/modal.js +38 -19
  17. package/eslint.config.mjs +14 -14
  18. package/examples/enable-if.ts +127 -127
  19. package/examples/live-data.ts +61 -61
  20. package/examples/render-if.ts +128 -128
  21. package/examples/simple.ts +74 -74
  22. package/index.ts +5 -5
  23. package/package.json +46 -47
  24. package/src/components/input-upload/input-upload.tsx +67 -67
  25. package/src/components/make-button/make-button.tsx +18 -18
  26. package/src/components/make-description/make-description.tsx +15 -15
  27. package/src/components/make-input/make-input.tsx +53 -53
  28. package/src/components/make-select/make-select.tsx +55 -55
  29. package/src/components/make-textarea/make-textarea.tsx +53 -53
  30. package/src/components/make-toggle/make-toggle.tsx +53 -53
  31. package/src/components/make-upload/make-upload.tsx +40 -40
  32. package/src/components/portal/portal.tsx +37 -37
  33. package/src/context/component/component-state.tsx +17 -17
  34. package/src/hooks/field-render.ts +109 -109
  35. package/src/hooks/modal-handler.ts +38 -38
  36. package/src/interfaces/component-state.ts +33 -33
  37. package/src/interfaces/field.ts +37 -36
  38. package/src/interfaces/input-upload.ts +21 -21
  39. package/src/interfaces/make-button.ts +19 -19
  40. package/src/interfaces/make-description.ts +14 -14
  41. package/src/interfaces/make-field-group.ts +14 -14
  42. package/src/interfaces/make-input.ts +14 -14
  43. package/src/interfaces/make-select.ts +15 -14
  44. package/src/interfaces/make-textarea.ts +11 -11
  45. package/src/interfaces/make-toggle.ts +9 -9
  46. package/src/interfaces/make-upload.ts +14 -14
  47. package/src/interfaces/modal.ts +47 -45
  48. package/src/interfaces/option.ts +3 -3
  49. package/src/interfaces/portal.ts +8 -8
  50. package/src/modal.tsx +196 -164
  51. package/src/tools/general.ts +8 -8
  52. package/tsconfig.json +13 -13
@@ -16,23 +16,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
36
26
  var __rest = (this && this.__rest) || function (s, e) {
37
27
  var t = {};
38
28
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -52,9 +42,9 @@ const general_1 = require("../../tools/general");
52
42
  const component_state_1 = require("../../context/component/component-state");
53
43
  const MakeToggle = (_a) => {
54
44
  var _b, _c;
55
- var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), element = __rest(_d, ["validation"]), props = __rest(_a, ["element"]);
45
+ var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), { enableIf, renderIf } = _d, element = __rest(_d, ["validation", "enableIf", "renderIf"]), props = __rest(_a, ["element"]);
56
46
  const { Toggle } = (0, react_1.useContext)(component_state_1.ComponentStateContext);
57
- const { render, enable, checkField } = (0, field_render_1.useFieldRender)(Object.assign(Object.assign({}, props), { element }));
47
+ const { render, enable, checkField } = (0, field_render_1.useFieldRender)(Object.assign(Object.assign({}, props), { element: Object.assign({ enableIf, renderIf }, element) }));
58
48
  const elementId = (0, react_1.useMemo)(() => { var _a; return (_a = element.id) !== null && _a !== void 0 ? _a : (0, general_1.generateId)(); }, []);
59
49
  (0, react_1.useEffect)(() => {
60
50
  const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }));
@@ -21,8 +21,8 @@ const input_upload_1 = __importDefault(require("../input-upload/input-upload"));
21
21
  const field_render_1 = require("../../hooks/field-render");
22
22
  const MakeUpload = (_a) => {
23
23
  var _b, _c;
24
- var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), element = __rest(_d, ["validation"]), props = __rest(_a, ["element"]);
25
- const { render, enable } = (0, field_render_1.useFieldRender)(Object.assign(Object.assign({}, props), { element }));
24
+ var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), { enableIf, renderIf } = _d, element = __rest(_d, ["validation", "enableIf", "renderIf"]), props = __rest(_a, ["element"]);
25
+ const { render, enable } = (0, field_render_1.useFieldRender)(Object.assign(Object.assign({}, props), { element: Object.assign({ enableIf, renderIf }, element) }));
26
26
  return (render
27
27
  ? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: Object.assign({ required: {
28
28
  value: required,
@@ -16,23 +16,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
36
26
  Object.defineProperty(exports, "__esModule", { value: true });
37
27
  exports.Portal = void 0;
38
28
  const react_1 = __importStar(require("react"));
@@ -16,23 +16,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
36
26
  Object.defineProperty(exports, "__esModule", { value: true });
37
27
  exports.ComponentState = exports.ComponentStateContext = void 0;
38
28
  const react_1 = __importStar(require("react"));
@@ -60,7 +60,7 @@ const useFieldRender = ({ element, setValue, unregister }) => {
60
60
  }
61
61
  }
62
62
  else if (enableCondition && enableConditionList.includes(key) && fieldValidValue) {
63
- const enableStatus = element.enableIf[key].includes(targetField) || element.enableIf[key].includes('');
63
+ const enableStatus = element.enableIf[key].includes(targetField) || element.enableIf[key].includes('*');
64
64
  if (enable !== enableStatus)
65
65
  setEnable(enableStatus);
66
66
  }
@@ -1,5 +1,6 @@
1
1
  import { CSSProperties } from 'react';
2
2
  import { Control, FieldValues, UseFormSetValue, UseFormUnregister, UseFormWatch } from 'react-hook-form';
3
+ import { IModalRenderCondition } from './modal';
3
4
  export interface IValidationBase<T> {
4
5
  value: T;
5
6
  message: string;
@@ -11,8 +12,8 @@ export interface IField {
11
12
  style?: CSSProperties;
12
13
  placeholder?: string;
13
14
  defaultValue?: any;
14
- renderIf?: Record<string, Array<string | number>>;
15
- enableIf?: Record<string, Array<string | number>>;
15
+ renderIf?: IModalRenderCondition;
16
+ enableIf?: IModalRenderCondition;
16
17
  validation: {
17
18
  required: boolean;
18
19
  regex?: RegExp;
@@ -1,8 +1,9 @@
1
1
  import { IField, IFieldProps } from './field';
2
2
  import { IModalLiveDataCondition } from './modal';
3
+ import { IOption } from './option';
3
4
  export interface IMakeSelect extends IField {
4
5
  elementType: 'select';
5
- options: Array<Record<'id' | 'name', string>>;
6
+ options: Array<IOption>;
6
7
  liveData?: IModalLiveDataCondition;
7
8
  isSearch?: boolean;
8
9
  isMulti?: boolean;
@@ -10,7 +10,7 @@ import { IOption } from './option';
10
10
  import { IMakeButton } from './make-button';
11
11
  export type IModalField = IMakeSelect | IMakeInput | IMakeFieldGroup | IMakeTextarea | IMakeToggle | IMakeDescription | IMakeUpload | IMakeButton;
12
12
  export type IFormField = IMakeSelect | IMakeInput | IMakeTextarea | IMakeToggle;
13
- export type IModalRenderCondition = Record<string, Array<string | number>>;
13
+ export type IModalRenderCondition = Record<string, Array<string | number | boolean> | undefined>;
14
14
  export type IModalLiveDataCondition = {
15
15
  action: (data: string, ...args: any[]) => Promise<Array<IOption>>;
16
16
  condition: Array<string>;
@@ -24,6 +24,7 @@ export interface IModalConfigProps {
24
24
  style?: CSSProperties;
25
25
  overFlowBody?: string | number;
26
26
  minHeightBody?: string | number;
27
+ useSubmit?: boolean;
27
28
  actions: {
28
29
  containerStyle?: CSSProperties;
29
30
  cancel?: Omit<IMakeButton, 'elementType'>;
package/dist/modal.js CHANGED
@@ -16,23 +16,22 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
36
35
  var __rest = (this && this.__rest) || function (s, e) {
37
36
  var t = {};
38
37
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -64,7 +63,7 @@ const Modal = ({ open, close, config }) => {
64
63
  const { ModalButtonAction, ModalButtonCancel } = (0, react_1.useContext)(component_state_1.ComponentStateContext);
65
64
  const [modalReady, setModalReady] = (0, react_1.useState)(undefined);
66
65
  const [defaultLoaded, setDefaultLoaded] = (0, react_1.useState)(false);
67
- const { control, handleSubmit, getValues, unregister, setValue, watch } = (0, react_hook_form_1.useForm)();
66
+ const { control, handleSubmit, getValues, unregister, setValue, watch, trigger, getFieldState } = (0, react_hook_form_1.useForm)();
68
67
  const formValueHandler = (element) => {
69
68
  var _a;
70
69
  if (['group', 'upload', 'text'].includes(element.elementType))
@@ -94,6 +93,10 @@ const Modal = ({ open, close, config }) => {
94
93
  });
95
94
  setDefaultLoaded(true);
96
95
  };
96
+ const getUseSubmit = (modalConfig) => {
97
+ const useSubmit = modalConfig.useSubmit === undefined ? true : modalConfig.useSubmit === false ? false : true;
98
+ return useSubmit;
99
+ };
97
100
  const getRender = (_a, index, isEndOfRender) => {
98
101
  var { elementType } = _a, element = __rest(_a, ["elementType"]);
99
102
  if (isEndOfRender === void 0) { isEndOfRender = false; }
@@ -132,6 +135,20 @@ const Modal = ({ open, close, config }) => {
132
135
  close();
133
136
  }, 200);
134
137
  };
138
+ const manualSubmit = () => __awaiter(void 0, void 0, void 0, function* () {
139
+ var _a;
140
+ const form = getValues();
141
+ const fields = Object.keys(form);
142
+ yield trigger(fields);
143
+ const validations = fields.map(field => {
144
+ const { invalid } = getFieldState(field);
145
+ return invalid;
146
+ });
147
+ const result = validations.some(isInvalid => isInvalid) ? undefined : form;
148
+ if (!result)
149
+ return;
150
+ actionHandler(Object.assign(Object.assign({}, ((_a = modalReady === null || modalReady === void 0 ? void 0 : modalReady.reservedData) !== null && _a !== void 0 ? _a : {})), form));
151
+ });
135
152
  const actionHandler = (data) => {
136
153
  var _a;
137
154
  modalReady === null || modalReady === void 0 ? void 0 : modalReady.out(Object.assign(Object.assign({}, ((_a = modalReady === null || modalReady === void 0 ? void 0 : modalReady.reservedData) !== null && _a !== void 0 ? _a : {})), data));
@@ -165,7 +182,9 @@ const Modal = ({ open, close, config }) => {
165
182
  })),
166
183
  react_1.default.createElement("div", { className: 'flex gap-4 items-center justify-center border-t', style: modalReady === null || modalReady === void 0 ? void 0 : modalReady.actions.containerStyle },
167
184
  modalReady.actions.cancel && react_1.default.createElement(ModalButtonCancel, Object.assign({}, modalReady.actions.cancel, { onClick: closeHandler })),
168
- react_1.default.createElement(ModalButtonAction, Object.assign({}, modalReady.actions.action, { type: 'submit' }))))))
185
+ getUseSubmit(modalReady) ?
186
+ react_1.default.createElement(ModalButtonAction, Object.assign({}, modalReady.actions.action, { type: 'submit' })) :
187
+ react_1.default.createElement(ModalButtonAction, Object.assign({}, modalReady.actions.action, { onClick: manualSubmit, type: 'button' }))))))
169
188
  : null);
170
189
  };
171
190
  exports.Modal = Modal;
package/eslint.config.mjs CHANGED
@@ -1,14 +1,14 @@
1
- import globals from "globals";
2
- import pluginJs from "@eslint/js";
3
- import tseslint from "typescript-eslint";
4
- import pluginReact from "eslint-plugin-react";
5
-
6
- export default [
7
- { files: ['**/*.{ts,tsx}'] },
8
- { languageOptions: { globals: globals.browser } },
9
- { settings: { react: { version: 'detect' } } },
10
- { ignores : ['dist/**', 'node_modules/**'] },
11
- pluginJs.configs.recommended,
12
- ...tseslint.configs.recommended,
13
- pluginReact.configs.flat.recommended,
14
- ];
1
+ import globals from "globals"
2
+ import pluginJs from "@eslint/js"
3
+ import tseslint from "typescript-eslint"
4
+ import pluginReact from "eslint-plugin-react"
5
+
6
+ export default [
7
+ { files: ['**/*.{ts,tsx}'] },
8
+ { languageOptions: { globals: globals.browser } },
9
+ { settings: { react: { version: 'detect' } } },
10
+ { ignores : ['dist/**', 'node_modules/**'] },
11
+ pluginJs.configs.recommended,
12
+ ...tseslint.configs.recommended,
13
+ pluginReact.configs.flat.recommended,
14
+ ]
@@ -1,128 +1,128 @@
1
-
2
- import { IModalConfigLoader } from '../src/interfaces/modal'
3
-
4
- export type IncomingProps = object
5
-
6
- type ResultProps = Record<'optionId', string> & Partial<Record<'input1ReadOnly' | 'input1WriteValue' | 'input2ReadOnly' | 'input2WriteValue', string>>
7
-
8
- export interface IEnableIfModal {
9
- default: IModalConfigLoader<IncomingProps, ResultProps>
10
- }
11
-
12
- const enableIfModal: IEnableIfModal = {
13
- default: (props, action) => {
14
- return {
15
- reservedData: {}, //Put here any data that you want store and receive into modal output
16
- fields: [ //Put here any elements for render into modal
17
- {
18
- elementType: 'select',
19
- label: 'option',
20
- defaultValue: '0',
21
- options: [
22
- {
23
- id: '0',
24
- name:'Select...'
25
- },
26
- {
27
- id: '1',
28
- name:'Option 1'
29
- },
30
- {
31
- id: '2',
32
- name:'Option 2'
33
- }
34
- ],
35
- name: 'optionId', //Element to be observed
36
- validation: {
37
- required: true,
38
- message: 'Please select a valid option'
39
- }
40
- },
41
- {
42
- elementType: 'group', //Put here groups of element into same line and customize using styles
43
- groups: [
44
- {
45
- elementType: 'input',
46
- label: 'Input 1 (Read)',
47
- name: 'input1ReadOnly',
48
- styles: {
49
- width: '50%'
50
- },
51
- validation: {
52
- required: false
53
- },
54
- //Define enable condition (element will be enabled when value of element observed match with array condition)
55
- enableIf: {
56
- optionId: ['1']
57
- }
58
- },
59
- {
60
- elementType: 'input',
61
- label: 'Input 1',
62
- name: 'input1WriteValue',
63
- styles: {
64
- width: '50%'
65
- },
66
- validation: {
67
- required: true,
68
- message: `Write a valid input value`
69
- },
70
- //Define enable condition (element will be enabled when value of element observed match with array condition)
71
- enableIf: {
72
- optionId: ['1']
73
- }
74
- },
75
- ]
76
- },
77
- {
78
- elementType: 'group', //Put here groups of element into same line and customize using styles
79
- groups: [
80
- {
81
- elementType: 'input',
82
- label: 'Input 2 (Read)',
83
- name: 'input2ReadOnly',
84
- disabled: true,
85
- styles: {
86
- width: '50%'
87
- },
88
- validation: {
89
- required: false
90
- },
91
- //Define enable condition (element will be enabled when value of element observed match with array condition)
92
- enableIf: {
93
- optionId: ['2']
94
- }
95
- },
96
- {
97
- elementType: 'input',
98
- label: 'Input 2',
99
- name: 'input2WriteValue',
100
- styles: {
101
- width: '50%'
102
- },
103
- validation: {
104
- required: true,
105
- message: `Write a valid input value`
106
- },
107
- //Define enable condition (element will be enabled when value of element observed match with array condition)
108
- enableIf: {
109
- optionId: ['2']
110
- }
111
- },
112
- ]
113
- },
114
- ],
115
- style: { // Put here styles for modal like height or width
116
- width: '500px'
117
- },
118
- title: `Title of enable if modal`, //Title of modal
119
- out: action, //Function to receive data from modal
120
- actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
121
- action: { text:'Action', color: 'primary' },
122
- cancel: { text: 'Cancel', color: 'danger' }
123
- }
124
- }
125
- }
126
- }
127
-
1
+
2
+ import { IModalConfigLoader } from '../src/interfaces/modal'
3
+
4
+ export type IncomingProps = object
5
+
6
+ type ResultProps = Record<'optionId', string> & Partial<Record<'input1ReadOnly' | 'input1WriteValue' | 'input2ReadOnly' | 'input2WriteValue', string>>
7
+
8
+ export interface IEnableIfModal {
9
+ default: IModalConfigLoader<IncomingProps, ResultProps>
10
+ }
11
+
12
+ const enableIfModal: IEnableIfModal = {
13
+ default: (props, action) => {
14
+ return {
15
+ reservedData: {}, //Put here any data that you want store and receive into modal output
16
+ fields: [ //Put here any elements for render into modal
17
+ {
18
+ elementType: 'select',
19
+ label: 'option',
20
+ defaultValue: '0',
21
+ options: [
22
+ {
23
+ id: '0',
24
+ name:'Select...'
25
+ },
26
+ {
27
+ id: '1',
28
+ name:'Option 1'
29
+ },
30
+ {
31
+ id: '2',
32
+ name:'Option 2'
33
+ }
34
+ ],
35
+ name: 'optionId', //Element to be observed
36
+ validation: {
37
+ required: true,
38
+ message: 'Please select a valid option'
39
+ }
40
+ },
41
+ {
42
+ elementType: 'group', //Put here groups of element into same line and customize using styles
43
+ groups: [
44
+ {
45
+ elementType: 'input',
46
+ label: 'Input 1 (Read)',
47
+ name: 'input1ReadOnly',
48
+ styles: {
49
+ width: '50%'
50
+ },
51
+ validation: {
52
+ required: false
53
+ },
54
+ //Define enable condition (element will be enabled when value of element observed match with array condition)
55
+ enableIf: {
56
+ optionId: ['1']
57
+ }
58
+ },
59
+ {
60
+ elementType: 'input',
61
+ label: 'Input 1',
62
+ name: 'input1WriteValue',
63
+ styles: {
64
+ width: '50%'
65
+ },
66
+ validation: {
67
+ required: true,
68
+ message: `Write a valid input value`
69
+ },
70
+ //Define enable condition (element will be enabled when value of element observed match with array condition)
71
+ enableIf: {
72
+ optionId: ['1']
73
+ }
74
+ },
75
+ ]
76
+ },
77
+ {
78
+ elementType: 'group', //Put here groups of element into same line and customize using styles
79
+ groups: [
80
+ {
81
+ elementType: 'input',
82
+ label: 'Input 2 (Read)',
83
+ name: 'input2ReadOnly',
84
+ disabled: true,
85
+ styles: {
86
+ width: '50%'
87
+ },
88
+ validation: {
89
+ required: false
90
+ },
91
+ //Define enable condition (element will be enabled when value of element observed match with array condition)
92
+ enableIf: {
93
+ optionId: ['2']
94
+ }
95
+ },
96
+ {
97
+ elementType: 'input',
98
+ label: 'Input 2',
99
+ name: 'input2WriteValue',
100
+ styles: {
101
+ width: '50%'
102
+ },
103
+ validation: {
104
+ required: true,
105
+ message: `Write a valid input value`
106
+ },
107
+ //Define enable condition (element will be enabled when value of element observed match with array condition)
108
+ enableIf: {
109
+ optionId: ['2']
110
+ }
111
+ },
112
+ ]
113
+ },
114
+ ],
115
+ style: { // Put here styles for modal like height or width
116
+ width: '500px'
117
+ },
118
+ title: `Title of enable if modal`, //Title of modal
119
+ out: action, //Function to receive data from modal
120
+ actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
121
+ action: { text:'Action', color: 'primary' },
122
+ cancel: { text: 'Cancel', color: 'danger' }
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
128
  export default enableIfModal