@primer/react 0.0.0-20260428150519 → 0.0.0-20260428191209

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 (362) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/ActionBar/ActionBar.js +705 -502
  3. package/dist/ActionBar/ActionBar.module.css.js +5 -10
  4. package/dist/ActionBar/index.js +8 -8
  5. package/dist/ActionList/{ActionList-53389912.css → ActionList-09f5c4a8.css} +2 -2
  6. package/dist/ActionList/ActionList-09f5c4a8.css.map +1 -0
  7. package/dist/ActionList/ActionList.module.css.js +5 -31
  8. package/dist/ActionList/ActionListContainerContext.js +5 -4
  9. package/dist/ActionList/Description.js +133 -117
  10. package/dist/ActionList/Divider.js +38 -31
  11. package/dist/ActionList/Group.js +349 -292
  12. package/dist/ActionList/Group.module.css.js +5 -10
  13. package/dist/ActionList/Heading.js +106 -88
  14. package/dist/ActionList/Heading.module.css.js +5 -5
  15. package/dist/ActionList/Item.js +811 -668
  16. package/dist/ActionList/LinkItem.js +56 -36
  17. package/dist/ActionList/List.js +210 -168
  18. package/dist/ActionList/Selection.d.ts +2 -3
  19. package/dist/ActionList/Selection.d.ts.map +1 -1
  20. package/dist/ActionList/Selection.js +112 -83
  21. package/dist/ActionList/TrailingAction.js +112 -97
  22. package/dist/ActionList/Visuals.js +191 -143
  23. package/dist/ActionList/index.d.ts +7 -0
  24. package/dist/ActionList/index.d.ts.map +1 -1
  25. package/dist/ActionList/index.js +38 -33
  26. package/dist/ActionList/shared.js +9 -5
  27. package/dist/ActionMenu/ActionMenu.js +310 -223
  28. package/dist/ActionMenu/ActionMenu.module.css.js +5 -5
  29. package/dist/AnchoredOverlay/AnchoredOverlay.js +280 -206
  30. package/dist/AnchoredOverlay/AnchoredOverlay.module.css.js +5 -9
  31. package/dist/Autocomplete/Autocomplete.js +141 -125
  32. package/dist/Autocomplete/AutocompleteContext.js +20 -18
  33. package/dist/Autocomplete/AutocompleteInput.js +146 -108
  34. package/dist/Autocomplete/AutocompleteMenu.js +238 -201
  35. package/dist/Autocomplete/AutocompleteMenu.module.css.js +5 -8
  36. package/dist/Autocomplete/AutocompleteOverlay.js +79 -54
  37. package/dist/Autocomplete/AutocompleteOverlay.module.css.js +5 -5
  38. package/dist/Avatar/Avatar.js +133 -106
  39. package/dist/Avatar/Avatar.module.css.js +5 -5
  40. package/dist/AvatarStack/AvatarStack.js +143 -102
  41. package/dist/AvatarStack/AvatarStack.module.css.js +5 -9
  42. package/dist/Banner/Banner.js +186 -133
  43. package/dist/Banner/Banner.module.css.js +5 -14
  44. package/dist/Banner/index.js +7 -7
  45. package/dist/BaseStyles.js +91 -74
  46. package/dist/BaseStyles.module.css.js +5 -5
  47. package/dist/Blankslate/Blankslate.js +328 -266
  48. package/dist/Blankslate/Blankslate.module.css.js +5 -12
  49. package/dist/Blankslate/BlankslateContext.js +9 -7
  50. package/dist/Blankslate/index.js +9 -9
  51. package/dist/BranchName/BranchName.js +59 -49
  52. package/dist/BranchName/BranchName.module.css.js +5 -5
  53. package/dist/Breadcrumbs/Breadcrumbs.js +431 -371
  54. package/dist/Breadcrumbs/Breadcrumbs.module.css.js +5 -15
  55. package/dist/Button/Button.js +18 -15
  56. package/dist/Button/ButtonBase.js +139 -76
  57. package/dist/Button/ButtonBase.module.css.js +5 -16
  58. package/dist/Button/IconButton.js +74 -42
  59. package/dist/Button/LinkButton.js +17 -13
  60. package/dist/ButtonGroup/ButtonGroup.js +97 -80
  61. package/dist/ButtonGroup/ButtonGroup.module.css.js +5 -5
  62. package/dist/Card/Card.js +491 -401
  63. package/dist/Card/Card.module.css.js +5 -18
  64. package/dist/Card/index.js +9 -9
  65. package/dist/Checkbox/Checkbox.js +71 -52
  66. package/dist/Checkbox/Checkbox.module.css.js +5 -9
  67. package/dist/Checkbox/shared.module.css.js +5 -5
  68. package/dist/CheckboxGroup/CheckboxGroup.js +132 -111
  69. package/dist/CheckboxGroup/CheckboxGroupContext.js +4 -4
  70. package/dist/CircleBadge/CircleBadge.js +90 -77
  71. package/dist/CircleBadge/CircleBadge.module.css.js +5 -8
  72. package/dist/ConfirmationDialog/ConfirmationDialog.js +92 -68
  73. package/dist/CounterLabel/CounterLabel.js +99 -83
  74. package/dist/CounterLabel/CounterLabel.module.css.js +5 -5
  75. package/dist/DataTable/DataTable.js +140 -100
  76. package/dist/DataTable/ErrorDialog.js +45 -33
  77. package/dist/DataTable/Pagination.js +592 -464
  78. package/dist/DataTable/Pagination.module.css.js +5 -13
  79. package/dist/DataTable/Table.js +710 -527
  80. package/dist/DataTable/Table.module.css.js +5 -26
  81. package/dist/DataTable/column.js +11 -10
  82. package/dist/DataTable/index.js +20 -22
  83. package/dist/DataTable/sorting.js +103 -65
  84. package/dist/DataTable/useTable.js +290 -207
  85. package/dist/Details/Details.js +126 -100
  86. package/dist/Details/Details.module.css.js +5 -5
  87. package/dist/Dialog/Dialog.js +351 -259
  88. package/dist/Dialog/Dialog.module.css.js +5 -22
  89. package/dist/FeatureFlags/DefaultFeatureFlags.js +7 -7
  90. package/dist/FeatureFlags/FeatureFlagContext.js +5 -5
  91. package/dist/FeatureFlags/FeatureFlagScope.js +44 -36
  92. package/dist/FeatureFlags/FeatureFlags.js +37 -29
  93. package/dist/FeatureFlags/useFeatureFlag.js +19 -17
  94. package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
  95. package/dist/FilteredActionList/FilteredActionList.js +559 -454
  96. package/dist/FilteredActionList/FilteredActionList.module.css.js +5 -15
  97. package/dist/FilteredActionList/FilteredActionListInput.d.ts +15 -0
  98. package/dist/FilteredActionList/FilteredActionListInput.d.ts.map +1 -0
  99. package/dist/FilteredActionList/FilteredActionListInput.js +119 -0
  100. package/dist/FilteredActionList/FilteredActionListLoaders.js +150 -119
  101. package/dist/FilteredActionList/FilteredActionListLoaders.module.css.js +5 -9
  102. package/dist/FilteredActionList/index.d.ts +9 -1
  103. package/dist/FilteredActionList/index.d.ts.map +1 -1
  104. package/dist/FilteredActionList/index.js +11 -0
  105. package/dist/FilteredActionList/useAnnouncements.js +180 -167
  106. package/dist/Flash/Flash.js +69 -57
  107. package/dist/Flash/Flash.module.css.js +5 -5
  108. package/dist/FormControl/FormControl.js +227 -211
  109. package/dist/FormControl/FormControl.module.css.js +5 -11
  110. package/dist/FormControl/FormControlCaption.js +49 -37
  111. package/dist/FormControl/FormControlCaption.module.css.js +5 -5
  112. package/dist/FormControl/FormControlLabel.js +115 -95
  113. package/dist/FormControl/FormControlLeadingVisual.js +37 -29
  114. package/dist/FormControl/FormControlLeadingVisual.module.css.js +5 -5
  115. package/dist/FormControl/_FormControlContext.js +48 -41
  116. package/dist/FormControl/_FormControlValidation.js +39 -29
  117. package/dist/Header/Header.js +165 -138
  118. package/dist/Header/Header.module.css.js +5 -9
  119. package/dist/Heading/Heading.js +37 -26
  120. package/dist/Heading/Heading.module.css.js +5 -5
  121. package/dist/Hidden/Hidden.js +77 -54
  122. package/dist/Hidden/Hidden.module.css.js +5 -5
  123. package/dist/InlineMessage/InlineMessage.js +116 -88
  124. package/dist/InlineMessage/InlineMessage.module.css.js +5 -8
  125. package/dist/KeybindingHint/KeybindingHint.js +88 -70
  126. package/dist/KeybindingHint/KeybindingHint.module.css.js +5 -5
  127. package/dist/KeybindingHint/components/Chord.js +93 -81
  128. package/dist/KeybindingHint/components/Chord.module.css.js +5 -11
  129. package/dist/KeybindingHint/components/Key.js +66 -49
  130. package/dist/KeybindingHint/components/Sequence.js +24 -12
  131. package/dist/KeybindingHint/key-names.js +114 -99
  132. package/dist/Label/Label.js +66 -56
  133. package/dist/Label/Label.module.css.js +5 -5
  134. package/dist/Label/index.js +5 -5
  135. package/dist/LabelGroup/LabelGroup.js +344 -260
  136. package/dist/LabelGroup/LabelGroup.module.css.js +5 -12
  137. package/dist/Link/Link.js +47 -31
  138. package/dist/Link/Link.module.css.js +5 -5
  139. package/dist/NavList/NavList.js +614 -424
  140. package/dist/NavList/NavList.module.css.js +5 -5
  141. package/dist/Octicon/Octicon.js +37 -35
  142. package/dist/Overlay/Overlay.js +318 -264
  143. package/dist/Overlay/Overlay.module.css.js +5 -8
  144. package/dist/PageHeader/PageHeader.js +823 -579
  145. package/dist/PageHeader/PageHeader.module.css.js +5 -21
  146. package/dist/PageLayout/PageLayout.js +913 -631
  147. package/dist/PageLayout/PageLayout.module.css.js +5 -31
  148. package/dist/PageLayout/paneUtils.js +29 -15
  149. package/dist/PageLayout/usePaneWidth.js +437 -334
  150. package/dist/Pagehead/Pagehead.js +14 -10
  151. package/dist/Pagehead/Pagehead.module.css.js +5 -5
  152. package/dist/Pagination/Pagination.js +114 -84
  153. package/dist/Pagination/Pagination.module.css.js +5 -9
  154. package/dist/Pagination/index.js +5 -5
  155. package/dist/Pagination/model.js +194 -118
  156. package/dist/Popover/Popover.js +151 -126
  157. package/dist/Popover/Popover.module.css.js +5 -8
  158. package/dist/Portal/Portal.js +85 -65
  159. package/dist/Portal/index.js +6 -5
  160. package/dist/ProgressBar/ProgressBar.js +255 -210
  161. package/dist/ProgressBar/ProgressBar.module.css.js +5 -9
  162. package/dist/ProgressBar/index.js +8 -6
  163. package/dist/Radio/Radio.js +115 -97
  164. package/dist/Radio/Radio.module.css.js +5 -5
  165. package/dist/RadioGroup/RadioGroup.js +118 -99
  166. package/dist/RelativeTime/RelativeTime.js +76 -64
  167. package/dist/ScrollableRegion/ScrollableRegion.js +79 -67
  168. package/dist/ScrollableRegion/ScrollableRegion.module.css.js +5 -5
  169. package/dist/SegmentedControl/SegmentedControl.js +287 -238
  170. package/dist/SegmentedControl/SegmentedControl.module.css.js +5 -15
  171. package/dist/SegmentedControl/SegmentedControlButton.js +187 -156
  172. package/dist/SegmentedControl/SegmentedControlIconButton.js +161 -133
  173. package/dist/Select/Select.js +234 -185
  174. package/dist/Select/Select.module.css.js +5 -10
  175. package/dist/SelectPanel/SelectPanel.d.ts +1 -0
  176. package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
  177. package/dist/SelectPanel/SelectPanel.js +829 -620
  178. package/dist/SelectPanel/SelectPanel.module.css.js +5 -27
  179. package/dist/SelectPanel/SelectPanelMessage.js +39 -37
  180. package/dist/SelectPanel/index.d.ts +1 -0
  181. package/dist/SelectPanel/index.d.ts.map +1 -1
  182. package/dist/SideNav.js +47 -24
  183. package/dist/SideNav.module.css.js +5 -12
  184. package/dist/Skeleton/SkeletonBox.js +111 -94
  185. package/dist/Skeleton/SkeletonBox.module.css.js +5 -8
  186. package/dist/SkeletonAvatar/SkeletonAvatar.js +120 -95
  187. package/dist/SkeletonAvatar/SkeletonAvatar.module.css.js +5 -5
  188. package/dist/SkeletonText/SkeletonText.js +137 -114
  189. package/dist/SkeletonText/SkeletonText.module.css.js +5 -8
  190. package/dist/Spinner/Spinner.js +211 -183
  191. package/dist/Spinner/Spinner.module.css.js +5 -9
  192. package/dist/SplitPageLayout/SplitPageLayout.js +276 -215
  193. package/dist/Stack/Stack.js +255 -207
  194. package/dist/Stack/Stack.module.css.js +5 -8
  195. package/dist/Stack/index.js +6 -4
  196. package/dist/StateLabel/StateLabel.js +123 -110
  197. package/dist/StateLabel/StateLabel.module.css.js +5 -8
  198. package/dist/SubNav/SubNav.js +197 -159
  199. package/dist/SubNav/SubNav.module.css.js +5 -11
  200. package/dist/TabNav/TabNav.js +199 -167
  201. package/dist/TabNav/TabNav.module.css.js +5 -10
  202. package/dist/Text/Text.js +67 -56
  203. package/dist/Text/Text.module.css.js +5 -5
  204. package/dist/TextInput/TextInput.js +228 -195
  205. package/dist/TextInput/TextInput.module.css.js +5 -8
  206. package/dist/TextInputWithTokens/TextInputWithTokens.js +673 -567
  207. package/dist/TextInputWithTokens/TextInputWithTokens.module.css.js +5 -14
  208. package/dist/Textarea/TextArea.module.css.js +5 -9
  209. package/dist/Textarea/Textarea.js +294 -264
  210. package/dist/ThemeProvider.js +257 -199
  211. package/dist/Timeline/Timeline.js +247 -204
  212. package/dist/Timeline/Timeline.module.css.js +5 -12
  213. package/dist/ToggleSwitch/ToggleSwitch.js +471 -403
  214. package/dist/ToggleSwitch/ToggleSwitch.module.css.js +5 -16
  215. package/dist/Token/IssueLabelToken.js +297 -256
  216. package/dist/Token/IssueLabelToken.module.css.js +5 -8
  217. package/dist/Token/Token.js +280 -232
  218. package/dist/Token/Token.module.css.js +5 -9
  219. package/dist/Token/TokenBase.js +126 -99
  220. package/dist/Token/TokenBase.module.css.js +5 -5
  221. package/dist/Token/_RemoveTokenButton.js +48 -27
  222. package/dist/Token/_RemoveTokenButton.module.css.js +5 -5
  223. package/dist/Token/_TokenTextContainer.js +65 -54
  224. package/dist/Token/_TokenTextContainer.module.css.js +5 -5
  225. package/dist/Tooltip/Tooltip.js +56 -49
  226. package/dist/Tooltip/Tooltip.module.css.js +5 -20
  227. package/dist/TooltipV2/Tooltip.js +305 -222
  228. package/dist/TooltipV2/Tooltip.module.css.js +5 -11
  229. package/dist/TopicTag/TopicTag.js +55 -46
  230. package/dist/TopicTag/TopicTag.module.css.js +5 -5
  231. package/dist/TopicTag/TopicTagGroup.js +48 -40
  232. package/dist/TopicTag/TopicTagGroup.module.css.js +5 -5
  233. package/dist/TopicTag/index.js +7 -5
  234. package/dist/TreeView/TreeView.js +1414 -1082
  235. package/dist/TreeView/TreeView.module.css.js +5 -24
  236. package/dist/TreeView/shared.js +9 -10
  237. package/dist/TreeView/useRovingTabIndex.js +203 -129
  238. package/dist/TreeView/useTreeItemCache.js +79 -64
  239. package/dist/TreeView/useTypeahead.js +112 -90
  240. package/dist/Truncate/Truncate.js +33 -21
  241. package/dist/Truncate/Truncate.module.css.js +5 -5
  242. package/dist/UnderlineNav/UnderlineNav.js +375 -278
  243. package/dist/UnderlineNav/UnderlineNav.module.css.js +5 -8
  244. package/dist/UnderlineNav/UnderlineNavContext.js +8 -8
  245. package/dist/UnderlineNav/UnderlineNavItem.js +72 -56
  246. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +5 -5
  247. package/dist/UnderlineNav/index.js +7 -5
  248. package/dist/UnderlineNav/styles.js +15 -11
  249. package/dist/VisuallyHidden/VisuallyHidden.js +49 -51
  250. package/dist/VisuallyHidden/VisuallyHidden.module.css.js +5 -5
  251. package/dist/_VisuallyHidden.js +62 -50
  252. package/dist/_VisuallyHidden.module.css.js +5 -5
  253. package/dist/deprecated/ActionList/Divider.js +23 -23
  254. package/dist/deprecated/ActionList/Divider.module.css.js +5 -5
  255. package/dist/deprecated/ActionList/Group.js +50 -43
  256. package/dist/deprecated/ActionList/Header.js +81 -69
  257. package/dist/deprecated/ActionList/Header.module.css.js +5 -5
  258. package/dist/deprecated/ActionList/Item.js +352 -308
  259. package/dist/deprecated/ActionList/Item.module.css.js +5 -18
  260. package/dist/deprecated/ActionList/List.js +196 -157
  261. package/dist/deprecated/ActionList/List.module.css.js +5 -5
  262. package/dist/deprecated/ActionList/index.js +14 -14
  263. package/dist/deprecated/ActionMenu.js +190 -159
  264. package/dist/deprecated/DialogV1/Dialog.js +200 -166
  265. package/dist/deprecated/DialogV1/Dialog.module.css.js +5 -11
  266. package/dist/deprecated/FilteredSearch/FilteredSearch.js +51 -43
  267. package/dist/deprecated/FilteredSearch/FilteredSearch.module.css.js +5 -5
  268. package/dist/deprecated/UnderlineNav/UnderlineNav.js +160 -132
  269. package/dist/deprecated/UnderlineNav/UnderlineNav.module.css.js +5 -14
  270. package/dist/deprecated/index.js +9 -20
  271. package/dist/experimental/IssueLabel/IssueLabel.js +158 -134
  272. package/dist/experimental/IssueLabel/IssueLabel.module.css.js +5 -5
  273. package/dist/experimental/SelectPanel2/SelectPanel.js +567 -419
  274. package/dist/experimental/SelectPanel2/SelectPanel.module.css.js +5 -32
  275. package/dist/experimental/Tabs/Tabs.js +297 -234
  276. package/dist/experimental/UnderlinePanels/UnderlinePanels.js +215 -165
  277. package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +5 -5
  278. package/dist/experimental/index.d.ts +2 -2
  279. package/dist/experimental/index.d.ts.map +1 -1
  280. package/dist/experimental/index.js +34 -44
  281. package/dist/hooks/useAnchoredPosition.js +144 -123
  282. package/dist/hooks/useControllableState.js +59 -34
  283. package/dist/hooks/useDetails.js +99 -84
  284. package/dist/hooks/useDialog.js +178 -140
  285. package/dist/hooks/useFocusTrap.js +71 -57
  286. package/dist/hooks/useFocusZone.js +38 -32
  287. package/dist/hooks/useId.js +16 -14
  288. package/dist/hooks/useIsMacOS.js +26 -21
  289. package/dist/hooks/useMedia.js +68 -54
  290. package/dist/hooks/useMenuInitialFocus.js +62 -65
  291. package/dist/hooks/useMenuKeyboardNavigation.js +126 -129
  292. package/dist/hooks/useMergedRefs.js +78 -63
  293. package/dist/hooks/useMnemonics.js +107 -77
  294. package/dist/hooks/useOnEscapePress.js +56 -45
  295. package/dist/hooks/useOnOutsideClick.js +63 -32
  296. package/dist/hooks/useOpenAndCloseFocus.js +43 -40
  297. package/dist/hooks/useOverflow.js +36 -32
  298. package/dist/hooks/useOverlay.js +75 -56
  299. package/dist/hooks/useProvidedRefOrCreate.js +24 -24
  300. package/dist/hooks/useProvidedStateOrCreate.js +39 -33
  301. package/dist/hooks/useRefObjectAsForwardedRef.js +32 -30
  302. package/dist/hooks/useRenderForcingRef.js +46 -42
  303. package/dist/hooks/useResizeObserver.js +43 -32
  304. package/dist/hooks/useResponsiveValue.js +57 -37
  305. package/dist/hooks/useSafeTimeout.js +29 -26
  306. package/dist/hooks/useScrollFlash.js +23 -16
  307. package/dist/hooks/useSlots.js +136 -102
  308. package/dist/hooks/useSyncedState.js +37 -31
  309. package/dist/index.d.ts +2 -2
  310. package/dist/index.d.ts.map +1 -1
  311. package/dist/index.js +86 -88
  312. package/dist/internal/components/ButtonReset.js +50 -45
  313. package/dist/internal/components/ButtonReset.module.css.js +5 -5
  314. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.js +105 -79
  315. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.module.css.js +5 -12
  316. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.js +21 -16
  317. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupContext.js +4 -4
  318. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.js +35 -26
  319. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupValidation.js +19 -14
  320. package/dist/internal/components/ConditionalWrapper.js +51 -41
  321. package/dist/internal/components/InputLabel.js +113 -92
  322. package/dist/internal/components/InputLabel.module.css.js +5 -8
  323. package/dist/internal/components/InputValidation.js +87 -67
  324. package/dist/internal/components/InputValidation.module.css.js +5 -9
  325. package/dist/internal/components/TextInputInnerAction.js +173 -134
  326. package/dist/internal/components/TextInputInnerAction.module.css.js +5 -9
  327. package/dist/internal/components/TextInputInnerVisualSlot.js +110 -89
  328. package/dist/internal/components/TextInputInnerVisualSlot.module.css.js +5 -11
  329. package/dist/internal/components/TextInputWrapper.js +230 -187
  330. package/dist/internal/components/TextInputWrapper.module.css.js +5 -8
  331. package/dist/internal/components/UnderlineTabbedInterface.js +238 -191
  332. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +5 -11
  333. package/dist/internal/components/UnstyledTextInput.js +47 -40
  334. package/dist/internal/components/UnstyledTextInput.module.css.js +5 -5
  335. package/dist/internal/components/ValidationAnimationContainer.js +66 -55
  336. package/dist/internal/components/ValidationAnimationContainer.module.css.js +5 -8
  337. package/dist/internal/hooks/useEffectCallback.js +38 -35
  338. package/dist/internal/hooks/useEffectOnce.js +25 -23
  339. package/dist/internal/utils/getResponsiveAttributes.js +26 -23
  340. package/dist/internal/utils/hasInteractiveNodes.js +46 -34
  341. package/dist/legacy-theme/ts/color-schemes.js +4732 -4250
  342. package/dist/live-region/Announce.js +183 -144
  343. package/dist/live-region/AriaAlert.js +22 -20
  344. package/dist/live-region/AriaStatus.js +22 -20
  345. package/dist/next/index.js +1 -3
  346. package/dist/test-helpers.js +62 -40
  347. package/dist/theme.js +47 -83
  348. package/dist/utils/character-counter.js +63 -45
  349. package/dist/utils/create-component.js +16 -15
  350. package/dist/utils/descendant-registry.js +218 -182
  351. package/dist/utils/environment.js +7 -7
  352. package/dist/utils/getBreakpointDeclarations.js +10 -9
  353. package/dist/utils/invariant.js +23 -17
  354. package/dist/utils/is-slot.js +11 -10
  355. package/dist/utils/isNumeric.js +3 -3
  356. package/dist/utils/modern-polymorphic.js +20 -12
  357. package/dist/utils/scroll.js +11 -8
  358. package/dist/utils/theme.js +10 -5
  359. package/dist/utils/useIsomorphicLayoutEffect.js +9 -4
  360. package/dist/utils/warning.js +21 -14
  361. package/package.json +10 -5
  362. package/dist/ActionList/ActionList-53389912.css.map +0 -1
