dry-ux 1.62.0 → 1.64.0
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/dist/styles/modal.css +51 -0
- package/dist/ui-utils/ActionsOverlay.d.ts +9 -0
- package/dist/ui-utils/{ConfirmOverlay.js → ActionsOverlay.js} +9 -7
- package/dist/ui-utils/Modal.d.ts +7 -11
- package/dist/ui-utils/Modal.js +37 -23
- package/dist/ui-utils/UIUtil.interface.d.ts +45 -30
- package/dist/ui-utils/UIUtilProvider.d.ts +18 -22
- package/dist/ui-utils/UIUtilProvider.js +69 -66
- package/dist/ui-utils/UIUtilRenderer.d.ts +2 -2
- package/dist/ui-utils/UIUtilRenderer.js +2 -5
- package/package.json +1 -1
- package/dist/styles/modal-overlay.css +0 -20
- package/dist/ui-utils/ConfirmOverlay.d.ts +0 -7
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
.dry-ux-overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
background-color: rgba(0, 0, 0, 0.65);
|
|
8
|
+
z-index: 1050;
|
|
9
|
+
border-radius: 10px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.dry-ux-overlay-content {
|
|
13
|
+
position: absolute;
|
|
14
|
+
top: 50%;
|
|
15
|
+
left: 50%;
|
|
16
|
+
transform: translate(-50%, -50%);
|
|
17
|
+
background-color: white;
|
|
18
|
+
padding: 5px;
|
|
19
|
+
border-radius: 5px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.dry-ux-modal {
|
|
23
|
+
opacity: 1!important;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.dry-ux-modal.default-styles .modal-dialog {
|
|
27
|
+
max-width: 95%;
|
|
28
|
+
margin-top: 100px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.dry-ux-modal.default-styles .modal-dialog .modal-header {
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.dry-ux-modal.default-styles .modal-dialog .modal-title {
|
|
36
|
+
margin-top: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.dry-ux-modal.centered .modal-dialog {
|
|
40
|
+
margin-top: unset;
|
|
41
|
+
position: absolute;
|
|
42
|
+
transform: translate(-50%, -50%);
|
|
43
|
+
top: 50%;
|
|
44
|
+
left: 50%;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@media only screen and (max-width: 767px) {
|
|
48
|
+
.dry-ux-overlay-content {
|
|
49
|
+
width: 90%;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Content, PopUpAction } from "./UIUtil.interface";
|
|
3
|
+
import { Omit } from "react-bootstrap";
|
|
4
|
+
export declare const ActionsOverlay: React.FC<{
|
|
5
|
+
title: Content;
|
|
6
|
+
content: Content;
|
|
7
|
+
hide: () => void;
|
|
8
|
+
actions: Omit<PopUpAction, "confirm">[];
|
|
9
|
+
}>;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ActionsOverlay = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const react_bootstrap_1 = require("react-bootstrap");
|
|
6
|
-
const
|
|
6
|
+
const ActionsOverlay = ({ title, content, actions, hide }) => {
|
|
7
7
|
return (React.createElement("div", { style: { minWidth: 200 } },
|
|
8
8
|
React.createElement("div", { style: {
|
|
9
9
|
fontWeight: "bold",
|
|
10
10
|
fontSize: 18,
|
|
11
11
|
paddingLeft: 5,
|
|
12
|
-
} },
|
|
12
|
+
} }, title),
|
|
13
13
|
React.createElement("hr", { style: { margin: 5 } }),
|
|
14
14
|
React.createElement("div", null, typeof content == "string" ? (React.createElement("h4", { className: "text-center", style: { margin: 10 } }, content)) : (content)),
|
|
15
15
|
React.createElement("hr", { style: { margin: 5 } }),
|
|
16
|
-
React.createElement("div", { style: { textAlign: "right" } },
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
React.createElement("div", { style: { textAlign: "right" } }, actions.map((action, index) => (React.createElement(react_bootstrap_1.Button, { key: index, bsClass: `btn btn-${action.type} btn-sm`, style: { marginRight: 10 }, onClick: () => {
|
|
17
|
+
var _a;
|
|
18
|
+
(_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action);
|
|
19
|
+
action.closeOnClick && hide();
|
|
20
|
+
} }, action.content))))));
|
|
19
21
|
};
|
|
20
|
-
exports.
|
|
22
|
+
exports.ActionsOverlay = ActionsOverlay;
|
package/dist/ui-utils/Modal.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import "../styles/modal
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
shown: boolean;
|
|
8
|
-
overlay: Content;
|
|
2
|
+
import { PopUpInstance, PopUpOptions } from "./UIUtil.interface";
|
|
3
|
+
import "../styles/modal.css";
|
|
4
|
+
export type ModalProps = {
|
|
5
|
+
id: string;
|
|
6
|
+
instance: PopUpInstance;
|
|
9
7
|
config: {
|
|
10
8
|
styles?: {
|
|
11
9
|
[selector: string]: React.CSSProperties;
|
|
@@ -16,8 +14,6 @@ export interface IModalProps {
|
|
|
16
14
|
onOpen?: (modal: Pick<PopUpOptions, "title" | "trackingId">) => void;
|
|
17
15
|
onClose?: (modal: Pick<PopUpOptions, "title" | "trackingId">) => void;
|
|
18
16
|
};
|
|
19
|
-
}
|
|
20
|
-
declare const Modal: React.FC<
|
|
21
|
-
handleClose: () => void;
|
|
22
|
-
}>;
|
|
17
|
+
};
|
|
18
|
+
declare const Modal: React.FC<ModalProps>;
|
|
23
19
|
export default Modal;
|
package/dist/ui-utils/Modal.js
CHANGED
|
@@ -2,28 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const react_bootstrap_1 = require("react-bootstrap");
|
|
5
|
-
require("../styles/modal
|
|
6
|
-
const
|
|
5
|
+
require("../styles/modal.css");
|
|
6
|
+
const classSet_1 = require("../helpers/classSet");
|
|
7
|
+
const ActionsOverlay_1 = require("./ActionsOverlay");
|
|
8
|
+
const Modal = ({ id, instance: { handleClose, toggleOverlay, shown, overlay, options: { content, footerContent, cssClass = "", closeBtn, title, width, onClose, titleCloseBtn = true, centered, trackingId, actions = [], }, }, config: { defaultModalStyles = false, styles = {}, setBackdropHeight = true, centered: globalCentered, onOpen, onClose: globalOnClose, }, }) => {
|
|
7
9
|
const isCentered = centered !== null && centered !== void 0 ? centered : globalCentered;
|
|
8
|
-
const modalRef = React.useRef(null);
|
|
9
10
|
const applyStyles = React.useCallback(() => {
|
|
10
11
|
document.querySelectorAll(".modal-dialog").forEach((el) => {
|
|
11
12
|
el.style.width = typeof width == "number" ? `${width}px` : width;
|
|
12
|
-
if (defaultModalStyles) {
|
|
13
|
-
el.style.maxWidth = "95%";
|
|
14
|
-
el.style.marginTop = "100px";
|
|
15
|
-
el.querySelectorAll(".modal-header").forEach((el) => (el.style.display = "block"));
|
|
16
|
-
el.querySelectorAll(".modal-title").forEach((el) => (el.style.marginTop = "0"));
|
|
17
|
-
}
|
|
18
|
-
if (isCentered) {
|
|
19
|
-
el.style.position = "absolute";
|
|
20
|
-
el.style.transform = "translate(-50%, -50%)";
|
|
21
|
-
el.style.top = "50%";
|
|
22
|
-
el.style.left = "50%";
|
|
23
|
-
el.style.marginTop = "unset";
|
|
24
|
-
}
|
|
25
13
|
});
|
|
26
|
-
document.querySelectorAll("[role=dialog]").forEach((el) => (el.style.opacity = "1"));
|
|
27
14
|
if (setBackdropHeight) {
|
|
28
15
|
document
|
|
29
16
|
.querySelectorAll(".modal-backdrop")
|
|
@@ -36,7 +23,7 @@ const Modal = React.memo(({ handleClose, shown, overlay, options: { content, foo
|
|
|
36
23
|
});
|
|
37
24
|
});
|
|
38
25
|
});
|
|
39
|
-
}, [width,
|
|
26
|
+
}, [width, styles, setBackdropHeight]);
|
|
40
27
|
React.useEffect(() => {
|
|
41
28
|
if (shown) {
|
|
42
29
|
applyStyles();
|
|
@@ -47,12 +34,39 @@ const Modal = React.memo(({ handleClose, shown, overlay, options: { content, foo
|
|
|
47
34
|
}
|
|
48
35
|
}, [shown, width, defaultModalStyles]);
|
|
49
36
|
const onHide = () => {
|
|
50
|
-
handleClose();
|
|
37
|
+
handleClose(id, false, true);
|
|
51
38
|
onClose && onClose();
|
|
52
39
|
};
|
|
53
40
|
const contentToRender = typeof content == "string" ? React.createElement("div", { dangerouslySetInnerHTML: { __html: content } }) : content;
|
|
54
|
-
const showFooter = closeBtn || footerContent;
|
|
55
|
-
|
|
41
|
+
const showFooter = closeBtn || footerContent || !!(actions === null || actions === void 0 ? void 0 : actions.length);
|
|
42
|
+
const modalCssClass = (0, classSet_1.classSet)({
|
|
43
|
+
"dry-ux-modal": true,
|
|
44
|
+
centered: isCentered,
|
|
45
|
+
[cssClass]: true,
|
|
46
|
+
"default-styles": defaultModalStyles,
|
|
47
|
+
});
|
|
48
|
+
const actionsToRender = React.useMemo(() => {
|
|
49
|
+
const _actions = [...(actions || [])];
|
|
50
|
+
if (closeBtn) {
|
|
51
|
+
_actions.push({ content: "Close", type: "danger", onClick: onHide });
|
|
52
|
+
}
|
|
53
|
+
return _actions.map(({ content, type = "success", closeOnClick, onClick, confirm }, index) => (React.createElement(react_bootstrap_1.Button, { bsClass: `btn btn-${type} mright`, onClick: () => {
|
|
54
|
+
const triggerClick = () => {
|
|
55
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
56
|
+
closeOnClick && onHide();
|
|
57
|
+
};
|
|
58
|
+
if (!!confirm) {
|
|
59
|
+
toggleOverlay(id, React.createElement(ActionsOverlay_1.ActionsOverlay, { title: "Confirm", content: confirm, hide: () => toggleOverlay(id), actions: [
|
|
60
|
+
{ content: "Yes", type: "success", onClick: triggerClick, closeOnClick: true },
|
|
61
|
+
{ content: "No", type: "danger", closeOnClick: true },
|
|
62
|
+
] }));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
triggerClick();
|
|
66
|
+
}
|
|
67
|
+
} }, content)));
|
|
68
|
+
}, [actions, toggleOverlay, onHide, closeBtn]);
|
|
69
|
+
return (React.createElement(react_bootstrap_1.Modal, { onHide: onHide, show: shown, animation: true, autoFocus: true, keyboard: false, className: modalCssClass, backdropStyle: { zIndex: 1040, opacity: 0.5 }, backdrop: "static" },
|
|
56
70
|
overlay && (React.createElement("div", { className: "dry-ux-overlay" },
|
|
57
71
|
React.createElement("div", { className: "dry-ux-overlay-content" }, overlay))),
|
|
58
72
|
!!title && (React.createElement(react_bootstrap_1.Modal.Header, { closeButton: titleCloseBtn, onHide: onHide },
|
|
@@ -60,6 +74,6 @@ const Modal = React.memo(({ handleClose, shown, overlay, options: { content, foo
|
|
|
60
74
|
React.createElement(react_bootstrap_1.Modal.Body, null, contentToRender),
|
|
61
75
|
showFooter && (React.createElement(react_bootstrap_1.Modal.Footer, null,
|
|
62
76
|
footerContent,
|
|
63
|
-
|
|
64
|
-
}
|
|
77
|
+
actionsToRender))));
|
|
78
|
+
};
|
|
65
79
|
exports.default = Modal;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Omit } from "react-bootstrap";
|
|
1
2
|
export type Content = JSX.Element | string;
|
|
2
3
|
export type PopUp = {
|
|
3
4
|
/**
|
|
@@ -12,6 +13,10 @@ export type PopUp = {
|
|
|
12
13
|
* Removes the modal.
|
|
13
14
|
*/
|
|
14
15
|
remove: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Updates the modal options.
|
|
18
|
+
*/
|
|
19
|
+
update: (options: Partial<PopUpOptions>) => void;
|
|
15
20
|
/**
|
|
16
21
|
* The overlay for the modal.
|
|
17
22
|
*/
|
|
@@ -21,15 +26,49 @@ export type PopUp = {
|
|
|
21
26
|
*/
|
|
22
27
|
show: (content: Content) => void;
|
|
23
28
|
/**
|
|
24
|
-
* Shows the overlay.
|
|
29
|
+
* Shows the overlay with yes/no buttons.
|
|
25
30
|
*/
|
|
26
31
|
showConfirm: (content: Content, onYes: () => void, onNo?: () => void) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Shows the overlay with custom actions.
|
|
34
|
+
*/
|
|
35
|
+
showActions: (title: Content, content: Content, actions: Omit<PopUpAction, "confirm">[]) => void;
|
|
27
36
|
/**
|
|
28
37
|
* Hides the overlay.
|
|
29
38
|
*/
|
|
30
39
|
hide: () => void;
|
|
31
40
|
};
|
|
32
41
|
};
|
|
42
|
+
export type ButtonType = "primary" | "secondary" | "info" | "success" | "warning" | "danger";
|
|
43
|
+
export type PopUpInstance = {
|
|
44
|
+
options: PopUpOptions;
|
|
45
|
+
shown: boolean;
|
|
46
|
+
overlay?: Content;
|
|
47
|
+
handleClose: (id: string, shown: boolean, destroyOnClose?: boolean) => void;
|
|
48
|
+
toggleOverlay: (id: string, content?: Content) => void;
|
|
49
|
+
};
|
|
50
|
+
export type PopUpAction = {
|
|
51
|
+
/**
|
|
52
|
+
* The content to display in the modal.
|
|
53
|
+
*/
|
|
54
|
+
content: Content;
|
|
55
|
+
/**
|
|
56
|
+
* The type of button to display.
|
|
57
|
+
*/
|
|
58
|
+
type?: ButtonType;
|
|
59
|
+
/**
|
|
60
|
+
* Function to call when the button is clicked.
|
|
61
|
+
*/
|
|
62
|
+
onClick?: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* If true, the modal will be closed when the button is clicked.
|
|
65
|
+
*/
|
|
66
|
+
closeOnClick?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* If set, confirm overlay will be shown before the action is executed.
|
|
69
|
+
*/
|
|
70
|
+
confirm?: Content;
|
|
71
|
+
};
|
|
33
72
|
export type PopUpOptions = {
|
|
34
73
|
/**
|
|
35
74
|
* The content of the modal.
|
|
@@ -75,29 +114,10 @@ export type PopUpOptions = {
|
|
|
75
114
|
* The tracking ID for the modal.
|
|
76
115
|
*/
|
|
77
116
|
trackingId?: string;
|
|
78
|
-
};
|
|
79
|
-
export type ButtonType = "primary" | "secondary" | "info" | "success" | "warning" | "danger";
|
|
80
|
-
export type PopUpAction = {
|
|
81
117
|
/**
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
content: Content;
|
|
85
|
-
/**
|
|
86
|
-
* The type of button to display.
|
|
118
|
+
* If true, the modal will be shown.
|
|
87
119
|
*/
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Function to call when the button is clicked.
|
|
91
|
-
*/
|
|
92
|
-
onClick?: () => void;
|
|
93
|
-
/**
|
|
94
|
-
* If true, the modal will be closed when the button is clicked.
|
|
95
|
-
*/
|
|
96
|
-
closeOnClick?: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* If set, confirm overlay will be shown before the action is executed.
|
|
99
|
-
*/
|
|
100
|
-
confirm?: Content;
|
|
120
|
+
actions?: PopUpAction[];
|
|
101
121
|
};
|
|
102
122
|
export type UIUtilModal = {
|
|
103
123
|
/**
|
|
@@ -115,12 +135,7 @@ export type UIUtilModal = {
|
|
|
115
135
|
* Dictionary of modal instances in memory.
|
|
116
136
|
*/
|
|
117
137
|
instances: {
|
|
118
|
-
[id: string]:
|
|
119
|
-
options: PopUpOptions;
|
|
120
|
-
shown: boolean;
|
|
121
|
-
overlay?: Content;
|
|
122
|
-
handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
|
|
123
|
-
};
|
|
138
|
+
[id: string]: PopUpInstance;
|
|
124
139
|
};
|
|
125
140
|
/**
|
|
126
141
|
* Gets the current modal instance.
|
|
@@ -137,13 +152,13 @@ export type UIUtilModal = {
|
|
|
137
152
|
* @param onYes The function to call when the yes button is clicked.
|
|
138
153
|
* @param onNo The function to call when the no button is clicked.
|
|
139
154
|
*/
|
|
140
|
-
showConfirm: (options: PopUpOptions, onYes: () => void, onNo?: () => void) => PopUp;
|
|
155
|
+
showConfirm: (options: Omit<PopUpOptions, "actions">, onYes: () => void, onNo?: () => void) => PopUp;
|
|
141
156
|
/**
|
|
142
157
|
* Shows a modal with custom actions.
|
|
143
158
|
* @param options The options for the modal.
|
|
144
159
|
* @param actions The actions to display in the modal.
|
|
145
160
|
*/
|
|
146
|
-
showActions: (options: PopUpOptions, actions: PopUpAction[]) => PopUp;
|
|
161
|
+
showActions: (options: Omit<PopUpOptions, "actions">, actions: PopUpAction[]) => PopUp;
|
|
147
162
|
};
|
|
148
163
|
export interface IUIUtilLoader {
|
|
149
164
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Content, IUIUtilLoader, PopUp, PopUpAction, PopUpInstance, PopUpOptions, UIUtilModal, UIUtilPrompt } from "./UIUtil.interface";
|
|
3
3
|
import "../types";
|
|
4
4
|
export interface IUIUtilProviderState {
|
|
5
5
|
modal: UIUtilModal;
|
|
@@ -9,9 +9,15 @@ export interface IUIUtilProviderState {
|
|
|
9
9
|
}
|
|
10
10
|
export declare const UIUtilContext: React.Context<IUIUtilProviderState>;
|
|
11
11
|
export declare const useUIUtilContext: () => IUIUtilProviderState;
|
|
12
|
+
declare const modalId: {
|
|
13
|
+
actions: string;
|
|
14
|
+
confirm: string;
|
|
15
|
+
alert: string;
|
|
16
|
+
modal: string;
|
|
17
|
+
};
|
|
18
|
+
type ModalId = (typeof modalId)[keyof typeof modalId];
|
|
12
19
|
export declare class UIUtilProvider extends React.PureComponent<{}, IUIUtilProviderState> {
|
|
13
20
|
private readonly loader;
|
|
14
|
-
private readonly modalId;
|
|
15
21
|
constructor(props: any);
|
|
16
22
|
get modalDefaults(): {
|
|
17
23
|
create: any;
|
|
@@ -21,12 +27,7 @@ export declare class UIUtilProvider extends React.PureComponent<{}, IUIUtilProvi
|
|
|
21
27
|
showConfirm: (options: PopUpOptions, onYes: () => void, onNo?: () => void) => PopUp;
|
|
22
28
|
showActions: (options: PopUpOptions, actions: PopUpAction[]) => PopUp;
|
|
23
29
|
instances: {
|
|
24
|
-
[id: string]:
|
|
25
|
-
options: PopUpOptions;
|
|
26
|
-
shown: boolean;
|
|
27
|
-
overlay?: Content;
|
|
28
|
-
handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
|
|
29
|
-
};
|
|
30
|
+
[id: string]: PopUpInstance;
|
|
30
31
|
};
|
|
31
32
|
};
|
|
32
33
|
get customLoaderDefaults(): {
|
|
@@ -40,22 +41,17 @@ export declare class UIUtilProvider extends React.PureComponent<{}, IUIUtilProvi
|
|
|
40
41
|
};
|
|
41
42
|
get promptDefaults(): {
|
|
42
43
|
getCurrent: () => PopUp;
|
|
43
|
-
showConfirm: (options: PopUpOptions, onYes: () => void, onNo?: () => void) => PopUp;
|
|
44
|
-
showActions: (options: PopUpOptions, actions: PopUpAction[]) => PopUp;
|
|
44
|
+
showConfirm: (options: import("react-bootstrap").Omit<PopUpOptions, "actions">, onYes: () => void, onNo?: () => void) => PopUp;
|
|
45
|
+
showActions: (options: import("react-bootstrap").Omit<PopUpOptions, "actions">, actions: PopUpAction[]) => PopUp;
|
|
45
46
|
instances: {
|
|
46
|
-
[id: string]:
|
|
47
|
-
options: PopUpOptions;
|
|
48
|
-
shown: boolean;
|
|
49
|
-
overlay?: Content;
|
|
50
|
-
handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
|
|
51
|
-
};
|
|
47
|
+
[id: string]: PopUpInstance;
|
|
52
48
|
};
|
|
53
49
|
};
|
|
54
|
-
toggleModalInstance
|
|
55
|
-
toggleModalOverlay
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
createModal(id: string, options: PopUpOptions): PopUp;
|
|
50
|
+
toggleModalInstance: PopUpInstance["handleClose"];
|
|
51
|
+
toggleModalOverlay: PopUpInstance["toggleOverlay"];
|
|
52
|
+
removeModalInstance(id: ModalId): void;
|
|
53
|
+
getCurrentModal(id: ModalId): PopUp;
|
|
54
|
+
createModal(id: ModalId, options: PopUpOptions): PopUp;
|
|
60
55
|
render(): React.JSX.Element;
|
|
61
56
|
}
|
|
57
|
+
export {};
|
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UIUtilProvider = exports.useUIUtilContext = exports.UIUtilContext = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
5
|
require("../types");
|
|
6
|
-
const react_bootstrap_1 = require("react-bootstrap");
|
|
7
6
|
const Loader_1 = require("./Loader");
|
|
8
|
-
const
|
|
7
|
+
const ActionsOverlay_1 = require("./ActionsOverlay");
|
|
9
8
|
const defaultState = {
|
|
10
9
|
modal: {
|
|
11
10
|
show: null,
|
|
@@ -35,33 +34,67 @@ const defaultState = {
|
|
|
35
34
|
exports.UIUtilContext = React.createContext(defaultState);
|
|
36
35
|
const useUIUtilContext = () => React.useContext(exports.UIUtilContext);
|
|
37
36
|
exports.useUIUtilContext = useUIUtilContext;
|
|
37
|
+
const modalId = {
|
|
38
|
+
actions: "actions",
|
|
39
|
+
confirm: "confirm",
|
|
40
|
+
alert: "alert",
|
|
41
|
+
modal: "modal",
|
|
42
|
+
};
|
|
38
43
|
class UIUtilProvider extends React.PureComponent {
|
|
39
44
|
constructor(props) {
|
|
40
45
|
super(props);
|
|
41
46
|
this.loader = Loader_1.Loader.getInstance();
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
this.toggleModalInstance = (id, shown, destroyOnClose = false) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const { modal: { instances }, } = this.state;
|
|
50
|
+
const instance = instances[id];
|
|
51
|
+
if (!instance) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Hide all other instances
|
|
55
|
+
Object.keys(instances).forEach(id => (instances[id].shown = false));
|
|
56
|
+
if (!shown) {
|
|
57
|
+
(_b = (_a = instance.options).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
58
|
+
}
|
|
59
|
+
if (!shown && destroyOnClose && instance.options.destroyOnClose) {
|
|
60
|
+
this.removeModalInstance(id);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
instance.shown = shown;
|
|
64
|
+
this.setState({
|
|
65
|
+
modal: Object.assign(Object.assign({}, this.state.modal), { instances }),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this.toggleModalOverlay = (id, content) => {
|
|
70
|
+
const { modal: { instances }, } = this.state;
|
|
71
|
+
instances[id].overlay = content;
|
|
72
|
+
this.setState({
|
|
73
|
+
modal: Object.assign(Object.assign({}, this.state.modal), { instances }),
|
|
74
|
+
});
|
|
45
75
|
};
|
|
46
76
|
this.state = Object.assign(Object.assign({}, defaultState), { modal: this.modalDefaults, customLoader: this.customLoaderDefaults, loader: this.loaderDefaults, prompt: this.promptDefaults });
|
|
47
77
|
}
|
|
48
78
|
get modalDefaults() {
|
|
49
|
-
return Object.assign(Object.assign({}, defaultState.modal), { create: this.createModal.bind(this), show: (options) => this.createModal(
|
|
79
|
+
return Object.assign(Object.assign({}, defaultState.modal), { create: this.createModal.bind(this), show: (options) => this.createModal(modalId.modal, options), getCurrent: () => {
|
|
50
80
|
const { modal: { instances }, } = this.state;
|
|
51
81
|
const id = Object.keys(instances).find(id => instances[id].shown);
|
|
52
82
|
return this.getCurrentModal(id);
|
|
53
|
-
}, showAlert: (content, onClose) => this.createModal(
|
|
83
|
+
}, showAlert: (content, onClose) => this.createModal(modalId.alert, {
|
|
54
84
|
content: typeof content == "string" ? React.createElement("h4", { className: "text-center mtop" }, content) : content,
|
|
55
85
|
destroyOnClose: true,
|
|
56
86
|
closeBtn: true,
|
|
57
87
|
width: 400,
|
|
58
88
|
onClose,
|
|
59
|
-
}), showConfirm: (options, onYes, onNo) => this.createModal(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
89
|
+
}), showConfirm: (options, onYes, onNo) => this.createModal(modalId.confirm, Object.assign(Object.assign({}, options), { actions: [
|
|
90
|
+
{ content: "Yes", type: "success", onClick: onYes },
|
|
91
|
+
{
|
|
92
|
+
content: "No",
|
|
93
|
+
type: "danger",
|
|
94
|
+
onClick: onNo,
|
|
95
|
+
closeOnClick: true,
|
|
96
|
+
},
|
|
97
|
+
] })), showActions: (options, actions) => this.createModal(modalId.actions, Object.assign(Object.assign({}, options), { actions })) });
|
|
65
98
|
}
|
|
66
99
|
get customLoaderDefaults() {
|
|
67
100
|
return Object.assign(Object.assign({}, defaultState.customLoader), { show: () => this.setState({
|
|
@@ -80,52 +113,6 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
80
113
|
return this.getCurrentModal(id);
|
|
81
114
|
} });
|
|
82
115
|
}
|
|
83
|
-
toggleModalInstance(id, shown, destroyOnClose = false) {
|
|
84
|
-
var _a, _b;
|
|
85
|
-
const { modal: { instances }, } = this.state;
|
|
86
|
-
const instance = instances[id];
|
|
87
|
-
if (!instance) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
// Hide all other instances
|
|
91
|
-
Object.keys(instances).forEach(id => (instances[id].shown = false));
|
|
92
|
-
if (!shown) {
|
|
93
|
-
(_b = (_a = instance.options).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
94
|
-
}
|
|
95
|
-
if (!shown && destroyOnClose && instance.options.destroyOnClose) {
|
|
96
|
-
this.removeModalInstance(id);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
instance.shown = shown;
|
|
100
|
-
this.setState({
|
|
101
|
-
modal: Object.assign(Object.assign({}, this.state.modal), { instances }),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
toggleModalOverlay(id, content) {
|
|
106
|
-
const { modal: { instances }, } = this.state;
|
|
107
|
-
instances[id].overlay = content;
|
|
108
|
-
this.setState({
|
|
109
|
-
modal: Object.assign(Object.assign({}, this.state.modal), { instances }),
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
getModalActionButtons(actions) {
|
|
113
|
-
return actions.map(({ content, type = "success", closeOnClick, onClick, confirm }, index) => (React.createElement(react_bootstrap_1.Button, { bsClass: `btn btn-${type} mright`, onClick: () => {
|
|
114
|
-
const triggerClick = () => {
|
|
115
|
-
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
116
|
-
closeOnClick && this.toggleModalInstance(this.modalId.actions, false, true);
|
|
117
|
-
};
|
|
118
|
-
if (!!confirm) {
|
|
119
|
-
this.toggleModalOverlay(this.modalId.actions, React.createElement(ConfirmOverlay_1.ConfirmOverlay, { content: confirm, onYes: () => {
|
|
120
|
-
triggerClick();
|
|
121
|
-
this.toggleModalOverlay(this.modalId.actions);
|
|
122
|
-
}, onNo: () => this.toggleModalOverlay(this.modalId.actions) }));
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
triggerClick();
|
|
126
|
-
}
|
|
127
|
-
} }, content)));
|
|
128
|
-
}
|
|
129
116
|
removeModalInstance(id) {
|
|
130
117
|
var _a, _b;
|
|
131
118
|
const { modal: { instances }, } = this.state;
|
|
@@ -141,15 +128,30 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
141
128
|
show: () => this.toggleModalInstance(id, true),
|
|
142
129
|
hide: () => this.toggleModalInstance(id, false),
|
|
143
130
|
remove: () => this.removeModalInstance(id),
|
|
131
|
+
update: (options) => {
|
|
132
|
+
const instance = this.state.modal.instances[id];
|
|
133
|
+
instance.options = Object.assign(Object.assign({}, instance.options), options);
|
|
134
|
+
this.setState({
|
|
135
|
+
modal: Object.assign(Object.assign({}, this.state.modal), { instances: Object.assign(Object.assign({}, this.state.modal.instances), { [id]: instance }) }),
|
|
136
|
+
});
|
|
137
|
+
},
|
|
144
138
|
overlay: {
|
|
145
139
|
show: (content) => this.toggleModalOverlay(id, content),
|
|
146
|
-
showConfirm: (content, onYes, onNo) => this.toggleModalOverlay(id, React.createElement(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
140
|
+
showConfirm: (content, onYes, onNo) => this.toggleModalOverlay(id, React.createElement(ActionsOverlay_1.ActionsOverlay, { title: "Confirm", content: content, hide: () => this.toggleModalOverlay(id), actions: [
|
|
141
|
+
{
|
|
142
|
+
content: "Yes",
|
|
143
|
+
type: "success",
|
|
144
|
+
onClick: onYes,
|
|
145
|
+
closeOnClick: true,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
content: "No",
|
|
149
|
+
type: "danger",
|
|
150
|
+
onClick: onNo,
|
|
151
|
+
closeOnClick: true,
|
|
152
|
+
},
|
|
153
|
+
] })),
|
|
154
|
+
showActions: (title, content, actions) => this.toggleModalOverlay(id, React.createElement(ActionsOverlay_1.ActionsOverlay, { title: title, content: content, hide: () => this.toggleModalOverlay(id), actions: actions })),
|
|
153
155
|
hide: () => this.toggleModalOverlay(id),
|
|
154
156
|
},
|
|
155
157
|
};
|
|
@@ -160,6 +162,7 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
160
162
|
options,
|
|
161
163
|
shown: false,
|
|
162
164
|
handleClose: this.toggleModalInstance.bind(this),
|
|
165
|
+
toggleOverlay: this.toggleModalOverlay.bind(this),
|
|
163
166
|
};
|
|
164
167
|
this.setState({
|
|
165
168
|
modal: Object.assign(Object.assign({}, this.state.modal), { instances }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ModalProps } from "./Modal";
|
|
3
3
|
export type UIUtilRendererProps = {
|
|
4
|
-
modalConfig?:
|
|
4
|
+
modalConfig?: ModalProps["config"];
|
|
5
5
|
};
|
|
6
6
|
export declare const UIUtilRenderer: React.FC<UIUtilRendererProps>;
|
|
@@ -5,9 +5,6 @@ const React = require("react");
|
|
|
5
5
|
const UIUtilProvider_1 = require("./UIUtilProvider");
|
|
6
6
|
const Modal_1 = require("./Modal");
|
|
7
7
|
exports.UIUtilRenderer = React.memo(({ modalConfig = {} }) => {
|
|
8
|
-
const { modal } = (0, UIUtilProvider_1.useUIUtilContext)();
|
|
9
|
-
return (React.createElement(React.Fragment, null, Object.keys(
|
|
10
|
-
const { shown, options, handleClose, overlay } = modal.instances[id];
|
|
11
|
-
return (React.createElement(Modal_1.default, { key: id, shown: shown, overlay: overlay, options: options, handleClose: () => handleClose(id, false, true), config: modalConfig }));
|
|
12
|
-
})));
|
|
8
|
+
const { modal: { instances }, } = (0, UIUtilProvider_1.useUIUtilContext)();
|
|
9
|
+
return (React.createElement(React.Fragment, null, Object.keys(instances).map(id => (React.createElement(Modal_1.default, { key: id, id: id, instance: instances[id], config: modalConfig })))));
|
|
13
10
|
});
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
.dry-ux-overlay {
|
|
2
|
-
position: fixed;
|
|
3
|
-
top: 0;
|
|
4
|
-
left: 0;
|
|
5
|
-
width: 100%;
|
|
6
|
-
height: 100%;
|
|
7
|
-
background-color: rgba(0, 0, 0, 0.65);
|
|
8
|
-
z-index: 1050;
|
|
9
|
-
border-radius: 10px;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.dry-ux-overlay-content {
|
|
13
|
-
position: absolute;
|
|
14
|
-
top: 50%;
|
|
15
|
-
left: 50%;
|
|
16
|
-
transform: translate(-50%, -50%);
|
|
17
|
-
background-color: white;
|
|
18
|
-
padding: 10px;
|
|
19
|
-
border-radius: 5px;
|
|
20
|
-
}
|