@primer/react 0.0.0-20260602215811 → 0.0.0-20260603152335

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +3 -5
  2. package/dist/ActionMenu/ActionMenu.d.ts.map +1 -1
  3. package/dist/ActionMenu/ActionMenu.js +2 -11
  4. package/dist/AnchoredOverlay/AnchoredOverlay.d.ts +0 -7
  5. package/dist/AnchoredOverlay/AnchoredOverlay.d.ts.map +1 -1
  6. package/dist/AnchoredOverlay/AnchoredOverlay.js +0 -5
  7. package/dist/Autocomplete/AutocompleteInput.d.ts.map +1 -1
  8. package/dist/Autocomplete/AutocompleteInput.js +1 -2
  9. package/dist/Autocomplete/AutocompleteMenu.d.ts.map +1 -1
  10. package/dist/Autocomplete/AutocompleteMenu.js +0 -1
  11. package/dist/Autocomplete/AutocompleteOverlay.d.ts.map +1 -1
  12. package/dist/Autocomplete/AutocompleteOverlay.js +0 -1
  13. package/dist/Dialog/Dialog.d.ts +0 -1
  14. package/dist/Dialog/Dialog.d.ts.map +1 -1
  15. package/dist/Dialog/Dialog.js +2 -16
  16. package/dist/NavList/NavList.d.ts.map +1 -1
  17. package/dist/NavList/NavList.js +0 -4
  18. package/dist/Overlay/Overlay.d.ts +0 -1
  19. package/dist/Overlay/Overlay.d.ts.map +1 -1
  20. package/dist/TextInput/TextInput.d.ts +0 -6
  21. package/dist/TextInput/TextInput.d.ts.map +1 -1
  22. package/dist/TextInput/TextInput.js +1 -2
  23. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css +2 -0
  24. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css.map +1 -0
  25. package/dist/UnderlineNav/UnderlineNav.d.ts +0 -2
  26. package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
  27. package/dist/UnderlineNav/UnderlineNav.js +86 -331
  28. package/dist/UnderlineNav/UnderlineNav.module.css.js +2 -2
  29. package/dist/UnderlineNav/UnderlineNavContext.d.ts +1 -11
  30. package/dist/UnderlineNav/UnderlineNavContext.d.ts.map +1 -1
  31. package/dist/UnderlineNav/UnderlineNavContext.js +1 -4
  32. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css +2 -0
  33. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css.map +1 -0
  34. package/dist/UnderlineNav/UnderlineNavItem.d.ts +6 -0
  35. package/dist/UnderlineNav/UnderlineNavItem.d.ts.map +1 -1
  36. package/dist/UnderlineNav/UnderlineNavItem.js +36 -39
  37. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +1 -1
  38. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css +2 -0
  39. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css.map +1 -0
  40. package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +1 -1
  41. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css +2 -0
  42. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css.map +1 -0
  43. package/dist/internal/components/UnderlineTabbedInterface.d.ts +0 -1
  44. package/dist/internal/components/UnderlineTabbedInterface.d.ts.map +1 -1
  45. package/dist/internal/components/UnderlineTabbedInterface.js +66 -60
  46. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +1 -1
  47. package/generated/components.json +2 -2
  48. package/package.json +1 -1
  49. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css +0 -2
  50. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css.map +0 -1
  51. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css +0 -2
  52. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css.map +0 -1
  53. package/dist/UnderlineNav/styles.d.ts +0 -16
  54. package/dist/UnderlineNav/styles.d.ts.map +0 -1
  55. package/dist/UnderlineNav/styles.js +0 -19
  56. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css +0 -2
  57. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css.map +0 -1
  58. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css +0 -2
  59. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css.map +0 -1
@@ -1,120 +1,23 @@
1
- import React, { forwardRef, useRef, useState, useCallback } from 'react';
2
- import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
3
- import { UnderlineNavContext } from './UnderlineNavContext.js';
4
- import { useResizeObserver } from '../hooks/useResizeObserver.js';
1
+ import React, { forwardRef, useRef, useState, useMemo } from 'react';
5
2
  import VisuallyHidden from '../_VisuallyHidden.js';
