blue-react 9.11.0 → 9.12.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.
@@ -72,9 +72,10 @@ var Layout = /*#__PURE__*/function (_Component) {
72
72
  _this = _super.call(this, props);
73
73
  window.blueLayoutRef = _assertThisInitialized(_this);
74
74
  _this.defaultMatch = ["home"];
75
+ var expandSidebar = props.hideSidebarMenu ? false : props.expandSidebar !== undefined ? props.expandSidebar : localStorage.getItem("blueLayoutShrinkSidebar") === null;
75
76
  _this.state = {
76
77
  sidebarIn: props.sidebarIn || false,
77
- expandSidebar: props.hideSidebarMenu ? false : props.expandSidebar !== undefined ? props.expandSidebar : localStorage.getItem("blueLayoutShrinkSidebar") === null,
78
+ expandSidebar: expandSidebar,
78
79
  match: null,
79
80
  history: [],
80
81
  hash: window.location.hash,
@@ -84,6 +85,7 @@ var Layout = /*#__PURE__*/function (_Component) {
84
85
  _this.hideSidebar = _this.hideSidebar.bind(_assertThisInitialized(_this));
85
86
  _this.toggleExpandSidebar = _this.toggleExpandSidebar.bind(_assertThisInitialized(_this));
86
87
  _this.eventListeners = [];
88
+ if (_this.props.onChangeExpandSidebar) _this.props.onChangeExpandSidebar(expandSidebar);
87
89
  return _this;
88
90
  }
89
91
 
@@ -33,10 +33,20 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
33
33
 
34
34
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
35
35
 
36
+ function findParentWithClass(element, className) {
37
+ while (element && !element.classList.contains(className)) {
38
+ element = element.parentElement;
39
+ }
40
+
41
+ return element;
42
+ }
43
+
36
44
  /**
37
45
  * Link, button or custom component for Sidebar, Actions or ActionMenu
38
46
  */
39
47
  function MenuItem(props) {
48
+ var id = "blue-menu-item-wrapper-".concat(Math.random().toString(36).substring(7));
49
+
40
50
  var _useState = (0, _react.useState)(false),
41
51
  _useState2 = _slicedToArray(_useState, 2),
42
52
  showDropdown = _useState2[0],
@@ -47,6 +57,8 @@ function MenuItem(props) {
47
57
  active = _useState4[0],
48
58
  setActive = _useState4[1];
49
59
 
60
+ var menuRef = (0, _react.useRef)(null);
61
+
50
62
  var checkActive = function checkActive() {
51
63
  setActive(props.href && window.location.hash.indexOf(props.href) > -1 || props.isHome && (window.location.hash === "" || window.location.hash === "#/") ? true : false);
52
64
  };
@@ -71,11 +83,17 @@ function MenuItem(props) {
71
83
 
72
84
  var onClickOutside = function onClickOutside(_ref) {
73
85
  var target = _ref.target;
74
-
75
- // Don't trigger when clicking on MenuItem
76
- if (!(target !== null && target !== void 0 && target.classList.contains("blue-menu-item-dropdown-toggle")) && !(target !== null && target !== void 0 && target.classList.contains("blue-menu-item-label"))) {
77
- setShowDropdown(false);
86
+ var ignoreClasses = props.outsideIgnoreClasses || [id];
87
+
88
+ if (ignoreClasses && target) {
89
+ for (var i = 0; i < ignoreClasses.length; i++) {
90
+ if (target !== null && target !== void 0 && target.classList.contains(ignoreClasses[i]) || findParentWithClass(target, ignoreClasses[i])) {
91
+ return;
92
+ }
93
+ }
78
94
  }
95
+
96
+ setShowDropdown(false);
79
97
  };
80
98
 
81
99
  (0, _react.useEffect)(function () {
@@ -92,6 +110,13 @@ function MenuItem(props) {
92
110
  props.onShowDropdown(showDropdown);
93
111
  }
94
112
  }, [props.onShowDropdown, showDropdown]);
113
+ (0, _react.useEffect)(function () {
114
+ if (menuRef && menuRef.current) {
115
+ var el = menuRef.current;
116
+ var rect = el.getBoundingClientRect();
117
+ el.style.setProperty("--offset-top", Math.round(rect.top) + "px");
118
+ }
119
+ }, [menuRef, showDropdown]);
95
120
  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" : "");
96
121
  var icon, iconForActive;
97
122
 
@@ -115,7 +140,9 @@ function MenuItem(props) {
115
140
  iconForActive = props.iconForActive;
116
141
  }
117
142
 
118
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/(0, _react.createElement)(props.elementType || (props.href ? "a" : "button"), {
143
+ return /*#__PURE__*/_react.default.createElement("div", {
144
+ className: "blue-menu-item-wrapper ".concat(id)
145
+ }, /*#__PURE__*/(0, _react.createElement)(props.elementType || (props.href ? "a" : "button"), {
119
146
  to: props.to,
120
147
  href: props.href,
121
148
  exact: props.exact,
@@ -160,10 +187,12 @@ function MenuItem(props) {
160
187
  className: (0, _clsx.default)("blue-menu-item-dropdown-caret ms-auto", props.caretClassName),
161
188
  style: props.caretStyle
162
189
  }))), showDropdown && (props.supportOutside ? /*#__PURE__*/_react.default.createElement(_Outside.default, {
190
+ wrapperRef: menuRef,
163
191
  className: (0, _clsx.default)("blue-menu-item-dropdown", props.dropdownClassName),
164
192
  onClickOutside: onClickOutside,
165
193
  style: props.dropdownStyle
166
194
  }, props.children) : /*#__PURE__*/_react.default.createElement("div", {
195
+ ref: menuRef,
167
196
  className: (0, _clsx.default)("blue-menu-item-dropdown", props.dropdownClassName),
168
197
  style: props.dropdownStyle
169
198
  }, props.children)));
@@ -45,11 +45,12 @@ function Outside(_ref) {
45
45
  className = _ref.className,
46
46
  onClickOutside = _ref.onClickOutside,
47
47
  onClick = _ref.onClick,
48
- style = _ref.style;
49
- var wrapperRef = (0, _react.useRef)(null);
50
- useOutside(wrapperRef, onClickOutside);
48
+ style = _ref.style,
49
+ wrapperRef = _ref.wrapperRef;
50
+ var ref = (0, _react.useRef)(null);
51
+ useOutside(wrapperRef || ref, onClickOutside);
51
52
  return /*#__PURE__*/_react.default.createElement("div", {
52
- ref: wrapperRef,
53
+ ref: wrapperRef || ref,
53
54
  className: className,
54
55
  style: style,
55
56
  onClick: onClick
@@ -39,14 +39,8 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
39
39
 
40
40
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
41
41
 
42
- function getOffset(el) {
43
- var rect = el.getBoundingClientRect();
44
- return {
45
- left: Math.round(rect.left + window.scrollX),
46
- top: Math.round(rect.top + window.scrollY)
47
- };
48
- }
49
42
  /**
43
+ * @deprecated `MenuItem` now has all the features of `SidebarMenuItem`. Use `MenuItem` instead.
50
44
  * Extends `MenuItem` with following features:
51
45
  * * Shows provided label as tooltip if sidebar is closed.
52
46
  * * Children will be displayed on the right side of the parent item.
@@ -61,8 +55,6 @@ function getOffset(el) {
61
55
  * </SidebarMenu>
62
56
  * ```
63
57
  */
64
-
65
-
66
58
  function SidebarMenuItem(_ref) {
67
59
  var _ref$outerClass = _ref.outerClass,
68
60
  outerClass = _ref$outerClass === void 0 ? "" : _ref$outerClass,
@@ -90,8 +82,7 @@ function SidebarMenuItem(_ref) {
90
82
  }, [window.location.hash]);
91
83
  (0, _react.useEffect)(function () {
92
84
  if (menuRef && menuRef.current) {
93
- var offset = getOffset(menuRef.current);
94
- setOffsetTop(offset.top);
85
+ setOffsetTop(menuRef.current.getBoundingClientRect().top);
95
86
  }
96
87
  }, [menuRef, open]);
97
88
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children ? /*#__PURE__*/_react.default.createElement(_Outside.default, {
@@ -104,7 +95,7 @@ function SidebarMenuItem(_ref) {
104
95
  onClick: toggle
105
96
  })), open && /*#__PURE__*/_react.default.createElement("div", {
106
97
  ref: menuRef,
107
- className: ["position-absolute", "shadow", "top-0", "ms-1", "rounded", "w-bla-sidebar-width", "blue-menu-item-dropdown", "blue-menu-item-dropdown-from-start"].join(" "),
98
+ className: ["position-absolute", "shadow", "top-0", "ms-1", "rounded", "w-bla-sidebar-width", "blue-menu-item-dropdown-from-start"].join(" "),
108
99
  style: {
109
100
  left: "var(--blue-sidebar-width, 3rem)",
110
101
  maxHeight: "calc(100vh - (".concat(offsetTop, "px + 1rem))"),