@@ -1,287 +1,384 @@
1
- import { useOnOutsideClick } from "../hooks/useOnOutsideClick.js";
2
- import { useOnEscapePress } from "../hooks/useOnEscapePress.js";
3
- import { useResizeObserver } from "../hooks/useResizeObserver.js";
4
- import { useId as useId$1 } from "../hooks/useId.js";
5
- import CounterLabel from "../CounterLabel/CounterLabel.js";
6
- import { invariant } from "../utils/invariant.js";
7
- import VisuallyHidden from "../_VisuallyHidden.js";
8
- import { ButtonComponent } from "../Button/Button.js";
9
- import { ActionList } from "../ActionList/index.js";
10
- import { UnderlineNavContext } from "./UnderlineNavContext.js";
11
- import { dividerStyles, menuItemStyles } from "./styles.js";
12
- import { LoadingCounter, UnderlineItemList, UnderlineWrapper } from "../internal/components/UnderlineTabbedInterface.js";
13
- import UnderlineNav_module_css_default from "./UnderlineNav.module.css.js";
14
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
- import React, { forwardRef, useCallback, useEffect, useRef, useState } from "react";
16
- import { getAnchoredPosition } from "@primer/behaviors";
17
- import { TriangleDownIcon } from "@primer/octicons-react";
1
+ import React, { forwardRef, useRef, useState, useEffect, useCallback } from 'react';
2
+ import { UnderlineNavContext } from './UnderlineNavContext.js';
3
+ import { useResizeObserver } from '../hooks/useResizeObserver.js';
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';
11
+ import { ActionList } from '../ActionList/index.js';
12
+ import { invariant } from '../utils/invariant.js';
13
+ import classes from './UnderlineNav.module.css.js';
14
+ import { getAnchoredPosition } from '@primer/behaviors';
15
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
16
+ import { ButtonComponent } from '../Button/Button.js';
17
+ import CounterLabel from '../CounterLabel/CounterLabel.js';
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;
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.
18
23
  const MORE_BTN_HEIGHT = 45;
