@primer/react 0.0.0-20260218210324 → 0.0.0-20260218211332

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 (77) hide show
  1. package/CHANGELOG.md +4 -22
  2. package/dist/ActionList/Description.js +35 -113
  3. package/dist/ActionList/Divider.js +11 -30
  4. package/dist/ActionList/Group.js +117 -294
  5. package/dist/ActionList/Heading.js +22 -77
  6. package/dist/ActionList/Item.js +37 -98
  7. package/dist/ActionList/LinkItem.js +24 -80
  8. package/dist/ActionList/List.js +33 -143
  9. package/dist/ActionList/Selection.js +30 -78
  10. package/dist/ActionList/TrailingAction.js +23 -83
  11. package/dist/ActionList/Visuals.js +64 -162
  12. package/dist/Banner/Banner.d.ts.map +1 -1
  13. package/dist/Banner/Banner.js +62 -72
  14. package/dist/Button/Button.js +11 -34
  15. package/dist/Button/ButtonBase.d.ts.map +1 -1
  16. package/dist/Button/ButtonBase.js +14 -9
  17. package/dist/Button/IconButton.js +51 -140
  18. package/dist/Button/LinkButton.js +11 -39
  19. package/dist/FilteredActionList/FilteredActionList-f6c2dc7a.css +2 -0
  20. package/dist/FilteredActionList/FilteredActionList-f6c2dc7a.css.map +1 -0
  21. package/dist/FilteredActionList/FilteredActionList.module.css.js +2 -2
  22. package/dist/PageLayout/PageLayout-06f4c069.css +2 -0
  23. package/dist/PageLayout/PageLayout-06f4c069.css.map +1 -0
  24. package/dist/PageLayout/PageLayout.d.ts +71 -2
  25. package/dist/PageLayout/PageLayout.d.ts.map +1 -1
  26. package/dist/PageLayout/PageLayout.js +498 -44
  27. package/dist/PageLayout/PageLayout.module.css.js +2 -2
  28. package/dist/PageLayout/usePaneWidth.d.ts +16 -4
  29. package/dist/PageLayout/usePaneWidth.d.ts.map +1 -1
  30. package/dist/PageLayout/usePaneWidth.js +123 -109
  31. package/dist/SplitPageLayout/SplitPageLayout.d.ts +4 -1
  32. package/dist/SplitPageLayout/SplitPageLayout.d.ts.map +1 -1
  33. package/dist/SplitPageLayout/SplitPageLayout.js +54 -2
  34. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css +2 -0
  35. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css.map +1 -0
  36. package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
  37. package/dist/UnderlineNav/UnderlineNav.js +317 -82
  38. package/dist/UnderlineNav/UnderlineNav.module.css.js +2 -2
  39. package/dist/UnderlineNav/UnderlineNavContext.d.ts +11 -4
  40. package/dist/UnderlineNav/UnderlineNavContext.d.ts.map +1 -1
  41. package/dist/UnderlineNav/UnderlineNavContext.js +3 -2
  42. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css +2 -0
  43. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css.map +1 -0
  44. package/dist/UnderlineNav/UnderlineNavItem.d.ts.map +1 -1
  45. package/dist/UnderlineNav/UnderlineNavItem.js +85 -94
  46. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +1 -1
  47. package/dist/UnderlineNav/styles.d.ts +16 -0
  48. package/dist/UnderlineNav/styles.d.ts.map +1 -0
  49. package/dist/UnderlineNav/styles.js +19 -0
  50. package/dist/experimental/SelectPanel2/SelectPanel-1f8c23b5.css +2 -0
  51. package/dist/experimental/SelectPanel2/{SelectPanel-f0c4b9ca.css.map → SelectPanel-1f8c23b5.css.map} +1 -1
  52. package/dist/experimental/SelectPanel2/SelectPanel.module.css.js +1 -1
  53. package/dist/hooks/useIsMacOS.d.ts +3 -15
  54. package/dist/hooks/useIsMacOS.d.ts.map +1 -1
  55. package/dist/hooks/useIsMacOS.js +26 -24
  56. package/dist/internal/components/UnderlineTabbedInterface-20c3ba3d.css +2 -0
  57. package/dist/internal/components/UnderlineTabbedInterface-20c3ba3d.css.map +1 -0
  58. package/dist/internal/components/UnderlineTabbedInterface.d.ts +1 -0
  59. package/dist/internal/components/UnderlineTabbedInterface.d.ts.map +1 -1
  60. package/dist/internal/components/UnderlineTabbedInterface.js +48 -41
  61. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +1 -1
  62. package/dist/live-region/Announce.d.ts.map +1 -1
  63. package/dist/live-region/Announce.js +4 -7
  64. package/dist/utils/environment.js +9 -0
  65. package/generated/components.json +200 -2
  66. package/package.json +2 -2
  67. package/dist/FilteredActionList/FilteredActionList-02db90c6.css +0 -2
  68. package/dist/FilteredActionList/FilteredActionList-02db90c6.css.map +0 -1
  69. package/dist/PageLayout/PageLayout-cb491b47.css +0 -2
  70. package/dist/PageLayout/PageLayout-cb491b47.css.map +0 -1
  71. package/dist/UnderlineNav/UnderlineNav-e56ca858.css +0 -2
  72. package/dist/UnderlineNav/UnderlineNav-e56ca858.css.map +0 -1
  73. package/dist/UnderlineNav/UnderlineNavItem-db9dc5d0.css +0 -2
  74. package/dist/UnderlineNav/UnderlineNavItem-db9dc5d0.css.map +0 -1
  75. package/dist/experimental/SelectPanel2/SelectPanel-f0c4b9ca.css +0 -2
  76. package/dist/internal/components/UnderlineTabbedInterface-135d7279.css +0 -2
  77. package/dist/internal/components/UnderlineTabbedInterface-135d7279.css.map +0 -1
