@rescui/tab-list 0.13.3 → 0.13.5
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/_virtual/index.css.js +7 -7
- package/lib/_virtual/left.js +8 -9
- package/lib/_virtual/right.js +8 -9
- package/lib/index.css +81 -187
- package/lib/parts/deep-map.js +4 -7
- package/lib/parts/separator.p.module.css.js +3 -3
- package/lib/parts/tab-list-context.js +3 -5
- package/lib/parts/tab-list.p.module.css.js +15 -15
- package/lib/parts/tab-separator.js +6 -4
- package/lib/parts/tab.js +36 -50
- package/lib/parts/use-indicator.js +27 -44
- package/lib/parts/use-scrollable-list.js +115 -137
- package/lib/parts/with-scroll-arrows.js +37 -55
- package/lib/parts/with-scroll-arrows.p.module.css.js +11 -11
- package/lib/tab-list.js +24 -26
- package/package.json +9 -10
- package/lib/parts/use-resize-observer.d.ts +0 -2
- package/lib/parts/use-resize-observer.js +0 -46
package/lib/parts/deep-map.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
2
1
|
import React, { isValidElement, cloneElement } from 'react';
|
|
3
2
|
|
|
4
3
|
function deepMap(children, fn) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
9
|
-
var returnChild = child;
|
|
4
|
+
const processChild = function (child) {
|
|
5
|
+
let i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
6
|
+
let returnChild = child;
|
|
10
7
|
|
|
11
8
|
if (! /*#__PURE__*/isValidElement(returnChild)) {
|
|
12
9
|
return returnChild;
|
|
@@ -26,7 +23,7 @@ function deepMap(children, fn) {
|
|
|
26
23
|
return processChild(children);
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
return
|
|
26
|
+
return React.Children.map(children, processChild);
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
export { deepMap };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
|
-
|
|
2
|
+
const TabListContext = /*#__PURE__*/createContext({
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
4
|
-
onChange:
|
|
4
|
+
onChange: () => {},
|
|
5
5
|
selectedId: 0
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
return useContext(TabListContext);
|
|
10
|
-
};
|
|
8
|
+
const useTabListContext = () => useContext(TabListContext);
|
|
11
9
|
|
|
12
10
|
export { TabListContext, useTabListContext };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"light": "
|
|
3
|
-
"dark": "
|
|
4
|
-
"sizeM": "
|
|
5
|
-
"sizeL": "
|
|
6
|
-
"classic": "
|
|
7
|
-
"rock": "
|
|
8
|
-
"sparse": "
|
|
9
|
-
"short": "
|
|
10
|
-
"tabsContainer": "
|
|
11
|
-
"indicator": "
|
|
12
|
-
"iconLeft": "
|
|
13
|
-
"iconRight": "
|
|
14
|
-
"tab": "
|
|
15
|
-
"selected": "
|
|
16
|
-
"icon": "
|
|
2
|
+
"light": "_light_yqgmx8_7",
|
|
3
|
+
"dark": "_dark_yqgmx8_10",
|
|
4
|
+
"sizeM": "_sizeM_yqgmx8_14",
|
|
5
|
+
"sizeL": "_sizeL_yqgmx8_17",
|
|
6
|
+
"classic": "_classic_yqgmx8_21",
|
|
7
|
+
"rock": "_rock_yqgmx8_24",
|
|
8
|
+
"sparse": "_sparse_yqgmx8_28",
|
|
9
|
+
"short": "_short_yqgmx8_32",
|
|
10
|
+
"tabsContainer": "_tabsContainer_yqgmx8_36",
|
|
11
|
+
"indicator": "_indicator_yqgmx8_46",
|
|
12
|
+
"iconLeft": "_iconLeft_yqgmx8_61",
|
|
13
|
+
"iconRight": "_iconRight_yqgmx8_64",
|
|
14
|
+
"tab": "_tab_yqgmx8_36",
|
|
15
|
+
"selected": "_selected_yqgmx8_154",
|
|
16
|
+
"icon": "_icon_yqgmx8_61"
|
|
17
17
|
};
|
|
18
18
|
export { styles as default };
|
|
@@ -3,10 +3,12 @@ import cn from 'classnames';
|
|
|
3
3
|
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
4
4
|
import styles from './separator.p.module.css.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const TabSeparator = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
className,
|
|
9
|
+
theme: themeFromProps
|
|
10
|
+
} = _ref;
|
|
11
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
10
12
|
return /*#__PURE__*/React.createElement("div", {
|
|
11
13
|
className: cn(styles.separator, styles[theme], className)
|
|
12
14
|
});
|
package/lib/parts/tab.js
CHANGED
|
@@ -1,81 +1,67 @@
|
|
|
1
|
-
import "core-js/modules/es.object.to-string.js";
|
|
2
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
4
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
5
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
6
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
7
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
8
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
9
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
10
|
-
var _excluded = ["value", "className", "children", "icon", "iconPosition", "itemId", "onClick", "onKeyDown", "data-e2e"];
|
|
11
|
-
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
-
|
|
16
1
|
import React, { forwardRef, cloneElement } from 'react';
|
|
17
2
|
import PropTypes from 'prop-types';
|
|
18
3
|
import cn from 'classnames';
|
|
19
4
|
import styles from './tab-list.p.module.css.js';
|
|
20
5
|
import { useTabListContext } from './tab-list-context.js';
|
|
21
|
-
|
|
6
|
+
const TabTag = /*#__PURE__*/forwardRef((props, ref) => {
|
|
22
7
|
if (typeof props.href !== 'undefined') {
|
|
23
|
-
return /*#__PURE__*/React.createElement("a",
|
|
24
|
-
ref: ref
|
|
25
|
-
|
|
8
|
+
return /*#__PURE__*/React.createElement("a", {
|
|
9
|
+
ref: ref,
|
|
10
|
+
...props
|
|
11
|
+
}, props.children);
|
|
26
12
|
}
|
|
27
13
|
|
|
28
|
-
return /*#__PURE__*/React.createElement("button",
|
|
29
|
-
ref: ref
|
|
30
|
-
|
|
14
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
15
|
+
ref: ref,
|
|
16
|
+
...props,
|
|
31
17
|
type: "button"
|
|
32
|
-
}
|
|
18
|
+
}, props.children);
|
|
33
19
|
});
|
|
34
20
|
TabTag.displayName = 'TabTag';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return /*#__PURE__*/React.createElement(TabTag,
|
|
21
|
+
const Tab = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
22
|
+
let {
|
|
23
|
+
value,
|
|
24
|
+
className,
|
|
25
|
+
children,
|
|
26
|
+
icon,
|
|
27
|
+
iconPosition = 'left',
|
|
28
|
+
itemId,
|
|
29
|
+
onClick,
|
|
30
|
+
onKeyDown,
|
|
31
|
+
['data-e2e']: e2eId,
|
|
32
|
+
...restProps
|
|
33
|
+
} = _ref;
|
|
34
|
+
const {
|
|
35
|
+
onChange,
|
|
36
|
+
selectedId
|
|
37
|
+
} = useTabListContext();
|
|
38
|
+
const selected = itemId === selectedId;
|
|
39
|
+
return /*#__PURE__*/React.createElement(TabTag, { ...restProps,
|
|
54
40
|
className: cn(styles.tab, selected && styles.selected, iconPosition === 'right' ? styles.iconRight : styles.iconLeft, className),
|
|
55
|
-
onClick:
|
|
56
|
-
if (
|
|
57
|
-
|
|
41
|
+
onClick: e => {
|
|
42
|
+
if (onClick) {
|
|
43
|
+
onClick(e);
|
|
58
44
|
}
|
|
59
45
|
|
|
60
46
|
onChange(value);
|
|
61
47
|
},
|
|
62
|
-
onKeyDown:
|
|
48
|
+
onKeyDown: e => {
|
|
63
49
|
if (e.key === ' ') {
|
|
64
50
|
e.target.click();
|
|
65
51
|
e.preventDefault();
|
|
66
52
|
}
|
|
67
53
|
|
|
68
|
-
if (
|
|
69
|
-
|
|
54
|
+
if (onKeyDown) {
|
|
55
|
+
onKeyDown(e);
|
|
70
56
|
}
|
|
71
57
|
},
|
|
72
58
|
role: "tab",
|
|
73
59
|
tabIndex: 0,
|
|
74
60
|
ref: ref,
|
|
75
61
|
"data-e2e": e2eId,
|
|
76
|
-
"data-test":
|
|
62
|
+
"data-test": `tab${selected ? ' tab-selected' : ''}`,
|
|
77
63
|
"data-rs-internal": 'tab-list__tab'
|
|
78
|
-
}
|
|
64
|
+
}, icon && /*#__PURE__*/cloneElement(icon, {
|
|
79
65
|
className: cn(icon.props.className, styles.icon)
|
|
80
66
|
}), /*#__PURE__*/React.createElement("div", null, children));
|
|
81
67
|
});
|
|
@@ -1,67 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
4
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
5
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
6
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
7
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
8
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
9
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
|
|
15
|
-
import { useState, useCallback } from 'react';
|
|
16
|
-
import { useResizeObserver } from './use-resize-observer.js';
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
17
3
|
|
|
18
4
|
function calculateIndicator(activeNodeRef, parentNode) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
const childPos = activeNodeRef.getBoundingClientRect();
|
|
6
|
+
const parentPos = parentNode.getBoundingClientRect();
|
|
7
|
+
const left = `${childPos.left - parentPos.left + parentNode.scrollLeft}px`;
|
|
8
|
+
const width = `${childPos.width}px`;
|
|
23
9
|
return {
|
|
24
|
-
left
|
|
25
|
-
width
|
|
10
|
+
left,
|
|
11
|
+
width
|
|
26
12
|
};
|
|
27
13
|
}
|
|
28
14
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
const useIndicator = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
activeNodeRef,
|
|
18
|
+
containerRef,
|
|
19
|
+
triggers
|
|
20
|
+
} = _ref;
|
|
21
|
+
const [indicator, setIndicator] = useState({
|
|
35
22
|
left: 0,
|
|
36
23
|
width: 0
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
indicator = _useState2[0],
|
|
40
|
-
setIndicator = _useState2[1];
|
|
41
|
-
|
|
42
|
-
var _useState3 = useState(true),
|
|
43
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
44
|
-
isSSR = _useState4[0],
|
|
45
|
-
setIsSSR = _useState4[1]; // Catch the resize of the container which is happening when the fonts downloads for example
|
|
46
|
-
// Also on value changing the resize observer will reattach itself, which triggers the function
|
|
24
|
+
});
|
|
25
|
+
const [isSSR, setIsSSR] = useState(true); // Catch the resize of the container which is happening when the fonts downloads for example
|
|
47
26
|
|
|
48
|
-
|
|
49
|
-
var onResize = useCallback(function () {
|
|
27
|
+
const onResize = () => {
|
|
50
28
|
if (!activeNodeRef.current || !containerRef.current) {
|
|
51
29
|
return;
|
|
52
30
|
}
|
|
53
31
|
|
|
54
32
|
if (isSSR) {
|
|
55
33
|
setIsSSR(false);
|
|
56
|
-
setIndicator(
|
|
34
|
+
setIndicator({ ...calculateIndicator(activeNodeRef.current, containerRef.current),
|
|
57
35
|
transitionDuration: '0ms'
|
|
58
|
-
})
|
|
36
|
+
});
|
|
59
37
|
return;
|
|
60
38
|
}
|
|
61
39
|
|
|
62
40
|
setIndicator(calculateIndicator(activeNodeRef.current, containerRef.current));
|
|
63
|
-
}
|
|
64
|
-
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
useResizeObserver(containerRef, onResize, {
|
|
44
|
+
ignoreFirstCall: true
|
|
45
|
+
}); // Also trigger it on value change for example
|
|
46
|
+
|
|
47
|
+
useEffect(onResize, triggers);
|
|
65
48
|
return indicator;
|
|
66
49
|
};
|
|
67
50
|
|