19
24
  const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
20
- let iconsVisible = true;
21
- if (childWidthArray.length === 0) {
22
- updateListAndMenu({
23
- items: childArray,
24
- menuItems: []
25
- }, iconsVisible, false);
26
- return;
27
- }
28
- const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
29
- const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
30
- const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || 86);
31
- const items = [];
32
- const menuItems = [];
33
- if (childArray.length <= numberOfItemsPossible) items.push(...childArray);
34
- else if (childArray.length <= numberOfItemsWithoutIconPossible) {
35
- iconsVisible = false;
36
- items.push(...childArray);
37
- } else {
38
- iconsVisible = false;
39
- const numberOfListItems = childArray.length - numberOfItemsPossibleWithMoreMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
40
- for (const [index, child] of childArray.entries()) if (index < numberOfListItems) items.push(child);
41
- else {
42
- const ariaCurrent = child.props["aria-current"];
43
- if (Boolean(ariaCurrent) && ariaCurrent !== "false" && numberOfListItems > 0) {
44
- const indexToReplaceAt = numberOfListItems - 1;
45
- const propsectiveAction = items.splice(indexToReplaceAt, 1, child)[0];
46
- menuItems.push(propsectiveAction);
47
- } else menuItems.push(child);
48
- }
49
- }
50
- updateListAndMenu({
51
- items,
52
- menuItems
53
- }, iconsVisible, true);
25
+ let iconsVisible = true;
26
+ if (childWidthArray.length === 0) {
27
+ updateListAndMenu({
28
+ items: childArray,
29
+ menuItems: []
30
+ }, iconsVisible, false);
31
+ return;
32
+ }
33
+ const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
34
+ const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
35
+ // We need to take more menu width into account when calculating the number of items possible
36
+ const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ const items = [];
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ const menuItems = [];
41
+
42
+ // First, we check if we can fit all the items with their icons
43
+ if (childArray.length <= numberOfItemsPossible) {
44
+ items.push(...childArray);
45
+ } else if (childArray.length <= numberOfItemsWithoutIconPossible) {
46
+ // if we can't fit all the items with their icons, we check if we can fit all the items without their icons
47
+ iconsVisible = false;
48
+ items.push(...childArray);
49
+ } else {
50
+ // 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
51
+ iconsVisible = false;
52
+
53
+ /* Below is an accessibility requirement. Never show only one item in the overflow menu.
54
+ * If there is only one item left to display in the overflow menu according to the calculation,
55
+ * we need to pull another item from the list into the overflow menu.
56
+ */
57
+ const numberOfItemsInMenu = childArray.length - numberOfItemsPossibleWithMoreMenu;
58
+ const numberOfListItems = numberOfItemsInMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
59
+ for (const [index, child] of childArray.entries()) {
60
+ if (index < numberOfListItems) {
61
+ items.push(child);
62
+ } else {
63
+ const ariaCurrent = child.props['aria-current'];
64
+ const isCurrent = Boolean(ariaCurrent) && ariaCurrent !== 'false';
65
+ // We need to make sure to keep the selected item always visible.
66
+ // 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.)
67
+ if (isCurrent && numberOfListItems > 0) {
68
+ // If selected item couldn't make in to the list, we swap it with the last item in the list.
69
+ const indexToReplaceAt = numberOfListItems - 1; // because we are replacing the last item in the list
70
+ // 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.
71
+ const propsectiveAction = items.splice(indexToReplaceAt, 1, child)[0];
72
+ menuItems.push(propsectiveAction);
73
+ } else {
74
+ menuItems.push(child);
75
+ }
76
+ }
77
+ }
78
+ }
79
+ updateListAndMenu({
80
+ items,
81
+ menuItems
82
+ }, iconsVisible, true);
54
83
  };
