@synerise/ds-tabs 0.13.101 → 0.13.103

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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.13.103](https://github.com/synerise/synerise-design/compare/@synerise/ds-tabs@0.13.102...@synerise/ds-tabs@0.13.103) (2024-04-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **tabs:** fixed calculating tabs width ([1c5397f](https://github.com/synerise/synerise-design/commit/1c5397fd0c935726046247a584ab8f58ec766773))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.13.102](https://github.com/synerise/synerise-design/compare/@synerise/ds-tabs@0.13.101...@synerise/ds-tabs@0.13.102) (2024-04-02)
18
+
19
+ **Note:** Version bump only for package @synerise/ds-tabs
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.13.101](https://github.com/synerise/synerise-design/compare/@synerise/ds-tabs@0.13.100...@synerise/ds-tabs@0.13.101) (2024-03-29)
7
26
 
8
27
  **Note:** Version bump only for package @synerise/ds-tabs
package/dist/Tab/Tab.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- import * as React from 'react';
2
1
  import { TabProps } from './Tab.types';
3
- declare const Tab: React.FC<TabProps>;
2
+ declare const Tab: {
3
+ ({ index, label, icon, isActive, disabled, onClick, forwardedRef, underscore, className, block, suffixel, }: TabProps): JSX.Element;
4
+ defaultProps: {
5
+ underscore: boolean;
6
+ };
7
+ };
4
8
  export default Tab;
package/dist/Tab/Tab.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import Icon from '@synerise/ds-icon';
3
3
  import classNames from 'classnames';
4
4
  import * as S from './Tab.styles';
@@ -16,9 +16,9 @@ var Tab = function Tab(_ref) {
16
16
  block = _ref.block,
17
17
  suffixel = _ref.suffixel;
18
18
 
19
- var _React$useState = React.useState(false),
20
- isPressed = _React$useState[0],
21
- setPressed = _React$useState[1];
19
+ var _useState = useState(false),
20
+ isPressed = _useState[0],
21
+ setPressed = _useState[1];
22
22
 
23
23
  var handleClick = function handleClick() {
24
24
  onClick(index);
@@ -1,14 +1,14 @@
1
- import * as React from 'react';
1
+ import { ReactNode, RefObject } from 'react';
2
2
  export type TabProps = {
3
3
  index: number;
4
- label?: string | React.ReactNode;
5
- icon?: React.ReactNode;
4
+ label?: ReactNode;
5
+ icon?: ReactNode;
6
6
  underscore?: boolean;
7
7
  isActive?: boolean;
8
8
  disabled?: boolean;
9
9
  className?: string;
10
10
  onClick: (index: number) => void;
11
- forwardedRef: React.RefObject<HTMLButtonElement>;
11
+ forwardedRef: RefObject<HTMLButtonElement>;
12
12
  block?: boolean;
13
- suffixel?: React.ReactNode | React.ReactText;
13
+ suffixel?: ReactNode;
14
14
  };
package/dist/Tabs.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- import * as React from 'react';
2
1
  import { TabsProps } from './Tabs.types';
3
- declare const Tabs: React.FC<TabsProps>;
2
+ declare const Tabs: {
3
+ ({ activeTab, tabs, handleTabClick, configuration, underscore, block }: TabsProps): JSX.Element;
4
+ defaultProps: {
5
+ underscore: boolean;
6
+ };
7
+ };
4
8
  export default Tabs;
package/dist/Tabs.js CHANGED
@@ -4,16 +4,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import * as React from 'react';
7
+ import React, { useCallback, createRef, useMemo, useState, useRef, useEffect } from 'react';
8
+ import { debounce } from 'lodash';
8
9
  import Dropdown from '@synerise/ds-dropdown';
9
10
  import Icon, { OptionHorizontalM } from '@synerise/ds-icon';
10
- import { useResize } from '@synerise/ds-utils';
11
+ import { useResizeObserver, NOOP } from '@synerise/ds-utils';
11
12
  import * as S from './Tabs.styles';
12
13
  import Tab from './Tab/Tab';
13
-
14
- // eslint-disable-next-line @typescript-eslint/no-empty-function
15
- var NOOP = function NOOP() {};
16
-
17
14
  var MARGIN_BETWEEN_TABS = 24;
18
15
  var DROPDOWN_TRIGGER_SIZE = 32;
19
16
 
@@ -23,53 +20,64 @@ var Tabs = function Tabs(_ref) {
23
20
  handleTabClick = _ref.handleTabClick,
24
21
  configuration = _ref.configuration,
25
22
  underscore = _ref.underscore,
26
- block = _ref.block,
27
- _ref$visible = _ref.visible,
28
- visible = _ref$visible === void 0 ? true : _ref$visible;
29
- var containerRef = React.useRef();
30
-
31
- var _useResize = useResize(containerRef, visible),
32
- width = _useResize.width;
33
-
34
- var _React$useState = React.useState(true),
35
- renderHelperTabs = _React$useState[0],
36
- setRenderHelperTabs = _React$useState[1];
37
-
38
- var _React$useState2 = React.useState([]),
39
- items = _React$useState2[0],
40
- setItems = _React$useState2[1];
41
-
42
- var _React$useState3 = React.useState([]),
43
- itemsWidths = _React$useState3[0],
44
- setItemsWidths = _React$useState3[1];
45
-
46
- var _React$useState4 = React.useState([]),
47
- visibleTabs = _React$useState4[0],
48
- setVisibleTabs = _React$useState4[1];
49
-
50
- var _React$useState5 = React.useState([]),
51
- hiddenTabs = _React$useState5[0],
52
- setHiddenTabs = _React$useState5[1];
53
-
54
- React.useEffect(function () {
23
+ block = _ref.block;
24
+
25
+ var _useState = useState(0),
26
+ containerWidth = _useState[0],
27
+ setContainerWidth = _useState[1];
28
+
29
+ var containerRef = useRef(null);
30
+ var helperContainerRef = useRef(null);
31
+
32
+ var _useResizeObserver = useResizeObserver(containerRef),
33
+ width = _useResizeObserver.width;
34
+
35
+ var _useResizeObserver2 = useResizeObserver(helperContainerRef),
36
+ helperWidth = _useResizeObserver2.width;
37
+
38
+ var _useState2 = useState([]),
39
+ items = _useState2[0],
40
+ setItems = _useState2[1];
41
+
42
+ var _useState3 = useState([]),
43
+ itemsWidths = _useState3[0],
44
+ setItemsWidths = _useState3[1];
45
+
46
+ var _useState4 = useState([]),
47
+ visibleTabs = _useState4[0],
48
+ setVisibleTabs = _useState4[1];
49
+
50
+ var _useState5 = useState([]),
51
+ hiddenTabs = _useState5[0],
52
+ setHiddenTabs = _useState5[1];
53
+
54
+ var debouncedEventHandler = useMemo(function () {
55
+ return debounce(function (newWidth) {
56
+ return setContainerWidth(newWidth);
57
+ }, 200);
58
+ }, []);
59
+ useEffect(function () {
60
+ debouncedEventHandler(width);
61
+ }, [width, debouncedEventHandler]);
62
+ useEffect(function () {
55
63
  var newTabs = tabs.map(function (tab) {
56
64
  return _objectSpread({}, tab, {
57
- ref: React.createRef()
65
+ ref: createRef()
58
66
  });
59
67
  });
60
- setRenderHelperTabs(true);
61
68
  setItems(newTabs);
62
69
  }, [tabs]);
63
- React.useEffect(function () {
64
- var itemsWithWidths = [];
65
- items.forEach(function (item, index) {
66
- itemsWithWidths[index] = item.ref.current !== null ? item.ref.current.offsetWidth + MARGIN_BETWEEN_TABS : 0;
67
- });
68
- setItemsWidths(itemsWithWidths);
69
- setRenderHelperTabs(false);
70
- }, [items]); // eslint-disable-line react-hooks/exhaustive-deps
70
+ useEffect(function () {
71
+ if (helperWidth > 0 && containerWidth > 0) {
72
+ var itemsWithWidths = [];
73
+ items.forEach(function (item, index) {
74
+ itemsWithWidths[index] = item.ref.current !== null ? item.ref.current.offsetWidth + MARGIN_BETWEEN_TABS : 0;
75
+ });
76
+ setItemsWidths(itemsWithWidths);
77
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
71
78
 
72
- React.useEffect(function () {
79
+ }, [items, helperWidth, containerWidth > 0]);
80
+ useEffect(function () {
73
81
  if (block) {
74
82
  setVisibleTabs(items);
75
83
  setHiddenTabs([]);
@@ -78,7 +86,7 @@ var Tabs = function Tabs(_ref) {
78
86
  var visibleItems = [];
79
87
  var hiddenItems = [];
80
88
  itemsWidths.forEach(function (itemWidth, index) {
81
- if (containerRef && tabsWidth + itemWidth < width) {
89
+ if (containerRef && tabsWidth + itemWidth < containerWidth) {
82
90
  visibleItems.push(items[index]);
83
91
  } else {
84
92
  hiddenItems.push(items[index]);
@@ -90,11 +98,11 @@ var Tabs = function Tabs(_ref) {
90
98
  setHiddenTabs(hiddenItems);
91
99
  } // eslint-disable-next-line react-hooks/exhaustive-deps
92
100
 
93
- }, [itemsWidths, width]);
94
- var handleConfigurationAction = React.useCallback(function () {
101
+ }, [itemsWidths, containerWidth]);
102
+ var handleConfigurationAction = useCallback(function () {
95
103
  configuration && configuration.action();
96
104
  }, [configuration]);
97
- var renderHiddenTabs = React.useMemo(function () {
105
+ var renderHiddenTabs = useMemo(function () {
98
106
  return /*#__PURE__*/React.createElement(S.TabsDropdownContainer, {
99
107
  "data-testid": "tabs-dropdown-container"
100
108
  }, hiddenTabs.length > 0 && /*#__PURE__*/React.createElement(S.DropdownMenu, null, hiddenTabs.map(function (item, index) {
@@ -131,7 +139,7 @@ var Tabs = function Tabs(_ref) {
131
139
  }))));
132
140
  };
133
141
 
134
- var renderVisibleTabs = React.useMemo(function () {
142
+ var renderVisibleTabs = useMemo(function () {
135
143
  return /*#__PURE__*/React.createElement(React.Fragment, null, visibleTabs.filter(function (tab) {
136
144
  return Boolean(tab);
137
145
  }).map(function (tab, index) {
@@ -151,8 +159,9 @@ var Tabs = function Tabs(_ref) {
151
159
  });
152
160
  }));
153
161
  }, [visibleTabs, activeTab, handleTabClick, underscore, block]);
154
- var renderHelpers = React.useMemo(function () {
162
+ var renderHelpers = useMemo(function () {
155
163
  return /*#__PURE__*/React.createElement(S.HiddenTabs, {
164
+ ref: helperContainerRef,
156
165
  className: "ds-hidden-helper"
157
166
  }, items.map(function (tab, index) {
158
167
  var key = "tabs-tab-helper-" + index;
@@ -170,12 +179,12 @@ var Tabs = function Tabs(_ref) {
170
179
  });
171
180
  }));
172
181
  }, [items, underscore, block]);
173
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(S.TabsContainer, {
182
+ return /*#__PURE__*/React.createElement(React.Fragment, null, tabs.length && /*#__PURE__*/React.createElement(S.TabsContainer, {
174
183
  className: "ds-tabs",
175
184
  ref: containerRef,
176
185
  "data-testid": "tabs-container",
177
186
  block: block
178
- }, renderVisibleTabs, renderDropdown()), !block && renderHelperTabs && renderHelpers);
187
+ }, renderVisibleTabs, renderDropdown()), !block && renderHelpers);
179
188
  };
180
189
 
181
190
  Tabs.defaultProps = {
@@ -4,7 +4,7 @@ import Menu from '@synerise/ds-menu';
4
4
  export var TabsContainer = styled.div.withConfig({
5
5
  displayName: "Tabsstyles__TabsContainer",
6
6
  componentId: "sc-16x3i3b-0"
7
- })(["padding-top:5px;display:flex;flex-direction:row;align-items:", ";justify-content:flex-start;max-width:100%;overflow-x:hidden;margin-bottom:-1px;"], function (props) {
7
+ })(["padding-top:5px;display:flex;flex-direction:row;align-items:", ";justify-content:flex-start;max-width:100%;overflow-x:hidden;margin-bottom:-1px;height:38px;"], function (props) {
8
8
  return props.block ? "center" : "flex-end";
9
9
  });
10
10
  export var TabsDropdownContainer = styled.div.withConfig({
@@ -31,7 +31,7 @@ export var ShowHiddenTabsTrigger = styled(Button).withConfig({
31
31
  export var HiddenTabs = styled.div.withConfig({
32
32
  displayName: "Tabsstyles__HiddenTabs",
33
33
  componentId: "sc-16x3i3b-4"
34
- })(["position:absolute;width:0;visibility:hidden;"]);
34
+ })(["position:absolute;display:flex;visibility:hidden;pointer-events:none;"]);
35
35
  export var DropdownMenu = styled(Menu).withConfig({
36
36
  displayName: "Tabsstyles__DropdownMenu",
37
37
  componentId: "sc-16x3i3b-5"
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { ReactNode, RefObject } from 'react';
2
2
  export type TabsProps = {
3
3
  activeTab: number;
4
4
  tabs: TabItem[];
@@ -14,11 +14,11 @@ export type Configuration = {
14
14
  disabled?: boolean;
15
15
  };
16
16
  export type TabItem = {
17
- label?: string | React.ReactNode;
18
- icon?: React.ReactNode;
17
+ label?: ReactNode;
18
+ icon?: ReactNode;
19
19
  disabled?: boolean;
20
- suffixel?: React.ReactNode | React.ReactText;
20
+ suffixel?: ReactNode;
21
21
  };
22
22
  export type TabWithRef = TabItem & {
23
- ref: React.RefObject<HTMLButtonElement>;
23
+ ref: RefObject<HTMLButtonElement>;
24
24
  };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default } from './Tabs';
2
+ export type { TabItem } from './Tabs.types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-tabs",
3
- "version": "0.13.101",
3
+ "version": "0.13.103",
4
4
  "description": "Tabs UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -33,12 +33,12 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-button": "^0.19.5",
37
- "@synerise/ds-dropdown": "^0.17.102",
38
- "@synerise/ds-icon": "^0.60.5",
39
- "@synerise/ds-menu": "^0.18.17",
36
+ "@synerise/ds-button": "^0.19.6",
37
+ "@synerise/ds-dropdown": "^0.17.103",
38
+ "@synerise/ds-icon": "^0.60.6",
39
+ "@synerise/ds-menu": "^0.18.18",
40
40
  "@synerise/ds-typography": "^0.14.3",
41
- "@synerise/ds-utils": "^0.26.1",
41
+ "@synerise/ds-utils": "^0.26.2",
42
42
  "classnames": "2.3.2"
43
43
  },
44
44
  "peerDependencies": {
@@ -50,5 +50,5 @@
50
50
  "devDependencies": {
51
51
  "@testing-library/jest-dom": "5.1.1"
52
52
  },
53
- "gitHead": "07304b7bf03826701df904c7be058d93588a9611"
53
+ "gitHead": "7506652551b234c2e30e3bb492d56ab822bdb5a1"
54
54
  }