@primer/react 0.0.0-20260619134534 → 0.0.0-20260619193118

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 (50) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/dist/ConfirmationDialog/useConfirm.d.ts.map +1 -1
  3. package/dist/ConfirmationDialog/useConfirm.js +8 -4
  4. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css +2 -0
  5. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css.map +1 -0
  6. package/dist/UnderlineNav/UnderlineNav.d.ts +1 -2
  7. package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
  8. package/dist/UnderlineNav/UnderlineNav.js +86 -332
  9. package/dist/UnderlineNav/UnderlineNav.module.css.js +2 -2
  10. package/dist/UnderlineNav/UnderlineNavContext.d.ts +1 -11
  11. package/dist/UnderlineNav/UnderlineNavContext.d.ts.map +1 -1
  12. package/dist/UnderlineNav/UnderlineNavContext.js +1 -4
  13. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css +2 -0
  14. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css.map +1 -0
  15. package/dist/UnderlineNav/UnderlineNavItem.d.ts +1 -32
  16. package/dist/UnderlineNav/UnderlineNavItem.d.ts.map +1 -1
  17. package/dist/UnderlineNav/UnderlineNavItem.js +33 -38
  18. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +1 -1
  19. package/dist/UnderlineNav/UnderlineNavItemsRegistry.d.ts +40 -0
  20. package/dist/UnderlineNav/UnderlineNavItemsRegistry.d.ts.map +1 -0
  21. package/dist/UnderlineNav/UnderlineNavItemsRegistry.js +6 -0
  22. package/dist/UnderlineNav/index.d.ts +1 -1
  23. package/dist/UnderlineNav/index.d.ts.map +1 -1
  24. package/dist/UnderlineNav/utils.d.ts +2 -0
  25. package/dist/UnderlineNav/utils.d.ts.map +1 -1
  26. package/dist/UnderlineNav/utils.js +2 -1
  27. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css +2 -0
  28. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css.map +1 -0
  29. package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +1 -1
  30. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css +2 -0
  31. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css.map +1 -0
  32. package/dist/internal/components/UnderlineTabbedInterface.d.ts +0 -1
  33. package/dist/internal/components/UnderlineTabbedInterface.d.ts.map +1 -1
  34. package/dist/internal/components/UnderlineTabbedInterface.js +66 -60
  35. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +1 -1
  36. package/generated/components.json +2 -2
  37. package/package.json +1 -1
  38. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css +0 -2
  39. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css.map +0 -1
  40. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css +0 -2
  41. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css.map +0 -1
  42. package/dist/UnderlineNav/styles.d.ts +0 -16
  43. package/dist/UnderlineNav/styles.d.ts.map +0 -1
  44. package/dist/UnderlineNav/styles.js +0 -19
  45. package/dist/UnderlineNav/types.d.ts +0 -10
  46. package/dist/UnderlineNav/types.d.ts.map +0 -1
  47. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css +0 -2
  48. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css.map +0 -1
  49. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css +0 -2
  50. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260619134534
3
+ ## 0.0.0-20260619193118
4
4
 
5
- ### Patch Changes
5
+ ### Minor Changes
6
6
 