55
- const getValidChildren = (children) => {
56
- return React.Children.toArray(children).filter((child) => /* @__PURE__ */ React.isValidElement(child));
84
+ const getValidChildren = children => {
85
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
57
87
  };
58
88
  const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
59
- const widthToFit = navWidth - moreMenuWidth;
60
- let breakpoint = childWidthArray.length;
61
- let sumsOfChildWidth = 0;
62
- for (const [index, childWidth] of childWidthArray.entries()) {
63
- sumsOfChildWidth = sumsOfChildWidth + childWidth.width + 8;
64
- if (sumsOfChildWidth > widthToFit) {
65
- breakpoint = index;
66
- break;
67
- } else continue;
68
- }
69
- return breakpoint;
89
+ const widthToFit = navWidth - moreMenuWidth;
90
+ let breakpoint = childWidthArray.length; // assume all items will fit
91
+ let sumsOfChildWidth = 0;
92
+ for (const [index, childWidth] of childWidthArray.entries()) {
93
+ sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
94
+ if (sumsOfChildWidth > widthToFit) {
95
+ breakpoint = index;
96
+ break;
97
+ } else {
98
+ continue;
99
+ }
100
+ }
101
+ return breakpoint;
70
102
  };
103
+
104
+ // Inline styles converted from baseMenuStyles for use as CSSProperties
71
105
  const baseMenuInlineStyles = {
72
- position: "absolute",
73
- zIndex: 1,
74
- top: "90%",
75
- boxShadow: "0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)",
76
- borderRadius: 12,
77
- background: "var(--overlay-bgColor)",
78
- listStyle: "none",
79
- minWidth: `192px`,
80
- maxWidth: "640px",
81
- right: 0
106
+ position: 'absolute',
107
+ zIndex: 1,
108
+ top: '90%',
109
+ boxShadow: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
110
+ borderRadius: 12,
111
+ background: 'var(--overlay-bgColor)',
112
+ listStyle: 'none',
113
+ minWidth: `${baseMenuMinWidth}px`,
114
+ maxWidth: '640px',
115
+ right: 0
82
116
  };
