dry-ux 1.59.0 → 1.60.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/ui-utils/Modal.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { PopUpOptions } from "./UIUtil.interface";
|
|
2
|
+
import { Content, PopUpOptions } from "./UIUtil.interface";
|
|
3
|
+
import "./overlay.css";
|
|
3
4
|
export interface IModalProps {
|
|
4
5
|
options: PopUpOptions;
|
|
5
6
|
handleClose: () => void;
|
|
6
7
|
shown: boolean;
|
|
8
|
+
overlay: Content;
|
|
7
9
|
config: {
|
|
8
10
|
styles?: {
|
|
9
11
|
[selector: string]: React.CSSProperties;
|
package/dist/ui-utils/Modal.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const react_bootstrap_1 = require("react-bootstrap");
|
|
5
|
-
|
|
5
|
+
require("./overlay.css");
|
|
6
|
+
const Modal = React.memo(({ handleClose, shown, overlay, options: { content, footerContent, cssClass, closeBtn, title, width, onClose, titleCloseBtn = true, centered, trackingId, }, config: { defaultModalStyles = false, styles = {}, setBackdropHeight = true, centered: globalCentered, onOpen, onClose: globalOnClose, }, }) => {
|
|
6
7
|
const isCentered = centered !== null && centered !== void 0 ? centered : globalCentered;
|
|
8
|
+
const modalRef = React.useRef(null);
|
|
7
9
|
const applyStyles = React.useCallback(() => {
|
|
8
10
|
document.querySelectorAll(".modal-dialog").forEach((el) => {
|
|
9
11
|
el.style.width = typeof width == "number" ? `${width}px` : width;
|
|
@@ -50,7 +52,9 @@ const Modal = React.memo(({ handleClose, shown, options: { content, footerConten
|
|
|
50
52
|
};
|
|
51
53
|
const contentToRender = typeof content == "string" ? React.createElement("div", { dangerouslySetInnerHTML: { __html: content } }) : content;
|
|
52
54
|
const showFooter = closeBtn || footerContent;
|
|
53
|
-
return (React.createElement(react_bootstrap_1.Modal, { onHide: onHide, show: shown, animation: true, autoFocus: true, keyboard: false, className: cssClass, backdropStyle: { zIndex: 1040, opacity: 0.5 }, backdrop: "static" },
|
|
55
|
+
return (React.createElement(react_bootstrap_1.Modal, { onHide: onHide, show: shown, animation: true, autoFocus: true, keyboard: false, ref: modalRef, className: cssClass, backdropStyle: { zIndex: 1040, opacity: 0.5 }, backdrop: "static" },
|
|
56
|
+
overlay && (React.createElement("div", { className: "dry-ux-overlay" },
|
|
57
|
+
React.createElement("div", { className: "dry-ux-overlay-content" }, overlay))),
|
|
54
58
|
!!title && (React.createElement(react_bootstrap_1.Modal.Header, { closeButton: titleCloseBtn, onHide: onHide },
|
|
55
59
|
React.createElement(react_bootstrap_1.Modal.Title, null, title))),
|
|
56
60
|
React.createElement(react_bootstrap_1.Modal.Body, null, contentToRender),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type Content = JSX.Element | string;
|
|
1
2
|
export type PopUp = {
|
|
2
3
|
/**
|
|
3
4
|
* Hides the modal.
|
|
@@ -11,16 +12,29 @@ export type PopUp = {
|
|
|
11
12
|
* Removes the modal.
|
|
12
13
|
*/
|
|
13
14
|
remove: () => void;
|
|
15
|
+
/**
|
|
16
|
+
* The overlay for the modal.
|
|
17
|
+
*/
|
|
18
|
+
overlay: {
|
|
19
|
+
/**
|
|
20
|
+
* Shows the overlay.
|
|
21
|
+
*/
|
|
22
|
+
show: (content: Content) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Hides the overlay.
|
|
25
|
+
*/
|
|
26
|
+
hide: () => void;
|
|
27
|
+
};
|
|
14
28
|
};
|
|
15
29
|
export type PopUpOptions = {
|
|
16
30
|
/**
|
|
17
31
|
* The content of the modal.
|
|
18
32
|
*/
|
|
19
|
-
content:
|
|
33
|
+
content: Content;
|
|
20
34
|
/**
|
|
21
35
|
* Footer content of the modal.
|
|
22
36
|
*/
|
|
23
|
-
footerContent?:
|
|
37
|
+
footerContent?: Content;
|
|
24
38
|
/**
|
|
25
39
|
* The class to apply to the modal.
|
|
26
40
|
*/
|
|
@@ -32,7 +46,7 @@ export type PopUpOptions = {
|
|
|
32
46
|
/**
|
|
33
47
|
* The title of the modal.
|
|
34
48
|
*/
|
|
35
|
-
title?:
|
|
49
|
+
title?: Content;
|
|
36
50
|
/**
|
|
37
51
|
* If true, the modal will have a close button in the title bar.
|
|
38
52
|
*/
|
|
@@ -63,7 +77,7 @@ export type PopUpAction = {
|
|
|
63
77
|
/**
|
|
64
78
|
* The content to display in the modal.
|
|
65
79
|
*/
|
|
66
|
-
content:
|
|
80
|
+
content: Content;
|
|
67
81
|
/**
|
|
68
82
|
* The type of button to display.
|
|
69
83
|
*/
|
|
@@ -76,6 +90,10 @@ export type PopUpAction = {
|
|
|
76
90
|
* If true, the modal will be closed when the button is clicked.
|
|
77
91
|
*/
|
|
78
92
|
closeOnClick?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* If set, confirm overlay will be shown before the action is executed.
|
|
95
|
+
*/
|
|
96
|
+
confirm?: Content;
|
|
79
97
|
};
|
|
80
98
|
export type UIUtilModal = {
|
|
81
99
|
/**
|
|
@@ -96,6 +114,7 @@ export type UIUtilModal = {
|
|
|
96
114
|
[id: string]: {
|
|
97
115
|
options: PopUpOptions;
|
|
98
116
|
shown: boolean;
|
|
117
|
+
overlay?: Content;
|
|
99
118
|
handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
|
|
100
119
|
};
|
|
101
120
|
};
|
|
@@ -107,7 +126,7 @@ export type UIUtilModal = {
|
|
|
107
126
|
* Shows an alert style modal.
|
|
108
127
|
* @param content The content to display in the modal.
|
|
109
128
|
*/
|
|
110
|
-
showAlert: (content:
|
|
129
|
+
showAlert: (content: Content, onClose?: PopUpOptions["onClose"]) => PopUp;
|
|
111
130
|
/**
|
|
112
131
|
* Shows a confirm style modal.
|
|
113
132
|
* @param options The options for the modal.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { IUIUtilLoader, UIUtilModal, PopUp, PopUpAction, PopUpOptions, UIUtilPrompt } from "./UIUtil.interface";
|
|
2
|
+
import { IUIUtilLoader, UIUtilModal, PopUp, PopUpAction, PopUpOptions, UIUtilPrompt, Content } from "./UIUtil.interface";
|
|
3
3
|
import "../types";
|
|
4
4
|
export interface IUIUtilProviderState {
|
|
5
5
|
modal: UIUtilModal;
|
|
@@ -11,18 +11,20 @@ export declare const UIUtilContext: React.Context<IUIUtilProviderState>;
|
|
|
11
11
|
export declare const useUIUtilContext: () => IUIUtilProviderState;
|
|
12
12
|
export declare class UIUtilProvider extends React.PureComponent<{}, IUIUtilProviderState> {
|
|
13
13
|
private readonly loader;
|
|
14
|
+
private readonly modalId;
|
|
14
15
|
constructor(props: any);
|
|
15
16
|
get modalDefaults(): {
|
|
16
17
|
create: any;
|
|
17
18
|
show: (options: PopUpOptions) => PopUp;
|
|
18
19
|
getCurrent: () => PopUp;
|
|
19
|
-
showAlert: (content:
|
|
20
|
+
showAlert: (content: Content, onClose?: PopUpOptions["onClose"]) => PopUp;
|
|
20
21
|
showConfirm: (options: PopUpOptions, onYes: () => void, onNo?: () => void) => PopUp;
|
|
21
22
|
showActions: (options: PopUpOptions, actions: PopUpAction[]) => PopUp;
|
|
22
23
|
instances: {
|
|
23
24
|
[id: string]: {
|
|
24
25
|
options: PopUpOptions;
|
|
25
26
|
shown: boolean;
|
|
27
|
+
overlay?: Content;
|
|
26
28
|
handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
|
|
27
29
|
};
|
|
28
30
|
};
|
|
@@ -44,11 +46,14 @@ export declare class UIUtilProvider extends React.PureComponent<{}, IUIUtilProvi
|
|
|
44
46
|
[id: string]: {
|
|
45
47
|
options: PopUpOptions;
|
|
46
48
|
shown: boolean;
|
|
49
|
+
overlay?: Content;
|
|
47
50
|
handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
|
|
48
51
|
};
|
|
49
52
|
};
|
|
50
53
|
};
|
|
51
54
|
toggleModalInstance(id: string, shown: boolean, destroyOnClose?: boolean): void;
|
|
55
|
+
toggleModalOverlay(id: string, content?: JSX.Element | string): void;
|
|
56
|
+
getModalActionButtons(actions: PopUpAction[]): React.JSX.Element[];
|
|
52
57
|
removeModalInstance(id: string): void;
|
|
53
58
|
getCurrentModal(id: string): PopUp;
|
|
54
59
|
createModal(id: string, options: PopUpOptions): PopUp;
|
|
@@ -38,6 +38,10 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
38
38
|
constructor(props) {
|
|
39
39
|
super(props);
|
|
40
40
|
this.loader = Loader_1.Loader.getInstance();
|
|
41
|
+
this.modalId = {
|
|
42
|
+
actions: "actions",
|
|
43
|
+
confirm: "confirm",
|
|
44
|
+
};
|
|
41
45
|
this.state = Object.assign(Object.assign({}, defaultState), { modal: this.modalDefaults, customLoader: this.customLoaderDefaults, loader: this.loaderDefaults, prompt: this.promptDefaults });
|
|
42
46
|
}
|
|
43
47
|
get modalDefaults() {
|
|
@@ -51,15 +55,12 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
51
55
|
closeBtn: true,
|
|
52
56
|
width: 400,
|
|
53
57
|
onClose,
|
|
54
|
-
}), showConfirm: (options, onYes, onNo) => this.createModal(
|
|
58
|
+
}), showConfirm: (options, onYes, onNo) => this.createModal(this.modalId.confirm, Object.assign(Object.assign({}, options), { footerContent: (React.createElement(React.Fragment, null,
|
|
55
59
|
options.footerContent,
|
|
56
60
|
React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-success mright", onClick: onYes }, "Yes"),
|
|
57
|
-
React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-danger", onClick: () =>
|
|
61
|
+
React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-danger", onClick: () => onNo ? onNo() : this.toggleModalInstance(this.modalId.confirm, false, true) }, "No"))) })), showActions: (options, actions) => this.createModal(this.modalId.actions, Object.assign(Object.assign({}, options), { footerContent: (React.createElement(React.Fragment, null,
|
|
58
62
|
options.footerContent,
|
|
59
|
-
|
|
60
|
-
onClick && onClick();
|
|
61
|
-
closeOnClick && this.toggleModalInstance("actions", false, true);
|
|
62
|
-
} }, content))))) })) });
|
|
63
|
+
this.getModalActionButtons(actions))) })) });
|
|
63
64
|
}
|
|
64
65
|
get customLoaderDefaults() {
|
|
65
66
|
return Object.assign(Object.assign({}, defaultState.customLoader), { show: () => this.setState({
|
|
@@ -100,6 +101,41 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
}
|
|
104
|
+
toggleModalOverlay(id, content) {
|
|
105
|
+
const { modal: { instances }, } = this.state;
|
|
106
|
+
instances[id].overlay = content;
|
|
107
|
+
this.setState({
|
|
108
|
+
modal: Object.assign(Object.assign({}, this.state.modal), { instances }),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
getModalActionButtons(actions) {
|
|
112
|
+
return actions.map(({ content, type = "success", closeOnClick, onClick, confirm }, index) => (React.createElement(react_bootstrap_1.Button, { bsClass: `btn btn-${type} mright`, onClick: () => {
|
|
113
|
+
const triggerClick = () => {
|
|
114
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
115
|
+
closeOnClick && this.toggleModalInstance(this.modalId.actions, false, true);
|
|
116
|
+
};
|
|
117
|
+
if (!!confirm) {
|
|
118
|
+
this.toggleModalOverlay(this.modalId.actions, React.createElement("div", { style: { minWidth: 200 } },
|
|
119
|
+
React.createElement("div", { style: {
|
|
120
|
+
fontWeight: "bold",
|
|
121
|
+
fontSize: 18,
|
|
122
|
+
paddingLeft: 5,
|
|
123
|
+
} }, "Confirm"),
|
|
124
|
+
React.createElement("hr", { style: { margin: 5 } }),
|
|
125
|
+
React.createElement("div", null, typeof confirm == "string" ? (React.createElement("h4", { className: "text-center", style: { margin: 10 } }, confirm)) : (confirm)),
|
|
126
|
+
React.createElement("hr", { style: { margin: 5 } }),
|
|
127
|
+
React.createElement("div", { style: { textAlign: "right" } },
|
|
128
|
+
React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-success", style: { marginRight: 10 }, onClick: () => {
|
|
129
|
+
triggerClick();
|
|
130
|
+
this.toggleModalOverlay(this.modalId.actions);
|
|
131
|
+
} }, "Yes"),
|
|
132
|
+
React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-danger", onClick: () => this.toggleModalOverlay(this.modalId.actions) }, "No"))));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
triggerClick();
|
|
136
|
+
}
|
|
137
|
+
} }, content)));
|
|
138
|
+
}
|
|
103
139
|
removeModalInstance(id) {
|
|
104
140
|
var _a, _b;
|
|
105
141
|
const { modal: { instances }, } = this.state;
|
|
@@ -115,6 +151,10 @@ class UIUtilProvider extends React.PureComponent {
|
|
|
115
151
|
show: () => this.toggleModalInstance(id, true),
|
|
116
152
|
hide: () => this.toggleModalInstance(id, false),
|
|
117
153
|
remove: () => this.removeModalInstance(id),
|
|
154
|
+
overlay: {
|
|
155
|
+
show: (content) => this.toggleModalOverlay(id, content),
|
|
156
|
+
hide: () => this.toggleModalOverlay(id),
|
|
157
|
+
},
|
|
118
158
|
};
|
|
119
159
|
}
|
|
120
160
|
createModal(id, options) {
|
|
@@ -7,7 +7,7 @@ const Modal_1 = require("./Modal");
|
|
|
7
7
|
exports.UIUtilRenderer = React.memo(({ modalConfig = {} }) => {
|
|
8
8
|
const { modal } = (0, UIUtilProvider_1.useUIUtilContext)();
|
|
9
9
|
return (React.createElement(React.Fragment, null, Object.keys(modal.instances).map(id => {
|
|
10
|
-
const { shown, options, handleClose } = modal.instances[id];
|
|
11
|
-
return (React.createElement(Modal_1.default, { key: id, shown: shown, options: options, handleClose: () => handleClose(id, false, true), config: modalConfig }));
|
|
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
12
|
})));
|
|
13
13
|
});
|