@4i/modal-manager 1.0.12 → 1.0.14
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/package.json
CHANGED
package/readme.md
CHANGED
@@ -17,33 +17,32 @@ npm install @4i/modal-manager
|
|
17
17
|
|
18
18
|
#### Instance methods:
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Close all modals.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Close
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
Remove an event listener from the modal manager.
|
20
|
+
create table with methods
|
21
|
+
|
22
|
+
| Method | Description |
|
23
|
+
| ------------------------------------ | ----------------------------------------------------- |
|
24
|
+
| call(action, props) | Call a modal by its action name and pass props to it. |
|
25
|
+
| |
|
26
|
+
| close('all') | Close all modals. |
|
27
|
+
| |
|
28
|
+
| close(-1) | Close last modals. |
|
29
|
+
| |
|
30
|
+
| close(0) | Close first modals. |
|
31
|
+
| |
|
32
|
+
| close() | Close last modals. (default) |
|
33
|
+
| |
|
34
|
+
| addEventListener(event, callback) | Add an event listener to the modal manager. |
|
35
|
+
| |
|
36
|
+
| removeEventListener(event, callback) | Remove an event listener from the modal manager. |
|
37
|
+
| |
|
38
|
+
|
39
|
+
#### ModalProvider props
|
40
|
+
|
41
|
+
| Prop | Type | Description |
|
42
|
+
| ---------- | ------- | -------------------------------------------------------------------------- |
|
43
|
+
| modalList | Object | An object containing modal actions as keys and modal components as values. |
|
44
|
+
| className | string | |
|
45
|
+
| isOverflow | boolean | Set "overflow: hidden" on body |
|
47
46
|
|
48
47
|
#### Define Modal Actions:
|
49
48
|
|
@@ -4,6 +4,8 @@ export type ModalList = {
|
|
4
4
|
};
|
5
5
|
interface ModalProviderProps {
|
6
6
|
modalList: any;
|
7
|
+
isOverflow?: boolean;
|
8
|
+
className?: string;
|
7
9
|
}
|
8
|
-
declare const ModalProvider: ({ modalList }: ModalProviderProps) => false | React.JSX.Element[];
|
10
|
+
declare const ModalProvider: ({ modalList, isOverflow, className, }: ModalProviderProps) => false | React.JSX.Element[];
|
9
11
|
export default ModalProvider;
|
@@ -50,7 +50,7 @@ var react_1 = __importStar(require("react"));
|
|
50
50
|
var ModalManager_1 = __importDefault(require("../utils/ModalManager"));
|
51
51
|
var ModalManager_2 = __importDefault(require("../utils/ModalManager"));
|
52
52
|
var ModalProvider = function (_a) {
|
53
|
-
var modalList = _a.modalList;
|
53
|
+
var modalList = _a.modalList, isOverflow = _a.isOverflow, className = _a.className;
|
54
54
|
var _b = (0, react_1.useState)([]), data = _b[0], setData = _b[1];
|
55
55
|
var _c = (0, react_1.useState)([]), names = _c[0], setNames = _c[1];
|
56
56
|
var modalRef = (0, react_1.useRef)([]);
|
@@ -58,8 +58,18 @@ var ModalProvider = function (_a) {
|
|
58
58
|
var handleOpenModal = function (name, data) {
|
59
59
|
setData(function (prev) { return __spreadArray(__spreadArray([], prev, true), [data], false); });
|
60
60
|
setNames(function (prev) { return __spreadArray(__spreadArray([], prev, true), [name], false); });
|
61
|
+
if (isOverflow) {
|
62
|
+
if (typeof document === "undefined")
|
63
|
+
return;
|
64
|
+
document.body.style.overflow = "hidden";
|
65
|
+
}
|
61
66
|
};
|
62
67
|
var handleClose = function (position) {
|
68
|
+
if (isOverflow) {
|
69
|
+
if (typeof document !== "undefined") {
|
70
|
+
document.body.style.overflow = "";
|
71
|
+
}
|
72
|
+
}
|
63
73
|
if (position === "all") {
|
64
74
|
setData([]);
|
65
75
|
setNames([]);
|
@@ -101,7 +111,6 @@ var ModalProvider = function (_a) {
|
|
101
111
|
return Component;
|
102
112
|
});
|
103
113
|
var handleCloseModal = function (index, e) {
|
104
|
-
console.log(index);
|
105
114
|
if (modalRef.current[index] &&
|
106
115
|
!modalRef.current[index].contains(e.target)) {
|
107
116
|
ModalManager_2.default.close(index);
|
@@ -116,7 +125,7 @@ var ModalProvider = function (_a) {
|
|
116
125
|
return (react_1.default.createElement("div", { key: item.modalId, onClick: function (e) {
|
117
126
|
handleCloseModal(i, e);
|
118
127
|
} },
|
119
|
-
react_1.default.createElement("div", { className: "backdrop_modal_manager" },
|
128
|
+
react_1.default.createElement("div", { className: "".concat(className, " backdrop_modal_manager") },
|
120
129
|
react_1.default.createElement("div", { ref: function (ref) {
|
121
130
|
refReducer(i, ref);
|
122
131
|
} },
|
@@ -6,11 +6,17 @@ export type ModalList = { [key: string]: React.ComponentType };
|
|
6
6
|
|
7
7
|
interface ModalProviderProps {
|
8
8
|
modalList: any;
|
9
|
+
isOverflow?: boolean;
|
10
|
+
className?: string;
|
9
11
|
}
|
10
12
|
|
11
13
|
type TData = { [key: string]: any };
|
12
14
|
|
13
|
-
const ModalProvider = ({
|
15
|
+
const ModalProvider = ({
|
16
|
+
modalList,
|
17
|
+
isOverflow,
|
18
|
+
className,
|
19
|
+
}: ModalProviderProps) => {
|
14
20
|
const [data, setData] = useState<TData[]>([]);
|
15
21
|
const [names, setNames] = useState<string[]>([]);
|
16
22
|
const modalRef = useRef<any[]>([]);
|
@@ -19,9 +25,20 @@ const ModalProvider = ({ modalList }: ModalProviderProps) => {
|
|
19
25
|
const handleOpenModal = (name: string, data: TData) => {
|
20
26
|
setData((prev: TData[]) => [...prev, data]);
|
21
27
|
setNames((prev: string[]) => [...prev, name]);
|
28
|
+
|
29
|
+
if (isOverflow) {
|
30
|
+
if (typeof document === "undefined") return;
|
31
|
+
document.body.style.overflow = "hidden";
|
32
|
+
}
|
22
33
|
};
|
23
34
|
|
24
35
|
const handleClose = (position: number | string) => {
|
36
|
+
if (isOverflow) {
|
37
|
+
if (typeof document !== "undefined") {
|
38
|
+
document.body.style.overflow = "";
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
25
42
|
if (position === "all") {
|
26
43
|
setData([]);
|
27
44
|
setNames([]);
|
@@ -69,7 +86,6 @@ const ModalProvider = ({ modalList }: ModalProviderProps) => {
|
|
69
86
|
});
|
70
87
|
|
71
88
|
const handleCloseModal = (index: number, e: any) => {
|
72
|
-
console.log(index);
|
73
89
|
if (
|
74
90
|
modalRef.current[index] &&
|
75
91
|
!modalRef.current[index].contains(e.target)
|
@@ -94,7 +110,7 @@ const ModalProvider = ({ modalList }: ModalProviderProps) => {
|
|
94
110
|
handleCloseModal(i, e);
|
95
111
|
}}
|
96
112
|
>
|
97
|
-
<div className=
|
113
|
+
<div className={`${className} backdrop_modal_manager`}>
|
98
114
|
<div
|
99
115
|
ref={(ref) => {
|
100
116
|
refReducer(i, ref);
|
@@ -29,7 +29,11 @@ var constants = {
|
|
29
29
|
var ModalManager = /** @class */ (function (_super) {
|
30
30
|
__extends(ModalManager, _super);
|
31
31
|
function ModalManager() {
|
32
|
-
|
32
|
+
var _this = _super.call(this) || this;
|
33
|
+
_this.create = _this.create.bind(_this);
|
34
|
+
_this.call = _this.call.bind(_this);
|
35
|
+
_this.close = _this.close.bind(_this);
|
36
|
+
return _this;
|
33
37
|
}
|
34
38
|
ModalManager.prototype.create = function (name, payload) {
|
35
39
|
this.name = name;
|
@@ -12,6 +12,9 @@ const constants = {
|
|
12
12
|
class ModalManager extends Manager {
|
13
13
|
constructor() {
|
14
14
|
super();
|
15
|
+
this.create = this.create.bind(this);
|
16
|
+
this.call = this.call.bind(this);
|
17
|
+
this.close = this.close.bind(this);
|
15
18
|
}
|
16
19
|
|
17
20
|
create<T>(name: string, payload: { modalId: number; data?: T }) {
|