83
- const UnderlineNav = /* @__PURE__ */ forwardRef(({ as = "nav", "aria-label": ariaLabel, loadingCounters = false, variant = "inset", className, children }, forwardedRef) => {
84
- var _listRef$current2;
85
- const backupRef = useRef(null);
86
- const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
87
- const listRef = useRef(null);
88
- const moreMenuRef = useRef(null);
89
- const moreMenuBtnRef = useRef(null);
90
- const containerRef = React.useRef(null);
91
- const disclosureWidgetId = useId$1();
92
- const [isWidgetOpen, setIsWidgetOpen] = useState(false);
93
- const [iconsVisible, setIconsVisible] = useState(true);
94
- const [childWidthArray, setChildWidthArray] = useState([]);
95
- const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
96
- const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
97
- const validChildren = getValidChildren(children);
98
- const [responsiveProps, setResponsiveProps] = useState({
99
- items: validChildren,
100
- menuItems: []
101
- });
102
- const listItems = responsiveProps.items.map((item) => {
103
- var _validChildren$find;
104
- return (_validChildren$find = validChildren.find((child) => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
105
- });
106
- const menuItems = responsiveProps.menuItems.map((menuItem) => {
107
- var _validChildren$find2;
108
- return (_validChildren$find2 = validChildren.find((child) => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
109
- });
110
- const onlyMenuVisible = responsiveProps.items.length === 0;
111
- useEffect(() => {
112
- !(validChildren.filter((child) => {
113
- return child.props["aria-current"] !== void 0;
114
- }).length <= 1) && invariant(false, "Only one current element is allowed");
115
- !ariaLabel && invariant(false, "Use the `aria-label` prop to provide an accessible label for assistive technology");
116
- });
117
- function getItemsWidth(itemText) {
118
- var _noIconChildWidthArra, _noIconChildWidthArra2;
119
- return (_noIconChildWidthArra = (_noIconChildWidthArra2 = noIconChildWidthArray.find((item) => item.text === itemText)) === null || _noIconChildWidthArra2 === void 0 ? void 0 : _noIconChildWidthArra2.width) !== null && _noIconChildWidthArra !== void 0 ? _noIconChildWidthArra : 0;
120
- }
121
- const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem, event, callback) => {
122
- var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
123
- const index = getBreakpointForItemSwapping(getItemsWidth(prospectiveListItem.props.children), ((_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));
124
- const indexToSliceAt = responsiveProps.items.length - 1 - index;
125
- const updatedItemList = [...[...responsiveProps.items].slice(0, indexToSliceAt), prospectiveListItem];
126
- const itemsToAddToMenu = [...responsiveProps.items].slice(indexToSliceAt);
127
- const updatedMenuItems = [...menuItems];
128
- updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
129
- callback({
130
- items: updatedItemList,
131
- menuItems: updatedMenuItems
132
- }, false, true);
133
- };
134
- function getBreakpointForItemSwapping(widthToFitIntoList, availableSpace) {
135
- let widthToSwap = 0;
136
- let breakpoint = 0;
137
- for (const [index, item] of [...responsiveProps.items].reverse().entries()) {
138
- widthToSwap += getItemsWidth(item.props.children);
139
- if (widthToFitIntoList < widthToSwap + availableSpace) {
140
- breakpoint = index;
141
- break;
142
- }
143
- }
144
- return breakpoint;
145
- }
146
- const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
147
- setResponsiveProps(props);
148
- setIconsVisible(displayIcons);
149
- if (overflowMeasured) setIsOverflowMeasured(true);
150
- }, []);
151
- const setChildrenWidth = useCallback((size) => {
152
- setChildWidthArray((arr) => {
153
- return [...arr, size];
154
- });
155
- }, []);
156
- const setNoIconChildrenWidth = useCallback((size) => {
157
- setNoIconChildWidthArray((arr) => {
158
- return [...arr, size];
159
- });
160
- }, []);
161
- const closeOverlay = React.useCallback(() => {
162
- setIsWidgetOpen(false);
163
- }, [setIsWidgetOpen]);
164
- const focusOnMoreMenuBtn = React.useCallback(() => {
165
- var _moreMenuBtnRef$curre;
166
- (_moreMenuBtnRef$curre = moreMenuBtnRef.current) === null || _moreMenuBtnRef$curre === void 0 || _moreMenuBtnRef$curre.focus();
167
- }, []);
168
- const onAnchorClick = useCallback((event) => {
169
- if (event.defaultPrevented || event.button !== 0) return;
170
- setIsWidgetOpen((isWidgetOpen) => !isWidgetOpen);
171
- }, []);
172
- useOnEscapePress((event) => {
173
- if (isWidgetOpen) {
174
- event.preventDefault();
175
- closeOverlay();
176
- focusOnMoreMenuBtn();
177
- }
178
- }, [isWidgetOpen]);
179
- useOnOutsideClick({
180
- onClickOutside: closeOverlay,
181
- containerRef,
182
- ignoreClickRefs: [moreMenuBtnRef]
183
- });
184
- useResizeObserver((resizeObserverEntries) => {
185
- var _moreMenuRef$current$, _moreMenuRef$current;
186
- const navWidth = resizeObserverEntries[0].contentRect.width;
187
- 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;
188
- navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
189
- }, navRef);
190
- let menuInlineStyles = { ...baseMenuInlineStyles };
191
- if (containerRef.current && listRef.current) {
192
- const { left } = getAnchoredPosition(containerRef.current, listRef.current, {
193
- align: "start",
194
- side: "outside-bottom"
195
- });
196
- menuInlineStyles = {
197
- ...baseMenuInlineStyles,
198
- right: void 0,
199
- left
200
- };
201
- }
202
- return /* @__PURE__ */ jsxs(UnderlineNavContext.Provider, {
203
- value: {
204
- setChildrenWidth,
205
- setNoIconChildrenWidth,
206
- loadingCounters,
207
- iconsVisible
208
- },
209
- children: [ariaLabel && /* @__PURE__ */ jsx(VisuallyHidden, {
210
- as: "h2",
211
- children: `${ariaLabel} navigation`
212
- }), /* @__PURE__ */ jsx(UnderlineWrapper, {
213
- as,
214
- "aria-label": ariaLabel,
215
- className,
216
- ref: navRef,
217
- "data-variant": variant,
218
- "data-overflow-measured": isOverflowMeasured ? "true" : "false",
219
- children: /* @__PURE__ */ jsxs(UnderlineItemList, {
220
- ref: listRef,
221
- role: "list",
222
- children: [listItems, menuItems.length > 0 && /* @__PURE__ */ jsxs("li", {
223
- ref: moreMenuRef,
224
- style: {
225
- display: "flex",
226
- alignItems: "center",
227
- height: `${MORE_BTN_HEIGHT}px`
228
- },
229
- children: [
230
- !onlyMenuVisible && /* @__PURE__ */ jsx("div", { style: dividerStyles }),
231
- /* @__PURE__ */ jsx(ButtonComponent, {
232
- ref: moreMenuBtnRef,
233
- className: UnderlineNav_module_css_default.MoreButton,
234
- "aria-controls": disclosureWidgetId,
235
- "aria-expanded": isWidgetOpen,
236
- onClick: onAnchorClick,
237
- trailingAction: TriangleDownIcon,
238
- children: /* @__PURE__ */ jsx("span", { children: onlyMenuVisible ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(VisuallyHidden, {
239
- as: "span",
240
- children: [`${ariaLabel}`, "\xA0"]
241
- }), "Menu"] }) : /* @__PURE__ */ jsxs(Fragment, { children: ["More", /* @__PURE__ */ jsxs(VisuallyHidden, {
242
- as: "span",
243
- children: ["\xA0", `${ariaLabel} items`]
244
- })] }) })
245
- }),
246
- /* @__PURE__ */ jsx(ActionList, {
247
- selectionVariant: "single",
248
- ref: containerRef,
249
- id: disclosureWidgetId,
250
- style: {
251
- ...(_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= 192 ? baseMenuInlineStyles : menuInlineStyles,
252
- display: isWidgetOpen ? "block" : "none"
253
- },
254
- children: menuItems.map((menuItem, index) => {
255
- const { children: menuItemChildren, counter, "aria-current": ariaCurrent, onSelect, ...menuItemProps } = menuItem.props;
256
- if (Boolean(ariaCurrent) && ariaCurrent !== "false") {
257
- const event = new MouseEvent("click");
258
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
259
- }
260
- return /* @__PURE__ */ jsx(ActionList.LinkItem, {
261
- style: menuItemStyles,
262
- onClick: (event) => {
263
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
264
- closeOverlay();
265
- focusOnMoreMenuBtn();
266
- typeof onSelect === "function" && onSelect(event);
267
- },
268
- ...menuItemProps,
269
- children: /* @__PURE__ */ jsxs("span", {
270
- className: UnderlineNav_module_css_default.MenuItemContent,
271
- children: [menuItemChildren, loadingCounters ? /* @__PURE__ */ jsx(LoadingCounter, {}) : counter !== void 0 && /* @__PURE__ */ jsx("span", {
272
- "data-component": "counter",
273
- children: /* @__PURE__ */ jsx(CounterLabel, { children: counter })
274
- })]
275
- })
276
- }, menuItemChildren);
277
- })
278
- })
279
- ]
280
- })]
281
- })
282
- })]
283
- });
117
+ const UnderlineNav = /*#__PURE__*/forwardRef(({
118
+ as = 'nav',
119
+ 'aria-label': ariaLabel,
120
+ loadingCounters = false,
121
+ variant = 'inset',
122
+ className,
123
+ children
124
+ }, forwardedRef) => {
125
+ var _listRef$current2;
126
+ const backupRef = useRef(null);
127
+ const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
128
+ const listRef = useRef(null);
129
+ const moreMenuRef = useRef(null);
130
+ const moreMenuBtnRef = useRef(null);
131
+ const containerRef = React.useRef(null);
132
+ const disclosureWidgetId = useId();
133
+ const [isWidgetOpen, setIsWidgetOpen] = useState(false);
134
+ const [iconsVisible, setIconsVisible] = useState(true);
135
+ const [childWidthArray, setChildWidthArray] = useState([]);
136
+ const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
137
+ // Track whether the initial overflow calculation is complete to prevent CLS
138
+ const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
139
+ const validChildren = getValidChildren(children);
140
+
141
+ // Responsive props object manages which items are in the list and which items are in the menu.
142
+ const [responsiveProps, setResponsiveProps] = useState({
143
+ items: validChildren,
144
+ menuItems: []
145
+ });
146
+
147
+ // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
148
+ const listItems = responsiveProps.items.map(item => {
149
+ var _validChildren$find;
150
+ return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
151
+ });
152
+
153
+ // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
154
+ const menuItems = responsiveProps.menuItems.map(menuItem => {
155
+ var _validChildren$find2;
156
+ return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
157
+ });
158
+ // 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
159
+ const onlyMenuVisible = responsiveProps.items.length === 0;
160
+ if (process.env.NODE_ENV !== "production") {
161
+ // Practically, this is not a conditional hook, it is just making sure this hook runs only on DEV not PROD.
162
+ // eslint-disable-next-line react-hooks/rules-of-hooks
163
+ useEffect(() => {
164
+ // Address illegal state where there are multiple items that have `aria-current='page'` attribute
165
+ const activeElements = validChildren.filter(child => {
166
+ return child.props['aria-current'] !== undefined;
167
+ });
168
+ !(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
169
+ !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;
170
+ });
171
+ }
172
+ function getItemsWidth(itemText) {
173
+ var _noIconChildWidthArra, _noIconChildWidthArra2;
174
+ return (_noIconChildWidthArra = (_noIconChildWidthArra2 = noIconChildWidthArray.find(item => item.text === itemText)) === null || _noIconChildWidthArra2 === void 0 ? void 0 : _noIconChildWidthArra2.width) !== null && _noIconChildWidthArra !== void 0 ? _noIconChildWidthArra : 0;
175
+ }
176
+ const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem, event, callback) => {
177
+ var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
178
+ // get the selected menu item's width
179
+ const widthToFitIntoList = getItemsWidth(prospectiveListItem.props.children);
180
+ // Check if there is any empty space on the right side of the list
181
+ 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);
182
+
183
+ // Calculate how many items need to be pulled in to the menu to make room for the selected menu item
184
+ // I.e. if we need to pull 2 items in (index 0 and index 1), breakpoint (index) will return 1.
185
+ const index = getBreakpointForItemSwapping(widthToFitIntoList, availableSpace);
186
+ const indexToSliceAt = responsiveProps.items.length - 1 - index;
187
+ // Form the new list of items
188
+ const itemsLeftInList = [...responsiveProps.items].slice(0, indexToSliceAt);
189
+ const updatedItemList = [...itemsLeftInList, prospectiveListItem];
190
+ // Form the new menu items
191
+ const itemsToAddToMenu = [...responsiveProps.items].slice(indexToSliceAt);
192
+ const updatedMenuItems = [...menuItems];
193
+ // Add itemsToAddToMenu array's items to the menu at the index of the prospectiveListItem and remove 1 count of items (prospectiveListItem)
194
+ updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
195
+ callback({
196
+ items: updatedItemList,
197
+ menuItems: updatedMenuItems
198
+ }, false, true);
199
+ };
200
+ // How many items do we need to pull in to the menu to make room for the selected menu item.
201
+ function getBreakpointForItemSwapping(widthToFitIntoList, availableSpace) {
202
+ let widthToSwap = 0;
203
+ let breakpoint = 0;
204
+ for (const [index, item] of [...responsiveProps.items].reverse().entries()) {
205
+ widthToSwap += getItemsWidth(item.props.children);
206
+ if (widthToFitIntoList < widthToSwap + availableSpace) {
207
+ breakpoint = index;
208
+ break;
209
+ }
210
+ }
211
+ return breakpoint;
212
+ }
213
+ const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
214
+ setResponsiveProps(props);
215
+ setIconsVisible(displayIcons);
216
+ if (overflowMeasured) {
217
+ setIsOverflowMeasured(true);
218
+ }
219
+ }, []);
220
+ const setChildrenWidth = useCallback(size => {
221
+ setChildWidthArray(arr => {
222
+ const newArr = [...arr, size];
223
+ return newArr;
224
+ });
225
+ }, []);
226
+ const setNoIconChildrenWidth = useCallback(size => {
227
+ setNoIconChildWidthArray(arr => {
228
+ const newArr = [...arr, size];
229
+ return newArr;
230
+ });
231
+ }, []);
232
+ const closeOverlay = React.useCallback(() => {
233
+ setIsWidgetOpen(false);
234
+ }, [setIsWidgetOpen]);
235
+ const focusOnMoreMenuBtn = React.useCallback(() => {
236
+ var _moreMenuBtnRef$curre;
237
+ (_moreMenuBtnRef$curre = moreMenuBtnRef.current) === null || _moreMenuBtnRef$curre === void 0 ? void 0 : _moreMenuBtnRef$curre.focus();
238
+ }, []);
239
+ const onAnchorClick = useCallback(event => {
240
+ if (event.defaultPrevented || event.button !== 0) {
241
+ return;
242
+ }
243
+ setIsWidgetOpen(isWidgetOpen => !isWidgetOpen);
244
+ }, []);
245
+ useOnEscapePress(event => {
246
+ if (isWidgetOpen) {
247
+ event.preventDefault();
248
+ closeOverlay();
249
+ focusOnMoreMenuBtn();
250
+ }
251
+ }, [isWidgetOpen]);
252
+ useOnOutsideClick({
253
+ onClickOutside: closeOverlay,
254
+ containerRef,
255
+ ignoreClickRefs: [moreMenuBtnRef]
256
+ });
257
+ useResizeObserver(resizeObserverEntries => {
258
+ var _moreMenuRef$current$, _moreMenuRef$current;
259
+ const navWidth = resizeObserverEntries[0].contentRect.width;
260
+ 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;
261
+ navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
262
+ }, navRef);
263
+
264
+ // Compute menuInlineStyles if needed
265
+ let menuInlineStyles = {
266
+ ...baseMenuInlineStyles
267
+ };
268
+ if (containerRef.current && listRef.current) {
269
+ const {
270
+ left
271
+ } = getAnchoredPosition(containerRef.current, listRef.current, {
272
+ align: 'start',
273
+ side: 'outside-bottom'
274
+ });
275
+ menuInlineStyles = {
276
+ ...baseMenuInlineStyles,
277
+ right: undefined,
278
+ left
279
+ };
280
+ }
281
+ return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
282
+ value: {
283
+ setChildrenWidth,
284
+ setNoIconChildrenWidth,
285
+ loadingCounters,
286
+ iconsVisible
287
+ },
288
+ children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
289
+ as: "h2",
290
+ children: `${ariaLabel} navigation`
291
+ }), /*#__PURE__*/jsx(UnderlineWrapper, {
292
+ as: as,
293
+ "aria-label": ariaLabel,
294
+ className: className,
295
+ ref: navRef,
296
+ "data-variant": variant,
297
+ "data-overflow-measured": isOverflowMeasured ? 'true' : 'false',
298
+ children: /*#__PURE__*/jsxs(UnderlineItemList, {
299
+ ref: listRef,
300
+ role: "list",
301
+ children: [listItems, menuItems.length > 0 && /*#__PURE__*/jsxs("li", {
302
+ ref: moreMenuRef,
303
+ style: {
304
+ display: 'flex',
305
+ alignItems: 'center',
306
+ height: `${MORE_BTN_HEIGHT}px`
307
+ },
308
+ children: [!onlyMenuVisible && /*#__PURE__*/jsx("div", {
309
+ style: dividerStyles
310
+ }), /*#__PURE__*/jsx(ButtonComponent, {
311
+ ref: moreMenuBtnRef,
312
+ className: classes.MoreButton,
313
+ "aria-controls": disclosureWidgetId,
314
+ "aria-expanded": isWidgetOpen,
315
+ onClick: onAnchorClick,
316
+ trailingAction: TriangleDownIcon,
317
+ children: /*#__PURE__*/jsx("span", {
318
+ children: onlyMenuVisible ? /*#__PURE__*/jsxs(Fragment, {
319
+ children: [/*#__PURE__*/jsxs(VisuallyHidden, {
320
+ as: "span",
321
+ children: [`${ariaLabel}`, "\xA0"]
322
+ }), "Menu"]
323
+ }) : /*#__PURE__*/jsxs(Fragment, {
324
+ children: ["More", /*#__PURE__*/jsxs(VisuallyHidden, {
325
+ as: "span",
326
+ children: ["\xA0", `${ariaLabel} items`]
327
+ })]
328
+ })
329
+ })
330
+ }), /*#__PURE__*/jsx(ActionList, {
331
+ selectionVariant: "single",
332
+ ref: containerRef,
333
+ id: disclosureWidgetId,
334
+ style: {
335
+ ...((_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= baseMenuMinWidth ? baseMenuInlineStyles : menuInlineStyles),
336
+ display: isWidgetOpen ? 'block' : 'none'
337
+ },
338
+ children: menuItems.map((menuItem, index) => {
339
+ const {
340
+ children: menuItemChildren,
341
+ counter,
342
+ 'aria-current': ariaCurrent,
343
+ onSelect,
344
+ ...menuItemProps
345
+ } = menuItem.props;
346
+
347
+ // This logic is used to pop the selected item out of the menu and into the list when the navigation is control externally
348
+ if (Boolean(ariaCurrent) && ariaCurrent !== 'false') {
349
+ const event = new MouseEvent('click');
350
+ !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index,
351
+ // @ts-ignore - not a big deal because it is internally creating an event but ask help
352
+ event, updateListAndMenu);
353
+ }
354
+ return /*#__PURE__*/jsx(ActionList.LinkItem, {
355
+ style: menuItemStyles,
356
+ onClick: event => {
357
+ // When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
358
+ !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
359
+ closeOverlay();
360
+ focusOnMoreMenuBtn();
361
+ // fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
362
+ typeof onSelect === 'function' && onSelect(event);
363
+ },
364
+ ...menuItemProps,
365
+ children: /*#__PURE__*/jsxs("span", {
366
+ className: classes.MenuItemContent,
367
+ children: [menuItemChildren, loadingCounters ? /*#__PURE__*/jsx(LoadingCounter, {}) : counter !== undefined && /*#__PURE__*/jsx("span", {
368
+ "data-component": "counter",
369
+ children: /*#__PURE__*/jsx(CounterLabel, {
370
+ children: counter
371
+ })
372
+ })]
373
+ })
374
+ }, menuItemChildren);
375
+ })
376
+ })]
377
+ })]
378
+ })
379
+ })]
380
+ });
284
381
  });
285
- UnderlineNav.displayName = "UnderlineNav";
286
- //#endregion
287
- export { UnderlineNav };
382
+ UnderlineNav.displayName = 'UnderlineNav';
383
+
384
+ export { MORE_BTN_WIDTH, UnderlineNav, getValidChildren };