6
- import { dividerStyles, baseMenuMinWidth, menuItemStyles } from './styles.js';
7
- import { UnderlineWrapper, UnderlineItemList, LoadingCounter, GAP } from '../internal/components/UnderlineTabbedInterface.js';
8
- import { TriangleDownIcon } from '@primer/octicons-react';
9
- import { useOnEscapePress } from '../hooks/useOnEscapePress.js';
10
- import { useOnOutsideClick } from '../hooks/useOnOutsideClick.js';
11
- import { useId } from '../hooks/useId.js';
12
3
  import { ActionList } from '../ActionList/index.js';
4
+ import { UnderlineWrapper, UnderlineItemList, LoadingCounter } from '../internal/components/UnderlineTabbedInterface.js';
13
5
  import { invariant } from '../utils/invariant.js';
14
6
  import classes from './UnderlineNav.module.css.js';
15
- import { getAnchoredPosition } from '@primer/behaviors';
16
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
17
- import { ButtonComponent } from '../Button/Button.js';
7
+ import { UnderlineNavContext } from './UnderlineNavContext.js';
8
+ import { UnderlineNavItemsRegistry } from './UnderlineNavItem.js';
9
+ import { clsx } from 'clsx';
10
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
11
+ import { jsxs, jsx } from 'react/jsx-runtime';
12
+ import { SkeletonText } from '../SkeletonText/SkeletonText.js';
18
13
  import CounterLabel from '../CounterLabel/CounterLabel.js';
14
+ import { ActionMenu } from '../ActionMenu/ActionMenu.js';
19
15
 
20
- // When page is loaded, we don't have ref for the more button as it is not on the DOM yet.
21
- // However, we need to calculate number of possible items when the more button present as well. So using the width of the more button as a constant.
22
- const MORE_BTN_WIDTH = 86;
23
- // 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.
24
- const MORE_BTN_HEIGHT = 45;
25
- const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
26
- let iconsVisible = true;
27
- if (childWidthArray.length === 0) {
28
- updateListAndMenu({
29
- items: childArray,
30
- menuItems: []
31
- }, iconsVisible, false);
32
- return;
33
- }
34
- const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
35
- const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
36
- // We need to take more menu width into account when calculating the number of items possible
37
- const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- const items = [];
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- const menuItems = [];
42
-
43
- // First, we check if we can fit all the items with their icons
44
- if (childArray.length <= numberOfItemsPossible) {
45
- items.push(...childArray);
46
- } else if (childArray.length <= numberOfItemsWithoutIconPossible) {
47
- // if we can't fit all the items with their icons, we check if we can fit all the items without their icons
48
- iconsVisible = false;
49
- items.push(...childArray);
50
- } else {
51
- // if we can't fit all the items without their icons, we keep the icons hidden and show the ones that doesn't fit into the list in the overflow menu
52
- iconsVisible = false;
53
-
54
- /* Below is an accessibility requirement. Never show only one item in the overflow menu.
55
- * If there is only one item left to display in the overflow menu according to the calculation,
56
- * we need to pull another item from the list into the overflow menu.
57
- */
58
- const numberOfItemsInMenu = childArray.length - numberOfItemsPossibleWithMoreMenu;
59
- const numberOfListItems = numberOfItemsInMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
60
- for (const [index, child] of childArray.entries()) {
61
- if (index < numberOfListItems) {
62
- items.push(child);
63
- } else {
64
- const ariaCurrent = child.props['aria-current'];
65
- const isCurrent = Boolean(ariaCurrent) && ariaCurrent !== 'false';
66
- // We need to make sure to keep the selected item always visible.
67
- // To do that, we swap the selected item with the last item in the list to make it visible. (When there is at least 1 item in the list to swap.)
68
- if (isCurrent && numberOfListItems > 0) {
69
- // If selected item couldn't make in to the list, we swap it with the last item in the list.
70
- const indexToReplaceAt = numberOfListItems - 1; // because we are replacing the last item in the list
71
- // splice method modifies the array by removing 1 item here at the given index and replace it with the "child" element then returns the removed item.
72
- const propsectiveAction = items.splice(indexToReplaceAt, 1, child)[0];
73
- menuItems.push(propsectiveAction);
74
- } else {
75
- menuItems.push(child);
76
- }
77
- }
78
- }
79
- }
80
- updateListAndMenu({
81
- items,
82
- menuItems
83
- }, iconsVisible, true);
84
- };
85
16
  const getValidChildren = children => {
86
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
18
  return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
88
19
  };