@@ -1,20 +1,118 @@
1
- import React, { forwardRef, useRef, useState, useCallback, useEffect } from 'react';
1
+ import React, { forwardRef, useRef, useState, useEffect, useCallback } from 'react';
2
+ import { UnderlineNavContext } from './UnderlineNavContext.js';
3
+ import { useResizeObserver } from '../hooks/useResizeObserver.js';
2
4
  import VisuallyHidden from '../_VisuallyHidden.js';
5
+ import { dividerStyles, baseMenuMinWidth, menuItemStyles } from './styles.js';
6
+ import { UnderlineWrapper, UnderlineItemList, LoadingCounter, GAP } from '../internal/components/UnderlineTabbedInterface.js';
7
+ import { TriangleDownIcon } from '@primer/octicons-react';
8
+ import { useOnEscapePress } from '../hooks/useOnEscapePress.js';
9
+ import { useOnOutsideClick } from '../hooks/useOnOutsideClick.js';
10
+ import { useId } from '../hooks/useId.js';
3
11
  import { ActionList } from '../ActionList/index.js';
4
- import { UnderlineWrapper, UnderlineItemList, LoadingCounter } from '../internal/components/UnderlineTabbedInterface.js';
5
12
  import { invariant } from '../utils/invariant.js';
6
13
  import classes from './UnderlineNav.module.css.js';
7
- import { UnderlineNavContext } from './UnderlineNavContext.js';
8
- import { jsxs, jsx } from 'react/jsx-runtime';
14
+ import { getAnchoredPosition } from '@primer/behaviors';
15
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
16
+ import { ButtonComponent } from '../Button/Button.js';
9
17
  import CounterLabel from '../CounterLabel/CounterLabel.js';
10
- import { ActionMenu } from '../ActionMenu/ActionMenu.js';
11
18
 
19
+ // When page is loaded, we don't have ref for the more button as it is not on the DOM yet.
20
+ // 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.
21
+ const MORE_BTN_WIDTH = 86;
12
22
  // 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.
