@hi-ui/tabs 4.0.0-beta.20 → 4.0.0-beta.23
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/lib/cjs/TabInk.js +18 -5
- package/lib/cjs/TabList.js +1 -1
- package/lib/esm/TabInk.js +18 -6
- package/lib/esm/TabList.js +1 -1
- package/lib/types/TabInk.d.ts +1 -1
- package/package.json +3 -3
package/lib/cjs/TabInk.js
CHANGED
|
@@ -19,6 +19,8 @@ var React = require('react');
|
|
|
19
19
|
|
|
20
20
|
var classname = require('@hi-ui/classname');
|
|
21
21
|
|
|
22
|
+
var index = require('./hooks/index.js');
|
|
23
|
+
|
|
22
24
|
function _interopDefaultLegacy(e) {
|
|
23
25
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
|
24
26
|
'default': e
|
|
@@ -33,11 +35,11 @@ var TabInk = function TabInk(_ref) {
|
|
|
33
35
|
var disabled = _ref.disabled,
|
|
34
36
|
prefixCls = _ref.prefixCls,
|
|
35
37
|
activeItemElement = _ref.activeItemElement,
|
|
36
|
-
direction = _ref.direction,
|
|
37
38
|
activeTabId = _ref.activeTabId,
|
|
38
|
-
getTabOffset = _ref.getTabOffset
|
|
39
|
+
getTabOffset = _ref.getTabOffset,
|
|
40
|
+
showHorizontal = _ref.showHorizontal;
|
|
39
41
|
var inkRef = React.useRef(null);
|
|
40
|
-
React.
|
|
42
|
+
var setTabLnkPositionStyle = React.useCallback(function () {
|
|
41
43
|
if (!inkRef.current) return;
|
|
42
44
|
if (!activeItemElement) return;
|
|
43
45
|
var computedStyle = getComputedStyle(activeItemElement);
|
|
@@ -46,7 +48,7 @@ var TabInk = function TabInk(_ref) {
|
|
|
46
48
|
|
|
47
49
|
var _style;
|
|
48
50
|
|
|
49
|
-
if (
|
|
51
|
+
if (!showHorizontal) {
|
|
50
52
|
var paddingTop = parseFloat(computedStyle.getPropertyValue('padding-top'));
|
|
51
53
|
var paddingBottom = parseFloat(computedStyle.getPropertyValue('padding-bottom'));
|
|
52
54
|
_style = {
|
|
@@ -68,7 +70,18 @@ var TabInk = function TabInk(_ref) {
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
Object.assign(inkRef.current.style, _style);
|
|
71
|
-
}, [activeItemElement,
|
|
73
|
+
}, [activeItemElement, activeTabId, getTabOffset, showHorizontal]);
|
|
74
|
+
React.useEffect(function () {
|
|
75
|
+
setTabLnkPositionStyle();
|
|
76
|
+
}, [setTabLnkPositionStyle]);
|
|
77
|
+
index.useResizeObserver({
|
|
78
|
+
element: activeItemElement,
|
|
79
|
+
getSize: function getSize(element) {
|
|
80
|
+
var itemRect = element.getBoundingClientRect();
|
|
81
|
+
return showHorizontal ? itemRect.width : itemRect.height;
|
|
82
|
+
},
|
|
83
|
+
onResize: setTabLnkPositionStyle
|
|
84
|
+
});
|
|
72
85
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
73
86
|
className: classname.cx(prefixCls + "__ink", (_cx = {}, _cx[prefixCls + "__ink--disabled"] = disabled, _cx)),
|
|
74
87
|
ref: inkRef
|
package/lib/cjs/TabList.js
CHANGED
|
@@ -256,7 +256,7 @@ var TabList = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
256
256
|
}));
|
|
257
257
|
}), type === 'line' ? /*#__PURE__*/React__default["default"].createElement(TabInk.TabInk, {
|
|
258
258
|
prefixCls: prefixCls,
|
|
259
|
-
|
|
259
|
+
showHorizontal: true,
|
|
260
260
|
activeItemElement: itemsRef.current[activeTabId],
|
|
261
261
|
activeTabId: activeTabId,
|
|
262
262
|
getTabOffset: getTabOffset
|
package/lib/esm/TabInk.js
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
|
-
import React, { useRef, useEffect } from 'react';
|
|
10
|
+
import React, { useRef, useCallback, useEffect } from 'react';
|
|
11
11
|
import { cx } from '@hi-ui/classname';
|
|
12
|
+
import { useResizeObserver } from './hooks/index.js';
|
|
12
13
|
|
|
13
14
|
var TabInk = function TabInk(_ref) {
|
|
14
15
|
var _cx;
|
|
@@ -16,11 +17,11 @@ var TabInk = function TabInk(_ref) {
|
|
|
16
17
|
var disabled = _ref.disabled,
|
|
17
18
|
prefixCls = _ref.prefixCls,
|
|
18
19
|
activeItemElement = _ref.activeItemElement,
|
|
19
|
-
direction = _ref.direction,
|
|
20
20
|
activeTabId = _ref.activeTabId,
|
|
21
|
-
getTabOffset = _ref.getTabOffset
|
|
21
|
+
getTabOffset = _ref.getTabOffset,
|
|
22
|
+
showHorizontal = _ref.showHorizontal;
|
|
22
23
|
var inkRef = useRef(null);
|
|
23
|
-
|
|
24
|
+
var setTabLnkPositionStyle = useCallback(function () {
|
|
24
25
|
if (!inkRef.current) return;
|
|
25
26
|
if (!activeItemElement) return;
|
|
26
27
|
var computedStyle = getComputedStyle(activeItemElement);
|
|
@@ -29,7 +30,7 @@ var TabInk = function TabInk(_ref) {
|
|
|
29
30
|
|
|
30
31
|
var _style;
|
|
31
32
|
|
|
32
|
-
if (
|
|
33
|
+
if (!showHorizontal) {
|
|
33
34
|
var paddingTop = parseFloat(computedStyle.getPropertyValue('padding-top'));
|
|
34
35
|
var paddingBottom = parseFloat(computedStyle.getPropertyValue('padding-bottom'));
|
|
35
36
|
_style = {
|
|
@@ -51,7 +52,18 @@ var TabInk = function TabInk(_ref) {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
Object.assign(inkRef.current.style, _style);
|
|
54
|
-
}, [activeItemElement,
|
|
55
|
+
}, [activeItemElement, activeTabId, getTabOffset, showHorizontal]);
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
setTabLnkPositionStyle();
|
|
58
|
+
}, [setTabLnkPositionStyle]);
|
|
59
|
+
useResizeObserver({
|
|
60
|
+
element: activeItemElement,
|
|
61
|
+
getSize: function getSize(element) {
|
|
62
|
+
var itemRect = element.getBoundingClientRect();
|
|
63
|
+
return showHorizontal ? itemRect.width : itemRect.height;
|
|
64
|
+
},
|
|
65
|
+
onResize: setTabLnkPositionStyle
|
|
66
|
+
});
|
|
55
67
|
return /*#__PURE__*/React.createElement("div", {
|
|
56
68
|
className: cx(prefixCls + "__ink", (_cx = {}, _cx[prefixCls + "__ink--disabled"] = disabled, _cx)),
|
|
57
69
|
ref: inkRef
|
package/lib/esm/TabList.js
CHANGED
|
@@ -227,7 +227,7 @@ var TabList = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
227
227
|
}));
|
|
228
228
|
}), type === 'line' ? /*#__PURE__*/React.createElement(TabInk, {
|
|
229
229
|
prefixCls: prefixCls,
|
|
230
|
-
|
|
230
|
+
showHorizontal: true,
|
|
231
231
|
activeItemElement: itemsRef.current[activeTabId],
|
|
232
232
|
activeTabId: activeTabId,
|
|
233
233
|
getTabOffset: getTabOffset
|
package/lib/types/TabInk.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ interface TabInkProps {
|
|
|
4
4
|
prefixCls?: string;
|
|
5
5
|
disabled?: boolean;
|
|
6
6
|
activeItemElement: HTMLElement | null;
|
|
7
|
-
direction: 'vertical' | 'horizontal';
|
|
8
7
|
activeTabId: React.ReactText;
|
|
9
8
|
getTabOffset: (tabId: React.ReactText) => number;
|
|
9
|
+
showHorizontal: boolean;
|
|
10
10
|
}
|
|
11
11
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ui/tabs",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.23",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HIUI <mi-hiui@xiaomi.com>",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@hi-ui/type-assertion": "^4.0.0-beta.5",
|
|
54
54
|
"@hi-ui/use-latest": "^4.0.0-beta.5",
|
|
55
55
|
"@hi-ui/use-uncontrolled-state": "^4.0.0-beta.5",
|
|
56
|
-
"@hi-ui/use-unmount-effect": "^4.0.0-beta.
|
|
56
|
+
"@hi-ui/use-unmount-effect": "^4.0.0-beta.8"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"react": ">=16.8.6",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"react": "^17.0.1",
|
|
65
65
|
"react-dom": "^17.0.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "29f4d9450879b9bffe83ea928fc2491b70d1bcce"
|
|
68
68
|
}
|