@auth0/quantum-product 2.10.8 → 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/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/package.json +6 -1
- 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
|
@@ -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 {};
|
|
@@ -0,0 +1,93 @@
|
|
|
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.useTabListKeyboard = void 0;
|
|
37
|
+
var React = __importStar(require("react"));
|
|
38
|
+
var useTabListKeyboard = function (_a) {
|
|
39
|
+
var containerRef = _a.containerRef, overflowButtonRef = _a.overflowButtonRef, hasOverflow = _a.hasOverflow, menuId = _a.menuId, menuOpen = _a.menuOpen;
|
|
40
|
+
var shouldFocusOverflowMenuRef = React.useRef(false);
|
|
41
|
+
var focusLastVisibleTab = React.useCallback(function () {
|
|
42
|
+
var _a;
|
|
43
|
+
var visibleTabs = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="tab"]');
|
|
44
|
+
var lastVisibleTab = visibleTabs === null || visibleTabs === void 0 ? void 0 : visibleTabs[visibleTabs.length - 1];
|
|
45
|
+
lastVisibleTab === null || lastVisibleTab === void 0 ? void 0 : lastVisibleTab.focus();
|
|
46
|
+
}, [containerRef]);
|
|
47
|
+
var handleTabsKeyDown = React.useCallback(function (event) {
|
|
48
|
+
var _a;
|
|
49
|
+
if (!hasOverflow || !overflowButtonRef.current || event.key !== 'ArrowRight') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var visibleTabs = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="tab"]');
|
|
53
|
+
var lastVisibleTab = visibleTabs === null || visibleTabs === void 0 ? void 0 : visibleTabs[visibleTabs.length - 1];
|
|
54
|
+
if (lastVisibleTab && event.target === lastVisibleTab) {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
overflowButtonRef.current.focus();
|
|
57
|
+
}
|
|
58
|
+
}, [containerRef, hasOverflow, overflowButtonRef]);
|
|
59
|
+
var handleOverflowKeyDown = React.useCallback(function (event) {
|
|
60
|
+
if ((event.key === 'Enter' || event.key === ' ' || event.key === 'Spacebar') && !menuOpen) {
|
|
61
|
+
shouldFocusOverflowMenuRef.current = true;
|
|
62
|
+
}
|
|
63
|
+
if (event.key !== 'ArrowLeft') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
focusLastVisibleTab();
|
|
68
|
+
}, [focusLastVisibleTab, menuOpen]);
|
|
69
|
+
React.useEffect(function () {
|
|
70
|
+
if (!menuOpen || !shouldFocusOverflowMenuRef.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var focusOverflowMenuItem = function () {
|
|
74
|
+
var overflowMenu = document.getElementById(menuId !== null && menuId !== void 0 ? menuId : '');
|
|
75
|
+
if (!overflowMenu) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var nextFocusedItem = overflowMenu.querySelector('[role="menuitem"][aria-selected="true"]:not([aria-disabled="true"])') || overflowMenu.querySelector('[role="menuitem"]:not([aria-disabled="true"])');
|
|
79
|
+
if (!nextFocusedItem) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
nextFocusedItem.focus();
|
|
83
|
+
shouldFocusOverflowMenuRef.current = false;
|
|
84
|
+
};
|
|
85
|
+
var frameId = window.requestAnimationFrame(focusOverflowMenuItem);
|
|
86
|
+
return function () { return window.cancelAnimationFrame(frameId); };
|
|
87
|
+
}, [menuId, menuOpen]);
|
|
88
|
+
return {
|
|
89
|
+
handleTabsKeyDown: handleTabsKeyDown,
|
|
90
|
+
handleOverflowKeyDown: handleOverflowKeyDown,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
exports.useTabListKeyboard = useTabListKeyboard;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IOverflowState } from '../tab-list-utils';
|
|
3
|
+
interface IUseTabListOverflowProps {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
maxVisibleTabs: number;
|
|
6
|
+
moreLabel: string;
|
|
7
|
+
getOverflowCountLabel: (overflowCount: number) => string;
|
|
8
|
+
}
|
|
9
|
+
export declare const useTabListOverflow: ({ children, maxVisibleTabs, moreLabel, getOverflowCountLabel, }: IUseTabListOverflowProps) => {
|
|
10
|
+
value: any;
|
|
11
|
+
onChange: ((value: any) => void) | undefined;
|
|
12
|
+
baseVisibleTabCount: number;
|
|
13
|
+
minimumVisibleTabCount: number;
|
|
14
|
+
defaultTabOrder: unknown[];
|
|
15
|
+
visibleChildren: React.ReactNode[];
|
|
16
|
+
overflowChildren: React.ReactNode[];
|
|
17
|
+
hasOverflow: boolean;
|
|
18
|
+
overflowCountLabel: string;
|
|
19
|
+
isSelectedValueVisible: boolean;
|
|
20
|
+
isSelectedValueInOverflow: boolean;
|
|
21
|
+
handleChange: (_evt: React.SyntheticEvent, newValue: unknown) => void;
|
|
22
|
+
setOverflowState: React.Dispatch<React.SetStateAction<IOverflowState>>;
|
|
23
|
+
promoteTabValue: (tabValue: unknown) => void;
|
|
24
|
+
};
|
|
25
|
+
export {};
|