dynamic-modal 1.0.13 → 1.1.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-ES.md +109 -11
- package/README.md +111 -13
- package/dist/components/input-upload/input-upload.js +8 -42
- package/dist/components/make-button/make-button.js +41 -18
- package/dist/components/make-description/make-description.d.ts +4 -0
- package/dist/components/make-description/make-description.js +13 -0
- package/dist/components/make-input/make-input.d.ts +1 -1
- package/dist/components/make-input/make-input.js +14 -8
- package/dist/components/make-select/make-select.js +14 -8
- package/dist/components/make-textarea/make-textarea.js +14 -8
- package/dist/components/make-toggle/make-toggle.js +14 -11
- package/dist/components/make-upload/make-upload.js +10 -9
- package/dist/context/component/component-state.d.ts +4 -0
- package/dist/context/component/component-state.js +45 -0
- package/dist/hooks/field-render.js +1 -1
- package/dist/interfaces/component-state.d.ts +27 -0
- package/dist/interfaces/field.d.ts +6 -4
- package/dist/interfaces/input-upload.d.ts +1 -1
- package/dist/interfaces/make-button.d.ts +5 -6
- package/dist/interfaces/make-description.d.ts +12 -0
- package/dist/interfaces/make-field-group.d.ts +1 -0
- package/dist/interfaces/{make-field.d.ts → make-input.d.ts} +2 -2
- package/dist/interfaces/make-select.d.ts +5 -2
- package/dist/interfaces/make-textarea.d.ts +1 -1
- package/dist/interfaces/make-toggle.d.ts +1 -1
- package/dist/interfaces/make-upload.d.ts +1 -1
- package/dist/interfaces/modal.d.ts +15 -20
- package/dist/modal.js +42 -35
- package/dist/tools/general.js +1 -0
- package/examples/enable-if.ts +5 -7
- package/examples/live-data.ts +7 -9
- package/examples/render-if.ts +6 -8
- package/examples/simple.ts +6 -8
- package/index.ts +4 -2
- package/package.json +15 -16
- package/src/components/input-upload/input-upload.tsx +7 -12
- package/src/components/make-button/make-button.tsx +11 -10
- package/src/components/make-description/make-description.tsx +15 -0
- package/src/components/make-input/make-input.tsx +27 -21
- package/src/components/make-select/make-select.tsx +25 -24
- package/src/components/make-textarea/make-textarea.tsx +21 -16
- package/src/components/make-toggle/make-toggle.tsx +26 -17
- package/src/components/make-upload/make-upload.tsx +14 -8
- package/src/components/portal/portal.tsx +1 -0
- package/src/context/component/component-state.tsx +18 -0
- package/src/hooks/field-render.ts +6 -5
- package/src/hooks/modal-handler.ts +1 -0
- package/src/interfaces/component-state.ts +33 -0
- package/src/interfaces/field.ts +11 -9
- package/src/interfaces/input-upload.ts +11 -11
- package/src/interfaces/make-button.ts +10 -11
- package/src/interfaces/make-description.ts +14 -0
- package/src/interfaces/make-field-group.ts +5 -4
- package/src/interfaces/{make-field.ts → make-input.ts} +2 -2
- package/src/interfaces/make-select.ts +5 -2
- package/src/interfaces/make-textarea.ts +1 -1
- package/src/interfaces/make-toggle.ts +2 -2
- package/src/interfaces/make-upload.ts +7 -7
- package/src/interfaces/modal.ts +16 -21
- package/src/interfaces/option.ts +2 -2
- package/src/interfaces/portal.ts +4 -4
- package/src/modal.tsx +43 -53
- package/src/tools/general.ts +2 -0
- package/.idea/dynamic-modal.iml +0 -12
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/components/make-autocomplete/make-autocomplete.d.ts +0 -4
- package/dist/components/make-autocomplete/make-autocomplete.js +0 -70
- package/dist/components/make-multi-select/make-multi-select.d.ts +0 -4
- package/dist/components/make-multi-select/make-multi-select.js +0 -70
- package/dist/components/make-text/make-text.d.ts +0 -4
- package/dist/components/make-text/make-text.js +0 -11
- package/dist/components/make-title/make-title.d.ts +0 -4
- package/dist/components/make-title/make-title.js +0 -10
- package/dist/interfaces/make-autocomplete.d.ts +0 -11
- package/dist/interfaces/make-multi-select.d.ts +0 -12
- package/dist/interfaces/make-text.d.ts +0 -10
- package/dist/interfaces/make-text.js +0 -2
- package/dist/interfaces/make-title.d.ts +0 -3
- package/dist/interfaces/make-title.js +0 -2
- package/src/components/make-autocomplete/make-autocomplete.tsx +0 -54
- package/src/components/make-multi-select/make-multi-select.tsx +0 -56
- package/src/components/make-text/make-text.tsx +0 -16
- package/src/components/make-title/make-title.tsx +0 -12
- package/src/interfaces/make-autocomplete.ts +0 -13
- package/src/interfaces/make-multi-select.ts +0 -14
- package/src/interfaces/make-text.ts +0 -12
- package/src/interfaces/make-title.ts +0 -3
- /package/dist/interfaces/{make-autocomplete.js → component-state.js} +0 -0
- /package/dist/interfaces/{make-field.js → make-description.js} +0 -0
- /package/dist/interfaces/{make-multi-select.js → make-input.js} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
4
|
if (k2 === undefined) k2 = k;
|
|
4
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -47,26 +48,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
47
48
|
const react_1 = __importStar(require("react"));
|
|
48
49
|
const react_hook_form_1 = require("react-hook-form");
|
|
49
50
|
const field_render_1 = require("../../hooks/field-render");
|
|
50
|
-
const react_2 = require("@nextui-org/react");
|
|
51
51
|
const general_1 = require("../../tools/general");
|
|
52
|
+
const component_state_1 = require("../../context/component/component-state");
|
|
52
53
|
const MakeToggle = (_a) => {
|
|
53
54
|
var _b, _c;
|
|
54
|
-
var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), element = __rest(_d, ["validation"]), props = __rest(_a, ["element"]);
|
|
55
|
-
const {
|
|
55
|
+
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
|
+
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: Object.assign({ enableIf, renderIf }, element) }));
|
|
58
|
+
const elementId = (0, react_1.useMemo)(() => { var _a; return (_a = element.id) !== null && _a !== void 0 ? _a : (0, general_1.generateId)(); }, []);
|
|
56
59
|
(0, react_1.useEffect)(() => {
|
|
57
60
|
const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }));
|
|
58
61
|
return () => subscription.unsubscribe();
|
|
59
62
|
}, [checkField, props, props.watch]);
|
|
60
63
|
return (render
|
|
61
|
-
? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: Object.assign({ required: {
|
|
65
|
+
value: required,
|
|
66
|
+
message: (_b = validation.message) !== null && _b !== void 0 ? _b : ''
|
|
67
|
+
}, pattern: validation.regex ? {
|
|
68
|
+
value: validation.regex,
|
|
65
69
|
message: (_c = validation.message) !== null && _c !== void 0 ? _c : ''
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return (react_1.default.createElement(react_2.Switch, Object.assign({}, element, { id: (_a = element.id) !== null && _a !== void 0 ? _a : (0, general_1.generateId)(), isSelected: value, onValueChange: onChange, isDisabled: (_b = element.disabled) !== null && _b !== void 0 ? _b : !enable }), element.label));
|
|
70
|
+
} : undefined }, validation), render: ({ field: { onChange, value }, fieldState: { invalid, error } }) => {
|
|
71
|
+
var _a;
|
|
72
|
+
return (react_1.default.createElement(Toggle, Object.assign({}, element, { id: elementId, onChange: onChange, value: value !== null && value !== void 0 ? value : '', invalid: invalid, error: error, disabled: (_a = element.disabled) !== null && _a !== void 0 ? _a : !enable })));
|
|
70
73
|
} })
|
|
71
74
|
: null);
|
|
72
75
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
4
|
var t = {};
|
|
4
5
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -20,18 +21,18 @@ const input_upload_1 = __importDefault(require("../input-upload/input-upload"));
|
|
|
20
21
|
const field_render_1 = require("../../hooks/field-render");
|
|
21
22
|
const MakeUpload = (_a) => {
|
|
22
23
|
var _b, _c;
|
|
23
|
-
var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), element = __rest(_d, ["validation"]), props = __rest(_a, ["element"]);
|
|
24
|
-
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) }));
|
|
25
26
|
return (render
|
|
26
|
-
? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: Object.assign({ required: {
|
|
28
|
+
value: required,
|
|
29
|
+
message: (_b = validation.message) !== null && _b !== void 0 ? _b : ''
|
|
30
|
+
}, pattern: validation.regex ? {
|
|
31
|
+
value: validation.regex,
|
|
30
32
|
message: (_c = validation.message) !== null && _c !== void 0 ? _c : ''
|
|
31
|
-
}
|
|
32
|
-
}, render: ({ field: { onChange } }) => {
|
|
33
|
+
} : undefined }, validation), render: ({ field: { onChange } }) => {
|
|
33
34
|
var _a;
|
|
34
|
-
return (react_1.default.createElement(input_upload_1.default, Object.assign({}, element, { disabled: (_a = element.disabled) !== null && _a !== void 0 ? _a : !enable
|
|
35
|
+
return (react_1.default.createElement(input_upload_1.default, Object.assign({}, element, { onChange: onChange, disabled: (_a = element.disabled) !== null && _a !== void 0 ? _a : !enable })));
|
|
35
36
|
} })
|
|
36
37
|
: null);
|
|
37
38
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IComponentState, IComponentStateProps } from "../../interfaces/component-state";
|
|
3
|
+
export declare const ComponentStateContext: React.Context<IComponentState>;
|
|
4
|
+
export declare const ComponentState: ({ children, components }: IComponentStateProps) => React.JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
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
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.ComponentState = exports.ComponentStateContext = void 0;
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_2 = require("react");
|
|
40
|
+
exports.ComponentStateContext = (0, react_2.createContext)({});
|
|
41
|
+
const ComponentState = ({ children, components }) => {
|
|
42
|
+
const value = (0, react_1.useMemo)(() => components, []);
|
|
43
|
+
return (react_1.default.createElement(exports.ComponentStateContext.Provider, { value: value }, children));
|
|
44
|
+
};
|
|
45
|
+
exports.ComponentState = ComponentState;
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from "react";
|
|
2
|
+
import { FieldError } from "react-hook-form";
|
|
3
|
+
import { IOption } from "./option";
|
|
4
|
+
import { IMakeInput } from "./make-input";
|
|
5
|
+
import { IMakeButton } from "./make-button";
|
|
6
|
+
import { IMakeSelect } from "./make-select";
|
|
7
|
+
import { IMakeTextarea } from "./make-textarea";
|
|
8
|
+
import { IMakeToggle } from "./make-toggle";
|
|
9
|
+
export interface IComponentAditionalProps {
|
|
10
|
+
onChange: (...event: any[]) => void;
|
|
11
|
+
value: any;
|
|
12
|
+
invalid: boolean;
|
|
13
|
+
error?: FieldError;
|
|
14
|
+
liveSearching?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface IComponentState {
|
|
17
|
+
ModalButtonCancel: FC<Omit<IMakeButton, 'elementType'>>;
|
|
18
|
+
ModalButtonAction: FC<Omit<IMakeButton, 'elementType'>>;
|
|
19
|
+
Button: FC<Omit<IMakeButton, 'elementType'>>;
|
|
20
|
+
Input: FC<Omit<IMakeInput, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
|
|
21
|
+
Select: FC<Omit<IMakeSelect, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps & Record<'options', Array<IOption>>>;
|
|
22
|
+
Textarea: FC<Omit<IMakeTextarea, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
|
|
23
|
+
Toggle: FC<Omit<IMakeToggle, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
|
|
24
|
+
}
|
|
25
|
+
export interface IComponentStateProps extends PropsWithChildren {
|
|
26
|
+
components: IComponentState;
|
|
27
|
+
}
|
|
@@ -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;
|
|
@@ -8,10 +9,11 @@ export interface IField {
|
|
|
8
9
|
name: string;
|
|
9
10
|
id?: string;
|
|
10
11
|
label?: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
defaultValue?: any;
|
|
15
|
+
renderIf?: IModalRenderCondition;
|
|
16
|
+
enableIf?: IModalRenderCondition;
|
|
15
17
|
validation: {
|
|
16
18
|
required: boolean;
|
|
17
19
|
regex?: RegExp;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
2
|
import { IFieldProps } from './field';
|
|
3
3
|
export interface IMakeButton {
|
|
4
|
+
id?: string;
|
|
4
5
|
elementType: 'button';
|
|
5
6
|
disabled?: boolean;
|
|
6
7
|
className?: string;
|
|
7
|
-
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
variant?: string;
|
|
8
10
|
text?: string;
|
|
9
11
|
type?: 'button' | 'submit' | 'reset';
|
|
10
12
|
onClick?: () => void;
|
|
11
|
-
|
|
12
|
-
iconSize?: number | string;
|
|
13
|
-
iconClassName?: CSSProperties;
|
|
14
|
-
color?: 'primary' | 'secondary' | 'default' | 'success' | 'warning' | 'danger';
|
|
13
|
+
color?: string;
|
|
15
14
|
}
|
|
16
15
|
export interface IMakeButtonProps extends IFieldProps {
|
|
17
|
-
element: IMakeButton
|
|
16
|
+
element: Omit<IMakeButton, 'elementType'>;
|
|
18
17
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CSSProperties, FC } from 'react';
|
|
2
|
+
import { IFieldProps } from './field';
|
|
3
|
+
export interface IMakeDescription {
|
|
4
|
+
elementType: 'text';
|
|
5
|
+
text: string;
|
|
6
|
+
containerStyle?: CSSProperties;
|
|
7
|
+
textStyle?: CSSProperties;
|
|
8
|
+
Icon?: FC;
|
|
9
|
+
}
|
|
10
|
+
export interface IMakeDescriptionProps extends IFieldProps {
|
|
11
|
+
element: Omit<IMakeDescription, 'elementType'>;
|
|
12
|
+
}
|
|
@@ -2,11 +2,11 @@ import { HTMLInputTypeAttribute } from 'react';
|
|
|
2
2
|
import { IField, IFieldProps } from './field';
|
|
3
3
|
export interface IMakeInput extends IField {
|
|
4
4
|
elementType: 'input';
|
|
5
|
-
|
|
5
|
+
placeholder?: string;
|
|
6
6
|
min?: string;
|
|
7
7
|
max?: string;
|
|
8
8
|
type?: HTMLInputTypeAttribute;
|
|
9
9
|
}
|
|
10
10
|
export interface IMakeInputProps extends IFieldProps {
|
|
11
|
-
element: IMakeInput
|
|
11
|
+
element: Omit<IMakeInput, 'elementType'>;
|
|
12
12
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
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<
|
|
6
|
+
options: Array<IOption>;
|
|
6
7
|
liveData?: IModalLiveDataCondition;
|
|
8
|
+
isSearch?: boolean;
|
|
9
|
+
isMulti?: boolean;
|
|
7
10
|
}
|
|
8
11
|
export interface IMakeSelectProps extends IFieldProps {
|
|
9
|
-
element: IMakeSelect
|
|
12
|
+
element: Omit<IMakeSelect, 'elementType'>;
|
|
10
13
|
}
|
|
@@ -1,39 +1,34 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
2
|
import { IMakeSelect } from './make-select';
|
|
3
|
-
import { IMakeInput } from './make-
|
|
3
|
+
import { IMakeInput } from './make-input';
|
|
4
4
|
import { IMakeTextarea } from './make-textarea';
|
|
5
5
|
import { IMakeToggle } from './make-toggle';
|
|
6
|
-
import {
|
|
7
|
-
import { IMakeText } from './make-text';
|
|
6
|
+
import { IMakeDescription } from './make-description';
|
|
8
7
|
import { IMakeFieldGroup } from './make-field-group';
|
|
9
8
|
import { IMakeUpload } from './make-upload';
|
|
10
9
|
import { IOption } from './option';
|
|
11
10
|
import { IMakeButton } from './make-button';
|
|
12
|
-
|
|
13
|
-
export type
|
|
14
|
-
export type
|
|
15
|
-
export type IModalRenderCondition = Record<string, Array<string | number>>;
|
|
11
|
+
export type IModalField = IMakeSelect | IMakeInput | IMakeFieldGroup | IMakeTextarea | IMakeToggle | IMakeDescription | IMakeUpload | IMakeButton;
|
|
12
|
+
export type IFormField = IMakeSelect | IMakeInput | IMakeTextarea | IMakeToggle;
|
|
13
|
+
export type IModalRenderCondition = Record<string, Array<string | number | boolean> | undefined>;
|
|
16
14
|
export type IModalLiveDataCondition = {
|
|
17
15
|
action: (data: string, ...args: any[]) => Promise<Array<IOption>>;
|
|
18
16
|
condition: Array<string>;
|
|
19
17
|
};
|
|
20
18
|
export interface IModalConfigProps {
|
|
21
|
-
fields: Array<IModalField>;
|
|
22
|
-
title: string;
|
|
23
|
-
action: {
|
|
24
|
-
name: string;
|
|
25
|
-
action?: (data: any) => void;
|
|
26
|
-
hide?: boolean;
|
|
27
|
-
};
|
|
28
|
-
cancel?: {
|
|
29
|
-
name?: string;
|
|
30
|
-
action?: () => void;
|
|
31
|
-
hide?: boolean;
|
|
32
|
-
};
|
|
33
19
|
reservedData?: Record<string, any>;
|
|
34
|
-
|
|
20
|
+
title: string;
|
|
21
|
+
fields: Array<IModalField>;
|
|
22
|
+
out: (data: any) => void;
|
|
23
|
+
onClose?: () => void;
|
|
24
|
+
style?: CSSProperties;
|
|
35
25
|
overFlowBody?: string | number;
|
|
36
26
|
minHeightBody?: string | number;
|
|
27
|
+
actions: {
|
|
28
|
+
containerStyle?: CSSProperties;
|
|
29
|
+
cancel?: Omit<IMakeButton, 'elementType'>;
|
|
30
|
+
action: Omit<IMakeButton, 'elementType'>;
|
|
31
|
+
};
|
|
37
32
|
}
|
|
38
33
|
export type IModalConfigLoader<T = any, D = any> = (props: T, action: (modalResult: D) => void) => IModalConfigProps;
|
|
39
34
|
export interface IModal {
|
package/dist/modal.js
CHANGED
|
@@ -33,6 +33,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
37
|
+
var t = {};
|
|
38
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
39
|
+
t[p] = s[p];
|
|
40
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
41
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
42
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
43
|
+
t[p[i]] = s[p[i]];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
36
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
49
|
};
|
|
@@ -40,19 +51,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
40
51
|
exports.Modal = void 0;
|
|
41
52
|
const react_1 = __importStar(require("react"));
|
|
42
53
|
const react_hook_form_1 = require("react-hook-form");
|
|
43
|
-
const react_2 = require("@nextui-org/react");
|
|
44
54
|
const portal_1 = require("./components/portal/portal");
|
|
45
55
|
const make_toggle_1 = __importDefault(require("./components/make-toggle/make-toggle"));
|
|
46
56
|
const make_input_1 = __importDefault(require("./components/make-input/make-input"));
|
|
47
57
|
const make_select_1 = __importDefault(require("./components/make-select/make-select"));
|
|
48
58
|
const make_textarea_1 = __importDefault(require("./components/make-textarea/make-textarea"));
|
|
49
|
-
const
|
|
50
|
-
const make_text_1 = __importDefault(require("./components/make-text/make-text"));
|
|
59
|
+
const make_description_1 = __importDefault(require("./components/make-description/make-description"));
|
|
51
60
|
const make_upload_1 = __importDefault(require("./components/make-upload/make-upload"));
|
|
52
61
|
const make_button_1 = __importDefault(require("./components/make-button/make-button"));
|
|
53
|
-
const
|
|
62
|
+
const component_state_1 = require("./context/component/component-state");
|
|
54
63
|
const Modal = ({ open, close, config }) => {
|
|
55
|
-
|
|
64
|
+
const { ModalButtonAction, ModalButtonCancel } = (0, react_1.useContext)(component_state_1.ComponentStateContext);
|
|
56
65
|
const [modalReady, setModalReady] = (0, react_1.useState)(undefined);
|
|
57
66
|
const [defaultLoaded, setDefaultLoaded] = (0, react_1.useState)(false);
|
|
58
67
|
const { control, handleSubmit, getValues, unregister, setValue, watch } = (0, react_hook_form_1.useForm)();
|
|
@@ -85,7 +94,9 @@ const Modal = ({ open, close, config }) => {
|
|
|
85
94
|
});
|
|
86
95
|
setDefaultLoaded(true);
|
|
87
96
|
};
|
|
88
|
-
const getRender = (
|
|
97
|
+
const getRender = (_a, index, isEndOfRender) => {
|
|
98
|
+
var { elementType } = _a, element = __rest(_a, ["elementType"]);
|
|
99
|
+
if (isEndOfRender === void 0) { isEndOfRender = false; }
|
|
89
100
|
if (isEndOfRender && modalReady)
|
|
90
101
|
setTimeout(() => autoLoadField(modalReady.fields), 200);
|
|
91
102
|
const props = {
|
|
@@ -94,29 +105,25 @@ const Modal = ({ open, close, config }) => {
|
|
|
94
105
|
setValue,
|
|
95
106
|
unregister
|
|
96
107
|
};
|
|
97
|
-
return
|
|
108
|
+
return elementType === 'input'
|
|
98
109
|
? react_1.default.createElement(make_input_1.default, Object.assign({}, props, { key: `modal-input-${index}`, element: element }))
|
|
99
|
-
:
|
|
110
|
+
: elementType === 'select'
|
|
100
111
|
? react_1.default.createElement(make_select_1.default, Object.assign({}, props, { key: `modal-select-${index}`, element: element }))
|
|
101
|
-
:
|
|
112
|
+
: elementType === 'textarea'
|
|
102
113
|
? react_1.default.createElement(make_textarea_1.default, Object.assign({}, props, { key: `modal-textarea-${index}`, element: element }))
|
|
103
|
-
:
|
|
114
|
+
: elementType === 'toggle'
|
|
104
115
|
? react_1.default.createElement(make_toggle_1.default, Object.assign({}, props, { key: `modal-toggle-${index}`, element: element }))
|
|
105
|
-
:
|
|
106
|
-
? react_1.default.createElement(
|
|
107
|
-
:
|
|
108
|
-
? react_1.default.createElement(
|
|
109
|
-
:
|
|
110
|
-
? react_1.default.createElement(
|
|
111
|
-
:
|
|
112
|
-
? react_1.default.createElement(make_button_1.default, Object.assign({}, props, { key: `modal-button-${index}`, element: element }))
|
|
113
|
-
: element.elementType === 'autocomplete'
|
|
114
|
-
? react_1.default.createElement(make_autocomplete_1.default, Object.assign({}, props, { key: `modal-autocomplete-${index}`, element: element }))
|
|
115
|
-
: null;
|
|
116
|
+
: elementType === 'text'
|
|
117
|
+
? react_1.default.createElement(make_description_1.default, Object.assign({}, props, { key: `modal-text-${index}`, element: element }))
|
|
118
|
+
: elementType === 'upload'
|
|
119
|
+
? react_1.default.createElement(make_upload_1.default, Object.assign({}, props, { key: `modal-upload-${index}`, element: element }))
|
|
120
|
+
: elementType === 'button'
|
|
121
|
+
? react_1.default.createElement(make_button_1.default, Object.assign({}, props, { key: `modal-button-${index}`, element: element }))
|
|
122
|
+
: null;
|
|
116
123
|
};
|
|
117
124
|
const closeHandler = () => {
|
|
118
|
-
if (
|
|
119
|
-
modalReady.
|
|
125
|
+
if (modalReady === null || modalReady === void 0 ? void 0 : modalReady.onClose)
|
|
126
|
+
modalReady.onClose();
|
|
120
127
|
setTimeout(() => {
|
|
121
128
|
const form = getValues();
|
|
122
129
|
unregister(Object.keys(form));
|
|
@@ -126,8 +133,8 @@ const Modal = ({ open, close, config }) => {
|
|
|
126
133
|
}, 200);
|
|
127
134
|
};
|
|
128
135
|
const actionHandler = (data) => {
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
var _a;
|
|
137
|
+
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));
|
|
131
138
|
closeHandler();
|
|
132
139
|
};
|
|
133
140
|
(0, react_1.useEffect)(() => {
|
|
@@ -136,29 +143,29 @@ const Modal = ({ open, close, config }) => {
|
|
|
136
143
|
}, [config, modalReady, open]);
|
|
137
144
|
return (modalReady
|
|
138
145
|
? react_1.default.createElement(portal_1.Portal, { closeTime: 200, portalOpen: open, portalTag: '#modal-portal' },
|
|
139
|
-
react_1.default.createElement("div", { className: 'rounded bg-white relative w-auto h-auto min-h-[200px] min-w-[500px]', style:
|
|
146
|
+
react_1.default.createElement("div", { className: 'rounded bg-white relative w-auto h-auto min-h-[200px] min-w-[500px]', style: modalReady.style },
|
|
140
147
|
react_1.default.createElement("form", { className: 'flex flex-col p-4 gap-4', autoComplete: 'off', onSubmit: handleSubmit(actionHandler) },
|
|
141
148
|
react_1.default.createElement("h2", { className: 'text-bold text-center border-b pb-4 font-semibold' }, modalReady.title),
|
|
142
|
-
react_1.default.createElement("div", { className: 'flex flex-col
|
|
149
|
+
react_1.default.createElement("div", { className: 'flex flex-col gap-4 py-4', style: {
|
|
143
150
|
overflowY: modalReady.overFlowBody ? 'auto' : undefined,
|
|
144
151
|
height: modalReady.overFlowBody,
|
|
145
152
|
minHeight: modalReady.minHeightBody
|
|
146
153
|
} }, modalReady.fields.map((element, index) => {
|
|
147
154
|
const isEndOfRender = index + 1 === modalReady.fields.length;
|
|
148
155
|
if (element.elementType === 'group') {
|
|
149
|
-
return (react_1.default.createElement("div", { key: `modal-group-${index}`, className: 'flex
|
|
150
|
-
.
|
|
151
|
-
.
|
|
156
|
+
return (react_1.default.createElement("div", { key: `modal-group-${index}`, className: 'flex flex-col w-full gap-2' },
|
|
157
|
+
element.title && react_1.default.createElement("h3", { className: 'font-bold border-b-2 pb-2 mb-2' }, element.title),
|
|
158
|
+
react_1.default.createElement("div", { key: `modal-group-${index}`, className: 'flex gap-4 w-full', style: element.style }, element.groups
|
|
159
|
+
.filter(sub => ['input', 'select', 'toggle', 'multiselect', 'upload', 'button', 'autocomplete'].includes(sub.elementType))
|
|
160
|
+
.map((sub, subIndex) => getRender(sub, index + subIndex, isEndOfRender)))));
|
|
152
161
|
}
|
|
153
162
|
else {
|
|
154
163
|
return getRender(element, index, isEndOfRender);
|
|
155
164
|
}
|
|
156
165
|
})),
|
|
157
|
-
react_1.default.createElement("div", { className: 'flex items-center justify-
|
|
158
|
-
modalReady.cancel &&
|
|
159
|
-
|
|
160
|
-
modalReady.action &&
|
|
161
|
-
react_1.default.createElement(react_2.Button, { color: 'primary', type: 'submit', className: 'w-[140px]' }, (_b = modalReady.action.name) !== null && _b !== void 0 ? _b : 'Ok')))))
|
|
166
|
+
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
|
+
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' }))))))
|
|
162
169
|
: null);
|
|
163
170
|
};
|
|
164
171
|
exports.Modal = Modal;
|
package/dist/tools/general.js
CHANGED
package/examples/enable-if.ts
CHANGED
|
@@ -112,16 +112,14 @@ const enableIfModal: IEnableIfModal = {
|
|
|
112
112
|
]
|
|
113
113
|
},
|
|
114
114
|
],
|
|
115
|
-
|
|
115
|
+
style: { // Put here styles for modal like height or width
|
|
116
116
|
width: '500px'
|
|
117
117
|
},
|
|
118
118
|
title: `Title of enable if modal`, //Title of modal
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
action
|
|
122
|
-
|
|
123
|
-
cancel: {
|
|
124
|
-
name: 'Cancel' //Name of cancel button
|
|
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' }
|
|
125
123
|
}
|
|
126
124
|
}
|
|
127
125
|
}
|
package/examples/live-data.ts
CHANGED
|
@@ -42,20 +42,18 @@ const liveDataModal: ILiveDataModal = {
|
|
|
42
42
|
},
|
|
43
43
|
liveData: {
|
|
44
44
|
action: props.optionReadAction, //Define live data action (function that receive data selected from other field for execute and build other options)
|
|
45
|
-
condition: 'typeId' //Define element into modal was to observed
|
|
45
|
+
condition: ['typeId'] //Define element into modal was to observed
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
],
|
|
49
|
-
|
|
49
|
+
style: { // Put here styles for modal like height or width
|
|
50
50
|
width: '500px'
|
|
51
51
|
},
|
|
52
|
-
title: `Title of
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
action
|
|
56
|
-
|
|
57
|
-
cancel: {
|
|
58
|
-
name: 'Cancel' //Name of cancel button
|
|
52
|
+
title: `Title of enable if modal`, //Title of modal
|
|
53
|
+
out: action, //Function to receive data from modal
|
|
54
|
+
actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
|
|
55
|
+
action: { text:'Action', color: 'primary' },
|
|
56
|
+
cancel: { text: 'Cancel', color: 'danger' }
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
}
|
package/examples/render-if.ts
CHANGED
|
@@ -113,16 +113,14 @@ const renderIfModal: IRenderIfModal = {
|
|
|
113
113
|
]
|
|
114
114
|
},
|
|
115
115
|
],
|
|
116
|
-
|
|
116
|
+
style: { // Put here styles for modal like height or width
|
|
117
117
|
width: '500px'
|
|
118
118
|
},
|
|
119
|
-
title: `Title of
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
action
|
|
123
|
-
|
|
124
|
-
cancel: {
|
|
125
|
-
name: 'Cancel' //Name of cancel button
|
|
119
|
+
title: `Title of enable if modal`, //Title of modal
|
|
120
|
+
out: action, //Function to receive data from modal
|
|
121
|
+
actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
|
|
122
|
+
action: { text:'Action', color: 'Primary' },
|
|
123
|
+
cancel: { text: 'Cancel', color: 'Danger' }
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
126
|
}
|
package/examples/simple.ts
CHANGED
|
@@ -59,16 +59,14 @@ const simpleModal: ISimpleModal = {
|
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
61
|
],
|
|
62
|
-
|
|
62
|
+
style: { // Put here styles for modal like height or width
|
|
63
63
|
width: '500px'
|
|
64
64
|
},
|
|
65
|
-
title: `Title of
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
action
|
|
69
|
-
|
|
70
|
-
cancel: {
|
|
71
|
-
name: 'Cancel', //Name of cancel button
|
|
65
|
+
title: `Title of enable if modal`, //Title of modal
|
|
66
|
+
out: action, //Function to receive data from modal
|
|
67
|
+
actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
|
|
68
|
+
action: { text:'Action', color: 'Primary' },
|
|
69
|
+
cancel: { text: 'Cancel', color: 'Danger' }
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
}
|