13
- const MORE_BTN_HEIGHT = 32;
23
+ const MORE_BTN_HEIGHT = 45;
24
+ const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
25
+ let iconsVisible = true;
26
+ if (childWidthArray.length === 0) {
27
+ updateListAndMenu({
28
+ items: childArray,
29
+ menuItems: []
30
+ }, iconsVisible);
31
+ }
32
+ const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
33
+ const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
34
+ // We need to take more menu width into account when calculating the number of items possible
35
+ const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ const items = [];
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ const menuItems = [];
40
+
41
+ // First, we check if we can fit all the items with their icons
42
+ if (childArray.length <= numberOfItemsPossible) {
43
+ items.push(...childArray);
44
+ } else if (childArray.length <= numberOfItemsWithoutIconPossible) {
45
+ // if we can't fit all the items with their icons, we check if we can fit all the items without their icons
46
+ iconsVisible = false;
47
+ items.push(...childArray);
48
+ } else {
49
+ // 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
50
+ iconsVisible = false;
51
+
52
+ /* Below is an accessibility requirement. Never show only one item in the overflow menu.
53
+ * If there is only one item left to display in the overflow menu according to the calculation,
54
+ * we need to pull another item from the list into the overflow menu.
55
+ */
56
+ const numberOfItemsInMenu = childArray.length - numberOfItemsPossibleWithMoreMenu;
57
+ const numberOfListItems = numberOfItemsInMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
58
+ for (const [index, child] of childArray.entries()) {
59
+ if (index < numberOfListItems) {
60
+ items.push(child);
61
+ } else {
62
+ const ariaCurrent = child.props['aria-current'];
63
+ const isCurrent = Boolean(ariaCurrent) && ariaCurrent !== 'false';
64
+ // We need to make sure to keep the selected item always visible.
65
+ // 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.)
66
+ if (isCurrent && numberOfListItems > 0) {
67
+ // If selected item couldn't make in to the list, we swap it with the last item in the list.
68
+ const indexToReplaceAt = numberOfListItems - 1; // because we are replacing the last item in the list
69
+ // 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.
70
+ const propsectiveAction = items.splice(indexToReplaceAt, 1, child)[0];
71
+ menuItems.push(propsectiveAction);
72
+ } else {
73
+ menuItems.push(child);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ updateListAndMenu({
79
+ items,
80
+ menuItems
81
+ }, iconsVisible);
82
+ };
14
83
  const getValidChildren = children => {
15
84
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
85
  return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
17
86
  };
87
+ const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
88
+ const widthToFit = navWidth - moreMenuWidth;
89
+ let breakpoint = childWidthArray.length; // assume all items will fit
90
+ let sumsOfChildWidth = 0;
91
+ for (const [index, childWidth] of childWidthArray.entries()) {
92
+ sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
93
+ if (sumsOfChildWidth > widthToFit) {
94
+ breakpoint = index;
95
+ break;
96
+ } else {
97
+ continue;
98
+ }
99
+ }
100
+ return breakpoint;
101
+ };
102
+
103
+ // Inline styles converted from baseMenuStyles for use as CSSProperties
104
+ const baseMenuInlineStyles = {
105
+ position: 'absolute',
106
+ zIndex: 1,
107
+ top: '90%',
108
+ boxShadow: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
109
+ borderRadius: 12,
110
+ background: 'var(--overlay-bgColor)',
111
+ listStyle: 'none',
112
+ minWidth: `${baseMenuMinWidth}px`,
113
+ maxWidth: '640px',
114
+ right: 0
115
+ };
18
116
  const UnderlineNav = /*#__PURE__*/forwardRef(({
19
117
  as = 'nav',
20
118
  'aria-label': ariaLabel,
@@ -23,31 +121,39 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
23
121
  className,
24
122
  children
25
123
  }, forwardedRef) => {
124
+ var _listRef$current2;
26
125
  const backupRef = useRef(null);
27
126
  const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
28
127
  const listRef = useRef(null);
29
-
30
- /** Tracks whether any item has ever overflowed for the lifecycle of this component. Used to prevent flickering. */
31
- const [isOrEverHasOverflowed, setIsOrEverHasOverflowed] = useState(false);
32
- const [registeredItems, setRegisteredItems] = useState(() => new Map());
33
- const registerItem = useCallback((id, menuItemProps) => {
34
- setRegisteredItems(prev => {
35
- if (menuItemProps === null && prev.get(id) === null) return prev;
36
- if (menuItemProps !== null) setIsOrEverHasOverflowed(true);
37
- const copy = new Map(prev);
38
- copy.set(id, menuItemProps);
39
- return copy;
40
- });
41
- }, []);
42
- const unregisterItem = useCallback(id => {
43
- setRegisteredItems(prev => {
44
- if (!prev.has(id)) return prev;
45
- const copy = new Map(prev);
46
- copy.delete(id);
47
- return copy;
48
- });
49
- }, []);
128
+ const moreMenuRef = useRef(null);
129
+ const moreMenuBtnRef = useRef(null);
130
+ const containerRef = React.useRef(null);
131
+ const disclosureWidgetId = useId();
132
+ const [isWidgetOpen, setIsWidgetOpen] = useState(false);
133
+ const [iconsVisible, setIconsVisible] = useState(true);
134
+ const [childWidthArray, setChildWidthArray] = useState([]);
135
+ const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
50
136
  const validChildren = getValidChildren(children);
137
+
138
+ // Responsive props object manages which items are in the list and which items are in the menu.
139
+ const [responsiveProps, setResponsiveProps] = useState({
140
+ items: validChildren,
141
+ menuItems: []
142
+ });
143
+
144
+ // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
145
+ const listItems = responsiveProps.items.map(item => {
146
+ var _validChildren$find;
147
+ return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
148
+ });
149
+
150
+ // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
151
+ const menuItems = responsiveProps.menuItems.map(menuItem => {
152
+ var _validChildren$find2;
153
+ return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
154
+ });
155
+ // 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
156
+ const onlyMenuVisible = responsiveProps.items.length === 0;
51
157
  if (process.env.NODE_ENV !== "production") {
52
158
  // Practically, this is not a conditional hook, it is just making sure this hook runs only on DEV not PROD.
53
159
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -60,83 +166,212 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
60
166
  !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;
61
167
  });
62
168
  }
63
- const menuItems = Array.from(registeredItems.entries()).filter(entry => entry[1] !== null);
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);
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) => {
211
+ setResponsiveProps(props);
212
+ setIconsVisible(displayIcons);
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
+ }, []);
226
+ const closeOverlay = React.useCallback(() => {
227
+ setIsWidgetOpen(false);
228
+ }, [setIsWidgetOpen]);
229
+ const focusOnMoreMenuBtn = React.useCallback(() => {
230
+ var _moreMenuBtnRef$curre;
231
+ (_moreMenuBtnRef$curre = moreMenuBtnRef.current) === null || _moreMenuBtnRef$curre === void 0 ? void 0 : _moreMenuBtnRef$curre.focus();
232
+ }, []);
233
+ const onAnchorClick = useCallback(event => {
234
+ if (event.defaultPrevented || event.button !== 0) {
235
+ return;
236
+ }
237
+ setIsWidgetOpen(isWidgetOpen => !isWidgetOpen);
238
+ }, []);
239
+ useOnEscapePress(event => {
240
+ if (isWidgetOpen) {
241
+ event.preventDefault();
242
+ closeOverlay();
243
+ focusOnMoreMenuBtn();
244
+ }
245
+ }, [isWidgetOpen]);
246
+ useOnOutsideClick({
247
+ onClickOutside: closeOverlay,
248
+ containerRef,
249
+ ignoreClickRefs: [moreMenuBtnRef]
250
+ });
251
+ useResizeObserver(resizeObserverEntries => {
252
+ var _moreMenuRef$current$, _moreMenuRef$current;
253
+ const navWidth = resizeObserverEntries[0].contentRect.width;
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);
256
+ }, navRef);
257
+
258
+ // Compute menuInlineStyles if needed
259
+ let menuInlineStyles = {
260
+ ...baseMenuInlineStyles
261
+ };
262
+ if (containerRef.current && listRef.current) {
263
+ const {
264
+ left
265
+ } = getAnchoredPosition(containerRef.current, listRef.current, {
266
+ align: 'start',
267
+ side: 'outside-bottom'
268
+ });
269
+ menuInlineStyles = {
270
+ ...baseMenuInlineStyles,
271
+ right: undefined,
272
+ left
273
+ };
274
+ }
64
275
  return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
