dry-ux 1.59.0 → 1.61.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.
@@ -0,0 +1,7 @@
1
+ import * as React from "react";
2
+ import { Content } from "./UIUtil.interface";
3
+ export declare const ConfirmOverlay: React.FC<{
4
+ content: Content;
5
+ onYes: () => void;
6
+ onNo: () => void;
7
+ }>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfirmOverlay = void 0;
4
+ const React = require("react");
5
+ const react_bootstrap_1 = require("react-bootstrap");
6
+ const ConfirmOverlay = ({ content, onYes, onNo, }) => {
7
+ return (React.createElement("div", { style: { minWidth: 200 } },
8
+ React.createElement("div", { style: {
9
+ fontWeight: "bold",
10
+ fontSize: 18,
11
+ paddingLeft: 5,
12
+ } }, "Confirm"),
13
+ React.createElement("hr", { style: { margin: 5 } }),
14
+ React.createElement("div", null, typeof content == "string" ? (React.createElement("h4", { className: "text-center", style: { margin: 10 } }, content)) : (content)),
15
+ React.createElement("hr", { style: { margin: 5 } }),
16
+ React.createElement("div", { style: { textAlign: "right" } },
17
+ React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-success", style: { marginRight: 10 }, onClick: onYes }, "Yes"),
18
+ React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-danger", onClick: onNo }, "No"))));
19
+ };
20
+ exports.ConfirmOverlay = ConfirmOverlay;
@@ -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;
@@ -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
- const Modal = React.memo(({ handleClose, shown, options: { content, footerContent, cssClass, closeBtn, title, width, onClose, titleCloseBtn = true, centered, trackingId, }, config: { defaultModalStyles = false, styles = {}, setBackdropHeight = true, centered: globalCentered, onOpen, onClose: globalOnClose, }, }) => {
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,33 @@ 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
+ * Shows the overlay.
25
+ */
26
+ showConfirm: (content: Content, onYes: () => void, onNo?: () => void) => void;
27
+ /**
28
+ * Hides the overlay.
29
+ */
30
+ hide: () => void;
31
+ };
14
32
  };
15
33
  export type PopUpOptions = {
16
34
  /**
17
35
  * The content of the modal.
18
36
  */
19
- content: JSX.Element | string;
37
+ content: Content;
20
38
  /**
21
39
  * Footer content of the modal.
22
40
  */
23
- footerContent?: JSX.Element | string;
41
+ footerContent?: Content;
24
42
  /**
25
43
  * The class to apply to the modal.
26
44
  */
@@ -32,7 +50,7 @@ export type PopUpOptions = {
32
50
  /**
33
51
  * The title of the modal.
34
52
  */
35
- title?: JSX.Element | string;
53
+ title?: Content;
36
54
  /**
37
55
  * If true, the modal will have a close button in the title bar.
38
56
  */
@@ -63,7 +81,7 @@ export type PopUpAction = {
63
81
  /**
64
82
  * The content to display in the modal.
65
83
  */
66
- content: JSX.Element | string;
84
+ content: Content;
67
85
  /**
68
86
  * The type of button to display.
69
87
  */
@@ -76,6 +94,10 @@ export type PopUpAction = {
76
94
  * If true, the modal will be closed when the button is clicked.
77
95
  */
78
96
  closeOnClick?: boolean;
97
+ /**
98
+ * If set, confirm overlay will be shown before the action is executed.
99
+ */
100
+ confirm?: Content;
79
101
  };
80
102
  export type UIUtilModal = {
81
103
  /**
@@ -96,6 +118,7 @@ export type UIUtilModal = {
96
118
  [id: string]: {
97
119
  options: PopUpOptions;
98
120
  shown: boolean;
121
+ overlay?: Content;
99
122
  handleClose: (id: string, shown: boolean, destroyOnClose: boolean) => void;
100
123
  };
101
124
  };
@@ -107,7 +130,7 @@ export type UIUtilModal = {
107
130
  * Shows an alert style modal.
108
131
  * @param content The content to display in the modal.
109
132
  */
110
- showAlert: (content: PopUpOptions["content"], onClose?: PopUpOptions["onClose"]) => PopUp;
133
+ showAlert: (content: Content, onClose?: PopUpOptions["onClose"]) => PopUp;
111
134
  /**
112
135
  * Shows a confirm style modal.
113
136
  * @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: PopUpOptions["content"], onClose?: PopUpOptions["onClose"]) => PopUp;
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;
@@ -5,6 +5,7 @@ const React = require("react");
5
5
  require("../types");
6
6
  const react_bootstrap_1 = require("react-bootstrap");
7
7
  const Loader_1 = require("./Loader");
8
+ const ConfirmOverlay_1 = require("./ConfirmOverlay");
8
9
  const defaultState = {
9
10
  modal: {
10
11
  show: null,
@@ -38,6 +39,10 @@ class UIUtilProvider extends React.PureComponent {
38
39
  constructor(props) {
39
40
  super(props);
40
41
  this.loader = Loader_1.Loader.getInstance();
42
+ this.modalId = {
43
+ actions: "actions",
44
+ confirm: "confirm",
45
+ };
41
46
  this.state = Object.assign(Object.assign({}, defaultState), { modal: this.modalDefaults, customLoader: this.customLoaderDefaults, loader: this.loaderDefaults, prompt: this.promptDefaults });
42
47
  }
43
48
  get modalDefaults() {
@@ -51,15 +56,12 @@ class UIUtilProvider extends React.PureComponent {
51
56
  closeBtn: true,
52
57
  width: 400,
53
58
  onClose,
54
- }), showConfirm: (options, onYes, onNo) => this.createModal("confirm", Object.assign(Object.assign({}, options), { footerContent: (React.createElement(React.Fragment, null,
59
+ }), showConfirm: (options, onYes, onNo) => this.createModal(this.modalId.confirm, Object.assign(Object.assign({}, options), { footerContent: (React.createElement(React.Fragment, null,
55
60
  options.footerContent,
56
61
  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: () => (onNo ? onNo() : this.toggleModalInstance("confirm", false, true)) }, "No"))) })), showActions: (options, actions) => this.createModal("actions", Object.assign(Object.assign({}, options), { footerContent: (React.createElement(React.Fragment, null,
62
+ 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
63
  options.footerContent,
59
- actions.map(({ content, type = "success", closeOnClick, onClick }, index) => (React.createElement(react_bootstrap_1.Button, { bsClass: `btn btn-${type} mright`, onClick: () => {
60
- onClick && onClick();
61
- closeOnClick && this.toggleModalInstance("actions", false, true);
62
- } }, content))))) })) });
64
+ this.getModalActionButtons(actions))) })) });
63
65
  }
64
66
  get customLoaderDefaults() {
65
67
  return Object.assign(Object.assign({}, defaultState.customLoader), { show: () => this.setState({
@@ -100,6 +102,30 @@ class UIUtilProvider extends React.PureComponent {
100
102
  });
101
103
  }
102
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
+ }
103
129
  removeModalInstance(id) {
104
130
  var _a, _b;
105
131
  const { modal: { instances }, } = this.state;
@@ -115,6 +141,17 @@ class UIUtilProvider extends React.PureComponent {
115
141
  show: () => this.toggleModalInstance(id, true),
116
142
  hide: () => this.toggleModalInstance(id, false),
117
143
  remove: () => this.removeModalInstance(id),
144
+ overlay: {
145
+ show: (content) => this.toggleModalOverlay(id, content),
146
+ showConfirm: (content, onYes, onNo) => this.toggleModalOverlay(id, React.createElement(ConfirmOverlay_1.ConfirmOverlay, { content: content, onYes: () => {
147
+ onYes();
148
+ this.toggleModalOverlay(id);
149
+ }, onNo: () => {
150
+ onNo === null || onNo === void 0 ? void 0 : onNo();
151
+ this.toggleModalOverlay(id);
152
+ } })),
153
+ hide: () => this.toggleModalOverlay(id),
154
+ },
118
155
  };
119
156
  }
120
157
  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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.59.0",
3
+ "version": "1.61.0",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "scripts": {