@unbxd-ui/unbxd-react-components 0.2.139 → 0.2.140

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.
@@ -48,11 +48,15 @@ var AccordianItem = function AccordianItem(props) {
48
48
  return item === id;
49
49
  }) ? true : false;
50
50
  var onItemClick = function onItemClick() {
51
- var newList = [id];
51
+ var newList = [];
52
52
  if (!allowOneOpen) {
53
53
  newList = isOpen ? openedItems.filter(function (item) {
54
54
  return item !== id;
55
55
  }) : [].concat(_toConsumableArray(openedItems), [id]);
56
+ } else {
57
+ if (!openedItems.includes(id)) {
58
+ newList = [id];
59
+ }
56
60
  }
57
61
  setOpenedItems(newList);
58
62
  };
@@ -39,6 +39,8 @@ var Tooltip = function Tooltip(props, ref) {
39
39
  _useState4 = _slicedToArray(_useState3, 2),
40
40
  isOpen = _useState4[0],
41
41
  setIsOpen = _useState4[1];
42
+ var tooltipBodyRef = (0, _react.useRef)(null);
43
+ var tooltipRef = (0, _react.useRef)(null);
42
44
  var dirClassName = "RCB-tooltip-right";
43
45
  switch (direction) {
44
46
  case "bottom":
@@ -73,6 +75,39 @@ var Tooltip = function Tooltip(props, ref) {
73
75
  var hideToolTip = function hideToolTip() {
74
76
  setIsOpen(false);
75
77
  };
78
+ var changeModalState = function changeModalState(newState) {
79
+ setIsOpen(newState);
80
+ };
81
+ var onBodyClick = function onBodyClick(e) {
82
+ var eventTarget = e.target;
83
+ var inlineModalNode = tooltipRef.current;
84
+ var eventPathNodes = e.composedPath();
85
+ var isWithinModal = false;
86
+ if (inlineModalNode.contains(eventTarget)) {
87
+ isWithinModal = true;
88
+ } else {
89
+ for (var i = 0; i < eventPathNodes.length; i++) {
90
+ var node = eventPathNodes[i];
91
+ if (node !== window && inlineModalNode.contains(node)) {
92
+ isWithinModal = true;
93
+ break;
94
+ }
95
+ }
96
+ }
97
+ if (!isWithinModal) {
98
+ /* outside click -> close modal */
99
+ changeModalState(false);
100
+ }
101
+ };
102
+ (0, _react.useEffect)(function () {
103
+ /* add when mounted */
104
+ document.addEventListener("click", onBodyClick);
105
+
106
+ /* return function to be called when unmounted */
107
+ return function () {
108
+ document.removeEventListener("click", onBodyClick);
109
+ };
110
+ }, []);
76
111
  var eventProps = activatorAction === "click" ? {
77
112
  onClick: showToolTipClick
78
113
  } : {
@@ -80,11 +115,13 @@ var Tooltip = function Tooltip(props, ref) {
80
115
  onMouseLeave: hideToolTip
81
116
  };
82
117
  return /*#__PURE__*/_react["default"].createElement("div", {
83
- className: "RCB-tooltip ".concat(className)
118
+ className: "RCB-tooltip ".concat(className),
119
+ ref: tooltipRef
84
120
  }, /*#__PURE__*/_react["default"].createElement("div", _extends({
85
121
  className: "RCB-tooltip-btn"
86
122
  }, eventProps), /*#__PURE__*/_react["default"].createElement(TooltipActivator, restProps)), isOpen && /*#__PURE__*/_react["default"].createElement("div", {
87
- className: "RCB-tooltip-body ".concat(dirClassName, " ").concat(actionClassName)
123
+ className: "RCB-tooltip-body ".concat(dirClassName, " ").concat(actionClassName),
124
+ ref: tooltipBodyRef
88
125
  }, children));
89
126
  };
90
127
  Tooltip = /*#__PURE__*/(0, _react.forwardRef)(Tooltip);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unbxd-ui/unbxd-react-components",
3
- "version": "0.2.139",
3
+ "version": "0.2.140",
4
4
  "description": "React components library",
5
5
  "keywords": [
6
6
  "react components",