@auth0/quantum-product 2.10.7 → 2.11.0
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/dropdown-menu/dropdown-menu-list-item/dropdown-menu-list-item.js +2 -1
- package/dropdown-menu/dropdown-menu.js +1 -1
- package/esm/dropdown-menu/dropdown-menu-list-item/dropdown-menu-list-item.js +2 -1
- package/esm/dropdown-menu/dropdown-menu.js +1 -1
- package/esm/icon/index.js +87 -69
- package/esm/tabs/tab/tab-override.js +18 -7
- package/esm/tabs/tab-list/tab-list-overrides.js +94 -0
- package/esm/tabs/tab-list/tab-list-utils.js +29 -0
- package/esm/tabs/tab-list/tab-list.js +111 -10
- package/esm/tabs/tab-list/use-tab-list-indicator/index.js +189 -0
- package/esm/tabs/tab-list/use-tab-list-keyboard/index.js +56 -0
- package/esm/tabs/tab-list/use-tab-list-overflow/index.js +149 -0
- package/esm/tabs/tabs-overrides.js +6 -7
- package/esm/tabs/tabs.js +12 -20
- package/icon/index.d.ts +81 -68
- package/icon/index.js +94 -76
- package/package.json +7 -2
- package/tabs/tab/tab-override.d.ts +1 -1
- package/tabs/tab/tab-override.js +18 -7
- package/tabs/tab-list/tab-list-overrides.d.ts +12 -0
- package/tabs/tab-list/tab-list-overrides.js +97 -0
- package/tabs/tab-list/tab-list-utils.d.ts +32 -0
- package/tabs/tab-list/tab-list-utils.js +70 -0
- package/tabs/tab-list/tab-list.d.ts +9 -2
- package/tabs/tab-list/tab-list.js +111 -11
- package/tabs/tab-list/use-tab-list-indicator/index.d.ts +26 -0
- package/tabs/tab-list/use-tab-list-indicator/index.js +226 -0
- package/tabs/tab-list/use-tab-list-keyboard/index.d.ts +13 -0
- package/tabs/tab-list/use-tab-list-keyboard/index.js +93 -0
- package/tabs/tab-list/use-tab-list-overflow/index.d.ts +25 -0
- package/tabs/tab-list/use-tab-list-overflow/index.js +186 -0
- package/tabs/tabs-overrides.d.ts +1 -1
- package/tabs/tabs-overrides.js +6 -7
- package/tabs/tabs.js +12 -20
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectionIndicator = exports.OverflowLabel = exports.OverflowLabelContainer = exports.OverflowButtonWrapper = exports.TabListContainer = exports.tabListComponentName = void 0;
|
|
4
|
+
var styled_1 = require("../../styled");
|
|
5
|
+
exports.tabListComponentName = 'QuantumTabList';
|
|
6
|
+
exports.TabListContainer = (0, styled_1.styled)('div', {
|
|
7
|
+
name: exports.tabListComponentName,
|
|
8
|
+
slot: 'Root',
|
|
9
|
+
})(function (_a) {
|
|
10
|
+
var theme = _a.theme;
|
|
11
|
+
return ({
|
|
12
|
+
display: 'flex',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
position: 'relative',
|
|
15
|
+
isolation: 'isolate',
|
|
16
|
+
borderBottom: "1px solid ".concat(theme.tokens.color_border_default),
|
|
17
|
+
overflow: 'hidden',
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
exports.OverflowButtonWrapper = (0, styled_1.styled)('div', {
|
|
21
|
+
name: exports.tabListComponentName,
|
|
22
|
+
slot: 'OverflowButtonWrapper',
|
|
23
|
+
})(function (_a) {
|
|
24
|
+
var theme = _a.theme;
|
|
25
|
+
return ({
|
|
26
|
+
display: 'flex',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
marginLeft: theme.spacing(0.5),
|
|
29
|
+
flexShrink: 0,
|
|
30
|
+
height: theme.spacing(3.5),
|
|
31
|
+
marginBottom: theme.spacing(1),
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
exports.OverflowLabelContainer = (0, styled_1.styled)('span', {
|
|
35
|
+
name: exports.tabListComponentName,
|
|
36
|
+
slot: 'OverflowLabelContainer',
|
|
37
|
+
})(function (_a) {
|
|
38
|
+
var theme = _a.theme;
|
|
39
|
+
return ({
|
|
40
|
+
position: 'relative',
|
|
41
|
+
display: 'inline-flex',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
gap: theme.spacing(0.5),
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
exports.OverflowLabel = (0, styled_1.styled)('span', {
|
|
47
|
+
name: exports.tabListComponentName,
|
|
48
|
+
slot: 'OverflowLabel',
|
|
49
|
+
})(function (_a) {
|
|
50
|
+
var theme = _a.theme;
|
|
51
|
+
return ({
|
|
52
|
+
display: 'flex',
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
justifyContent: 'space-between',
|
|
55
|
+
gap: theme.spacing(1),
|
|
56
|
+
fontSize: theme.typography.pxToRem(14),
|
|
57
|
+
fontWeight: theme.typography.fontWeightSemibold,
|
|
58
|
+
color: theme.tokens.color_fg_default,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var TIMING_FUNCTION = 'cubic-bezier(0.19, 1, 0.22, 1)';
|
|
62
|
+
exports.SelectionIndicator = (0, styled_1.styled)('span', {
|
|
63
|
+
name: exports.tabListComponentName,
|
|
64
|
+
slot: 'SelectionIndicator',
|
|
65
|
+
shouldForwardProp: function (prop) { return !['ownerState'].includes(String(prop)); },
|
|
66
|
+
})(function (_a) {
|
|
67
|
+
var theme = _a.theme, _b = _a.ownerState, leftOffset = _b.leftOffset, indicatorWidth = _b.indicatorWidth, isVisible = _b.isVisible;
|
|
68
|
+
return ({
|
|
69
|
+
position: 'absolute',
|
|
70
|
+
top: 0,
|
|
71
|
+
bottom: theme.spacing(1),
|
|
72
|
+
left: 0,
|
|
73
|
+
width: indicatorWidth,
|
|
74
|
+
borderRadius: theme.spacing(0.5),
|
|
75
|
+
backgroundColor: theme.tokens.color_bg_layer_alternate_bold,
|
|
76
|
+
pointerEvents: 'none',
|
|
77
|
+
zIndex: 0,
|
|
78
|
+
opacity: isVisible ? 1 : 0,
|
|
79
|
+
transform: "translate3d(".concat(leftOffset, "px, 0, 0)"),
|
|
80
|
+
willChange: 'transform, width, opacity',
|
|
81
|
+
transition: "transform ".concat(theme.transitions.duration.short, "ms ").concat(TIMING_FUNCTION, ", width ").concat(theme.transitions.duration.short, "ms ").concat(TIMING_FUNCTION, ", opacity ").concat(theme.transitions.duration.short, "ms ").concat(TIMING_FUNCTION),
|
|
82
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
83
|
+
transition: 'none',
|
|
84
|
+
},
|
|
85
|
+
'&::before': {
|
|
86
|
+
content: '""',
|
|
87
|
+
position: 'absolute',
|
|
88
|
+
display: 'block',
|
|
89
|
+
bottom: theme.spacing(-1),
|
|
90
|
+
left: '50%',
|
|
91
|
+
transform: 'translateX(-50%)',
|
|
92
|
+
height: theme.spacing(0.25),
|
|
93
|
+
width: "calc(100% - ".concat(theme.spacing(2), ")"),
|
|
94
|
+
backgroundColor: theme.tokens.color_bg_brand_primary,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type TabChildProps = {
|
|
3
|
+
component?: React.ElementType;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
href?: string;
|
|
6
|
+
label?: React.ReactNode;
|
|
7
|
+
onClick?: (event: React.MouseEvent) => void;
|
|
8
|
+
value?: unknown;
|
|
9
|
+
analyticsId?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type TabChild = React.ReactElement<TabChildProps>;
|
|
13
|
+
export interface IOverflowState {
|
|
14
|
+
overflowCompensation: number;
|
|
15
|
+
orderedTabValues?: unknown[];
|
|
16
|
+
baselineVisibleTabCount: number;
|
|
17
|
+
baselineMoreLabel: string;
|
|
18
|
+
baselineTabOrder: unknown[];
|
|
19
|
+
}
|
|
20
|
+
export declare const isTabChild: (child: React.ReactNode) => child is TabChild;
|
|
21
|
+
export declare const getResolvedChildValue: (child: TabChild, index: number) => unknown;
|
|
22
|
+
export declare const getChildOrderValue: (child: React.ReactNode, index: number) => unknown;
|
|
23
|
+
export declare const areValueArraysEqual: (left: unknown[], right: unknown[]) => boolean;
|
|
24
|
+
interface ICreateOverflowStateProps {
|
|
25
|
+
baseVisibleTabCount: number;
|
|
26
|
+
moreLabel: string;
|
|
27
|
+
defaultTabOrder: unknown[];
|
|
28
|
+
overflowCompensation?: number;
|
|
29
|
+
orderedTabValues?: unknown[];
|
|
30
|
+
}
|
|
31
|
+
export declare const createOverflowState: ({ baseVisibleTabCount, moreLabel, defaultTabOrder, overflowCompensation, orderedTabValues, }: ICreateOverflowStateProps) => IOverflowState;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createOverflowState = exports.areValueArraysEqual = exports.getChildOrderValue = exports.getResolvedChildValue = exports.isTabChild = void 0;
|
|
37
|
+
var React = __importStar(require("react"));
|
|
38
|
+
var isTabChild = function (child) { return React.isValidElement(child); };
|
|
39
|
+
exports.isTabChild = isTabChild;
|
|
40
|
+
var getResolvedChildValue = function (child, index) { var _a; return (_a = child.props.value) !== null && _a !== void 0 ? _a : index; };
|
|
41
|
+
exports.getResolvedChildValue = getResolvedChildValue;
|
|
42
|
+
var getChildOrderValue = function (child, index) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if ((0, exports.isTabChild)(child)) {
|
|
45
|
+
return (_b = (_a = child.props.value) !== null && _a !== void 0 ? _a : child.key) !== null && _b !== void 0 ? _b : index;
|
|
46
|
+
}
|
|
47
|
+
return index;
|
|
48
|
+
};
|
|
49
|
+
exports.getChildOrderValue = getChildOrderValue;
|
|
50
|
+
// Tab selection uses identity equality for object values elsewhere in the tabs stack,
|
|
51
|
+
// so overflow ordering should follow the same semantics.
|
|
52
|
+
var areTabValuesEqual = function (left, right) { return left === right; };
|
|
53
|
+
var areValueArraysEqual = function (left, right) {
|
|
54
|
+
if (left.length !== right.length) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return left.every(function (value, index) { return areTabValuesEqual(value, right[index]); });
|
|
58
|
+
};
|
|
59
|
+
exports.areValueArraysEqual = areValueArraysEqual;
|
|
60
|
+
var createOverflowState = function (_a) {
|
|
61
|
+
var baseVisibleTabCount = _a.baseVisibleTabCount, moreLabel = _a.moreLabel, defaultTabOrder = _a.defaultTabOrder, _b = _a.overflowCompensation, overflowCompensation = _b === void 0 ? 0 : _b, orderedTabValues = _a.orderedTabValues;
|
|
62
|
+
return ({
|
|
63
|
+
overflowCompensation: overflowCompensation,
|
|
64
|
+
orderedTabValues: orderedTabValues,
|
|
65
|
+
baselineVisibleTabCount: baseVisibleTabCount,
|
|
66
|
+
baselineMoreLabel: moreLabel,
|
|
67
|
+
baselineTabOrder: defaultTabOrder,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.createOverflowState = createOverflowState;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { TabsProps } from '@mui/material/Tabs';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export interface ITabListProps extends Omit<TabsProps, 'onChange' | 'value'> {
|
|
4
|
+
/** Maximum number of tabs to show before collapsing into an overflow menu. @default Infinity */
|
|
5
|
+
maxVisibleTabs?: number;
|
|
6
|
+
/** Label for the overflow menu trigger button. @default "More" */
|
|
7
|
+
moreLabel?: string;
|
|
8
|
+
/** Accessible label generator for the overflow menu trigger button count. */
|
|
9
|
+
getOverflowCountLabel?: (overflowCount: number) => string;
|
|
10
|
+
}
|
|
11
|
+
export declare const TabList: React.ForwardRefExoticComponent<Omit<ITabListProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -43,6 +43,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
43
43
|
return result;
|
|
44
44
|
};
|
|
45
45
|
})();
|
|
46
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
47
|
+
var t = {};
|
|
48
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
49
|
+
t[p] = s[p];
|
|
50
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
51
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
52
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
53
|
+
t[p[i]] = s[p[i]];
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
};
|
|
46
57
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
58
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
59
|
};
|
|
@@ -50,15 +61,104 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
61
|
exports.TabList = void 0;
|
|
51
62
|
var React = __importStar(require("react"));
|
|
52
63
|
var Tabs_1 = __importDefault(require("@mui/material/Tabs"));
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
var label_1 = require("../../label");
|
|
65
|
+
var button_1 = require("../../button");
|
|
66
|
+
var dropdown_menu_1 = require("../../dropdown-menu/dropdown-menu");
|
|
67
|
+
var dropdown_menu_list_1 = require("../../dropdown-menu/dropdown-menu-list");
|
|
68
|
+
var dropdown_menu_list_item_1 = require("../../dropdown-menu/dropdown-menu-list-item");
|
|
69
|
+
var dropdown_menu_state_1 = require("../../dropdown-menu/dropdown-menu-state");
|
|
70
|
+
var use_id_1 = require("../../utils/use-id");
|
|
71
|
+
var quantum_icons_1 = require("@auth0/quantum-icons");
|
|
72
|
+
var useForkRef_1 = __importDefault(require("@mui/utils/useForkRef"));
|
|
73
|
+
var tab_list_overrides_1 = require("./tab-list-overrides");
|
|
74
|
+
var tab_list_utils_1 = require("./tab-list-utils");
|
|
75
|
+
var index_1 = require("./use-tab-list-indicator/index");
|
|
76
|
+
var index_2 = require("./use-tab-list-keyboard/index");
|
|
77
|
+
var index_3 = require("./use-tab-list-overflow/index");
|
|
78
|
+
var defaultGetOverflowCountLabel = function (overflowCount) {
|
|
79
|
+
return "".concat(overflowCount, " more tab").concat(overflowCount === 1 ? '' : 's');
|
|
63
80
|
};
|
|
64
|
-
exports.TabList =
|
|
81
|
+
exports.TabList = React.forwardRef(function (_a, ref) {
|
|
82
|
+
var _b;
|
|
83
|
+
var _c = _a.maxVisibleTabs, maxVisibleTabs = _c === void 0 ? Infinity : _c, _d = _a.moreLabel, moreLabel = _d === void 0 ? 'More' : _d, _e = _a.getOverflowCountLabel, getOverflowCountLabel = _e === void 0 ? defaultGetOverflowCountLabel : _e, props = __rest(_a, ["maxVisibleTabs", "moreLabel", "getOverflowCountLabel"]);
|
|
84
|
+
var overflowMenuId = (0, use_id_1.useId)();
|
|
85
|
+
var _f = (0, dropdown_menu_state_1.useDropdownMenuState)({ baseId: "tab-overflow-menu-".concat(overflowMenuId) }), triggerProps = _f.triggerProps, menuProps = _f.menuProps;
|
|
86
|
+
var containerRef = React.useRef(null);
|
|
87
|
+
var handleRef = (0, useForkRef_1.default)(ref, containerRef);
|
|
88
|
+
var overflowRef = React.useRef(null);
|
|
89
|
+
var overflowButtonRef = React.useRef(null);
|
|
90
|
+
var _g = (0, index_3.useTabListOverflow)({
|
|
91
|
+
children: props.children,
|
|
92
|
+
maxVisibleTabs: maxVisibleTabs,
|
|
93
|
+
moreLabel: moreLabel,
|
|
94
|
+
getOverflowCountLabel: getOverflowCountLabel,
|
|
95
|
+
}), value = _g.value, onChange = _g.onChange, baseVisibleTabCount = _g.baseVisibleTabCount, minimumVisibleTabCount = _g.minimumVisibleTabCount, defaultTabOrder = _g.defaultTabOrder, visibleChildren = _g.visibleChildren, overflowChildren = _g.overflowChildren, hasOverflow = _g.hasOverflow, overflowCountLabel = _g.overflowCountLabel, isSelectedValueVisible = _g.isSelectedValueVisible, isSelectedValueInOverflow = _g.isSelectedValueInOverflow, handleChange = _g.handleChange, setOverflowState = _g.setOverflowState, promoteTabValue = _g.promoteTabValue;
|
|
96
|
+
var _h = (0, index_2.useTabListKeyboard)({
|
|
97
|
+
containerRef: containerRef,
|
|
98
|
+
overflowButtonRef: overflowButtonRef,
|
|
99
|
+
hasOverflow: hasOverflow,
|
|
100
|
+
menuId: menuProps.id,
|
|
101
|
+
menuOpen: menuProps.open,
|
|
102
|
+
}), handleTabsKeyDown = _h.handleTabsKeyDown, handleOverflowKeyDown = _h.handleOverflowKeyDown;
|
|
103
|
+
var indicatorState = (0, index_1.useTabListIndicator)({
|
|
104
|
+
containerRef: containerRef,
|
|
105
|
+
overflowRef: overflowRef,
|
|
106
|
+
overflowButtonRef: overflowButtonRef,
|
|
107
|
+
baseVisibleTabCount: baseVisibleTabCount,
|
|
108
|
+
minimumVisibleTabCount: minimumVisibleTabCount,
|
|
109
|
+
moreLabel: moreLabel,
|
|
110
|
+
defaultTabOrder: defaultTabOrder,
|
|
111
|
+
hasOverflow: hasOverflow,
|
|
112
|
+
visibleChildren: visibleChildren,
|
|
113
|
+
overflowChildrenLength: overflowChildren.length,
|
|
114
|
+
isSelectedValueInOverflow: isSelectedValueInOverflow,
|
|
115
|
+
value: value,
|
|
116
|
+
setOverflowState: setOverflowState,
|
|
117
|
+
}).indicatorState;
|
|
118
|
+
return (React.createElement(tab_list_overrides_1.TabListContainer, { ref: handleRef },
|
|
119
|
+
React.createElement(tab_list_overrides_1.SelectionIndicator, { className: (_b = props.classes) === null || _b === void 0 ? void 0 : _b.indicator, ownerState: {
|
|
120
|
+
leftOffset: indicatorState.leftOffset,
|
|
121
|
+
indicatorWidth: indicatorState.indicatorWidth,
|
|
122
|
+
isVisible: indicatorState.isVisible,
|
|
123
|
+
} }),
|
|
124
|
+
React.createElement(Tabs_1.default, __assign({}, props, { TabIndicatorProps: { style: { display: 'none' } }, onChange: onChange ? handleChange : undefined, onKeyDown: handleTabsKeyDown, value: isSelectedValueVisible ? value : false }), visibleChildren),
|
|
125
|
+
hasOverflow && (React.createElement(tab_list_overrides_1.OverflowButtonWrapper, { ref: overflowRef },
|
|
126
|
+
React.createElement(button_1.Button, __assign({}, triggerProps, { ref: overflowButtonRef, "aria-controls": menuProps.open ? triggerProps['aria-controls'] : undefined, "aria-label": overflowCountLabel, "data-selected": isSelectedValueInOverflow ? 'true' : undefined, onKeyDown: handleOverflowKeyDown, label: React.createElement(tab_list_overrides_1.OverflowLabelContainer, null,
|
|
127
|
+
React.createElement(tab_list_overrides_1.OverflowLabel, null,
|
|
128
|
+
moreLabel,
|
|
129
|
+
React.createElement(label_1.Label, { color: "default" }, overflowChildren.length)),
|
|
130
|
+
React.createElement(quantum_icons_1.ChevronDown, { size: 16, color: "currentColor" })), size: "small", variant: "link", sx: function (theme) { return ({
|
|
131
|
+
padding: theme.spacing(0.65, 1),
|
|
132
|
+
transition: 'none',
|
|
133
|
+
'&:hover': { background: 'transparent' },
|
|
134
|
+
'&:hover *': {
|
|
135
|
+
color: theme.tokens.color_fg_bold,
|
|
136
|
+
},
|
|
137
|
+
'&:focus': { outline: 'none' },
|
|
138
|
+
'&:focus-visible': {
|
|
139
|
+
boxShadow: "0 0 0 2px ".concat(theme.tokens.color_border_focus, " inset"),
|
|
140
|
+
transition: 'none',
|
|
141
|
+
},
|
|
142
|
+
}); } })),
|
|
143
|
+
React.createElement(dropdown_menu_1.DropdownMenu, __assign({}, menuProps),
|
|
144
|
+
React.createElement(dropdown_menu_list_1.DropdownMenuList, null, overflowChildren.map(function (child) {
|
|
145
|
+
if (!(0, tab_list_utils_1.isTabChild)(child))
|
|
146
|
+
return null;
|
|
147
|
+
var _a = child.props, label = _a.label, tabValue = _a.value, disabled = _a.disabled, tabOnClick = _a.onClick, _icon = _a.icon, _iconPosition = _a.iconPosition, _labelIcon = _a.labelIcon, _productReleaseStage = _a.productReleaseStage, _sx = _a.sx, _textColor = _a.textColor, _wrapped = _a.wrapped, overflowItemProps = __rest(_a, ["label", "value", "disabled", "onClick", "icon", "iconPosition", "labelIcon", "productReleaseStage", "sx", "textColor", "wrapped"]);
|
|
148
|
+
var isSelected = tabValue === value;
|
|
149
|
+
return (React.createElement(dropdown_menu_list_item_1.DropdownMenuListItem, __assign({ key: String(tabValue), title: label, selected: isSelected, disabled: disabled }, overflowItemProps, { onClick: function (event) {
|
|
150
|
+
if (disabled)
|
|
151
|
+
return;
|
|
152
|
+
if (tabOnClick) {
|
|
153
|
+
tabOnClick(event);
|
|
154
|
+
}
|
|
155
|
+
promoteTabValue(tabValue);
|
|
156
|
+
if (onChange) {
|
|
157
|
+
onChange(tabValue);
|
|
158
|
+
}
|
|
159
|
+
if (menuProps.onClose) {
|
|
160
|
+
menuProps.onClose({}, 'itemSelect');
|
|
161
|
+
}
|
|
162
|
+
} })));
|
|
163
|
+
})))))));
|
|
164
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IOverflowState } from '../tab-list-utils';
|
|
3
|
+
interface IIndicatorState {
|
|
4
|
+
leftOffset: number;
|
|
5
|
+
indicatorWidth: number;
|
|
6
|
+
isVisible: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface IUseTabListIndicatorProps {
|
|
9
|
+
containerRef: React.RefObject<HTMLDivElement>;
|
|
10
|
+
overflowRef: React.RefObject<HTMLDivElement>;
|
|
11
|
+
overflowButtonRef: React.RefObject<HTMLButtonElement>;
|
|
12
|
+
baseVisibleTabCount: number;
|
|
13
|
+
minimumVisibleTabCount: number;
|
|
14
|
+
moreLabel: string;
|
|
15
|
+
defaultTabOrder: unknown[];
|
|
16
|
+
hasOverflow: boolean;
|
|
17
|
+
visibleChildren: React.ReactNode[];
|
|
18
|
+
overflowChildrenLength: number;
|
|
19
|
+
isSelectedValueInOverflow: boolean;
|
|
20
|
+
value: unknown;
|
|
21
|
+
setOverflowState: React.Dispatch<React.SetStateAction<IOverflowState>>;
|
|
22
|
+
}
|
|
23
|
+
export declare const useTabListIndicator: ({ containerRef, overflowRef, overflowButtonRef, baseVisibleTabCount, minimumVisibleTabCount, moreLabel, defaultTabOrder, hasOverflow, visibleChildren, overflowChildrenLength, isSelectedValueInOverflow, value, setOverflowState, }: IUseTabListIndicatorProps) => {
|
|
24
|
+
indicatorState: IIndicatorState;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
47
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
48
|
+
if (!m) return o;
|
|
49
|
+
var i = m.call(o), r, ar = [], e;
|
|
50
|
+
try {
|
|
51
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
52
|
+
}
|
|
53
|
+
catch (error) { e = { error: error }; }
|
|
54
|
+
finally {
|
|
55
|
+
try {
|
|
56
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
57
|
+
}
|
|
58
|
+
finally { if (e) throw e.error; }
|
|
59
|
+
}
|
|
60
|
+
return ar;
|
|
61
|
+
};
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.useTabListIndicator = void 0;
|
|
64
|
+
var React = __importStar(require("react"));
|
|
65
|
+
var tab_list_utils_1 = require("../tab-list-utils");
|
|
66
|
+
var RESIZE_SETTLE_DELAY = 120;
|
|
67
|
+
var HIDDEN_INDICATOR_STATE = { leftOffset: 0, indicatorWidth: 0, isVisible: false };
|
|
68
|
+
var getHiddenIndicatorState = function (currentValue) {
|
|
69
|
+
if (currentValue.isVisible === HIDDEN_INDICATOR_STATE.isVisible &&
|
|
70
|
+
currentValue.leftOffset === HIDDEN_INDICATOR_STATE.leftOffset &&
|
|
71
|
+
currentValue.indicatorWidth === HIDDEN_INDICATOR_STATE.indicatorWidth) {
|
|
72
|
+
return currentValue;
|
|
73
|
+
}
|
|
74
|
+
return HIDDEN_INDICATOR_STATE;
|
|
75
|
+
};
|
|
76
|
+
var useTabListIndicator = function (_a) {
|
|
77
|
+
var containerRef = _a.containerRef, overflowRef = _a.overflowRef, overflowButtonRef = _a.overflowButtonRef, baseVisibleTabCount = _a.baseVisibleTabCount, minimumVisibleTabCount = _a.minimumVisibleTabCount, moreLabel = _a.moreLabel, defaultTabOrder = _a.defaultTabOrder, hasOverflow = _a.hasOverflow, visibleChildren = _a.visibleChildren, overflowChildrenLength = _a.overflowChildrenLength, isSelectedValueInOverflow = _a.isSelectedValueInOverflow, value = _a.value, setOverflowState = _a.setOverflowState;
|
|
78
|
+
var _b = __read(React.useState(0), 2), measurementVersion = _b[0], setMeasurementVersion = _b[1];
|
|
79
|
+
var _c = __read(React.useState(HIDDEN_INDICATOR_STATE), 2), indicatorState = _c[0], setIndicatorState = _c[1];
|
|
80
|
+
var resizeResetTimeoutRef = React.useRef();
|
|
81
|
+
var previousContainerWidthRef = React.useRef(null);
|
|
82
|
+
var clearResizeResetTimeout = React.useCallback(function () {
|
|
83
|
+
if (resizeResetTimeoutRef.current === undefined) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
window.clearTimeout(resizeResetTimeoutRef.current);
|
|
87
|
+
resizeResetTimeoutRef.current = undefined;
|
|
88
|
+
}, []);
|
|
89
|
+
React.useLayoutEffect(function () {
|
|
90
|
+
if (!hasOverflow || !containerRef.current || !overflowRef.current) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
var visibleTabs = containerRef.current.querySelectorAll('[role="tab"]');
|
|
94
|
+
var firstVisibleTab = visibleTabs[0];
|
|
95
|
+
var lastVisibleTab = visibleTabs[visibleTabs.length - 1];
|
|
96
|
+
if (!firstVisibleTab || !lastVisibleTab) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var containerRect = containerRef.current.getBoundingClientRect();
|
|
100
|
+
var firstVisibleTabRect = firstVisibleTab.getBoundingClientRect();
|
|
101
|
+
var lastVisibleTabRect = lastVisibleTab.getBoundingClientRect();
|
|
102
|
+
var overflowRect = overflowRef.current.getBoundingClientRect();
|
|
103
|
+
if (containerRect.width === 0 ||
|
|
104
|
+
firstVisibleTabRect.width === 0 ||
|
|
105
|
+
lastVisibleTabRect.width === 0 ||
|
|
106
|
+
overflowRect.width === 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
var isClippedAtStart = firstVisibleTabRect.left < containerRect.left;
|
|
110
|
+
var overlapsOverflowTrigger = lastVisibleTabRect.right >= overflowRect.left;
|
|
111
|
+
if (isClippedAtStart || overlapsOverflowTrigger) {
|
|
112
|
+
setOverflowState(function (currentValue) {
|
|
113
|
+
var nextOverflowCompensation = Math.min(currentValue.overflowCompensation + 1, baseVisibleTabCount - minimumVisibleTabCount);
|
|
114
|
+
if (nextOverflowCompensation === currentValue.overflowCompensation) {
|
|
115
|
+
return currentValue;
|
|
116
|
+
}
|
|
117
|
+
return __assign(__assign({}, currentValue), { overflowCompensation: nextOverflowCompensation, baselineVisibleTabCount: baseVisibleTabCount, baselineMoreLabel: moreLabel, baselineTabOrder: defaultTabOrder });
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}, [
|
|
121
|
+
baseVisibleTabCount,
|
|
122
|
+
containerRef,
|
|
123
|
+
defaultTabOrder,
|
|
124
|
+
measurementVersion,
|
|
125
|
+
minimumVisibleTabCount,
|
|
126
|
+
moreLabel,
|
|
127
|
+
hasOverflow,
|
|
128
|
+
overflowChildrenLength,
|
|
129
|
+
overflowRef,
|
|
130
|
+
setOverflowState,
|
|
131
|
+
visibleChildren,
|
|
132
|
+
]);
|
|
133
|
+
React.useLayoutEffect(function () {
|
|
134
|
+
if (!containerRef.current) {
|
|
135
|
+
setIndicatorState(getHiddenIndicatorState);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
var selectedVisibleTab = containerRef.current.querySelector('[role="tab"][aria-selected="true"]');
|
|
139
|
+
var indicatorTarget = selectedVisibleTab || (isSelectedValueInOverflow ? overflowButtonRef.current : null);
|
|
140
|
+
if (!indicatorTarget) {
|
|
141
|
+
setIndicatorState(getHiddenIndicatorState);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
var containerRect = containerRef.current.getBoundingClientRect();
|
|
145
|
+
var targetRect = indicatorTarget.getBoundingClientRect();
|
|
146
|
+
if (containerRect.width === 0 || targetRect.width === 0) {
|
|
147
|
+
setIndicatorState(getHiddenIndicatorState);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
var nextIndicatorState = {
|
|
151
|
+
leftOffset: targetRect.left - containerRect.left,
|
|
152
|
+
indicatorWidth: targetRect.width,
|
|
153
|
+
isVisible: true,
|
|
154
|
+
};
|
|
155
|
+
setIndicatorState(function (currentValue) {
|
|
156
|
+
if (currentValue.isVisible === nextIndicatorState.isVisible &&
|
|
157
|
+
currentValue.leftOffset === nextIndicatorState.leftOffset &&
|
|
158
|
+
currentValue.indicatorWidth === nextIndicatorState.indicatorWidth) {
|
|
159
|
+
return currentValue;
|
|
160
|
+
}
|
|
161
|
+
return nextIndicatorState;
|
|
162
|
+
});
|
|
163
|
+
}, [
|
|
164
|
+
containerRef,
|
|
165
|
+
isSelectedValueInOverflow,
|
|
166
|
+
measurementVersion,
|
|
167
|
+
overflowButtonRef,
|
|
168
|
+
overflowChildrenLength,
|
|
169
|
+
value,
|
|
170
|
+
visibleChildren,
|
|
171
|
+
]);
|
|
172
|
+
React.useLayoutEffect(function () {
|
|
173
|
+
if (!containerRef.current || typeof ResizeObserver === 'undefined') {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
previousContainerWidthRef.current = containerRef.current.getBoundingClientRect().width;
|
|
177
|
+
var observer = new ResizeObserver(function () {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
var nextContainerWidth = (_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) !== null && _b !== void 0 ? _b : 0;
|
|
180
|
+
var previousContainerWidth = previousContainerWidthRef.current;
|
|
181
|
+
var isExpanding = previousContainerWidth !== null && nextContainerWidth > previousContainerWidth;
|
|
182
|
+
previousContainerWidthRef.current = nextContainerWidth;
|
|
183
|
+
if (isExpanding) {
|
|
184
|
+
clearResizeResetTimeout();
|
|
185
|
+
resizeResetTimeoutRef.current = window.setTimeout(function () {
|
|
186
|
+
setOverflowState(function (currentValue) {
|
|
187
|
+
if (currentValue.overflowCompensation === 0) {
|
|
188
|
+
return currentValue;
|
|
189
|
+
}
|
|
190
|
+
return (0, tab_list_utils_1.createOverflowState)({
|
|
191
|
+
baseVisibleTabCount: baseVisibleTabCount,
|
|
192
|
+
moreLabel: moreLabel,
|
|
193
|
+
defaultTabOrder: defaultTabOrder,
|
|
194
|
+
overflowCompensation: 0,
|
|
195
|
+
orderedTabValues: currentValue.orderedTabValues,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
setMeasurementVersion(function (currentValue) { return currentValue + 1; });
|
|
199
|
+
resizeResetTimeoutRef.current = undefined;
|
|
200
|
+
}, RESIZE_SETTLE_DELAY);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
clearResizeResetTimeout();
|
|
204
|
+
}
|
|
205
|
+
setMeasurementVersion(function (currentValue) { return currentValue + 1; });
|
|
206
|
+
});
|
|
207
|
+
observer.observe(containerRef.current);
|
|
208
|
+
if (overflowRef.current) {
|
|
209
|
+
observer.observe(overflowRef.current);
|
|
210
|
+
}
|
|
211
|
+
return function () {
|
|
212
|
+
clearResizeResetTimeout();
|
|
213
|
+
observer.disconnect();
|
|
214
|
+
};
|
|
215
|
+
}, [
|
|
216
|
+
baseVisibleTabCount,
|
|
217
|
+
clearResizeResetTimeout,
|
|
218
|
+
containerRef,
|
|
219
|
+
defaultTabOrder,
|
|
220
|
+
moreLabel,
|
|
221
|
+
overflowRef,
|
|
222
|
+
setOverflowState,
|
|
223
|
+
]);
|
|
224
|
+
return { indicatorState: indicatorState };
|
|
225
|
+
};
|
|
226
|
+
exports.useTabListIndicator = useTabListIndicator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface IUseTabListKeyboardProps {
|
|
3
|
+
containerRef: React.RefObject<HTMLDivElement>;
|
|
4
|
+
overflowButtonRef: React.RefObject<HTMLButtonElement>;
|
|
5
|
+
hasOverflow: boolean;
|
|
6
|
+
menuId?: string;
|
|
7
|
+
menuOpen: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const useTabListKeyboard: ({ containerRef, overflowButtonRef, hasOverflow, menuId, menuOpen, }: IUseTabListKeyboardProps) => {
|
|
10
|
+
handleTabsKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
11
|
+
handleOverflowKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
|
|
12
|
+
};
|
|
13
|
+
export {};
|