@primer/react 0.0.0-20260612121015 → 0.0.0-20260612172313
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 +13 -14
- package/dist/ActionList/Group.d.ts +0 -5
- package/dist/ActionList/Group.d.ts.map +1 -1
- package/dist/ActionList/Group.js +2 -5
- package/dist/ActionList/GroupContext.d.ts +8 -0
- package/dist/ActionList/GroupContext.d.ts.map +1 -0
- package/dist/ActionList/GroupContext.js +8 -0
- package/dist/ActionList/Item.js +3 -2
- package/dist/ActionList/Selection.js +1 -1
- package/dist/ActionList/index.d.ts.map +1 -1
- package/dist/ActionList/index.js +2 -1
- package/dist/ActionMenu/ActionMenu.d.ts.map +1 -1
- package/dist/ActionMenu/ActionMenu.js +6 -2
- package/dist/AnchoredOverlay/AnchoredOverlay.d.ts.map +1 -1
- package/dist/AnchoredOverlay/AnchoredOverlay.js +3 -1
- package/dist/Autocomplete/AutocompleteInput.d.ts.map +1 -1
- package/dist/Autocomplete/AutocompleteInput.js +2 -1
- package/dist/Autocomplete/AutocompleteMenu.d.ts.map +1 -1
- package/dist/Autocomplete/AutocompleteMenu.js +1 -0
- package/dist/Autocomplete/AutocompleteOverlay.d.ts.map +1 -1
- package/dist/Autocomplete/AutocompleteOverlay.js +1 -0
- package/dist/Button/IconButton.d.ts.map +1 -1
- package/dist/Button/IconButton.js +3 -2
- package/dist/ConfirmationDialog/ConfirmationDialog.d.ts +0 -9
- package/dist/ConfirmationDialog/ConfirmationDialog.d.ts.map +1 -1
- package/dist/ConfirmationDialog/ConfirmationDialog.js +1 -42
- package/dist/ConfirmationDialog/useConfirm.d.ts +12 -0
- package/dist/ConfirmationDialog/useConfirm.d.ts.map +1 -0
- package/dist/ConfirmationDialog/useConfirm.js +44 -0
- package/dist/Dialog/Dialog.d.ts +0 -1
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +2 -4
- package/dist/Dialog/DialogContext.d.ts +3 -0
- package/dist/Dialog/DialogContext.d.ts.map +1 -0
- package/dist/Dialog/DialogContext.js +5 -0
- package/dist/FilteredActionList/FilteredActionList.js +2 -1
- package/dist/FilteredActionList/FilteredActionListLoaders.d.ts +2 -10
- package/dist/FilteredActionList/FilteredActionListLoaders.d.ts.map +1 -1
- package/dist/FilteredActionList/FilteredActionListLoaders.js +3 -12
- package/dist/FilteredActionList/constants.d.ts +11 -0
- package/dist/FilteredActionList/constants.d.ts.map +1 -0
- package/dist/FilteredActionList/constants.js +13 -0
- package/dist/FilteredActionList/index.js +0 -1
- package/dist/KeybindingHint/KeybindingHint.d.ts +0 -14
- package/dist/KeybindingHint/KeybindingHint.d.ts.map +1 -1
- package/dist/KeybindingHint/KeybindingHint.js +2 -16
- package/dist/KeybindingHint/components/Chord.d.ts +0 -3
- package/dist/KeybindingHint/components/Chord.d.ts.map +1 -1
- package/dist/KeybindingHint/components/Chord.js +2 -21
- package/dist/KeybindingHint/components/Sequence.d.ts +0 -3
- package/dist/KeybindingHint/components/Sequence.d.ts.map +1 -1
- package/dist/KeybindingHint/components/Sequence.js +2 -5
- package/dist/KeybindingHint/components/utils.d.ts +8 -0
- package/dist/KeybindingHint/components/utils.d.ts.map +1 -0
- package/dist/KeybindingHint/components/utils.js +32 -0
- package/dist/KeybindingHint/index.d.ts +2 -1
- package/dist/KeybindingHint/index.d.ts.map +1 -1
- package/dist/KeybindingHint/utils.d.ts +15 -0
- package/dist/KeybindingHint/utils.d.ts.map +1 -0
- package/dist/KeybindingHint/utils.js +17 -0
- package/dist/NavList/NavList.d.ts.map +1 -1
- package/dist/NavList/NavList.js +4 -0
- package/dist/Overlay/Overlay.d.ts +2 -18
- package/dist/Overlay/Overlay.d.ts.map +1 -1
- package/dist/Overlay/Overlay.js +1 -20
- package/dist/Overlay/constants.d.ts +19 -0
- package/dist/Overlay/constants.d.ts.map +1 -0
- package/dist/Overlay/constants.js +20 -0
- package/dist/PageHeader/PageHeader.d.ts.map +1 -1
- package/dist/PageHeader/PageHeader.js +63 -35
- package/dist/Portal/Portal.d.ts +0 -14
- package/dist/Portal/Portal.d.ts.map +1 -1
- package/dist/Portal/Portal.js +4 -46
- package/dist/Portal/PortalContext.d.ts +5 -0
- package/dist/Portal/PortalContext.d.ts.map +1 -0
- package/dist/Portal/PortalContext.js +5 -0
- package/dist/Portal/index.d.ts +3 -1
- package/dist/Portal/index.d.ts.map +1 -1
- package/dist/Portal/index.js +0 -1
- package/dist/Portal/portalRoot.d.ts +11 -0
- package/dist/Portal/portalRoot.d.ts.map +1 -0
- package/dist/Portal/portalRoot.js +39 -0
- package/dist/Radio/Radio.js +1 -1
- package/dist/RadioGroup/RadioGroup.d.ts +1 -6
- package/dist/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/RadioGroup/RadioGroup.js +2 -3
- package/dist/RadioGroup/RadioGroupContext.d.ts +7 -0
- package/dist/RadioGroup/RadioGroupContext.d.ts.map +1 -0
- package/dist/RadioGroup/RadioGroupContext.js +5 -0
- package/dist/RadioGroup/index.d.ts +2 -1
- package/dist/RadioGroup/index.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +2 -1
- package/dist/TextInput/TextInput.d.ts +6 -0
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +2 -1
- package/dist/ThemeContext.d.ts +15 -0
- package/dist/ThemeContext.d.ts.map +1 -0
- package/dist/ThemeContext.js +9 -0
- package/dist/ThemeProvider.d.ts +1 -14
- package/dist/ThemeProvider.d.ts.map +1 -1
- package/dist/ThemeProvider.js +3 -18
- package/dist/Timeline/Timeline.d.ts +1 -1
- package/dist/Timeline/Timeline.d.ts.map +1 -1
- package/dist/Timeline/constants.d.ts +2 -0
- package/dist/Timeline/constants.d.ts.map +1 -0
- package/dist/Token/IssueLabelToken.d.ts.map +1 -1
- package/dist/Token/IssueLabelToken.js +3 -1
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +3 -1
- package/dist/Token/TokenBase.d.ts +2 -5
- package/dist/Token/TokenBase.d.ts.map +1 -1
- package/dist/Token/TokenBase.js +3 -14
- package/dist/Token/_RemoveTokenButton.js +1 -1
- package/dist/Token/constants.d.ts +4 -0
- package/dist/Token/constants.d.ts.map +1 -0
- package/dist/Token/constants.js +3 -0
- package/dist/Token/utils.d.ts +3 -0
- package/dist/Token/utils.d.ts.map +1 -0
- package/dist/Token/utils.js +14 -0
- package/dist/Tooltip/Tooltip.d.ts +0 -3
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +2 -3
- package/dist/Tooltip/TooltipContext.d.ts +5 -0
- package/dist/Tooltip/TooltipContext.d.ts.map +1 -0
- package/dist/Tooltip/TooltipContext.js +5 -0
- package/dist/TooltipV2/Tooltip.d.ts +0 -3
- package/dist/TooltipV2/Tooltip.d.ts.map +1 -1
- package/dist/TooltipV2/Tooltip.js +4 -3
- package/dist/TooltipV2/TooltipContext.d.ts +5 -0
- package/dist/TooltipV2/TooltipContext.d.ts.map +1 -0
- package/dist/TooltipV2/TooltipContext.js +5 -0
- package/dist/TreeView/TreeView.js +1 -1
- package/dist/UnderlineNav/UnderlineNav.d.ts +1 -0
- package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
- package/dist/UnderlineNav/UnderlineNav.js +124 -267
- package/dist/UnderlineNav/UnderlineNavContext.d.ts +10 -1
- package/dist/UnderlineNav/UnderlineNavContext.d.ts.map +1 -1
- package/dist/UnderlineNav/UnderlineNavContext.js +2 -0
- package/dist/UnderlineNav/UnderlineNavItem.d.ts +1 -3
- package/dist/UnderlineNav/UnderlineNavItem.d.ts.map +1 -1
- package/dist/UnderlineNav/UnderlineNavItem.js +22 -7
- package/dist/UnderlineNav/types.d.ts +5 -1
- package/dist/UnderlineNav/types.d.ts.map +1 -1
- package/dist/UnderlineNav/utils.d.ts +3 -0
- package/dist/UnderlineNav/utils.d.ts.map +1 -0
- package/dist/UnderlineNav/utils.js +8 -0
- package/dist/experimental/SelectPanel2/SelectPanel.d.ts.map +1 -1
- package/dist/experimental/SelectPanel2/SelectPanel.js +2 -1
- package/dist/experimental/SelectPanel2/index.d.ts +2 -1
- package/dist/experimental/SelectPanel2/index.d.ts.map +1 -1
- package/dist/experimental/Tabs/Tabs.d.ts +3 -111
- package/dist/experimental/Tabs/Tabs.d.ts.map +1 -1
- package/dist/experimental/Tabs/Tabs.js +3 -237
- package/dist/experimental/Tabs/TabsContext.d.ts +3 -0
- package/dist/experimental/Tabs/TabsContext.d.ts.map +1 -0
- package/dist/experimental/Tabs/TabsContext.js +5 -0
- package/dist/experimental/Tabs/index.d.ts +5 -2
- package/dist/experimental/Tabs/index.d.ts.map +1 -1
- package/dist/experimental/Tabs/types.d.ts +107 -0
- package/dist/experimental/Tabs/types.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTab.d.ts +7 -0
- package/dist/experimental/Tabs/useTab.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTab.js +97 -0
- package/dist/experimental/Tabs/useTabList.d.ts +3 -0
- package/dist/experimental/Tabs/useTabList.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTabList.js +100 -0
- package/dist/experimental/Tabs/useTabPanel.d.ts +4 -0
- package/dist/experimental/Tabs/useTabPanel.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTabPanel.js +37 -0
- package/dist/experimental/Tabs/useTabs.d.ts +3 -0
- package/dist/experimental/Tabs/useTabs.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTabs.js +12 -0
- package/dist/experimental/index.js +7 -3
- package/dist/hooks/MatchMedia.d.ts +23 -0
- package/dist/hooks/MatchMedia.d.ts.map +1 -0
- package/dist/hooks/MatchMediaContext.d.ts +5 -0
- package/dist/hooks/MatchMediaContext.d.ts.map +1 -0
- package/dist/hooks/MatchMediaContext.js +8 -0
- package/dist/hooks/useMedia.d.ts +1 -24
- package/dist/hooks/useMedia.d.ts.map +1 -1
- package/dist/hooks/useMedia.js +15 -6
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/useTheme.d.ts +15 -0
- package/dist/useTheme.d.ts.map +1 -0
- package/dist/useTheme.js +16 -0
- package/dist/utils/story-helpers.d.ts +70 -0
- package/dist/utils/story-helpers.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import React, { forwardRef, useRef, useState, useCallback
|
|
1
|
+
import React, { forwardRef, useRef, useState, useCallback } from 'react';
|
|
2
2
|
import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
|
|
3
3
|
import { UnderlineNavContext } from './UnderlineNavContext.js';
|
|
4
4
|
import { useResizeObserver } from '../hooks/useResizeObserver.js';
|
|
5
|
-
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
6
5
|
import VisuallyHidden from '../_VisuallyHidden.js';
|
|
7
|
-
import {
|
|
6
|
+
import { dividerStyles, baseMenuMinWidth, menuItemStyles } from './styles.js';
|
|
8
7
|
import { UnderlineWrapper, UnderlineItemList, LoadingCounter, GAP } from '../internal/components/UnderlineTabbedInterface.js';
|
|
9
8
|
import { TriangleDownIcon } from '@primer/octicons-react';
|
|
10
9
|
import { useOnEscapePress } from '../hooks/useOnEscapePress.js';
|
|
@@ -14,6 +13,7 @@ import { ActionList } from '../ActionList/index.js';
|
|
|
14
13
|
import { invariant } from '../utils/invariant.js';
|
|
15
14
|
import classes from './UnderlineNav.module.css.js';
|
|
16
15
|
import { getAnchoredPosition } from '@primer/behaviors';
|
|
16
|
+
import { getValidChildren } from './utils.js';
|
|
17
17
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
18
18
|
import { ButtonComponent } from '../Button/Button.js';
|
|
19
19
|
import CounterLabel from '../CounterLabel/CounterLabel.js';
|
|
@@ -23,19 +23,19 @@ import CounterLabel from '../CounterLabel/CounterLabel.js';
|
|
|
23
23
|
const MORE_BTN_WIDTH = 86;
|
|
24
24
|
// The height is needed to make sure we don't have a layout shift when the more button is the only item in the nav.
|
|
25
25
|
const MORE_BTN_HEIGHT = 45;
|
|
26
|
-
const
|
|
26
|
+
const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
|
|
27
27
|
let iconsVisible = true;
|
|
28
|
-
if (
|
|
29
|
-
|
|
28
|
+
if (childWidthArray.length === 0) {
|
|
29
|
+
updateListAndMenu({
|
|
30
30
|
items: childArray,
|
|
31
|
-
menuItems: []
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
menuItems: []
|
|
32
|
+
}, iconsVisible, false);
|
|
33
|
+
return;
|
|
34
34
|
}
|
|
35
|
-
const numberOfItemsPossible = calculatePossibleItems(
|
|
36
|
-
const numberOfItemsWithoutIconPossible = calculatePossibleItems(
|
|
35
|
+
const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
|
|
36
|
+
const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
|
|
37
37
|
// We need to take more menu width into account when calculating the number of items possible
|
|
38
|
-
const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(
|
|
38
|
+
const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
40
|
const items = [];
|
|
41
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -78,27 +78,22 @@ const computeOverflow = (navWidth, moreMenuWidth, childArray, childWidths, noIco
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
updateListAndMenu({
|
|
82
82
|
items,
|
|
83
|
-
menuItems
|
|
84
|
-
|
|
85
|
-
};
|
|
83
|
+
menuItems
|
|
84
|
+
}, iconsVisible, true);
|
|
86
85
|
};
|
|
87
|
-
const
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
-
return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
|
|
90
|
-
};
|
|
91
|
-
const calculatePossibleItems = (childArray, widthMap, navWidth, moreMenuWidth = 0) => {
|
|
86
|
+
const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
|
|
92
87
|
const widthToFit = navWidth - moreMenuWidth;
|
|
93
|
-
let breakpoint =
|
|
88
|
+
let breakpoint = childWidthArray.length; // assume all items will fit
|
|
94
89
|
let sumsOfChildWidth = 0;
|
|
95
|
-
for (const [index,
|
|
96
|
-
|
|
97
|
-
const width = (_widthMap$get = widthMap.get(String(child.key))) !== null && _widthMap$get !== void 0 ? _widthMap$get : 0;
|
|
98
|
-
sumsOfChildWidth = sumsOfChildWidth + width + GAP;
|
|
90
|
+
for (const [index, childWidth] of childWidthArray.entries()) {
|
|
91
|
+
sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
|
|
99
92
|
if (sumsOfChildWidth > widthToFit) {
|
|
100
93
|
breakpoint = index;
|
|
101
94
|
break;
|
|
95
|
+
} else {
|
|
96
|
+
continue;
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
return breakpoint;
|
|
@@ -125,6 +120,7 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
125
120
|
className,
|
|
126
121
|
children
|
|
127
122
|
}, forwardedRef) => {
|
|
123
|
+
var _listRef$current2;
|
|
128
124
|
const backupRef = useRef(null);
|
|
129
125
|
const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
|
|
130
126
|
const listRef = useRef(null);
|
|
@@ -133,70 +129,32 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
133
129
|
const containerRef = React.useRef(null);
|
|
134
130
|
const disclosureWidgetId = useId();
|
|
135
131
|
const [isWidgetOpen, setIsWidgetOpen] = useState(false);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
132
|
+
const [iconsVisible, setIconsVisible] = useState(true);
|
|
133
|
+
const [childWidthArray, setChildWidthArray] = useState([]);
|
|
134
|
+
const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
|
|
135
|
+
// Track whether the initial overflow calculation is complete to prevent CLS
|
|
136
|
+
const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
|
|
141
137
|
const validChildren = getValidChildren(children);
|
|
142
|
-
// Stable signature of the children list — when it changes we re-run the
|
|
143
|
-
// measurement pass with all items rendered (with icons) in the list. The
|
|
144
|
-
// delimiter is U+0000 (NUL) because React rejects NUL inside element keys,
|
|
145
|
-
// so consumer-provided keys cannot collide with the separator.
|
|
146
|
-
const childrenKey = validChildren.map(c => String(c.key)).join('\u0000');
|
|
147
|
-
|
|
148
|
-
// Single consolidated overflow state. Bundling `items`, `menuItems`,
|
|
149
|
-
// `iconsVisible`, `measured`, and `childrenKey` together means every
|
|
150
|
-
// overflow update — measurement, swap, resize, or children-change reset —
|
|
151
|
-
// is exactly one setState call (one commit), instead of fanning out to
|
|
152
|
-
// multiple back-to-back commits.
|
|
153
138
|
|
|
154
|
-
|
|
139
|
+
// Responsive props object manages which items are in the list and which items are in the menu.
|
|
140
|
+
const [responsiveProps, setResponsiveProps] = useState({
|
|
155
141
|
items: validChildren,
|
|
156
|
-
menuItems: []
|
|
157
|
-
|
|
158
|
-
measured: false,
|
|
159
|
-
childrenKey
|
|
160
|
-
}));
|
|
161
|
-
|
|
162
|
-
// Derived-state reset: when the children list changes, push everything back into
|
|
163
|
-
// the list (with icons) so the next layout effect can measure all items in one
|
|
164
|
-
// pass. This is React's recommended "store information from previous renders"
|
|
165
|
-
// pattern — calling setState during render lets React discard the in-progress
|
|
166
|
-
// render and re-render immediately with the reset state, before paint.
|
|
167
|
-
if (overflowState.childrenKey !== childrenKey) {
|
|
168
|
-
setOverflowState({
|
|
169
|
-
items: validChildren,
|
|
170
|
-
menuItems: [],
|
|
171
|
-
iconsVisible: true,
|
|
172
|
-
measured: false,
|
|
173
|
-
childrenKey
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Build a key-indexed view of validChildren once per render so the listItems /
|
|
178
|
-
// menuItems prop-refresh below is O(N) instead of O(N^2) via Array.prototype.find.
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
180
|
-
const validChildrenByKey = new Map();
|
|
181
|
-
for (const c of validChildren) validChildrenByKey.set(String(c.key), c);
|
|
182
|
-
const {
|
|
183
|
-
iconsVisible,
|
|
184
|
-
measured: isOverflowMeasured
|
|
185
|
-
} = overflowState;
|
|
142
|
+
menuItems: []
|
|
143
|
+
});
|
|
186
144
|
|
|
187
145
|
// Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
|
|
188
|
-
const listItems =
|
|
189
|
-
var
|
|
190
|
-
return (
|
|
146
|
+
const listItems = responsiveProps.items.map(item => {
|
|
147
|
+
var _validChildren$find;
|
|
148
|
+
return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
|
|
191
149
|
});
|
|
192
150
|
|
|
193
151
|
// Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
|
|
194
|
-
const menuItems =
|
|
195
|
-
var
|
|
196
|
-
return (
|
|
152
|
+
const menuItems = responsiveProps.menuItems.map(menuItem => {
|
|
153
|
+
var _validChildren$find2;
|
|
154
|
+
return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
|
|
197
155
|
});
|
|
198
156
|
// This is the case where the viewport is too narrow to show any list item with the more menu. In this case, we only show the dropdown
|
|
199
|
-
const onlyMenuVisible =
|
|
157
|
+
const onlyMenuVisible = responsiveProps.items.length === 0;
|
|
200
158
|
useDevOnlyEffect(() => {
|
|
201
159
|
// Address illegal state where there are multiple items that have `aria-current='page'` attribute
|
|
202
160
|
const activeElements = validChildren.filter(child => {
|
|
@@ -205,145 +163,66 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
205
163
|
!(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
|
|
206
164
|
!ariaLabel ? process.env.NODE_ENV !== "production" ? invariant(false, 'Use the `aria-label` prop to provide an accessible label for assistive technology') : invariant(false) : void 0;
|
|
207
165
|
}, [validChildren, ariaLabel]);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const getItemNoIconWidth = item => {
|
|
214
|
-
var _noIconChildWidthsRef;
|
|
215
|
-
return (_noIconChildWidthsRef = noIconChildWidthsRef.current.get(String(item.key))) !== null && _noIconChildWidthsRef !== void 0 ? _noIconChildWidthsRef : 0;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// Pure: returns the {items, menuItems} that result from promoting
|
|
219
|
-
// `prospectiveListItem` (currently at position `indexOfProspectiveListItem`
|
|
220
|
-
// in `currentMenuItems`) into `currentItems`. Does not call setState.
|
|
221
|
-
const computeSwap = (currentItems, currentMenuItems, prospectiveListItem, indexOfProspectiveListItem) => {
|
|
166
|
+
function getItemsWidth(itemText) {
|
|
167
|
+
var _noIconChildWidthArra, _noIconChildWidthArra2;
|
|
168
|
+
return (_noIconChildWidthArra = (_noIconChildWidthArra2 = noIconChildWidthArray.find(item => item.text === itemText)) === null || _noIconChildWidthArra2 === void 0 ? void 0 : _noIconChildWidthArra2.width) !== null && _noIconChildWidthArra !== void 0 ? _noIconChildWidthArra : 0;
|
|
169
|
+
}
|
|
170
|
+
const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem, event, callback) => {
|
|
222
171
|
var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
|
|
223
|
-
|
|
172
|
+
// get the selected menu item's width
|
|
173
|
+
const widthToFitIntoList = getItemsWidth(prospectiveListItem.props.children);
|
|
174
|
+
// Check if there is any empty space on the right side of the list
|
|
224
175
|
const availableSpace = ((_navRef$current$getBo = (_navRef$current = navRef.current) === null || _navRef$current === void 0 ? void 0 : _navRef$current.getBoundingClientRect().width) !== null && _navRef$current$getBo !== void 0 ? _navRef$current$getBo : 0) - ((_listRef$current$getB = (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.getBoundingClientRect().width) !== null && _listRef$current$getB !== void 0 ? _listRef$current$getB : 0);
|
|
225
176
|
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (widthToFitIntoList < widthToSwap + availableSpace) {
|
|
233
|
-
breakpoint = index;
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const indexToSliceAt = currentItems.length - 1 - breakpoint;
|
|
238
|
-
const itemsLeftInList = currentItems.slice(0, indexToSliceAt);
|
|
177
|
+
// Calculate how many items need to be pulled in to the menu to make room for the selected menu item
|
|
178
|
+
// I.e. if we need to pull 2 items in (index 0 and index 1), breakpoint (index) will return 1.
|
|
179
|
+
const index = getBreakpointForItemSwapping(widthToFitIntoList, availableSpace);
|
|
180
|
+
const indexToSliceAt = responsiveProps.items.length - 1 - index;
|
|
181
|
+
// Form the new list of items
|
|
182
|
+
const itemsLeftInList = [...responsiveProps.items].slice(0, indexToSliceAt);
|
|
239
183
|
const updatedItemList = [...itemsLeftInList, prospectiveListItem];
|
|
240
|
-
|
|
241
|
-
const
|
|
184
|
+
// Form the new menu items
|
|
185
|
+
const itemsToAddToMenu = [...responsiveProps.items].slice(indexToSliceAt);
|
|
186
|
+
const updatedMenuItems = [...menuItems];
|
|
187
|
+
// Add itemsToAddToMenu array's items to the menu at the index of the prospectiveListItem and remove 1 count of items (prospectiveListItem)
|
|
242
188
|
updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
|
|
243
|
-
|
|
189
|
+
callback({
|
|
244
190
|
items: updatedItemList,
|
|
245
191
|
menuItems: updatedMenuItems
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem) => {
|
|
249
|
-
const swap = computeSwap(overflowState.items, menuItems, prospectiveListItem, indexOfProspectiveListItem);
|
|
250
|
-
setOverflowState(prev => ({
|
|
251
|
-
items: swap.items,
|
|
252
|
-
menuItems: swap.menuItems,
|
|
253
|
-
iconsVisible: false,
|
|
254
|
-
measured: true,
|
|
255
|
-
childrenKey: prev.childrenKey
|
|
256
|
-
}));
|
|
192
|
+
}, false, true);
|
|
257
193
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
// notice prop-only changes without rebuilding a signature. The body
|
|
268
|
-
// short-circuits cheaply on every render where neither pass needs to run.
|
|
269
|
-
useIsomorphicLayoutEffect(() => {
|
|
270
|
-
var _next;
|
|
271
|
-
const listEl = listRef.current;
|
|
272
|
-
const navEl = navRef.current;
|
|
273
|
-
if (!listEl || !navEl) return;
|
|
274
|
-
let next = null;
|
|
275
|
-
|
|
276
|
-
// Pass 1: measurement (runs once after each remeasure trigger).
|
|
277
|
-
if (!isOverflowMeasured) {
|
|
278
|
-
var _moreMenuRef$current$, _moreMenuRef$current;
|
|
279
|
-
const widths = new Map();
|
|
280
|
-
const noIconWidths = new Map();
|
|
281
|
-
const itemEls = listEl.querySelectorAll('[data-underlinenav-item="true"]');
|
|
282
|
-
|
|
283
|
-
// The N-th [data-underlinenav-item] element corresponds to validChildren[N]
|
|
284
|
-
// because the measurement pass runs only when all items are in the list,
|
|
285
|
-
// in render order. Pair them up positionally so we can key widths by the
|
|
286
|
-
// element's React key.
|
|
287
|
-
const upToBoundary = Math.min(itemEls.length, validChildren.length);
|
|
288
|
-
for (let index = 0; index < upToBoundary; index++) {
|
|
289
|
-
const liEl = itemEls[index];
|
|
290
|
-
const linkEl = liEl.querySelector('a, button');
|
|
291
|
-
if (!linkEl) continue;
|
|
292
|
-
const child = validChildren[index];
|
|
293
|
-
const key = String(child.key);
|
|
294
|
-
const domRect = linkEl.getBoundingClientRect();
|
|
295
|
-
const iconEl = linkEl.querySelector('[data-component="icon"]');
|
|
296
|
-
let iconWidthWithMargin = 0;
|
|
297
|
-
if (iconEl) {
|
|
298
|
-
const style = getComputedStyle(iconEl);
|
|
299
|
-
iconWidthWithMargin = iconEl.getBoundingClientRect().width + (parseFloat(style.marginRight) || 0) + (parseFloat(style.marginLeft) || 0);
|
|
300
|
-
}
|
|
301
|
-
widths.set(key, domRect.width);
|
|
302
|
-
noIconWidths.set(key, domRect.width - iconWidthWithMargin);
|
|
194
|
+
// How many items do we need to pull in to the menu to make room for the selected menu item.
|
|
195
|
+
function getBreakpointForItemSwapping(widthToFitIntoList, availableSpace) {
|
|
196
|
+
let widthToSwap = 0;
|
|
197
|
+
let breakpoint = 0;
|
|
198
|
+
for (const [index, item] of [...responsiveProps.items].reverse().entries()) {
|
|
199
|
+
widthToSwap += getItemsWidth(item.props.children);
|
|
200
|
+
if (widthToFitIntoList < widthToSwap + availableSpace) {
|
|
201
|
+
breakpoint = index;
|
|
202
|
+
break;
|
|
303
203
|
}
|
|
304
|
-
childWidthsRef.current = widths;
|
|
305
|
-
noIconChildWidthsRef.current = noIconWidths;
|
|
306
|
-
const navWidth = navEl.getBoundingClientRect().width;
|
|
307
|
-
if (navWidth === 0) return;
|
|
308
|
-
const moreMenuWidth = (_moreMenuRef$current$ = (_moreMenuRef$current = moreMenuRef.current) === null || _moreMenuRef$current === void 0 ? void 0 : _moreMenuRef$current.getBoundingClientRect().width) !== null && _moreMenuRef$current$ !== void 0 ? _moreMenuRef$current$ : 0;
|
|
309
|
-
const result = computeOverflow(navWidth, moreMenuWidth, validChildren, widths, noIconWidths);
|
|
310
|
-
next = {
|
|
311
|
-
items: result.items,
|
|
312
|
-
menuItems: result.menuItems,
|
|
313
|
-
iconsVisible: result.iconsVisible,
|
|
314
|
-
measured: true,
|
|
315
|
-
childrenKey: overflowState.childrenKey
|
|
316
|
-
};
|
|
317
204
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
// O(N) and ran inside a .map() — quadratic on every commit).
|
|
326
|
-
const freshMenuItems = considered.menuItems.map(item => {
|
|
327
|
-
var _validChildrenByKey$g3;
|
|
328
|
-
return (_validChildrenByKey$g3 = validChildrenByKey.get(String(item.key))) !== null && _validChildrenByKey$g3 !== void 0 ? _validChildrenByKey$g3 : item;
|
|
329
|
-
});
|
|
330
|
-
const indexOfCurrent = freshMenuItems.findIndex(item => {
|
|
331
|
-
const c = item.props['aria-current'];
|
|
332
|
-
return Boolean(c) && c !== 'false';
|
|
333
|
-
});
|
|
334
|
-
if (indexOfCurrent !== -1) {
|
|
335
|
-
const swap = computeSwap(considered.items, freshMenuItems, freshMenuItems[indexOfCurrent], indexOfCurrent);
|
|
336
|
-
next = {
|
|
337
|
-
items: swap.items,
|
|
338
|
-
menuItems: swap.menuItems,
|
|
339
|
-
iconsVisible: false,
|
|
340
|
-
measured: true,
|
|
341
|
-
childrenKey: considered.childrenKey
|
|
342
|
-
};
|
|
343
|
-
}
|
|
205
|
+
return breakpoint;
|
|
206
|
+
}
|
|
207
|
+
const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
|
|
208
|
+
setResponsiveProps(props);
|
|
209
|
+
setIconsVisible(displayIcons);
|
|
210
|
+
if (overflowMeasured) {
|
|
211
|
+
setIsOverflowMeasured(true);
|
|
344
212
|
}
|
|
345
|
-
|
|
346
|
-
|
|
213
|
+
}, []);
|
|
214
|
+
const setChildrenWidth = useCallback(size => {
|
|
215
|
+
setChildWidthArray(arr => {
|
|
216
|
+
const newArr = [...arr, size];
|
|
217
|
+
return newArr;
|
|
218
|
+
});
|
|
219
|
+
}, []);
|
|
220
|
+
const setNoIconChildrenWidth = useCallback(size => {
|
|
221
|
+
setNoIconChildWidthArray(arr => {
|
|
222
|
+
const newArr = [...arr, size];
|
|
223
|
+
return newArr;
|
|
224
|
+
});
|
|
225
|
+
}, []);
|
|
347
226
|
const closeOverlay = React.useCallback(() => {
|
|
348
227
|
setIsWidgetOpen(false);
|
|
349
228
|
}, [setIsWidgetOpen]);
|
|
@@ -370,66 +249,36 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
370
249
|
ignoreClickRefs: [moreMenuBtnRef]
|
|
371
250
|
});
|
|
372
251
|
useResizeObserver(resizeObserverEntries => {
|
|
373
|
-
var _moreMenuRef$current
|
|
252
|
+
var _moreMenuRef$current$, _moreMenuRef$current;
|
|
374
253
|
const navWidth = resizeObserverEntries[0].contentRect.width;
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const result = computeOverflow(navWidth, moreMenuWidth, validChildren, childWidthsRef.current, noIconChildWidthsRef.current);
|
|
378
|
-
setOverflowState(prev => ({
|
|
379
|
-
items: result.items,
|
|
380
|
-
menuItems: result.menuItems,
|
|
381
|
-
iconsVisible: result.iconsVisible,
|
|
382
|
-
measured: childWidthsRef.current.size > 0 || prev.measured,
|
|
383
|
-
childrenKey: prev.childrenKey
|
|
384
|
-
}));
|
|
254
|
+
const moreMenuWidth = (_moreMenuRef$current$ = (_moreMenuRef$current = moreMenuRef.current) === null || _moreMenuRef$current === void 0 ? void 0 : _moreMenuRef$current.getBoundingClientRect().width) !== null && _moreMenuRef$current$ !== void 0 ? _moreMenuRef$current$ : 0;
|
|
255
|
+
navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
|
|
385
256
|
}, navRef);
|
|
386
257
|
|
|
387
|
-
//
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
// This used to be computed inline during render by reading
|
|
393
|
-
// containerRef.current / listRef.current — refs are mutable and unsafe to
|
|
394
|
-
// read during render under concurrent rendering (the first render saw null
|
|
395
|
-
// refs and fell through to the unanchored fallback; subsequent renders
|
|
396
|
-
// anchored differently, producing a perceptible reflow).
|
|
397
|
-
const [menuAnchorLeft, setMenuAnchorLeft] = useState(undefined);
|
|
398
|
-
useIsomorphicLayoutEffect(() => {
|
|
399
|
-
const container = containerRef.current;
|
|
400
|
-
const list = listRef.current;
|
|
401
|
-
if (!container || !list) return;
|
|
402
|
-
if (list.clientWidth >= baseMenuMinWidth) {
|
|
403
|
-
if (menuAnchorLeft !== undefined) setMenuAnchorLeft(undefined);
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
258
|
+
// Compute menuInlineStyles if needed
|
|
259
|
+
let menuInlineStyles = {
|
|
260
|
+
...baseMenuInlineStyles
|
|
261
|
+
};
|
|
262
|
+
if (containerRef.current && listRef.current) {
|
|
406
263
|
const {
|
|
407
264
|
left
|
|
408
|
-
} = getAnchoredPosition(
|
|
265
|
+
} = getAnchoredPosition(containerRef.current, listRef.current, {
|
|
409
266
|
align: 'start',
|
|
410
267
|
side: 'outside-bottom'
|
|
411
268
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
const contextValue = useMemo(() => ({
|
|
419
|
-
loadingCounters,
|
|
420
|
-
iconsVisible
|
|
421
|
-
}), [loadingCounters, iconsVisible]);
|
|
422
|
-
const menuStyle = menuAnchorLeft !== undefined ? {
|
|
423
|
-
...baseMenuInlineStyles,
|
|
424
|
-
right: undefined,
|
|
425
|
-
left: menuAnchorLeft,
|
|
426
|
-
display: isWidgetOpen ? 'block' : 'none'
|
|
427
|
-
} : {
|
|
428
|
-
...baseMenuInlineStyles,
|
|
429
|
-
display: isWidgetOpen ? 'block' : 'none'
|
|
430
|
-
};
|
|
269
|
+
menuInlineStyles = {
|
|
270
|
+
...baseMenuInlineStyles,
|
|
271
|
+
right: undefined,
|
|
272
|
+
left
|
|
273
|
+
};
|
|
274
|
+
}
|
|
431
275
|
return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
|
|
432
|
-
value:
|
|
276
|
+
value: {
|
|
277
|
+
setChildrenWidth,
|
|
278
|
+
setNoIconChildrenWidth,
|
|
279
|
+
loadingCounters,
|
|
280
|
+
iconsVisible
|
|
281
|
+
},
|
|
433
282
|
children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
|
|
434
283
|
as: "h2",
|
|
435
284
|
children: `${ariaLabel} navigation`
|
|
@@ -476,23 +325,31 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
476
325
|
selectionVariant: "single",
|
|
477
326
|
ref: containerRef,
|
|
478
327
|
id: disclosureWidgetId,
|
|
479
|
-
style:
|
|
328
|
+
style: {
|
|
329
|
+
...((_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= baseMenuMinWidth ? baseMenuInlineStyles : menuInlineStyles),
|
|
330
|
+
display: isWidgetOpen ? 'block' : 'none'
|
|
331
|
+
},
|
|
480
332
|
children: menuItems.map((menuItem, index) => {
|
|
481
333
|
const {
|
|
482
334
|
children: menuItemChildren,
|
|
483
335
|
counter,
|
|
484
|
-
|
|
485
|
-
// directly from item.props (not via these destructured locals).
|
|
486
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
487
|
-
'aria-current': _ariaCurrent,
|
|
336
|
+
'aria-current': ariaCurrent,
|
|
488
337
|
onSelect,
|
|
489
338
|
...menuItemProps
|
|
490
339
|
} = menuItem.props;
|
|
340
|
+
|
|
341
|
+
// This logic is used to pop the selected item out of the menu and into the list when the navigation is control externally
|
|
342
|
+
if (Boolean(ariaCurrent) && ariaCurrent !== 'false') {
|
|
343
|
+
const event = new MouseEvent('click');
|
|
344
|
+
!onlyMenuVisible && swapMenuItemWithListItem(menuItem, index,
|
|
345
|
+
// @ts-ignore - not a big deal because it is internally creating an event but ask help
|
|
346
|
+
event, updateListAndMenu);
|
|
347
|
+
}
|
|
491
348
|
return /*#__PURE__*/jsx(ActionList.LinkItem, {
|
|
492
349
|
style: menuItemStyles,
|
|
493
350
|
onClick: event => {
|
|
494
351
|
// When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
|
|
495
|
-
!onlyMenuVisible && swapMenuItemWithListItem(menuItem, index);
|
|
352
|
+
!onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
|
|
496
353
|
closeOverlay();
|
|
497
354
|
focusOnMoreMenuBtn();
|
|
498
355
|
// fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
|
|
@@ -508,7 +365,7 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
508
365
|
})
|
|
509
366
|
})]
|
|
510
367
|
})
|
|
511
|
-
},
|
|
368
|
+
}, menuItemChildren);
|
|
512
369
|
})
|
|
513
370
|
})]
|
|
514
371
|
})]
|
|
@@ -518,4 +375,4 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
|
|
|
518
375
|
});
|
|
519
376
|
UnderlineNav.displayName = 'UnderlineNav';
|
|
520
377
|
|
|
521
|
-
export { UnderlineNav };
|
|
378
|
+
export { MORE_BTN_WIDTH, UnderlineNav };
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export declare const UnderlineNavContext: React.Context<{
|
|
3
|
+
setChildrenWidth: React.Dispatch<{
|
|
4
|
+
text: string;
|
|
5
|
+
width: number;
|
|
6
|
+
}>;
|
|
7
|
+
setNoIconChildrenWidth: React.Dispatch<{
|
|
8
|
+
text: string;
|
|
9
|
+
width: number;
|
|
10
|
+
}>;
|
|
2
11
|
loadingCounters: boolean;
|
|
3
12
|
iconsVisible: boolean;
|
|
4
13
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnderlineNavContext.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavContext.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UnderlineNavContext.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,eAAO,MAAM,mBAAmB;sBACZ,KAAK,CAAC,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;4BACvC,KAAK,CAAC,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;qBACpD,OAAO;kBACV,OAAO;EAMrB,CAAA"}
|
|
@@ -43,7 +43,5 @@ export type UnderlineNavItemProps = {
|
|
|
43
43
|
*/
|
|
44
44
|
counter?: number | string;
|
|
45
45
|
} & LinkProps;
|
|
46
|
-
declare const
|
|
47
|
-
export declare const UnderlineNavItem: typeof UnderlineNavItemImpl;
|
|
48
|
-
export {};
|
|
46
|
+
export declare const UnderlineNavItem: PolymorphicForwardRefComponent<"a", UnderlineNavItemProps>;
|
|
49
47
|
//# sourceMappingURL=UnderlineNavItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnderlineNavItem.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuC,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"UnderlineNavItem.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuC,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAO/F,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,gBAAgB,CAAC,CAAA;CACjF,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAExG;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;IAE5F;;;OAGG;IAEH,IAAI,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;IAEnE;;OAEG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,YAAY,CAAA;IAElC;;QAEI;IACJ,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,GAAG,CAAA;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAC1B,GAAG,SAAS,CAAA;AAEb,eAAO,MAAM,gBAAgB,EAgFxB,8BAA8B,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef, useRef, useContext } from 'react';
|
|
2
2
|
import { UnderlineNavContext } from './UnderlineNavContext.js';
|
|
3
|
+
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
3
4
|
import { UnderlineItem } from '../internal/components/UnderlineTabbedInterface.js';
|
|
4
5
|
import classes from './UnderlineNavItem.module.css.js';
|
|
5
6
|
import { jsx } from 'react/jsx-runtime';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const UnderlineNavItem = /*#__PURE__*/forwardRef(({
|
|
8
9
|
as: Component = 'a',
|
|
9
10
|
href = '#',
|
|
10
11
|
children,
|
|
@@ -18,9 +19,28 @@ const UnderlineNavItemImpl = /*#__PURE__*/forwardRef(({
|
|
|
18
19
|
const backupRef = useRef(null);
|
|
19
20
|
const ref = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
|
|
20
21
|
const {
|
|
22
|
+
setChildrenWidth,
|
|
23
|
+
setNoIconChildrenWidth,
|
|
21
24
|
loadingCounters,
|
|
22
25
|
iconsVisible
|
|
23
26
|
} = useContext(UnderlineNavContext);
|
|
27
|
+
useIsomorphicLayoutEffect(() => {
|
|
28
|
+
if (ref.current) {
|
|
29
|
+
const domRect = ref.current.getBoundingClientRect();
|
|
30
|
+
const icon = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'icon');
|
|
31
|
+
const content = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'text');
|
|
32
|
+
const text = content.textContent;
|
|
33
|
+
const iconWidthWithMargin = icon ? icon.getBoundingClientRect().width + Number(getComputedStyle(icon).marginRight.slice(0, -2)) + Number(getComputedStyle(icon).marginLeft.slice(0, -2)) : 0;
|
|
34
|
+
setChildrenWidth({
|
|
35
|
+
text,
|
|
36
|
+
width: domRect.width
|
|
37
|
+
});
|
|
38
|
+
setNoIconChildrenWidth({
|
|
39
|
+
text,
|
|
40
|
+
width: domRect.width - iconWidthWithMargin
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, [ref, setChildrenWidth, setNoIconChildrenWidth]);
|
|
24
44
|
const keyDownHandler = React.useCallback(event => {
|
|
25
45
|
if ((event.key === ' ' || event.key === 'Enter') && !event.defaultPrevented && typeof onSelect === 'function') {
|
|
26
46
|
onSelect(event);
|
|
@@ -33,7 +53,6 @@ const UnderlineNavItemImpl = /*#__PURE__*/forwardRef(({
|
|
|
33
53
|
}, [onSelect]);
|
|
34
54
|
return /*#__PURE__*/jsx("li", {
|
|
35
55
|
className: classes.UnderlineNavItem,
|
|
36
|
-
"data-underlinenav-item": "true",
|
|
37
56
|
children: /*#__PURE__*/jsx(UnderlineItem, {
|
|
38
57
|
ref: ref,
|
|
39
58
|
as: Component,
|
|
@@ -50,10 +69,6 @@ const UnderlineNavItemImpl = /*#__PURE__*/forwardRef(({
|
|
|
50
69
|
})
|
|
51
70
|
});
|
|
52
71
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// Memoized so that re-renders of UnderlineNav (e.g. when overflow state changes)
|
|
56
|
-
// do not re-render every item when the consumer-provided children haven't changed.
|
|
57
|
-
const UnderlineNavItem = /*#__PURE__*/React.memo(UnderlineNavItemImpl);
|
|
72
|
+
UnderlineNavItem.displayName = 'UnderlineNavItem';
|
|
58
73
|
|
|
59
74
|
export { UnderlineNavItem };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ChildSize = {
|
|
2
|
+
text: string;
|
|
3
|
+
width: number;
|
|
4
|
+
};
|
|
5
|
+
export type ChildWidthArray = Array<ChildSize>;
|
|
2
6
|
export type ResponsiveProps = {
|
|
3
7
|
items: Array<React.ReactElement<any>>;
|
|
4
8
|
menuItems: Array<React.ReactElement<any>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC,CAAA;AAC9C,MAAM,MAAM,eAAe,GAAG;IAE5B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IAErC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;CAC1C,CAAA"}
|