89
- const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
90
- const widthToFit = navWidth - moreMenuWidth;
91
- let breakpoint = childWidthArray.length; // assume all items will fit
92
- let sumsOfChildWidth = 0;
93
- for (const [index, childWidth] of childWidthArray.entries()) {
94
- sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
95
- if (sumsOfChildWidth > widthToFit) {
96
- breakpoint = index;
97
- break;
98
- } else {
99
- continue;
100
- }
101
- }
102
- return breakpoint;
103
- };
104
-
105
- // Inline styles converted from baseMenuStyles for use as CSSProperties
106
- const baseMenuInlineStyles = {
107
- position: 'absolute',
108
- zIndex: 1,
109
- top: '90%',
110
- boxShadow: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
111
- borderRadius: 12,
112
- background: 'var(--overlay-bgColor)',
113
- listStyle: 'none',
114
- minWidth: `${baseMenuMinWidth}px`,
115
- maxWidth: '640px',
116
- right: 0
117
- };
20
+ const isCurrent = props => props['aria-current'] !== undefined && props['aria-current'] !== false && props['aria-current'] !== 'false';
118
21
  const UnderlineNav = /*#__PURE__*/forwardRef(({
119
22
  as = 'nav',
120
23
  'aria-label': ariaLabel,
@@ -123,259 +26,111 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
123
26
  className,
124
27
  children
125
28
  }, forwardedRef) => {
126
- var _listRef$current2;
29
+ var _registeredItems$entr;
127
30
  const backupRef = useRef(null);
128
31
  const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
129
32
  const listRef = useRef(null);
130
- const moreMenuRef = useRef(null);
131
- const moreMenuBtnRef = useRef(null);
132
- const containerRef = React.useRef(null);
133
- const disclosureWidgetId = useId();
134
- const [isWidgetOpen, setIsWidgetOpen] = useState(false);
135
- const [iconsVisible, setIconsVisible] = useState(true);
136
- const [childWidthArray, setChildWidthArray] = useState([]);
137
- const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
138
- // Track whether the initial overflow calculation is complete to prevent CLS
139
- const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
140
- const validChildren = getValidChildren(children);
141
-
142
- // Responsive props object manages which items are in the list and which items are in the menu.
143
- const [responsiveProps, setResponsiveProps] = useState({
144
- items: validChildren,
145
- menuItems: []
146
- });
147
33
 
148
- // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
149
- const listItems = responsiveProps.items.map(item => {
150
- var _validChildren$find;
151
- return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
152
- });
34
+ /** Tracks whether any item has ever overflowed for the lifecycle of this component. Used to prevent flickering. */
35
+ const [hasEverOverflowed, setHasOverflowed] = useState(false);
36
+ const [registeredItems, setRegisteredItems] = UnderlineNavItemsRegistry.useRegistryState();
37
+ const overflowMenuItems = Array.from((_registeredItems$entr = registeredItems === null || registeredItems === void 0 ? void 0 : registeredItems.entries()) !== null && _registeredItems$entr !== void 0 ? _registeredItems$entr : []).filter(entry => entry[1] !== null);
38
+ const isOverflowing = overflowMenuItems.length > 0;
39
+ if (isOverflowing && !hasEverOverflowed) setHasOverflowed(true);
153
40
 
154
- // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
155
- const menuItems = responsiveProps.menuItems.map(menuItem => {
156
- var _validChildren$find2;
157
- return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
158
- });
159
- // 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
160
- const onlyMenuVisible = responsiveProps.items.length === 0;
41
+ // Find the current item if it has overflowed into the menu, so we can reflect
42
+ // its "current" state on the overflow menu anchor.
43
+ const overflowingCurrentItem = overflowMenuItems.some(([, itemProps]) => isCurrent(itemProps));
44
+ const validChildren = getValidChildren(children);
161
45
  useDevOnlyEffect(() => {
162
46
  // Address illegal state where there are multiple items that have `aria-current='page'` attribute
163
- const activeElements = validChildren.filter(child => {
164
- return child.props['aria-current'] !== undefined;
165
- });
47
+ const activeElements = validChildren.filter(child => isCurrent(child.props));
166
48
  !(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
167
49
  !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;
168
50
  }, [validChildren, ariaLabel]);
169
- function getItemsWidth(itemText) {
170
- var _noIconChildWidthArra, _noIconChildWidthArra2;
171
- return (_noIconChildWidthArra = (_noIconChildWidthArra2 = noIconChildWidthArray.find(item => item.text === itemText)) === null || _noIconChildWidthArra2 === void 0 ? void 0 : _noIconChildWidthArra2.width) !== null && _noIconChildWidthArra !== void 0 ? _noIconChildWidthArra : 0;
172
- }
173
- const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem, event, callback) => {
174
- var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
175
- // get the selected menu item's width
176
- const widthToFitIntoList = getItemsWidth(prospectiveListItem.props.children);
177
- // Check if there is any empty space on the right side of the list
178
- 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);
179
-
180
- // Calculate how many items need to be pulled in to the menu to make room for the selected menu item
181
- // I.e. if we need to pull 2 items in (index 0 and index 1), breakpoint (index) will return 1.
182
- const index = getBreakpointForItemSwapping(widthToFitIntoList, availableSpace);
183
- const indexToSliceAt = responsiveProps.items.length - 1 - index;
184
- // Form the new list of items
185
- const itemsLeftInList = [...responsiveProps.items].slice(0, indexToSliceAt);
186
- const updatedItemList = [...itemsLeftInList, prospectiveListItem];
187
- // Form the new menu items
188
- const itemsToAddToMenu = [...responsiveProps.items].slice(indexToSliceAt);
189
- const updatedMenuItems = [...menuItems];
190
- // Add itemsToAddToMenu array's items to the menu at the index of the prospectiveListItem and remove 1 count of items (prospectiveListItem)
191
- updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
192
- callback({
193
- items: updatedItemList,
194
- menuItems: updatedMenuItems
195
- }, false, true);
196
- };
197
- // How many items do we need to pull in to the menu to make room for the selected menu item.
198
- function getBreakpointForItemSwapping(widthToFitIntoList, availableSpace) {
199
- let widthToSwap = 0;
200
- let breakpoint = 0;
201
- for (const [index, item] of [...responsiveProps.items].reverse().entries()) {
202
- widthToSwap += getItemsWidth(item.props.children);
203
- if (widthToFitIntoList < widthToSwap + availableSpace) {
204
- breakpoint = index;
205
- break;
206
- }
207
- }
208
- return breakpoint;
209
- }
210
- const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
211
- setResponsiveProps(props);
212
- setIconsVisible(displayIcons);
213
- if (overflowMeasured) {
214
- setIsOverflowMeasured(true);
215
- }
216
- }, []);
217
- const setChildrenWidth = useCallback(size => {
218
- setChildWidthArray(arr => {
219
- const newArr = [...arr, size];
220
- return newArr;
221
- });
222
- }, []);
223
- const setNoIconChildrenWidth = useCallback(size => {
224
- setNoIconChildWidthArray(arr => {
225
- const newArr = [...arr, size];
226
- return newArr;
227
- });
228
- }, []);
229
- const closeOverlay = React.useCallback(() => {
230
- setIsWidgetOpen(false);
231
- }, [setIsWidgetOpen]);
232
- const focusOnMoreMenuBtn = React.useCallback(() => {
233
- var _moreMenuBtnRef$curre;
234
- (_moreMenuBtnRef$curre = moreMenuBtnRef.current) === null || _moreMenuBtnRef$curre === void 0 ? void 0 : _moreMenuBtnRef$curre.focus();
235
- }, []);
236
- const onAnchorClick = useCallback(event => {
237
- if (event.defaultPrevented || event.button !== 0) {
238
- return;
239
- }
240
- setIsWidgetOpen(isWidgetOpen => !isWidgetOpen);
241
- }, []);
242
- useOnEscapePress(event => {
243
- if (isWidgetOpen) {
244
- event.preventDefault();
245
- closeOverlay();
246
- focusOnMoreMenuBtn();
247
- }
248
- }, [isWidgetOpen]);
249
- useOnOutsideClick({
250
- onClickOutside: closeOverlay,
251
- containerRef,
252
- ignoreClickRefs: [moreMenuBtnRef]
253
- });
254
- useResizeObserver(resizeObserverEntries => {
255
- var _moreMenuRef$current$, _moreMenuRef$current;
256
- const navWidth = resizeObserverEntries[0].contentRect.width;
257
- 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;
258
- navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
259
- }, navRef);
260
-
261
- // Compute menuInlineStyles if needed
262
- let menuInlineStyles = {
263
- ...baseMenuInlineStyles
264
- };
265
- if (containerRef.current && listRef.current) {
266
- const {
267
- left
268
- } = getAnchoredPosition(containerRef.current, listRef.current, {
269
- align: 'start',
270
- side: 'outside-bottom'
271
- });
272
- menuInlineStyles = {
273
- ...baseMenuInlineStyles,
274
- right: undefined,
275
- left
276
- };
277
- }
51
+ const contextValue = useMemo(() => ({
52
+ loadingCounters
53
+ }), [loadingCounters]);
278
54
  return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
