linear-react-components-ui 0.4.75-rc.0 → 0.4.76-beta.10

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.
@@ -73,10 +73,11 @@ var withTooltip = function withTooltip(WrappedComponent) {
73
73
  tooltipDimensions = _useState8[0],
74
74
  setTooltipDimensions = _useState8[1];
75
75
 
76
- var targetElement = (0, _react.useRef)();
76
+ var targetElement = (0, _react.useRef)(null);
77
+ var tooltipElement = (0, _react.useRef)(null);
77
78
 
78
79
  var onMouseOver = function onMouseOver(e) {
79
- if (targetElement.current.contains(e.target)) {
80
+ if (targetElement && targetElement.current && targetElement.current.contains(e.target)) {
80
81
  setShowTooltip(true);
81
82
  } else setShowTooltip(false);
82
83
  };
@@ -116,9 +117,10 @@ var withTooltip = function withTooltip(WrappedComponent) {
116
117
  height = tooltipDimensions.height;
117
118
  var targetDimensions = targetElement.current.getBoundingClientRect();
118
119
  var targetVerticalCenter = (targetDimensions.top + targetDimensions.bottom) / 2;
119
- var style = "width: ".concat(width, "px");
120
- var left = targetDimensions.left + targetDimensions.width / 2 - width / 2;
121
- left = Math.min(left, document.body.clientWidth - width - space);
120
+ var tooltipClientWidth = tooltipElement.current && tooltipElement.current.clientWidth;
121
+ var style = "width: ".concat(typeof width === 'string' ? width : "".concat(width, "px"));
122
+ var left = targetDimensions.left + targetDimensions.width / 2 - tooltipClientWidth / 2;
123
+ left = Math.min(left, document.body.clientWidth - tooltipClientWidth - space);
122
124
  style += "; left: ".concat(Math.max(space, left), "px");
123
125
 
124
126
  switch (tooltipPosition) {
@@ -141,17 +143,17 @@ var withTooltip = function withTooltip(WrappedComponent) {
141
143
  break;
142
144
 
143
145
  case 'left':
144
- if (targetDimensions.left < width) {
146
+ if (targetDimensions.left < tooltipClientWidth) {
145
147
  setTooltipPosition('right');
146
148
  } else {
147
149
  style += "; top: ".concat(targetVerticalCenter + window.scrollY - height / 2, "px");
148
- style += "; left: ".concat(targetDimensions.left - width - 6, "px");
150
+ style += "; left: ".concat(targetDimensions.left - tooltipClientWidth - 6, "px");
149
151
  }
150
152
 
151
153
  break;
152
154
 
153
155
  case 'right':
154
- if (window.innerWidth - targetDimensions.right < width) {
156
+ if (window.innerWidth - targetDimensions.right < tooltipClientWidth) {
155
157
  setTooltipPosition('left');
156
158
  } else {
157
159
  style += "; top: ".concat(targetVerticalCenter + window.scrollY - height / 2, "px");
@@ -166,7 +168,7 @@ var withTooltip = function withTooltip(WrappedComponent) {
166
168
 
167
169
  setTooltipStyle(style);
168
170
  }
169
- }, [tooltipDimensions, targetElement.current, tooltipPosition]);
171
+ }, [tooltipDimensions, tooltipElement.current, targetElement.current, tooltipPosition]);
170
172
  (0, _react.useEffect)(function () {
171
173
  setTooltipPosition(props.tooltipPosition);
172
174
  }, [window.scrollY, window.scrollX, window.innerWidth]);
@@ -175,6 +177,7 @@ var withTooltip = function withTooltip(WrappedComponent) {
175
177
  if (tooltip) {
176
178
  return /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
177
179
  text: tooltip,
180
+ tooltipRef: tooltipElement,
178
181
  style: tooltipStyle,
179
182
  className: tooltipPosition,
180
183
  tooltipDimensions: tooltipDimensions,
package/lib/tabs/index.js CHANGED
@@ -96,18 +96,75 @@ var Tabs = function Tabs(props) {
96
96
  tabsContentWidth = _useState14[0],
97
97
  setTabsContentWidth = _useState14[1];
98
98
 
99
- var componentRef = (0, _react.useRef)();
99
+ var _useState15 = (0, _react.useState)(false),
100
+ _useState16 = _slicedToArray(_useState15, 2),
101
+ hasMenuAttributes = _useState16[0],
102
+ setHasMenuAttributes = _useState16[1];
100
103
 
101
- var _menuRef = (0, _react.useRef)();
104
+ var _useState17 = (0, _react.useState)(0),
105
+ _useState18 = _slicedToArray(_useState17, 2),
106
+ dropdownWidth = _useState18[0],
107
+ setDropdownWidth = _useState18[1];
102
108
 
103
- var _toolBarRef = (0, _react.useRef)();
109
+ var componentRef = (0, _react.useRef)(null);
110
+
111
+ var _menuRef = (0, _react.useRef)(null);
112
+
113
+ var _toolBarRef = (0, _react.useRef)(null);
114
+
115
+ var getTabListWidth = function getTabListWidth() {
116
+ var tabMenu = _menuRef.current.children[0];
117
+
118
+ var tabList = _toConsumableArray(tabMenu.children);
119
+
120
+ var tabsListWidth = tabList.reduce(function (total, tab) {
121
+ return total + tab.clientWidth;
122
+ }, 0);
123
+ return tabsListWidth;
124
+ };
125
+
126
+ var getMenuAttributes = function getMenuAttributes() {
127
+ var menuSize = _menuRef.current.clientWidth;
128
+ var toolbarSize = toolbar && _toolBarRef ? _toolBarRef.current.clientWidth : 0;
129
+ var contentWidth = (toolbar ? menuSize - toolbarSize : menuSize) - dropdownWidth;
130
+ setTabsContentWidth(contentWidth);
131
+ };
132
+
133
+ var getTabsList = function getTabsList() {
134
+ var tabsListWidth = getTabListWidth();
135
+
136
+ var newDropdownPanels = _toConsumableArray(dropdownPanels);
137
+
138
+ var newCurrentPanels = _toConsumableArray(panels);
139
+
140
+ if (newDropdownPanels.length) {
141
+ var newDropdownPanelsIds = newDropdownPanels.map(function (dd) {
142
+ return dd.props.id;
143
+ });
144
+ newCurrentPanels = newCurrentPanels.filter(function (tab) {
145
+ return !newDropdownPanelsIds.includes(tab.props.id);
146
+ });
147
+ }
148
+
149
+ if (tabsListWidth > tabsContentWidth) {
150
+ var lastPanel = newCurrentPanels[newCurrentPanels.length - 1];
151
+ newDropdownPanels.push(lastPanel);
152
+ newCurrentPanels.pop();
153
+ } else if (tabsListWidth + 110 < tabsContentWidth && newDropdownPanels.length) {
154
+ newCurrentPanels.push(newDropdownPanels[0]);
155
+ newDropdownPanels.shift();
156
+ }
157
+
158
+ setCurrentPanels(newCurrentPanels);
159
+ setDropdownPanels(newDropdownPanels);
160
+ };
104
161
 
105
162
  var onMenuClick = function onMenuClick(tabId) {
106
163
  var includedInDropdown = dropdownPanels.filter(function (item) {
107
164
  return item.props.id === tabId;
108
165
  });
109
166
 
110
- if (includedInDropdown.length > 0) {
167
+ if (includedInDropdown.length > 0 && getTabListWidth() > 0) {
111
168
  var newDropdownPanels = dropdownPanels.filter(function (item) {
112
169
  return item.props.id !== tabId;
113
170
  });
@@ -148,53 +205,14 @@ var Tabs = function Tabs(props) {
148
205
  if (handlerCloseTab) handlerCloseTab(closedPanelId, newSelectedTabId);
149
206
  };
150
207
 
151
- var getMenuAttributes = function getMenuAttributes() {
152
- var menuSize = _menuRef.current.clientWidth;
153
- var dropdownWidth = dropdownPanels.length > 0 ? _menuRef.current.children[1].clientWidth : 0;
154
- var toolbarSize = toolbar && _toolBarRef ? _toolBarRef.current.clientWidth : 0;
155
- var contentWidth = (toolbar ? menuSize - toolbarSize : menuSize) - dropdownWidth;
156
- setTabsContentWidth(contentWidth);
157
- };
158
-
159
- var getTabsList = function getTabsList() {
160
- var tabMenu = _menuRef.current.children[0];
161
-
162
- var tabList = _toConsumableArray(tabMenu.children);
163
-
164
- var tabsListWidth = tabList.reduce(function (total, tab) {
165
- return total + tab.clientWidth;
166
- }, 0);
167
-
168
- var dropdownTabs = _toConsumableArray(dropdownPanels);
169
-
170
- var currentTabs = _toConsumableArray(panels);
171
-
172
- if (dropdownTabs.length) {
173
- var dropDownTabsIds = dropdownTabs.map(function (dd) {
174
- return dd.props.id;
175
- });
176
- currentTabs = currentTabs.filter(function (tab) {
177
- return !dropDownTabsIds.includes(tab.props.id);
178
- });
179
- }
180
-
181
- if (tabsListWidth > tabsContentWidth) {
182
- var lastPanel = currentTabs[currentTabs.length - 1];
183
- dropdownTabs.push(lastPanel);
184
- currentTabs.pop();
185
- } else if (tabsListWidth + 110 < tabsContentWidth && dropdownTabs.length) {
186
- currentTabs.push(dropdownTabs[0]);
187
- dropdownTabs.shift();
188
- }
189
-
190
- setCurrentPanels(currentTabs);
191
- setDropdownPanels(dropdownTabs);
192
- };
193
-
194
208
  var onResize = function onResize() {
195
209
  if (componentRef.current && _menuRef.current) {
196
210
  setContentHeight(componentRef.current.offsetHeight - _menuRef.current.offsetHeight);
197
- getMenuAttributes();
211
+
212
+ if (!hasMenuAttributes && _menuRef.current && _menuRef.current.clientWidth > 0 && dropdownWidth) {
213
+ getMenuAttributes();
214
+ setHasMenuAttributes(true);
215
+ }
198
216
  }
199
217
  };
200
218
 
@@ -231,14 +249,18 @@ var Tabs = function Tabs(props) {
231
249
  return function () {
232
250
  return window.removeEventListener('resize', onResize);
233
251
  };
234
- }, []);
252
+ }, [_menuRef.current, dropdownWidth]);
235
253
  (0, _react.useEffect)(function () {
236
254
  if (selectedTab) setSelectedTabId(selectedTab);
237
255
  if (children) setPanels((0, _tabHelpers.buildPanels)(children));
238
256
  }, [selectedTab, children]);
239
257
  (0, _react.useEffect)(function () {
240
258
  getTabsList();
241
- }, [panels.length, currentPanels.length]);
259
+ }, [panels.length, currentPanels.length, tabsContentWidth]);
260
+ (0, _react.useEffect)(function () {
261
+ var currentDropdownWidth = dropdownPanels.length > 0 ? _menuRef.current.children[1].clientWidth : 0;
262
+ setDropdownWidth(currentDropdownWidth);
263
+ }, [dropdownPanels.length]);
242
264
 
243
265
  var getContextValues = function getContextValues() {
244
266
  return {
@@ -135,7 +135,7 @@ describe('Tabs', function () {
135
135
  container = _render10.container;
136
136
 
137
137
  expect(container.querySelector('.tabs-component')).toHaveClass('menu-bottom');
138
- expect(container.querySelector('.tabs-component').lastChild).toHaveClass('menu');
138
+ expect(container.querySelector('.tabs-component').lastChild).toHaveClass('menucontainer');
139
139
  });
140
140
  it('should apply tabMenuAlign', function () {
141
141
  var _render11 = (0, _react2.render)(tabsMockRender({
@@ -328,7 +328,8 @@ describe('Tabs', function () {
328
328
  })),
329
329
  container = _render23.container;
330
330
 
331
- expect(container.querySelector('ul.menu li.menuitem button')).not.toHaveAttribute('disabled');
331
+ var noPermissionComponent = container.querySelector('.no-permission-component');
332
+ expect(noPermissionComponent).toBeFalsy();
332
333
  });
333
334
  it('should check permission and be unavailable', function () {
334
335
  Object.defineProperty(window, 'sessionStorage', {
@@ -336,11 +337,13 @@ describe('Tabs', function () {
336
337
  });
337
338
 
338
339
  var _render24 = (0, _react2.render)(tabsMockRender({}, {
339
- permissionAttr: (0, _storageMock.permissionAttrMockUnauthorized)('disabled')
340
+ permissionAttr: (0, _storageMock.permissionAttrMockUnauthorized)('hideContent')
340
341
  })),
341
- container = _render24.container;
342
+ container = _render24.container; // debug();
342
343
 
343
- expect(container.querySelector('ul.menu li.menuitem button')).toHaveAttribute('disabled');
344
+
345
+ var noPermissionComponent = container.querySelector('.no-permission-component');
346
+ expect(noPermissionComponent).toBeTruthy();
344
347
  });
345
348
  });
346
349
  });
@@ -28,7 +28,8 @@ var Tooltip = function Tooltip(props) {
28
28
  tooltipDimensions = props.tooltipDimensions,
29
29
  handlerSetDimensions = props.handlerSetDimensions,
30
30
  style = props.style,
31
- text = props.text;
31
+ text = props.text,
32
+ tooltipRef = props.tooltipRef;
32
33
  var tooltipComponent = (0, _react.useRef)(document.createElement('div'));
33
34
  tooltipComponent.current.id = "tooltip-".concat(_uuid["default"].v1());
34
35
  tooltipComponent.current.className = "tooltip-component ".concat(className, " ");
@@ -42,7 +43,7 @@ var Tooltip = function Tooltip(props) {
42
43
  var tooltipEl = document.querySelector("div#".concat(tooltipComponent.current.id));
43
44
  var width = tooltipEl.offsetWidth;
44
45
 
45
- if (tooltipDimensions.width) {
46
+ if (tooltipDimensions.width && tooltipDimensions.width !== 'auto') {
46
47
  width = tooltipDimensions.width;
47
48
  }
48
49
 
@@ -51,6 +52,7 @@ var Tooltip = function Tooltip(props) {
51
52
  width: width,
52
53
  height: height
53
54
  });
55
+ if (tooltipRef) tooltipRef.current = tooltipEl;
54
56
  return function () {
55
57
  return document.body.removeChild(tooltipComponent.current);
56
58
  };
@@ -75,13 +77,15 @@ Tooltip.propTypes = {
75
77
  text: _propTypes["default"].string,
76
78
  style: _propTypes["default"].string,
77
79
  className: _propTypes["default"].string,
78
- handlerSetDimensions: _propTypes["default"].func
80
+ handlerSetDimensions: _propTypes["default"].func,
81
+ tooltipRef: _propTypes["default"].object
79
82
  };
80
83
  Tooltip.defaultProps = {
81
84
  text: undefined,
82
85
  className: 'bottom',
83
86
  style: '',
84
- handlerSetDimensions: undefined
87
+ handlerSetDimensions: undefined,
88
+ tooltipRef: null
85
89
  };
86
90
  var _default = Tooltip;
87
91
  exports["default"] = _default;