65
276
  value: {
277
+ setChildrenWidth,
278
+ setNoIconChildrenWidth,
66
279
  loadingCounters,
67
- registerItem,
68
- unregisterItem
280
+ iconsVisible
69
281
  },
70
282
  children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
71
283
  as: "h2",
72
284
  children: `${ariaLabel} navigation`
73
- }), /*#__PURE__*/jsxs(UnderlineWrapper, {
285
+ }), /*#__PURE__*/jsx(UnderlineWrapper, {
74
286
  as: as,
75
287
  "aria-label": ariaLabel,
76
288
  className: className,
77
289
  ref: navRef,
78
- "data-variant": variant
79
- // When the component is first rendered, we use a scroll-state CSS container query to determine whether to
80
- // hide icons. This works well for SSR where we can't have run any effects yet. But the pure CSS approach
81
- // can cause flickering because hiding the icons makes more space, allowing them to show, which fills that
82
- // space...so after that, if anything has ever wrapped, we just keep the icons hidden to prevent that flickering.
83
- ,
84
- "data-hide-icons": isOrEverHasOverflowed ? 'true' : 'false',
85
- children: [/*#__PURE__*/jsx(UnderlineItemList, {
290
+ "data-variant": variant,
291
+ children: /*#__PURE__*/jsxs(UnderlineItemList, {
86
292
  ref: listRef,
87
293
  role: "list",
88
- children: children
89
- }), /*#__PURE__*/jsxs("div", {
90
- style: {
91
- height: `${MORE_BTN_HEIGHT}px`
92
- },
93
- className: classes.MoreButtonContainer,
94
- children: [/*#__PURE__*/jsx("div", {
95
- className: classes.MoreButtonDivider
96
- }), /*#__PURE__*/jsxs(ActionMenu, {
97
- children: [/*#__PURE__*/jsx(ActionMenu.Button, {
294
+ children: [listItems, menuItems.length > 0 && /*#__PURE__*/jsxs("li", {
295
+ ref: moreMenuRef,
296
+ style: {
297
+ display: 'flex',
298
+ alignItems: 'center',
299
+ height: `${MORE_BTN_HEIGHT}px`
300
+ },
301
+ children: [!onlyMenuVisible && /*#__PURE__*/jsx("div", {
302
+ style: dividerStyles
303
+ }), /*#__PURE__*/jsx(ButtonComponent, {
304
+ ref: moreMenuBtnRef,
98
305
  className: classes.MoreButton,
99
- children: /*#__PURE__*/jsxs("span", {
100
- children: ["More", /*#__PURE__*/jsx(VisuallyHidden, {
101
- as: "span",
102
- children: "\xA0 items"
103
- })]
306
+ "aria-controls": disclosureWidgetId,
307
+ "aria-expanded": isWidgetOpen,
308
+ onClick: onAnchorClick,
309
+ trailingAction: TriangleDownIcon,
310
+ children: /*#__PURE__*/jsx("span", {
311
+ children: onlyMenuVisible ? /*#__PURE__*/jsxs(Fragment, {
312
+ children: [/*#__PURE__*/jsxs(VisuallyHidden, {
313
+ as: "span",
314
+ children: [`${ariaLabel}`, "\xA0"]
315
+ }), "Menu"]
316
+ }) : /*#__PURE__*/jsxs(Fragment, {
317
+ children: ["More", /*#__PURE__*/jsxs(VisuallyHidden, {
318
+ as: "span",
319
+ children: ["\xA0", `${ariaLabel} items`]
320
+ })]
321
+ })
104
322
  })
105
- }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
106
- children: /*#__PURE__*/jsx(ActionList, {
107
- children: menuItems.map(([key, allProps]) => {
108
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
109
- const {
110
- children: menuItemChildren,
111
- counter,
112
- as,
113
- onSelect,
114
- ...menuItemProps
115
- } = allProps;
116
- return /*#__PURE__*/jsxs(ActionList.LinkItem, {
117
- className: classes.OverflowMenuItem,
118
- onClick: event => onSelect === null || onSelect === void 0 ? void 0 : onSelect(event),
119
- ...menuItemProps,
120
- children: [/*#__PURE__*/jsx("span", {
121
- className: classes.OverflowMenuItemLabel,
122
- children: menuItemChildren
123
- }), /*#__PURE__*/jsx(ActionList.TrailingVisual, {
124
- children: loadingCounters ? /*#__PURE__*/jsx(LoadingCounter, {}) : counter !== undefined && /*#__PURE__*/jsx("span", {
125
- "data-component": "counter",
126
- children: /*#__PURE__*/jsx(CounterLabel, {
127
- children: counter
128
- })
323
+ }), /*#__PURE__*/jsx(ActionList, {
324
+ selectionVariant: "single",
325
+ ref: containerRef,
326
+ id: disclosureWidgetId,
327
+ style: {
328
+ ...((_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= baseMenuMinWidth ? baseMenuInlineStyles : menuInlineStyles),
329
+ display: isWidgetOpen ? 'block' : 'none'
330
+ },
331
+ children: menuItems.map((menuItem, index) => {
332
+ const {
333
+ children: menuItemChildren,
334
+ counter,
335
+ 'aria-current': ariaCurrent,
336
+ onSelect,
337
+ ...menuItemProps
338
+ } = menuItem.props;
339
+
340
+ // This logic is used to pop the selected item out of the menu and into the list when the navigation is control externally
341
+ if (Boolean(ariaCurrent) && ariaCurrent !== 'false') {
342
+ const event = new MouseEvent('click');
343
+ !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index,
344
+ // @ts-ignore - not a big deal because it is internally creating an event but ask help
345
+ event, updateListAndMenu);
346
+ }
347
+ return /*#__PURE__*/jsx(ActionList.LinkItem, {
348
+ style: menuItemStyles,
349
+ onClick: event => {
350
+ // When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
351
+ !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
352
+ closeOverlay();
353
+ focusOnMoreMenuBtn();
354
+ // fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
355
+ typeof onSelect === 'function' && onSelect(event);
356
+ },
357
+ ...menuItemProps,
358
+ children: /*#__PURE__*/jsxs("span", {
359
+ className: classes.MenuItemContent,
360
+ children: [menuItemChildren, loadingCounters ? /*#__PURE__*/jsx(LoadingCounter, {}) : counter !== undefined && /*#__PURE__*/jsx("span", {
361
+ "data-component": "counter",
362
+ children: /*#__PURE__*/jsx(CounterLabel, {
363
+ children: counter
129
364
  })
130
365
  })]
131
- }, key);
132
- })
366
+ })
367
+ }, menuItemChildren);
133
368
  })
134
369
  })]
135
370
  })]
136
- })]
371
+ })
137
372
  })]
138
373
  });
139
374
  });
140
375
  UnderlineNav.displayName = 'UnderlineNav';
141
376
 
142
- export { UnderlineNav, getValidChildren };
377
+ export { MORE_BTN_WIDTH, UnderlineNav, getValidChildren };
@@ -1,5 +1,5 @@
1
- import './UnderlineNav-e56ca858.css';
1
+ import './UnderlineNav-4344d9b0.css';
2
2
 
3
- var classes = {"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"};
3
+ var classes = {"MenuItemContent":"prc-UnderlineNav-MenuItemContent-3J7gB","MoreButton":"prc-UnderlineNav-MoreButton-Y8soj"};
4
4
 
5
5
  export { classes as default };
@@ -1,7 +1,14 @@
1
- import type { UnderlineNavItemProps } from './UnderlineNavItem';
2
- export declare const UnderlineNavContext: import("react").Context<{
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
+ }>;
3
11
  loadingCounters: boolean;
4
- registerItem: (id: string, props: UnderlineNavItemProps | null) => void;
5
- unregisterItem: (id: string) => void;
12
+ iconsVisible: boolean;
6
13
  }>;
7
14
  //# sourceMappingURL=UnderlineNavContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNavContext.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAA;AAE7D,eAAO,MAAM,mBAAmB;qBACb,OAAO;kBACV,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,IAAI,KAAK,IAAI;oBACvD,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI;EAKpC,CAAA"}
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,9 +1,10 @@
1
1
  import { createContext } from 'react';
2
2
 
3
3
  const UnderlineNavContext = /*#__PURE__*/createContext({
4
+ setChildrenWidth: () => null,
5
+ setNoIconChildrenWidth: () => null,
4
6
  loadingCounters: false,
5
- registerItem: () => {},
6
- unregisterItem: () => {}
7
+ iconsVisible: true
7
8
  });
8
9
 
9
10
  export { UnderlineNavContext };
@@ -0,0 +1,2 @@
1
+ .prc-UnderlineNav-UnderlineNavItem-syRjR{align-items:center;display:flex;flex-direction:column}
2
+ /*# sourceMappingURL=UnderlineNavItem-b65e8fd3.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/UnderlineNav/UnderlineNavItem.module.css.js"],"names":[],"mappings":"AAAA,yCAGE,kBAAmB,CAFnB,YAAa,CACb,qBAEF","file":"UnderlineNavItem-b65e8fd3.css","sourcesContent":[".UnderlineNavItem {\n display: flex;\n flex-direction: column;\n align-items: center;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNavItem.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAmE,MAAM,OAAO,CAAA;AACvF,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAM/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,aAA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