279
- value: {
280
- setChildrenWidth,
281
- setNoIconChildrenWidth,
282
- loadingCounters,
283
- iconsVisible
284
- },
55
+ value: contextValue,
285
56
  children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
286
57
  as: "h2",
287
58
  children: `${ariaLabel} navigation`
288
- }), /*#__PURE__*/jsx(UnderlineWrapper, {
59
+ }), /*#__PURE__*/jsxs(UnderlineWrapper, {
289
60
  as: as,
290
61
  "aria-label": ariaLabel,
291
- className: className,
62
+ className: clsx(classes.UnderlineWrapper, className),
292
63
  ref: navRef,
293
64
  "data-variant": variant,
294
- "data-overflow-measured": isOverflowMeasured ? 'true' : 'false',
295
- children: /*#__PURE__*/jsxs(UnderlineItemList, {
65
+ "data-overflow-mode": "wrap"
66
+ // Force icons to stay hidden, avoiding flickering as icons create/remove overflow
67
+ ,
68
+ "data-hide-icons": hasEverOverflowed ? 'true' : undefined
69
+ // Ensure button is shown (after initial render) on browsers that don't support scroll-driven animations
70
+ ,
71
+ "data-has-overflow": isOverflowing ? 'true' : undefined,
72
+ children: [/*#__PURE__*/jsx(UnderlineItemList, {
296
73
  ref: listRef,
297
74
  role: "list",
298
- children: [listItems, menuItems.length > 0 && /*#__PURE__*/jsxs("li", {
299
- ref: moreMenuRef,
300
- style: {
301
- display: 'flex',
302
- alignItems: 'center',
303
- height: `${MORE_BTN_HEIGHT}px`
304
- },
305
- children: [!onlyMenuVisible && /*#__PURE__*/jsx("div", {
306
- style: dividerStyles
307
- }), /*#__PURE__*/jsx(ButtonComponent, {
308
- ref: moreMenuBtnRef,
75
+ className: classes.ItemsList,
76
+ children: /*#__PURE__*/jsx(UnderlineNavItemsRegistry.Provider, {
77
+ setRegistry: setRegisteredItems,
78
+ children: children
79
+ })
80
+ }), /*#__PURE__*/jsxs("div", {
81
+ className: classes.MoreButtonContainer,
82
+ children: [/*#__PURE__*/jsx("div", {
83
+ className: classes.MoreButtonDivider
84
+ }), /*#__PURE__*/jsxs(ActionMenu, {
85
+ children: [/*#__PURE__*/jsx(ActionMenu.Button, {
309
86
  className: classes.MoreButton,
310
- "aria-controls": disclosureWidgetId,
311
- "aria-expanded": isWidgetOpen,
312
- onClick: onAnchorClick,
313
- trailingAction: TriangleDownIcon,
314
- children: /*#__PURE__*/jsx("span", {
315
- children: onlyMenuVisible ? /*#__PURE__*/jsxs(Fragment, {
316
- children: [/*#__PURE__*/jsxs(VisuallyHidden, {
317
- as: "span",
318
- children: [`${ariaLabel}`, "\xA0"]
319
- }), "Menu"]
320
- }) : /*#__PURE__*/jsxs(Fragment, {
321
- children: ["More", /*#__PURE__*/jsxs(VisuallyHidden, {
322
- as: "span",
323
- children: ["\xA0", `${ariaLabel} items`]
324
- })]
325
- })
87
+ variant: "invisible",
88
+ "data-component": "overflow-menu-button",
89
+ "data-current": overflowingCurrentItem ? 'true' : undefined,
90
+ "aria-label": overflowingCurrentItem ? `More items, including current item` : undefined,
91
+ children: /*#__PURE__*/jsxs("span", {
92
+ children: ["More", /*#__PURE__*/jsx(VisuallyHidden, {
93
+ as: "span",
94
+ children: " items"
95
+ })]
326
96
  })
327
- }), /*#__PURE__*/jsx(ActionList, {
328
- selectionVariant: "single",
329
- ref: containerRef,
330
- id: disclosureWidgetId,
331
- style: {
332
- ...((_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= baseMenuMinWidth ? baseMenuInlineStyles : menuInlineStyles),
333
- display: isWidgetOpen ? 'block' : 'none'
334
- },
335
- children: menuItems.map((menuItem, index) => {
336
- const {
337
- children: menuItemChildren,
338
- counter,
339
- 'aria-current': ariaCurrent,
340
- onSelect,
341
- ...menuItemProps
342
- } = menuItem.props;
343
-
344
- // This logic is used to pop the selected item out of the menu and into the list when the navigation is control externally
345
- if (Boolean(ariaCurrent) && ariaCurrent !== 'false') {
346
- const event = new MouseEvent('click');
347
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index,
348
- // @ts-ignore - not a big deal because it is internally creating an event but ask help
349
- event, updateListAndMenu);
350
- }
351
- return /*#__PURE__*/jsx(ActionList.LinkItem, {
352
- style: menuItemStyles,
353
- onClick: event => {
354
- // When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
355
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
356
- closeOverlay();
357
- focusOnMoreMenuBtn();
358
- // fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
359
- typeof onSelect === 'function' && onSelect(event);
360
- },
361
- ...menuItemProps,
362
- children: /*#__PURE__*/jsxs("span", {
363
- className: classes.MenuItemContent,
364
- children: [menuItemChildren, loadingCounters ? /*#__PURE__*/jsx(LoadingCounter, {}) : counter !== undefined && /*#__PURE__*/jsx("span", {
365
- "data-component": "counter",
366
- children: /*#__PURE__*/jsx(CounterLabel, {
367
- children: counter
97
+ }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
98
+ children: /*#__PURE__*/jsx(ActionList, {
99
+ children: registeredItems === undefined ? /*#__PURE__*/jsx(ActionList.Item, {
100
+ children: /*#__PURE__*/jsx(SkeletonText, {})
101
+ }) : overflowMenuItems.map(([key, allProps]) => {
102
+ const {
103
+ children: menuItemChildren,
104
+ counter,
105
+ onSelect,
106
+ ...menuItemProps
107
+ } = allProps;
108
+ return /*#__PURE__*/jsxs(ActionList.LinkItem, {
109
+ className: classes.OverflowMenuItem,
110
+ onClick: event => onSelect === null || onSelect === void 0 ? void 0 : onSelect(event),
111
+ ...menuItemProps,
112
+ children: [/*#__PURE__*/jsx("span", {
113
+ className: classes.OverflowMenuItemLabel,
114
+ children: menuItemChildren
115
+ }), loadingCounters ? /*#__PURE__*/jsx(ActionList.TrailingVisual, {
116
+ children: /*#__PURE__*/jsx(LoadingCounter, {})
117
+ }) : counter !== undefined && /*#__PURE__*/jsx(ActionList.TrailingVisual, {
118
+ children: /*#__PURE__*/jsx("span", {
119
+ "data-component": "counter",
120
+ children: /*#__PURE__*/jsx(CounterLabel, {
121
+ children: counter
122
+ })
368
123
  })
369
124
  })]
370
- })
371
- }, menuItemChildren);
125
+ }, key);
126
+ })
372
127
  })
373
128
  })]
374
129
  })]
375
- })
130
+ })]
376
131
  })]
377
132
  });
378
133
  });
379
134
  UnderlineNav.displayName = 'UnderlineNav';
380
135
 
381
- export { MORE_BTN_WIDTH, UnderlineNav, getValidChildren };
136
+ export { UnderlineNav };
@@ -1,5 +1,5 @@
1
- import './UnderlineNav-4344d9b0.css';
1
+ import './UnderlineNav-263b4e8f.css';
2
2
 
3
- var classes = {"MenuItemContent":"prc-UnderlineNav-MenuItemContent-3J7gB","MoreButton":"prc-UnderlineNav-MoreButton-Y8soj"};
3
+ var classes = {"UnderlineWrapper":"prc-UnderlineNav-UnderlineWrapper-GWONT","detect-overflow":"prc-UnderlineNav-detect-overflow-6HuSH","ItemsList":"prc-UnderlineNav-ItemsList-oj8gN","MoreButtonContainer":"prc-UnderlineNav-MoreButtonContainer-Dnrq6","OverflowMenuItem":"prc-UnderlineNav-OverflowMenuItem-7SG7M","OverflowMenuItemLabel":"prc-UnderlineNav-OverflowMenuItemLabel-F80v6","MoreButtonDivider":"prc-UnderlineNav-MoreButtonDivider-dN0a-","MoreButton":"prc-UnderlineNav-MoreButton-Y8soj"};
4
4
 
5
5
  export { classes as default };
@@ -1,14 +1,4 @@
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
- }>;
1
+ export declare const UnderlineNavContext: import("react").Context<{
11
2
  loadingCounters: boolean;
12
- iconsVisible: boolean;
13
3
  }>;
14
4
  //# sourceMappingURL=UnderlineNavContext.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"UnderlineNavContext.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavContext.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;qBACb,OAAO;EAGxB,CAAA"}
@@ -1,10 +1,7 @@
1
1
  import { createContext } from 'react';
2
2
 
3
3
  const UnderlineNavContext = /*#__PURE__*/createContext({
4
- setChildrenWidth: () => null,
5
- setNoIconChildrenWidth: () => null,
6
- loadingCounters: false,
7
- iconsVisible: true
4
+ loadingCounters: false
8
5
  });
9
6
 
10
7
  export { UnderlineNavContext };
@@ -0,0 +1,2 @@
1
+ .prc-UnderlineNav-UnderlineNavItem-syRjR{align-items:center;display:flex;flex-direction:column;overflow:hidden}.prc-UnderlineNav-UnderlineNavItem-syRjR[aria-hidden]{visibility:hidden}
2
+ /*# sourceMappingURL=UnderlineNavItem-402cd41c.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/UnderlineNav/UnderlineNavItem.module.css.js"],"names":[],"mappings":"AAAA,yCAGE,kBAAmB,CAFnB,YAAa,CACb,qBAAsB,CAEtB,eAOF,CALE,sDAGE,iBACF","file":"UnderlineNavItem-402cd41c.css","sourcesContent":[".UnderlineNavItem {\n display: flex;\n flex-direction: column;\n align-items: center;\n overflow: hidden;\n\n &[aria-hidden] {\n /* Overflowing items will already be clipped out of view, but might as well\n also hide them for performance and to ensure they can't accidentally appear */\n visibility: hidden;\n }\n}\n"]}
@@ -43,5 +43,11 @@ export type UnderlineNavItemProps = {
43
43
  */
44
44
  counter?: number | string;
45
45
  } & LinkProps;
46
+ /** Registry of currently-overflowing underline items. If an item is not overflowing, its value will be `null`. */
47
+ export declare const UnderlineNavItemsRegistry: {
48
+ Provider: ({ children, setRegistry }: import("../utils/descendant-registry").ProviderProps<UnderlineNavItemProps | null>) => React.JSX.Element;
49
+ useRegistryState: () => [ReadonlyMap<string, UnderlineNavItemProps | null> | undefined, React.Dispatch<React.SetStateAction<ReadonlyMap<string, UnderlineNavItemProps | null> | undefined>>];
50
+ useRegisterDescendant: (value: UnderlineNavItemProps | null) => string;
51
+ };
46
52
  export declare const UnderlineNavItem: PolymorphicForwardRefComponent<"a", UnderlineNavItemProps>;
47
53
  //# 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;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,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