7
- - [#7935](https://github.com/primer/react/pull/7935) [`2765933`](https://github.com/primer/react/commit/276593387ec84f72aeba02a940b5e0a4d0a026a9) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - ConfirmationDialog: `useConfirm`/`confirm` now removes its host element from `document.body` after the dialog is closed, and uses a fresh host element per call, so the empty container no longer lingers or leaks into other components and tests
7
+ - [#7622](https://github.com/primer/react/pull/7622) [`4d8d5e6`](https://github.com/primer/react/commit/4d8d5e6b9b0b1d394d19154369f9c37eabe7cb87) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Refactors `UnderlineNav` overflow handling to use CSS-based overflow detection instead of JavaScript width measurements, eliminating layout shift (CLS) issues and improving performance. The overflow menu is now implemented with `ActionMenu`, and item registration uses a descendant registry instead of the `React.Children` API. Consumer-facing changes: items can now be wrapped in fragments or wrapper components; the current item may appear in the overflow menu when the viewport is narrow; and the overflow menu button is right-aligned.
8
+
9
+ ### Patch Changes
8
10
 
9
11
  - Fake entry to force publishing
10
12
 
@@ -1 +1 @@
1
- {"version":3,"file":"useConfirm.d.ts","sourceRoot":"","sources":["../../src/ConfirmationDialog/useConfirm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAA;AAGxC,OAAO,EAAqB,KAAK,uBAAuB,EAAC,MAAM,sBAAsB,CAAA;AAErF,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,uBAAuB,EAAE,SAAS,CAAC,GAAG;IAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAA;CAAC,CAAA;AAuBlG;;;;GAIG;AACH,wBAAgB,UAAU,cACa,cAAc,sBAIpD"}
1
+ {"version":3,"file":"useConfirm.d.ts","sourceRoot":"","sources":["../../src/ConfirmationDialog/useConfirm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAA;AAGxC,OAAO,EAAqB,KAAK,uBAAuB,EAAC,MAAM,sBAAsB,CAAA;AAIrF,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,uBAAuB,EAAE,SAAS,CAAC,GAAG;IAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAA;CAAC,CAAA;AA0BlG;;;;GAIG;AACH,wBAAgB,UAAU,cACa,cAAc,sBAIpD"}
@@ -3,19 +3,23 @@ import { createRoot } from 'react-dom/client';
3
3
  import BaseStyles from '../BaseStyles.js';
4
4
  import { ConfirmationDialog } from './ConfirmationDialog.js';
5
5
 
6
+ let hostElement = null;
6
7
  async function confirm(options) {
7
8
  const {
8
9
  content,
9
10
  ...confirmationDialogProps
10
11
  } = options;
11
12
  return new Promise(resolve => {
12
- const hostElement = document.createElement('div');
13
- document.body.append(hostElement);
13
+ hostElement ||= document.createElement('div');
14
+ if (!hostElement.isConnected) document.body.append(hostElement);
14
15
  const root = createRoot(hostElement);
15
16
  const onClose = gesture => {
16
17
  root.unmount();
17
- hostElement.remove();
18
- resolve(gesture === 'confirm');
18
+ if (gesture === 'confirm') {
19
+ resolve(true);
20
+ } else {
21
+ resolve(false);
22
+ }
19
23
  };
20
24
  root.render(/*#__PURE__*/React.createElement(BaseStyles, null, /*#__PURE__*/React.createElement(ConfirmationDialog, {
21
25
  ...confirmationDialogProps,
@@ -0,0 +1,2 @@
1
+ .prc-UnderlineNav-UnderlineWrapper-GWONT{animation:prc-UnderlineNav-detect-overflow-6HuSH linear;animation-timeline:scroll(self block);--UnderlineNav_moreButton-visibility:hidden;--UnderlineNav_icons-display:inline}.prc-UnderlineNav-UnderlineWrapper-GWONT[data-hide-icons=true]{--UnderlineNav_icons-display:none}.prc-UnderlineNav-UnderlineWrapper-GWONT[data-has-overflow=true]{--UnderlineNav_moreButton-visibility:visible}@keyframes prc-UnderlineNav-detect-overflow-6HuSH{0%,to{--UnderlineNav_moreButton-visibility:visible;--UnderlineNav_icons-display:none}}.prc-UnderlineNav-ItemsList-oj8gN [data-component=icon]{display:var(--UnderlineNav_icons-display)}.prc-UnderlineNav-MoreButtonContainer-Dnrq6{align-items:center;display:flex;visibility:var(--UnderlineNav_moreButton-visibility)}.prc-UnderlineNav-OverflowMenuItem-7SG7M [aria-current]{position:relative}.prc-UnderlineNav-OverflowMenuItem-7SG7M [aria-current] .prc-UnderlineNav-OverflowMenuItemLabel-F80v6{font-weight:var(--base-text-weight-semibold,600)}.prc-UnderlineNav-OverflowMenuItem-7SG7M [aria-current]:after{background:var(--underlineNav-borderColor-active,#fd8c73);content:"";inset:var(--base-size-2,.125rem) auto var(--base-size-2,.125rem) 0;position:absolute;width:var(--base-size-2,.125rem)}.prc-UnderlineNav-MoreButtonDivider-dN0a-{border-left:var(--borderWidth-thin,.0625rem) solid var(--borderColor-muted,#d1d9e0b3);display:inline-block;height:var(--base-size-24,1.5rem);margin-inline:var(--base-size-4,.25rem);width:0}.prc-UnderlineNav-MoreButton-Y8soj{font-weight:var(--base-text-weight-normal,400);margin:0;position:relative}.prc-UnderlineNav-MoreButton-Y8soj>[data-component=trailingVisual]{margin-left:0}.prc-UnderlineNav-MoreButton-Y8soj[data-current=true]{font-weight:var(--base-text-weight-semibold,600)}.prc-UnderlineNav-MoreButton-Y8soj[data-current=true]:after{background-color:var(--underlineNav-borderColor-active,var(--color-primer-border-active,#fd8c73));content:"";height:2px;inset:auto 0 0;margin-bottom:calc(var(--base-size-8,.5rem)*-1);pointer-events:none;position:absolute}@media (forced-colors:active){.prc-UnderlineNav-MoreButton-Y8soj[data-current=true]:after{background-color:LinkText}}
2
+ /*# sourceMappingURL=UnderlineNav-263b4e8f.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/UnderlineNav/UnderlineNav.module.css.js"],"names":[],"mappings":"AAAA,yCAIE,uDAAiC,CACjC,qCAAsC,CAEtC,2CAA4C,CAC5C,mCASF,CAPE,+DACE,iCACF,CAEA,iEACE,4CACF,CAGF,kDACE,MAEE,4CAA6C,CAC7C,iCACF,CACF,CAEA,wDACE,yCACF,CAEA,4CAGE,kBAAmB,CAFnB,YAAa,CACb,oDAEF,CAEA,wDACE,iBAcF,CAZE,sGACE,gDACF,CAEA,8DAME,yDAAkD,CALlD,UAAW,CAGX,kEAAmD,CADnD,iBAAkB,CADlB,gCAKF,CAGF,0CAEE,qFAAmE,CADnE,oBAAqB,CAIrB,iCAA2B,CAD3B,uCAAiC,CADjC,OAGF,CAEA,mCAEE,8CAA2C,CAD3C,QAAS,CAET,iBA2BF,CAzBE,mEACE,aACF,CAIA,sDACE,gDAiBF,CAfE,4DAQE,iGAAoG,CAFpG,UAAW,CAFX,UAAW,CAFX,cAAe,CACf,+CAA4C,CAE5C,mBAAoB,CAJpB,iBAaF,CAJE,8BAVF,4DAYI,yBAEJ,CADE","file":"UnderlineNav-263b4e8f.css","sourcesContent":[".UnderlineWrapper {\n /* Progressive enhancement: Detect overflow using scroll-based animations.\n The idiomatic way would be a scroll-state container query but browser support\n is slightly better for animations. */\n animation: detect-overflow linear;\n animation-timeline: scroll(self block);\n\n --UnderlineNav_moreButton-visibility: hidden;\n --UnderlineNav_icons-display: inline;\n\n &[data-hide-icons='true'] {\n --UnderlineNav_icons-display: none;\n }\n\n &[data-has-overflow='true'] {\n --UnderlineNav_moreButton-visibility: visible;\n }\n}\n\n@keyframes detect-overflow {\n 0%,\n 100% {\n --UnderlineNav_moreButton-visibility: visible;\n --UnderlineNav_icons-display: none;\n }\n}\n\n.ItemsList [data-component='icon'] {\n display: var(--UnderlineNav_icons-display);\n}\n\n.MoreButtonContainer {\n display: flex;\n visibility: var(--UnderlineNav_moreButton-visibility);\n align-items: center;\n}\n\n.OverflowMenuItem [aria-current] {\n position: relative;\n\n .OverflowMenuItemLabel {\n font-weight: var(--base-text-weight-semibold);\n }\n\n &::after {\n content: '';\n width: var(--base-size-2);\n position: absolute;\n inset: var(--base-size-2) auto var(--base-size-2) 0;\n /* stylelint-disable-next-line primer/colors */\n background: var(--underlineNav-borderColor-active);\n }\n}\n\n.MoreButtonDivider {\n display: inline-block;\n border-left: var(--borderWidth-thin) solid var(--borderColor-muted);\n width: 0;\n margin-inline: var(--base-size-4);\n height: var(--base-size-24);\n}\n\n.MoreButton {\n margin: 0; /* reset Safari extra margin */\n font-weight: var(--base-text-weight-normal);\n position: relative;\n\n & > [data-component='trailingVisual'] {\n margin-left: 0;\n }\n\n /* When the current item has overflowed into the menu, style the overflow\n anchor so it looks like the current item (semibold text + active underline). */\n &[data-current='true'] {\n font-weight: var(--base-text-weight-semibold);\n\n &::after {\n position: absolute;\n inset: auto 0 0;\n margin-bottom: calc(-1 * var(--base-size-8));\n height: 2px;\n pointer-events: none;\n content: '';\n /* stylelint-disable-next-line primer/colors */\n background-color: var(--underlineNav-borderColor-active, var(--color-primer-border-active, #fd8c73));\n\n @media (forced-colors: active) {\n /* Support for Windows Forced Color Mode https://learn.microsoft.com/en-us/fluent-ui/web-components/design-system/high-contrast */\n background-color: LinkText;\n }\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  export type UnderlineNavProps = {
3
3
  children: React.ReactNode;
4
4
  'aria-label'?: React.AriaAttributes['aria-label'];
@@ -15,6 +15,5 @@ export type UnderlineNavProps = {
15
15
  */
16
16
  variant?: 'inset' | 'flush';
17
17
  };
18
- export declare const MORE_BTN_WIDTH = 86;
19
18
  export declare const UnderlineNav: React.ForwardRefExoticComponent<UnderlineNavProps & React.RefAttributes<unknown>>;
20
19
  //# sourceMappingURL=UnderlineNav.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAqBtE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAGD,eAAO,MAAM,cAAc,KAAK,CAAA;AAsGhC,eAAO,MAAM,YAAY,mFA0SxB,CAAA"}
1
+ {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAgB9B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,YAAY,mFAiIxB,CAAA"}
@@ -1,117 +1,19 @@
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 { 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 { getValidChildren } from './utils.js';
17
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
18
- import { ButtonComponent } from '../Button/Button.js';
7
+ import { UnderlineNavContext } from './UnderlineNavContext.js';
8
+ import { UnderlineNavItemsRegistry } from './UnderlineNavItemsRegistry.js';
9
+ import { clsx } from 'clsx';
10
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
11
+ import { isCurrent, getValidChildren } from './utils.js';
12
+ import { jsxs, jsx } from 'react/jsx-runtime';
13
+ import { SkeletonText } from '../SkeletonText/SkeletonText.js';
19
14
  import CounterLabel from '../CounterLabel/CounterLabel.js';
15
+ import { ActionMenu } from '../ActionMenu/ActionMenu.js';
20
16
 
21
- // When page is loaded, we don't have ref for the more button as it is not on the DOM yet.
22
- // 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.
23
- const MORE_BTN_WIDTH = 86;
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
- const MORE_BTN_HEIGHT = 45;
26
- const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
27
- let iconsVisible = true;
28
- if (childWidthArray.length === 0) {
29
- updateListAndMenu({
30
- items: childArray,
31
- menuItems: []
32
- }, iconsVisible, false);
33
- return;
34
- }
35
- const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
36
- const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
37
- // We need to take more menu width into account when calculating the number of items possible
38
- const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
39
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
- const items = [];
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- const menuItems = [];
43
-
44
- // First, we check if we can fit all the items with their icons
45
- if (childArray.length <= numberOfItemsPossible) {
46
- items.push(...childArray);
47
- } else if (childArray.length <= numberOfItemsWithoutIconPossible) {
48
- // if we can't fit all the items with their icons, we check if we can fit all the items without their icons
49
- iconsVisible = false;
50
- items.push(...childArray);
51
- } else {
52
- // 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
53
- iconsVisible = false;
54
-
55
- /* Below is an accessibility requirement. Never show only one item in the overflow menu.
56
- * If there is only one item left to display in the overflow menu according to the calculation,
57
- * we need to pull another item from the list into the overflow menu.
58
- */
59
- const numberOfItemsInMenu = childArray.length - numberOfItemsPossibleWithMoreMenu;
60
- const numberOfListItems = numberOfItemsInMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
61
- for (const [index, child] of childArray.entries()) {
62
- if (index < numberOfListItems) {
63
- items.push(child);
64
- } else {
65
- const ariaCurrent = child.props['aria-current'];
66
- const isCurrent = Boolean(ariaCurrent) && ariaCurrent !== 'false';
67
- // We need to make sure to keep the selected item always visible.
68
- // 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.)
69
- if (isCurrent && numberOfListItems > 0) {
70
- // If selected item couldn't make in to the list, we swap it with the last item in the list.
71
- const indexToReplaceAt = numberOfListItems - 1; // because we are replacing the last item in the list
72
- // 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.
73
- const propsectiveAction = items.splice(indexToReplaceAt, 1, child)[0];
74
- menuItems.push(propsectiveAction);
75
- } else {
76
- menuItems.push(child);
77
- }
78
- }
79
- }
80
- }
81
- updateListAndMenu({
82
- items,
83
- menuItems
84
- }, iconsVisible, true);
85
- };
86
- const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
87
- const widthToFit = navWidth - moreMenuWidth;
88
- let breakpoint = childWidthArray.length; // assume all items will fit
89
- let sumsOfChildWidth = 0;
90
- for (const [index, childWidth] of childWidthArray.entries()) {
91
- sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
92
- if (sumsOfChildWidth > widthToFit) {
93
- breakpoint = index;
94
- break;
95
- } else {
96
- continue;
97
- }
98
- }
99
- return breakpoint;
100
- };
101
-
102
- // Inline styles converted from baseMenuStyles for use as CSSProperties
103
- const baseMenuInlineStyles = {
104
- position: 'absolute',
105
- zIndex: 1,
106
- top: '90%',
107
- boxShadow: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
108
- borderRadius: 12,
109
- background: 'var(--overlay-bgColor)',
110
- listStyle: 'none',
111
- minWidth: `${baseMenuMinWidth}px`,
112
- maxWidth: '640px',
113
- right: 0
114
- };
115
17
  const UnderlineNav = /*#__PURE__*/forwardRef(({
116
18
  as = 'nav',
117
19
  'aria-label': ariaLabel,
@@ -120,259 +22,111 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
120
22
  className,
121
23
  children
122
24
  }, forwardedRef) => {
123
- var _listRef$current2;
25
+ var _registeredItems$entr;
124
26
  const backupRef = useRef(null);
125
27
  const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
126
28
  const listRef = useRef(null);
127
- const moreMenuRef = useRef(null);
128
- const moreMenuBtnRef = useRef(null);
129
- const containerRef = React.useRef(null);
130
- const disclosureWidgetId = useId();
131
- const [isWidgetOpen, setIsWidgetOpen] = useState(false);
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);
137
- const validChildren = getValidChildren(children);
138
29
 
139
- // Responsive props object manages which items are in the list and which items are in the menu.
140
- const [responsiveProps, setResponsiveProps] = useState({
141
- items: validChildren,
142
- menuItems: []
143
- });
30
+ /** Tracks whether any item has ever overflowed for the lifecycle of this component. Used to prevent flickering. */
31
+ const [hasEverOverflowed, setHasOverflowed] = useState(false);
32
+ const [registeredItems, setRegisteredItems] = UnderlineNavItemsRegistry.useRegistryState();
33
+ 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);
34
+ const isOverflowing = overflowMenuItems.length > 0;
35
+ if (isOverflowing && !hasEverOverflowed) setHasOverflowed(true);
144
36
 
145
- // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
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;
149
- });
150
-
151
- // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
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;
155
- });
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
157
- const onlyMenuVisible = responsiveProps.items.length === 0;
37
+ // Find the current item if it has overflowed into the menu, so we can reflect
38
+ // its "current" state on the overflow menu anchor.
39
+ const overflowingCurrentItem = overflowMenuItems.some(([, itemProps]) => isCurrent(itemProps));
40
+ const validChildren = getValidChildren(children);
158
41
  useDevOnlyEffect(() => {
159
42
  // Address illegal state where there are multiple items that have `aria-current='page'` attribute
160
- const activeElements = validChildren.filter(child => {
161
- return child.props['aria-current'] !== undefined;
162
- });
43
+ const activeElements = validChildren.filter(child => isCurrent(child.props));
163
44
  !(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
164
45
  !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;
165
46
  }, [validChildren, ariaLabel]);
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) => {
171
- var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
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
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);
176
-
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);
183
- const updatedItemList = [...itemsLeftInList, prospectiveListItem];
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)
188
- updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
189
- callback({
190
- items: updatedItemList,
191
- menuItems: updatedMenuItems
192
- }, false, true);
193
- };
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;
203
- }
204
- }
205
- return breakpoint;
206
- }
207
- const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
208
- setResponsiveProps(props);
209
- setIconsVisible(displayIcons);
210
- if (overflowMeasured) {
211
- setIsOverflowMeasured(true);
212
- }
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
- }
47
+ const contextValue = useMemo(() => ({
48
+ loadingCounters
49
+ }), [loadingCounters]);
275
50
  return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
276
- value: {
277
- setChildrenWidth,
278
- setNoIconChildrenWidth,
279
- loadingCounters,
280
- iconsVisible
281
- },
51
+ value: contextValue,
282
52
  children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
283
53
  as: "h2",
284
54
  children: `${ariaLabel} navigation`
285
- }), /*#__PURE__*/jsx(UnderlineWrapper, {
55
+ }), /*#__PURE__*/jsxs(UnderlineWrapper, {
286
56
  as: as,
287
57
  "aria-label": ariaLabel,
288
- className: className,
58
+ className: clsx(classes.UnderlineWrapper, className),
289
59
  ref: navRef,
290
60
  "data-variant": variant,
291
- "data-overflow-measured": isOverflowMeasured ? 'true' : 'false',
292
- children: /*#__PURE__*/jsxs(UnderlineItemList, {
61
+ "data-overflow-mode": "wrap"
62
+ // Force icons to stay hidden, avoiding flickering as icons create/remove overflow
63
+ ,
64
+ "data-hide-icons": hasEverOverflowed ? 'true' : undefined
65
+ // Ensure button is shown (after initial render) on browsers that don't support scroll-driven animations
66
+ ,
67
+ "data-has-overflow": isOverflowing ? 'true' : undefined,
68
+ children: [/*#__PURE__*/jsx(UnderlineItemList, {
293
69
  ref: listRef,
294
70
  role: "list",
295
- children: [listItems, menuItems.length > 0 && /*#__PURE__*/jsxs("li", {
296
- ref: moreMenuRef,
297
- style: {
298
- display: 'flex',
299
- alignItems: 'center',
300
- height: `${MORE_BTN_HEIGHT}px`
301
- },
302
- children: [!onlyMenuVisible && /*#__PURE__*/jsx("div", {
303
- style: dividerStyles
304
- }), /*#__PURE__*/jsx(ButtonComponent, {
305
- ref: moreMenuBtnRef,
71
+ className: classes.ItemsList,
72
+ children: /*#__PURE__*/jsx(UnderlineNavItemsRegistry.Provider, {
73
+ setRegistry: setRegisteredItems,
74
+ children: children
75
+ })
76
+ }), /*#__PURE__*/jsxs("div", {
77
+ className: classes.MoreButtonContainer,
78
+ children: [/*#__PURE__*/jsx("div", {
79
+ className: classes.MoreButtonDivider
80
+ }), /*#__PURE__*/jsxs(ActionMenu, {
81
+ children: [/*#__PURE__*/jsx(ActionMenu.Button, {
306
82
  className: classes.MoreButton,
307
- "aria-controls": disclosureWidgetId,
308
- "aria-expanded": isWidgetOpen,
309
- onClick: onAnchorClick,
310
- trailingAction: TriangleDownIcon,
311
- children: /*#__PURE__*/jsx("span", {
312
- children: onlyMenuVisible ? /*#__PURE__*/jsxs(Fragment, {
313
- children: [/*#__PURE__*/jsxs(VisuallyHidden, {
314
- as: "span",
315
- children: [`${ariaLabel}`, "\xA0"]
316
- }), "Menu"]
317
- }) : /*#__PURE__*/jsxs(Fragment, {
318
- children: ["More", /*#__PURE__*/jsxs(VisuallyHidden, {
319
- as: "span",
320
- children: ["\xA0", `${ariaLabel} items`]
321
- })]
322
- })
83
+ variant: "invisible",
84
+ "data-component": "overflow-menu-button",
85
+ "data-current": overflowingCurrentItem ? 'true' : undefined,
86
+ "aria-label": overflowingCurrentItem ? `More items, including current item` : undefined,
87
+ children: /*#__PURE__*/jsxs("span", {
88
+ children: ["More", /*#__PURE__*/jsx(VisuallyHidden, {
89
+ as: "span",
90
+ children: " items"
91
+ })]
323
92
  })
324
- }), /*#__PURE__*/jsx(ActionList, {
325
- selectionVariant: "single",
326
- ref: containerRef,
327
- id: disclosureWidgetId,
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
- },
332
- children: menuItems.map((menuItem, index) => {
333
- const {
334
- children: menuItemChildren,
335
- counter,
336
- 'aria-current': ariaCurrent,
337
- onSelect,
338
- ...menuItemProps
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
- }
348
- return /*#__PURE__*/jsx(ActionList.LinkItem, {
349
- style: menuItemStyles,
350
- onClick: event => {
351
- // When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
352
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
353
- closeOverlay();
354
- focusOnMoreMenuBtn();
355
- // fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
356
- typeof onSelect === 'function' && onSelect(event);
357
- },
358
- ...menuItemProps,
359
- children: /*#__PURE__*/jsxs("span", {
360
- className: classes.MenuItemContent,
361
- children: [menuItemChildren, loadingCounters ? /*#__PURE__*/jsx(LoadingCounter, {}) : counter !== undefined && /*#__PURE__*/jsx("span", {
362
- "data-component": "counter",
363
- children: /*#__PURE__*/jsx(CounterLabel, {
364
- children: counter
93
+ }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
94
+ children: /*#__PURE__*/jsx(ActionList, {
95
+ children: registeredItems === undefined ? /*#__PURE__*/jsx(ActionList.Item, {
96
+ children: /*#__PURE__*/jsx(SkeletonText, {})
97
+ }) : overflowMenuItems.map(([key, allProps]) => {
98
+ const {
99
+ children: menuItemChildren,
100
+ counter,
101
+ onSelect,
102
+ ...menuItemProps
103
+ } = allProps;
104
+ return /*#__PURE__*/jsxs(ActionList.LinkItem, {
105
+ className: classes.OverflowMenuItem,
106
+ onClick: event => onSelect === null || onSelect === void 0 ? void 0 : onSelect(event),
107
+ ...menuItemProps,
108
+ children: [/*#__PURE__*/jsx("span", {
109
+ className: classes.OverflowMenuItemLabel,
110
+ children: menuItemChildren
111
+ }), loadingCounters ? /*#__PURE__*/jsx(ActionList.TrailingVisual, {
112
+ children: /*#__PURE__*/jsx(LoadingCounter, {})
113
+ }) : counter !== undefined && /*#__PURE__*/jsx(ActionList.TrailingVisual, {
114
+ children: /*#__PURE__*/jsx("span", {
115
+ "data-component": "counter",
116
+ children: /*#__PURE__*/jsx(CounterLabel, {
117
+ children: counter
118
+ })
365
119
  })
366
120
  })]
367
- })
368
- }, menuItemChildren);
121
+ }, key);
122
+ })
369
123
  })
370
124
  })]
371
125
  })]
372
- })
126
+ })]
373
127
  })]
374
128
  });
375
129
  });
376
130
  UnderlineNav.displayName = 'UnderlineNav';
377
131
 
378
- export { MORE_BTN_WIDTH, UnderlineNav };
132
+ 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"]}