blue-react 9.12.1 → 10.0.0-rc2
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.md +37 -4
- package/dist/components/A.js +8 -23
- package/dist/components/ActionMenu.js +33 -65
- package/dist/components/ActionMenuItem.js +12 -36
- package/dist/components/Body.js +13 -27
- package/dist/components/Caret.js +6 -9
- package/dist/components/Chevron.js +14 -24
- package/dist/components/HashRouter.js +176 -0
- package/dist/components/Header.js +3 -13
- package/dist/components/HeaderTitle.js +24 -43
- package/dist/components/IconMenuItem.js +17 -33
- package/dist/components/Intro.js +12 -22
- package/dist/components/Layout.js +72 -360
- package/dist/components/MenuItem.js +41 -83
- package/dist/components/Modal.js +53 -86
- package/dist/components/ModalProvider.js +70 -125
- package/dist/components/Outside.js +13 -29
- package/dist/components/Page.js +18 -44
- package/dist/components/Search.js +47 -85
- package/dist/components/SidebarMenu.js +8 -68
- package/dist/components/SidebarMenuItem.js +34 -65
- package/dist/components/SidebarToggler.js +12 -22
- package/dist/components/SlimContainer.js +6 -16
- package/dist/components/Status.js +33 -44
- package/dist/components/StatusProvider.js +28 -65
- package/dist/components/Switch.js +17 -23
- package/dist/components/ToastProvider.js +43 -83
- package/dist/components/Utilities.js +23 -45
- package/dist/components/shared.js +1 -11
- package/dist/style.scss +1 -1
- package/dist/types/components/A.d.ts +9 -9
- package/dist/types/components/ActionMenu.d.ts +25 -25
- package/dist/types/components/ActionMenuItem.d.ts +34 -35
- package/dist/types/components/Body.d.ts +20 -21
- package/dist/types/components/Caret.d.ts +18 -18
- package/dist/types/components/Chevron.d.ts +17 -17
- package/dist/types/components/HashRouter.d.ts +76 -0
- package/dist/types/components/Header.d.ts +8 -8
- package/dist/types/components/HeaderTitle.d.ts +39 -40
- package/dist/types/components/IconMenuItem.d.ts +18 -19
- package/dist/types/components/Intro.d.ts +22 -23
- package/dist/types/components/Layout.d.ts +9 -144
- package/dist/types/components/MenuItem.d.ts +149 -149
- package/dist/types/components/Modal.d.ts +30 -30
- package/dist/types/components/ModalProvider.d.ts +21 -21
- package/dist/types/components/Outside.d.ts +17 -17
- package/dist/types/components/Page.d.ts +11 -12
- package/dist/types/components/Search.d.ts +36 -36
- package/dist/types/components/SidebarMenu.d.ts +31 -32
- package/dist/types/components/SidebarMenuItem.d.ts +21 -22
- package/dist/types/components/SidebarToggler.d.ts +10 -10
- package/dist/types/components/SlimContainer.d.ts +10 -10
- package/dist/types/components/Status.d.ts +12 -12
- package/dist/types/components/StatusProvider.d.ts +15 -15
- package/dist/types/components/Switch.d.ts +33 -33
- package/dist/types/components/ToastProvider.d.ts +22 -22
- package/dist/types/components/Utilities.d.ts +41 -41
- package/dist/types/components/shared.d.ts +15 -15
- package/index.d.ts +8 -12
- package/index.js +56 -29
- package/package.json +28 -45
- package/dist/components/ActionMenuSwitch.js +0 -44
- package/dist/style.css +0 -12836
- package/dist/style.min.css +0 -16
- package/dist/types/components/ActionMenuSwitch.d.ts +0 -12
|
@@ -1,90 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = MenuItem;
|
|
9
|
-
|
|
10
|
-
var _clsx = _interopRequireDefault(require("clsx"));
|
|
11
|
-
|
|
12
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
|
-
var _Outside = _interopRequireDefault(require("./Outside"));
|
|
15
|
-
|
|
16
|
-
var _Chevron = _interopRequireDefault(require("./Chevron"));
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
-
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
26
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import clsx from "clsx";
|
|
8
|
+
import React, { createElement, useEffect, useRef, useState } from "react";
|
|
9
|
+
import Outside from "./Outside";
|
|
10
|
+
import Chevron from "./Chevron";
|
|
36
11
|
function findParentWithClass(element, className) {
|
|
37
12
|
while (element && !element.classList.contains(className)) {
|
|
38
13
|
element = element.parentElement;
|
|
39
14
|
}
|
|
40
|
-
|
|
41
15
|
return element;
|
|
42
16
|
}
|
|
43
|
-
|
|
44
17
|
/**
|
|
45
18
|
* Link, button or custom component for Sidebar, Actions or ActionMenu
|
|
46
19
|
*/
|
|
47
|
-
function MenuItem(props) {
|
|
20
|
+
export default function MenuItem(props) {
|
|
48
21
|
var id = "blue-menu-item-wrapper-".concat(Math.random().toString(36).substring(7));
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
setActive = _useState4[1];
|
|
59
|
-
|
|
60
|
-
var menuRef = (0, _react.useRef)(null);
|
|
61
|
-
|
|
22
|
+
var _useState = useState(false),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
+
showDropdown = _useState2[0],
|
|
25
|
+
setShowDropdown = _useState2[1];
|
|
26
|
+
var _useState3 = useState(false),
|
|
27
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
|
+
active = _useState4[0],
|
|
29
|
+
setActive = _useState4[1];
|
|
30
|
+
var menuRef = useRef(null);
|
|
62
31
|
var checkActive = function checkActive() {
|
|
63
32
|
setActive(props.href && window.location.hash.indexOf(props.href) > -1 || props.isHome && (window.location.hash === "" || window.location.hash === "#/") ? true : false);
|
|
64
33
|
};
|
|
65
|
-
|
|
66
34
|
var onClick = function onClick(event) {
|
|
67
35
|
if (props.href === "#") {
|
|
68
36
|
event.preventDefault();
|
|
69
37
|
}
|
|
70
|
-
|
|
71
38
|
if (props.onClick) {
|
|
72
39
|
props.onClick(event);
|
|
73
40
|
}
|
|
74
|
-
|
|
75
41
|
if (props.children) {
|
|
76
42
|
setShowDropdown(!showDropdown);
|
|
77
43
|
}
|
|
78
|
-
|
|
79
44
|
if (props.onClickAttached !== undefined) {
|
|
80
45
|
props.onClickAttached(event);
|
|
81
46
|
}
|
|
82
47
|
};
|
|
83
|
-
|
|
84
48
|
var onClickOutside = function onClickOutside(_ref) {
|
|
85
49
|
var target = _ref.target;
|
|
86
50
|
var ignoreClasses = props.outsideIgnoreClasses || [id];
|
|
87
|
-
|
|
88
51
|
if (ignoreClasses && target) {
|
|
89
52
|
for (var i = 0; i < ignoreClasses.length; i++) {
|
|
90
53
|
if (target !== null && target !== void 0 && target.classList.contains(ignoreClasses[i]) || findParentWithClass(target, ignoreClasses[i])) {
|
|
@@ -92,25 +55,23 @@ function MenuItem(props) {
|
|
|
92
55
|
}
|
|
93
56
|
}
|
|
94
57
|
}
|
|
95
|
-
|
|
96
58
|
setShowDropdown(false);
|
|
97
59
|
};
|
|
98
|
-
|
|
99
|
-
(0, _react.useEffect)(function () {
|
|
60
|
+
useEffect(function () {
|
|
100
61
|
checkActive();
|
|
101
62
|
window.addEventListener("hashchange", function () {
|
|
102
63
|
checkActive();
|
|
103
64
|
});
|
|
104
65
|
}, []);
|
|
105
|
-
|
|
66
|
+
useEffect(function () {
|
|
106
67
|
if (props.showDropdown !== undefined) setShowDropdown(props.showDropdown);
|
|
107
68
|
}, [props.showDropdown]);
|
|
108
|
-
|
|
69
|
+
useEffect(function () {
|
|
109
70
|
if (props.onShowDropdown) {
|
|
110
71
|
props.onShowDropdown(showDropdown);
|
|
111
72
|
}
|
|
112
73
|
}, [props.onShowDropdown, showDropdown]);
|
|
113
|
-
|
|
74
|
+
useEffect(function () {
|
|
114
75
|
if (menuRef && menuRef.current) {
|
|
115
76
|
var el = menuRef.current;
|
|
116
77
|
var rect = el.getBoundingClientRect();
|
|
@@ -119,30 +80,27 @@ function MenuItem(props) {
|
|
|
119
80
|
}, [menuRef, showDropdown]);
|
|
120
81
|
var className = "blue-menu-item btn" + (props.isActive ? " active" : "") + (props.className ? " " + props.className : "") + (props.children ? " blue-menu-item-dropdown-toggle w-100" : "") + (props.highlighted ? " highlighted" : "");
|
|
121
82
|
var icon, iconForActive;
|
|
122
|
-
|
|
123
83
|
if (typeof props.icon === "string") {
|
|
124
84
|
// is className
|
|
125
|
-
icon = /*#__PURE__*/
|
|
85
|
+
icon = /*#__PURE__*/React.createElement("span", {
|
|
126
86
|
className: props.icon + (props.children ? " blue-menu-item-dropdown-icon" : "")
|
|
127
87
|
});
|
|
128
88
|
} else {
|
|
129
89
|
// is element / component
|
|
130
90
|
icon = props.icon;
|
|
131
91
|
}
|
|
132
|
-
|
|
133
92
|
if (typeof props.iconForActive === "string") {
|
|
134
93
|
// is className
|
|
135
|
-
iconForActive = /*#__PURE__*/
|
|
94
|
+
iconForActive = /*#__PURE__*/React.createElement("span", {
|
|
136
95
|
className: props.iconForActive + (props.children ? " blue-menu-item-dropdown-icon" : "")
|
|
137
96
|
});
|
|
138
97
|
} else {
|
|
139
98
|
// is element / component
|
|
140
99
|
iconForActive = props.iconForActive;
|
|
141
100
|
}
|
|
142
|
-
|
|
143
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
144
102
|
className: "blue-menu-item-wrapper ".concat(id)
|
|
145
|
-
}, /*#__PURE__*/
|
|
103
|
+
}, /*#__PURE__*/createElement(props.elementType || (props.href ? "a" : "button"), {
|
|
146
104
|
to: props.to,
|
|
147
105
|
href: props.href,
|
|
148
106
|
exact: props.exact,
|
|
@@ -164,36 +122,36 @@ function MenuItem(props) {
|
|
|
164
122
|
style: props.style,
|
|
165
123
|
type: props.type,
|
|
166
124
|
id: props.id
|
|
167
|
-
}, /*#__PURE__*/
|
|
125
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, props.draggable && props.hideDraggableIcon !== true && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("svg", {
|
|
168
126
|
xmlns: "http://www.w3.org/2000/svg",
|
|
169
127
|
width: ".5em",
|
|
170
128
|
height: "1em",
|
|
171
129
|
fill: "currentColor",
|
|
172
130
|
className: "bi bi-grip-vertical opacity-50",
|
|
173
131
|
viewBox: "0 0 8 16"
|
|
174
|
-
}, /*#__PURE__*/
|
|
132
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
175
133
|
d: "M3.376 1.876c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m-3 3c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1m3 0c0 .55-.45 1-1 1-.549 0-1-.45-1-1 0-.549.451-1 1-1 .55 0 1 .451 1 1"
|
|
176
|
-
})), " "), props.icon !== undefined && /*#__PURE__*/
|
|
177
|
-
className: (
|
|
134
|
+
})), " "), props.icon !== undefined && /*#__PURE__*/React.createElement("span", {
|
|
135
|
+
className: clsx("blue-menu-item-icon", props.iconClassName, {
|
|
178
136
|
hasIconForActive: iconForActive
|
|
179
137
|
})
|
|
180
|
-
}, icon), iconForActive && /*#__PURE__*/
|
|
181
|
-
className: (
|
|
182
|
-
}, iconForActive), props.label && /*#__PURE__*/
|
|
183
|
-
className: (
|
|
184
|
-
}, props.label), props.children && /*#__PURE__*/
|
|
138
|
+
}, icon), iconForActive && /*#__PURE__*/React.createElement("span", {
|
|
139
|
+
className: clsx("blue-menu-item-icon iconForActive", props.iconClassName)
|
|
140
|
+
}, iconForActive), props.label && /*#__PURE__*/React.createElement("span", {
|
|
141
|
+
className: clsx("blue-menu-item-label text-truncate", props.labelClassName)
|
|
142
|
+
}, props.label), props.children && /*#__PURE__*/React.createElement(Chevron, {
|
|
185
143
|
open: showDropdown,
|
|
186
144
|
mirrored: true,
|
|
187
|
-
className: (
|
|
145
|
+
className: clsx("blue-menu-item-dropdown-caret ms-auto", props.caretClassName),
|
|
188
146
|
style: props.caretStyle
|
|
189
|
-
}))), showDropdown && (props.supportOutside ? /*#__PURE__*/
|
|
147
|
+
}))), showDropdown && (props.supportOutside ? /*#__PURE__*/React.createElement(Outside, {
|
|
190
148
|
wrapperRef: menuRef,
|
|
191
|
-
className: (
|
|
149
|
+
className: clsx("blue-menu-item-dropdown", props.dropdownClassName),
|
|
192
150
|
onClickOutside: onClickOutside,
|
|
193
151
|
style: props.dropdownStyle
|
|
194
|
-
}, props.children) : /*#__PURE__*/
|
|
152
|
+
}, props.children) : /*#__PURE__*/React.createElement("div", {
|
|
195
153
|
ref: menuRef,
|
|
196
|
-
className: (
|
|
154
|
+
className: clsx("blue-menu-item-dropdown", props.dropdownClassName),
|
|
197
155
|
style: props.dropdownStyle
|
|
198
156
|
}, props.children)));
|
|
199
157
|
}
|
package/dist/components/Modal.js
CHANGED
|
@@ -1,147 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = Modal;
|
|
9
|
-
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
|
-
var _bootstrap = require("bootstrap");
|
|
13
|
-
|
|
14
|
-
var _shared = require("./shared");
|
|
15
|
-
|
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
21
|
-
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
22
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
31
|
-
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import React, { useEffect, useState, useRef } from "react";
|
|
8
|
+
import { Modal as BootstrapModal } from "bootstrap";
|
|
9
|
+
import { getPhrase } from "./shared";
|
|
32
10
|
/**
|
|
33
11
|
* Simple modal/dialog. Designed to work as an alternative to JavaScript's native `alert()`, `prompt()` and `confirm()` functions.
|
|
34
12
|
* It uses Bootstrap's Modal components.
|
|
35
13
|
*
|
|
36
14
|
* For easy use, you should use the hook `useModal` together with `ModalProvider`. See the example there.
|
|
37
15
|
*/
|
|
38
|
-
function Modal(_ref) {
|
|
16
|
+
export default function Modal(_ref) {
|
|
39
17
|
var modalContent = _ref.modalContent,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var modalRef =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
setInput = _useState2[1];
|
|
58
|
-
|
|
18
|
+
modalTitle = _ref.modalTitle,
|
|
19
|
+
modalIcon = _ref.modalIcon,
|
|
20
|
+
unSetModalContent = _ref.unSetModalContent,
|
|
21
|
+
onSubmit = _ref.onSubmit,
|
|
22
|
+
defaultInput = _ref.defaultInput,
|
|
23
|
+
type = _ref.type,
|
|
24
|
+
_ref$inputType = _ref.inputType,
|
|
25
|
+
inputType = _ref$inputType === void 0 ? "text" : _ref$inputType,
|
|
26
|
+
_ref$switchPrimaryBtn = _ref.switchPrimaryBtn,
|
|
27
|
+
switchPrimaryBtn = _ref$switchPrimaryBtn === void 0 ? false : _ref$switchPrimaryBtn,
|
|
28
|
+
acceptBtnText = _ref.acceptBtnText,
|
|
29
|
+
cancelBtnText = _ref.cancelBtnText;
|
|
30
|
+
var modalRef = useRef(null);
|
|
31
|
+
var _useState = useState(defaultInput || ""),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
input = _useState2[0],
|
|
34
|
+
setInput = _useState2[1];
|
|
59
35
|
var cancel = function cancel() {
|
|
60
36
|
unSetModalContent();
|
|
61
|
-
|
|
62
37
|
if (onSubmit) {
|
|
63
38
|
onSubmit(null);
|
|
64
39
|
}
|
|
65
40
|
};
|
|
66
|
-
|
|
67
41
|
var sayNo = function sayNo() {
|
|
68
42
|
unSetModalContent();
|
|
69
|
-
|
|
70
43
|
if (onSubmit) {
|
|
71
44
|
onSubmit(false);
|
|
72
45
|
}
|
|
73
46
|
};
|
|
74
|
-
|
|
75
47
|
var submit = function submit(e) {
|
|
76
48
|
e.preventDefault();
|
|
77
|
-
|
|
78
49
|
if (onSubmit) {
|
|
79
50
|
onSubmit(input || true);
|
|
80
51
|
}
|
|
81
52
|
};
|
|
82
|
-
|
|
83
53
|
var btnStyle = {
|
|
84
54
|
maxWidth: "10rem"
|
|
85
55
|
};
|
|
86
|
-
|
|
87
|
-
var focusFirstControl = function focusFirstControl() {
|
|
56
|
+
var _focusFirstControl = function focusFirstControl() {
|
|
88
57
|
var myModal = modalRef.current;
|
|
89
|
-
myModal.removeEventListener("shown.bs.modal",
|
|
58
|
+
myModal.removeEventListener("shown.bs.modal", _focusFirstControl);
|
|
90
59
|
var firstControl = myModal.querySelector(".btn-primary, .form-control");
|
|
91
|
-
|
|
92
60
|
if (firstControl) {
|
|
93
61
|
firstControl.focus();
|
|
94
62
|
}
|
|
95
63
|
};
|
|
96
|
-
|
|
97
|
-
(0, _react.useEffect)(function () {
|
|
64
|
+
useEffect(function () {
|
|
98
65
|
setInput(defaultInput || "");
|
|
99
66
|
}, [defaultInput]);
|
|
100
|
-
|
|
67
|
+
useEffect(function () {
|
|
101
68
|
var myModal = modalRef.current;
|
|
102
|
-
|
|
103
|
-
var bsModal = _bootstrap.Modal.getInstance(myModal);
|
|
104
|
-
|
|
69
|
+
var bsModal = BootstrapModal.getInstance(myModal);
|
|
105
70
|
if (!bsModal) {
|
|
106
|
-
bsModal = new
|
|
107
|
-
bsModal.hide();
|
|
71
|
+
bsModal = new BootstrapModal(myModal);
|
|
72
|
+
bsModal.hide();
|
|
108
73
|
|
|
74
|
+
// When the user clicks on underlay to close the modal
|
|
109
75
|
myModal.addEventListener("hidden.bs.modal", function () {
|
|
110
76
|
cancel();
|
|
111
77
|
});
|
|
112
78
|
} else {
|
|
113
|
-
modalContent !== undefined ? bsModal.show() : bsModal.hide();
|
|
114
|
-
// For accessibility: This way you can control the modal actions with a keyboard.
|
|
79
|
+
modalContent !== undefined ? bsModal.show() : bsModal.hide();
|
|
115
80
|
|
|
116
|
-
|
|
81
|
+
// Will focus first button or text field inside of modal when it is shown.
|
|
82
|
+
// For accessibility: This way you can control the modal actions with a keyboard.
|
|
83
|
+
myModal.addEventListener("shown.bs.modal", _focusFirstControl);
|
|
117
84
|
}
|
|
118
85
|
}, [modalContent]);
|
|
119
|
-
return /*#__PURE__*/
|
|
86
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
120
87
|
className: "modal",
|
|
121
88
|
ref: modalRef,
|
|
122
89
|
tabIndex: -1
|
|
123
|
-
}, /*#__PURE__*/
|
|
90
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
124
91
|
className: "modal-dialog"
|
|
125
|
-
}, /*#__PURE__*/
|
|
92
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
126
93
|
className: "modal-content"
|
|
127
|
-
}, /*#__PURE__*/
|
|
94
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
128
95
|
onSubmit: submit
|
|
129
|
-
}, /*#__PURE__*/
|
|
96
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
130
97
|
className: "modal-header align-items-center"
|
|
131
|
-
}, modalIcon !== undefined && /*#__PURE__*/
|
|
98
|
+
}, modalIcon !== undefined && /*#__PURE__*/React.createElement("div", {
|
|
132
99
|
className: "me-2"
|
|
133
|
-
}, modalIcon), /*#__PURE__*/
|
|
100
|
+
}, modalIcon), /*#__PURE__*/React.createElement("h5", {
|
|
134
101
|
className: "modal-title"
|
|
135
|
-
}, modalTitle ||
|
|
102
|
+
}, modalTitle || getPhrase("Message")), /*#__PURE__*/React.createElement("button", {
|
|
136
103
|
type: "button",
|
|
137
104
|
className: "btn-close",
|
|
138
105
|
onClick: cancel
|
|
139
|
-
})), /*#__PURE__*/
|
|
106
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
140
107
|
className: "modal-body",
|
|
141
108
|
style: {
|
|
142
109
|
whiteSpace: "pre-wrap"
|
|
143
110
|
}
|
|
144
|
-
}, modalContent, type === "ask" && /*#__PURE__*/
|
|
111
|
+
}, modalContent, type === "ask" && /*#__PURE__*/React.createElement("input", {
|
|
145
112
|
type: inputType,
|
|
146
113
|
className: "form-control mt-1",
|
|
147
114
|
value: input,
|
|
@@ -150,21 +117,21 @@ function Modal(_ref) {
|
|
|
150
117
|
return setInput(target.value);
|
|
151
118
|
},
|
|
152
119
|
autoFocus: true
|
|
153
|
-
})), /*#__PURE__*/
|
|
120
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
154
121
|
className: "modal-footer"
|
|
155
|
-
}, /*#__PURE__*/
|
|
122
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
156
123
|
type: "submit",
|
|
157
124
|
className: "btn ".concat(switchPrimaryBtn ? "btn-outline-primary" : "btn-primary", " d-block w-100"),
|
|
158
125
|
style: btnStyle
|
|
159
|
-
}, type === "verify" ? acceptBtnText ? acceptBtnText :
|
|
126
|
+
}, type === "verify" ? acceptBtnText ? acceptBtnText : getPhrase("Yes") : acceptBtnText ? acceptBtnText : "OK"), (type === "ask" || type === "verify") && (type === "verify" ? /*#__PURE__*/React.createElement("button", {
|
|
160
127
|
type: "button",
|
|
161
128
|
className: "btn ".concat(switchPrimaryBtn ? "btn-primary" : "btn-outline-primary", " d-block w-100"),
|
|
162
129
|
style: btnStyle,
|
|
163
130
|
onClick: sayNo
|
|
164
|
-
}, cancelBtnText ? cancelBtnText :
|
|
131
|
+
}, cancelBtnText ? cancelBtnText : getPhrase("No")) : /*#__PURE__*/React.createElement("button", {
|
|
165
132
|
type: "button",
|
|
166
133
|
className: "btn btn-outline-primary d-block w-100",
|
|
167
134
|
style: btnStyle,
|
|
168
135
|
onClick: cancel
|
|
169
|
-
}, cancelBtnText ? cancelBtnText :
|
|
136
|
+
}, cancelBtnText ? cancelBtnText : getPhrase("Cancel"))))))));
|
|
170
137
|
}
|