@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,443 +1,591 @@
1
- import { useProvidedRefOrCreate } from "../../hooks/useProvidedRefOrCreate.js";
2
- import { useAnchoredPosition } from "../../hooks/useAnchoredPosition.js";
3
- import { useId as useId$1 } from "../../hooks/useId.js";
4
- import Spinner from "../../Spinner/Spinner.js";
5
- import { AriaStatus } from "../../live-region/AriaStatus.js";
6
- import { invariant } from "../../utils/invariant.js";
7
- import { IconButton } from "../../Button/IconButton.js";
8
- import { ButtonComponent } from "../../Button/Button.js";
9
- import { useResponsiveValue } from "../../hooks/useResponsiveValue.js";
10
- import { isSlot } from "../../utils/is-slot.js";
11
- import { useSlots } from "../../hooks/useSlots.js";
12
- import { ActionListContainerContext } from "../../ActionList/ActionListContainerContext.js";
13
- import Heading from "../../Heading/Heading.js";
14
- import Link from "../../Link/Link.js";
15
- import { BaseOverlay, heightMap } from "../../Overlay/Overlay.js";
16
- import TextInput_default from "../../TextInput/TextInput.js";
17
- import { useFormControlForwardedProps } from "../../FormControl/_FormControlContext.js";
18
- import Checkbox from "../../Checkbox/Checkbox.js";
19
- import Octicon from "../../Octicon/Octicon.js";
20
- import { InputLabel } from "../../internal/components/InputLabel.js";
21
- import SelectPanel_module_css_default from "./SelectPanel.module.css.js";
22
- import { clsx } from "clsx";
23
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
24
- import React, { useEffect, useState } from "react";
25
- import { AlertIcon, ArrowLeftIcon, FilterRemoveIcon, SearchIcon, XCircleFillIcon, XIcon } from "@primer/octicons-react";
26
- //#region src/experimental/SelectPanel2/SelectPanel.tsx
27
- const SelectPanelContext = /* @__PURE__ */ React.createContext({
28
- title: "",
29
- description: void 0,
30
- panelId: "",
31
- onCancel: () => {},
32
- onClearSelection: void 0,
33
- searchQuery: "",
34
- setSearchQuery: () => {},
35
- selectionVariant: "multiple",
36
- moveFocusToList: () => {}
1
+ import React, { useState, useEffect } from 'react';
2
+ import { AlertIcon, SearchIcon, XCircleFillIcon, ArrowLeftIcon, FilterRemoveIcon, XIcon } from '@primer/octicons-react';
3
+ import { ActionListContainerContext } from '../../ActionList/ActionListContainerContext.js';
4
+ import { useSlots } from '../../hooks/useSlots.js';
5
+ import { BaseOverlay, heightMap } from '../../Overlay/Overlay.js';
6
+ import { InputLabel } from '../../internal/components/InputLabel.js';
7
+ import { invariant } from '../../utils/invariant.js';
8
+ import { useResponsiveValue } from '../../hooks/useResponsiveValue.js';
9
+ import { clsx } from 'clsx';
10
+ import classes from './SelectPanel.module.css.js';
11
+ import { isSlot } from '../../utils/is-slot.js';
12
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
13
+ import { useProvidedRefOrCreate } from '../../hooks/useProvidedRefOrCreate.js';
14
+ import { useId } from '../../hooks/useId.js';
15
+ import { useAnchoredPosition } from '../../hooks/useAnchoredPosition.js';
16
+ import { AriaStatus } from '../../live-region/AriaStatus.js';
17
+ import Octicon from '../../Octicon/Octicon.js';
18
+ import Spinner from '../../Spinner/Spinner.js';
19
+ import { ButtonComponent } from '../../Button/Button.js';
20
+ import TextInput from '../../TextInput/TextInput.js';
21
+ import { IconButton } from '../../Button/IconButton.js';
22
+ import Heading from '../../Heading/Heading.js';
23
+ import { useFormControlForwardedProps } from '../../FormControl/_FormControlContext.js';
24
+ import Link from '../../Link/Link.js';
25
+ import Checkbox from '../../Checkbox/Checkbox.js';
26
+
27
+ const SelectPanelContext = /*#__PURE__*/React.createContext({
28
+ title: '',
29
+ description: undefined,
30
+ panelId: '',
31
+ onCancel: () => {},
32
+ onClearSelection: undefined,
33
+ searchQuery: '',
34
+ setSearchQuery: () => {},
35
+ selectionVariant: 'multiple',
36
+ moveFocusToList: () => {}
37
37
  });
38
38
  const responsiveButtonSizes = {
39
- narrow: "medium",
40
- regular: "small"
39
+ narrow: 'medium',
40
+ regular: 'small'
41
41
  };
42
- const Panel = ({ title, description, variant: propsVariant, selectionVariant = "multiple", id, defaultOpen = false, open: propsOpen, anchorRef: providedAnchorRef, anchoredPositionSettings, onCancel: propsOnCancel, onClearSelection: propsOnClearSelection, onSubmit: propsOnSubmit, width = "medium", maxHeight = "large", className, ...props }) => {
43
- var _position$top, _position$left, _slots$header;
44
- const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
45
- const currentVariant = useResponsiveValue(Object.assign({
46
- regular: "anchored",
47
- narrow: "full-screen"
48
- }, typeof propsVariant === "string" ? { regular: propsVariant } : propsVariant), "anchored");
49
- if (propsOpen !== void 0 && internalOpen !== propsOpen) setInternalOpen(propsOpen);
50
- let Anchor;
51
- const anchorRef = useProvidedRefOrCreate(providedAnchorRef);
52
- const onAnchorClick = () => {
53
- if (!internalOpen) setInternalOpen(true);
54
- else onInternalCancel();
55
- };
56
- const contents = React.Children.map(props.children, (child) => {
57
- if (/* @__PURE__ */ React.isValidElement(child) && (child.type === SelectPanelButton || isSlot(child, SelectPanelButton))) {
58
- Anchor = /* @__PURE__ */ React.cloneElement(child, {
59
- ref: anchorRef,
60
- onClick: child.props.onClick || onAnchorClick,
61
- "aria-haspopup": true,
62
- "aria-expanded": internalOpen
63
- });
64
- return null;
65
- }
66
- return child;
67
- });
68
- const onInternalClose = React.useCallback(() => {
69
- if (internalOpen === false) return;
70
- if (propsOpen === void 0) setInternalOpen(false);
71
- }, [internalOpen, propsOpen]);
72
- const onInternalCancel = React.useCallback(() => {
73
- onInternalClose();
74
- if (typeof propsOnCancel === "function") propsOnCancel();
75
- }, [onInternalClose, propsOnCancel]);
76
- const onInternalSubmit = (event) => {
77
- event === null || event === void 0 || event.preventDefault();
78
- onInternalClose();
79
- if (typeof propsOnSubmit === "function") propsOnSubmit(event);
80
- };
81
- const onInternalClearSelection = () => {
82
- if (typeof propsOnClearSelection === "function") propsOnClearSelection();
83
- };
84
- const internalAfterSelect = (event) => {
85
- if (selectionVariant === "instant") onInternalSubmit();
86
- if (event.type === "keypress") {
87
- if (event.key === "Enter") onInternalSubmit();
88
- }
89
- };
90
- const [searchQuery, setSearchQuery] = React.useState("");
91
- const panelId = useId$1(id);
92
- const [slots, childrenInBody] = useSlots(contents, {
93
- header: SelectPanelHeader,
94
- footer: SelectPanelFooter
95
- });
96
- const moveFocusToList = () => {
97
- var _dialogRef$current;
98
- const firstListElement = (_dialogRef$current = dialogRef.current) === null || _dialogRef$current === void 0 ? void 0 : _dialogRef$current.querySelector("ul[role=listbox] li:not([role=none])");
99
- firstListElement === null || firstListElement === void 0 || firstListElement.focus();
100
- };
101
- const dialogRef = React.useRef(null);
102
- React.useEffect(() => {
103
- var _dialogRef$current2, _dialogRef$current3;
104
- if (internalOpen) (_dialogRef$current2 = dialogRef.current) === null || _dialogRef$current2 === void 0 || _dialogRef$current2.showModal();
105
- else if ((_dialogRef$current3 = dialogRef.current) !== null && _dialogRef$current3 !== void 0 && _dialogRef$current3.open) dialogRef.current.close();
106
- }, [internalOpen]);
107
- React.useEffect(() => {
108
- const dialogEl = dialogRef.current;
109
- dialogEl === null || dialogEl === void 0 || dialogEl.addEventListener("close", onInternalClose);
110
- return () => dialogEl === null || dialogEl === void 0 ? void 0 : dialogEl.removeEventListener("close", onInternalClose);
111
- }, [onInternalClose]);
112
- React.useEffect(() => {
113
- const dialogEl = dialogRef.current;
114
- const handler = (event) => {
115
- if (event.key === "Escape") onInternalCancel();
116
- };
117
- dialogEl === null || dialogEl === void 0 || dialogEl.addEventListener("keydown", handler);
118
- return () => dialogEl === null || dialogEl === void 0 ? void 0 : dialogEl.removeEventListener("keydown", handler);
119
- }, [onInternalCancel]);
120
- React.useEffect(function initialFocus() {
121
- if (internalOpen) {
122
- const searchInput = document.querySelector("dialog[open] input");
123
- if (searchInput) searchInput.focus();
124
- else moveFocusToList();
125
- }
126
- }, [internalOpen]);
127
- const { position } = useAnchoredPosition({
128
- anchorElementRef: anchorRef,
129
- floatingElementRef: dialogRef,
130
- side: "outside-bottom",
131
- align: "start",
132
- ...anchoredPositionSettings
133
- }, [
134
- internalOpen,
135
- anchorRef.current,
136
- dialogRef.current
137
- ]);
138
- const onClickOutside = onInternalCancel;
139
- let maxHeightValue = heightMap[maxHeight];
140
- if (currentVariant === "bottom-sheet") maxHeightValue = "calc(100vh - 64px)";
141
- else if (currentVariant === "full-screen") maxHeightValue = "100vh";
142
- return /* @__PURE__ */ jsxs(Fragment, { children: [Anchor, /* @__PURE__ */ jsx(BaseOverlay, {
143
- as: "dialog",
144
- ref: dialogRef,
145
- "aria-labelledby": `${panelId}--title`,
146
- "aria-describedby": description ? `${panelId}--description` : void 0,
147
- width,
148
- height: "fit-content",
149
- maxHeight,
150
- "data-variant": currentVariant,
151
- style: {
152
- "--max-height": maxHeightValue,
153
- "--position-top": `${(_position$top = position === null || position === void 0 ? void 0 : position.top) !== null && _position$top !== void 0 ? _position$top : 0}px`,
154
- "--position-left": `${(_position$left = position === null || position === void 0 ? void 0 : position.left) !== null && _position$left !== void 0 ? _position$left : 0}px`,
155
- visibility: internalOpen ? "visible" : "hidden",
156
- display: "flex"
157
- },
158
- className: clsx(SelectPanel_module_css_default.Overlay, className),
159
- ...props,
160
- onClick: (event) => {
161
- if (event.target === event.currentTarget) onClickOutside();
162
- },
163
- children: internalOpen && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(SelectPanelContext.Provider, {
164
- value: {
165
- panelId,
166
- title,
167
- description,
168
- onCancel: onInternalCancel,
169
- onClearSelection: propsOnClearSelection ? onInternalClearSelection : void 0,
170
- searchQuery,
171
- setSearchQuery,
172
- selectionVariant,
173
- moveFocusToList
174
- },
175
- children: /* @__PURE__ */ jsxs("form", {
176
- method: "dialog",
177
- onSubmit: onInternalSubmit,
178
- className: SelectPanel_module_css_default.Form,
179
- children: [
180
- (_slots$header = slots.header) !== null && _slots$header !== void 0 ? _slots$header : /* @__PURE__ */ jsx(SelectPanelHeader, {}),
181
- /* @__PURE__ */ jsx("div", {
182
- className: SelectPanel_module_css_default.Container,
183
- children: /* @__PURE__ */ jsx(ActionListContainerContext.Provider, {
184
- value: {
185
- container: "SelectPanel",
186
- listRole: "listbox",
187
- selectionAttribute: "aria-selected",
188
- selectionVariant: selectionVariant === "instant" ? "single" : selectionVariant,
189
- afterSelect: internalAfterSelect,
190
- listLabelledBy: `${panelId}--title`,
191
- enableFocusZone: true
192
- },
193
- children: childrenInBody
194
- })
195
- }),
196
- slots.footer
197
- ]
198
- })
199
- }) })
200
- })] });
42
+ const Panel = ({
43
+ title,
44
+ description,
45
+ variant: propsVariant,
46
+ selectionVariant = 'multiple',
47
+ id,
48
+ defaultOpen = false,
49
+ open: propsOpen,
50
+ anchorRef: providedAnchorRef,
51
+ anchoredPositionSettings,
52
+ onCancel: propsOnCancel,
53
+ onClearSelection: propsOnClearSelection,
54
+ onSubmit: propsOnSubmit,
55
+ width = 'medium',
56
+ maxHeight = 'large',
57
+ className,
58
+ ...props
59
+ }) => {
60
+ var _position$top, _position$left, _slots$header;
61
+ const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
62
+ const responsiveVariants = Object.assign({
63
+ regular: 'anchored',
64
+ narrow: 'full-screen'
65
+ },
66
+ // defaults
67
+ typeof propsVariant === 'string' ? {
68
+ regular: propsVariant
69
+ } : propsVariant);
70
+ const currentVariant = useResponsiveValue(responsiveVariants, 'anchored');
71
+
72
+ // sync open state with props
73
+ if (propsOpen !== undefined && internalOpen !== propsOpen) setInternalOpen(propsOpen);
74
+
75
+ // TODO: replace this hack with clone element?
76
+
77
+ // 🚨 Hack for good API!
78
+ // we strip out Anchor from children and wire it up to Dialog
79
+ // with additional props for accessibility
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ let Anchor;
82
+ const anchorRef = useProvidedRefOrCreate(providedAnchorRef);
83
+ const onAnchorClick = () => {
84
+ if (!internalOpen) setInternalOpen(true);else onInternalCancel();
85
+ };
86
+ const contents = React.Children.map(props.children, child => {
87
+ if (/*#__PURE__*/React.isValidElement(child) && (child.type === SelectPanelButton || isSlot(child, SelectPanelButton))) {
88
+ // eslint-disable-next-line react-hooks/immutability
89
+ Anchor = /*#__PURE__*/React.cloneElement(child, {
90
+ // @ts-ignore TODO
91
+ ref: anchorRef,
92
+ onClick: child.props.onClick || onAnchorClick,
93
+ 'aria-haspopup': true,
94
+ 'aria-expanded': internalOpen
95
+ });
96
+ return null;
97
+ }
98
+ return child;
99
+ });
100
+ const onInternalClose = React.useCallback(() => {
101
+ if (internalOpen === false) return; // nothing to do here
102
+ if (propsOpen === undefined) setInternalOpen(false);
103
+ }, [internalOpen, propsOpen]);
104
+ const onInternalCancel = React.useCallback(() => {
105
+ onInternalClose();
106
+ if (typeof propsOnCancel === 'function') propsOnCancel();
107
+ }, [onInternalClose, propsOnCancel]);
108
+ const onInternalSubmit = event => {
109
+ event === null || event === void 0 ? void 0 : event.preventDefault(); // there is no event with selectionVariant=instant
110
+ onInternalClose();
111
+ if (typeof propsOnSubmit === 'function') propsOnSubmit(event);
112
+ };
113
+ const onInternalClearSelection = () => {
114
+ if (typeof propsOnClearSelection === 'function') propsOnClearSelection();
115
+ };
116
+ const internalAfterSelect = event => {
117
+ if (selectionVariant === 'instant') onInternalSubmit();
118
+ if (event.type === 'keypress') {
119
+ if (event.key === 'Enter') onInternalSubmit();
120
+ }
121
+ };
122
+
123
+ /* Search/Filter */
124
+ const [searchQuery, setSearchQuery] = React.useState('');
125
+
126
+ /* Panel plumbing */
127
+ const panelId = useId(id);
128
+ const [slots, childrenInBody] = useSlots(contents, {
129
+ header: SelectPanelHeader,
130
+ footer: SelectPanelFooter
131
+ });
132
+
133
+ // used in SelectPanel.SearchInput
134
+ const moveFocusToList = () => {
135
+ var _dialogRef$current;
136
+ const selector = 'ul[role=listbox] li:not([role=none])';
137
+ // being specific about roles because there can be another ul (tabs in header) and an ActionList.Group (li[role=none])
138
+ const firstListElement = (_dialogRef$current = dialogRef.current) === null || _dialogRef$current === void 0 ? void 0 : _dialogRef$current.querySelector(selector);
139
+ firstListElement === null || firstListElement === void 0 ? void 0 : firstListElement.focus();
140
+ };
141
+
142
+ /* Dialog */
143
+ const dialogRef = React.useRef(null);
144
+
145
+ // sync dialog open state (imperative) with internal component state
146
+ React.useEffect(() => {
147
+ var _dialogRef$current2, _dialogRef$current3;
148
+ if (internalOpen) (_dialogRef$current2 = dialogRef.current) === null || _dialogRef$current2 === void 0 ? void 0 : _dialogRef$current2.showModal();else if ((_dialogRef$current3 = dialogRef.current) !== null && _dialogRef$current3 !== void 0 && _dialogRef$current3.open) dialogRef.current.close();
149
+ }, [internalOpen]);
150
+
151
+ // dialog handles Esc automatically, so we have to sync internal state
152
+ // but it doesn't call onCancel, so have another effect for that!
153
+ React.useEffect(() => {
154
+ const dialogEl = dialogRef.current;
155
+ dialogEl === null || dialogEl === void 0 ? void 0 : dialogEl.addEventListener('close', onInternalClose);
156
+ return () => dialogEl === null || dialogEl === void 0 ? void 0 : dialogEl.removeEventListener('close', onInternalClose);
157
+ }, [onInternalClose]);
158
+
159
+ // Esc handler
160
+ React.useEffect(() => {
161
+ const dialogEl = dialogRef.current;
162
+ const handler = event => {
163
+ if (event.key === 'Escape') onInternalCancel();
164
+ };
165
+ dialogEl === null || dialogEl === void 0 ? void 0 : dialogEl.addEventListener('keydown', handler);
166
+ return () => dialogEl === null || dialogEl === void 0 ? void 0 : dialogEl.removeEventListener('keydown', handler);
167
+ }, [onInternalCancel]);
168
+
169
+ // Autofocus hack: React doesn't support autoFocus for dialog: https://github.com/facebook/react/issues/23301
170
+ // tl;dr: react takes over autofocus instead of letting the browser handle it,
171
+ // but not for dialogs, so we have to do it
172
+ React.useEffect(function initialFocus() {
173
+ if (internalOpen) {
174
+ const searchInput = document.querySelector('dialog[open] input');
175
+ if (searchInput) searchInput.focus();else moveFocusToList();
176
+ }
177
+ }, [internalOpen]);
178
+
179
+ /* Anchored */
180
+ const {
181
+ position
182
+ } = useAnchoredPosition({
183
+ anchorElementRef: anchorRef,
184
+ floatingElementRef: dialogRef,
185
+ side: 'outside-bottom',
186
+ align: 'start',
187
+ ...anchoredPositionSettings
188
+ },
189
+ // eslint-disable-next-line react-hooks/refs
190
+ [internalOpen, anchorRef.current, dialogRef.current]);
191
+
192
+ /*
193
+ We want to cancel and close the panel when user clicks outside.
194
+ See decision log: https://github.com/github/primer/discussions/2614#discussioncomment-8544561
195
+ */
196
+ const onClickOutside = onInternalCancel;
197
+ let maxHeightValue = heightMap[maxHeight];
198
+ if (currentVariant === 'bottom-sheet') {
199
+ maxHeightValue = 'calc(100vh - 64px)';
200
+ } else if (currentVariant === 'full-screen') {
201
+ maxHeightValue = '100vh';
202
+ }
203
+ return /*#__PURE__*/jsxs(Fragment, {
204
+ children: [Anchor, /*#__PURE__*/jsx(BaseOverlay, {
205
+ as: "dialog",
206
+ ref: dialogRef,
207
+ "aria-labelledby": `${panelId}--title`,
208
+ "aria-describedby": description ? `${panelId}--description` : undefined,
209
+ width: width,
210
+ height: "fit-content",
211
+ maxHeight: maxHeight,
212
+ "data-variant": currentVariant,
213
+ style: {
214
+ '--max-height': maxHeightValue,
215
+ '--position-top': `${(_position$top = position === null || position === void 0 ? void 0 : position.top) !== null && _position$top !== void 0 ? _position$top : 0}px`,
216
+ '--position-left': `${(_position$left = position === null || position === void 0 ? void 0 : position.left) !== null && _position$left !== void 0 ? _position$left : 0}px`,
217
+ visibility: internalOpen ? 'visible' : 'hidden',
218
+ display: 'flex'
219
+ },
220
+ className: clsx(classes.Overlay, className),
221
+ ...props,
222
+ onClick: event => {
223
+ if (event.target === event.currentTarget) onClickOutside();
224
+ },
225
+ children: internalOpen && /*#__PURE__*/jsx(Fragment, {
226
+ children: /*#__PURE__*/jsx(SelectPanelContext.Provider, {
227
+ value: {
228
+ panelId,
229
+ title,
230
+ description,
231
+ onCancel: onInternalCancel,
232
+ onClearSelection: propsOnClearSelection ? onInternalClearSelection : undefined,
233
+ searchQuery,
234
+ setSearchQuery,
235
+ selectionVariant,
236
+ moveFocusToList
237
+ },
238
+ children: /*#__PURE__*/jsxs("form", {
239
+ method: "dialog",
240
+ onSubmit: onInternalSubmit,
241
+ className: classes.Form,
242
+ children: [(_slots$header = slots.header) !== null && _slots$header !== void 0 ? _slots$header :
243
+ /*#__PURE__*/
244
+ /* render default header as fallback */
245
+ jsx(SelectPanelHeader, {}), /*#__PURE__*/jsx("div", {
246
+ className: classes.Container,
247
+ children: /*#__PURE__*/jsx(ActionListContainerContext.Provider, {
248
+ value: {
249
+ container: 'SelectPanel',
250
+ listRole: 'listbox',
251
+ selectionAttribute: 'aria-selected',
252
+ selectionVariant: selectionVariant === 'instant' ? 'single' : selectionVariant,
253
+ afterSelect: internalAfterSelect,
254
+ listLabelledBy: `${panelId}--title`,
255
+ enableFocusZone: true // Arrow keys navigation for list items
256
+ },
257
+ children: childrenInBody
258
+ })
259
+ }), slots.footer]
260
+ })
261
+ })
262
+ })
263
+ })]
264
+ });
201
265
  };
202
- const SelectPanelButton = /* @__PURE__ */ React.forwardRef((props, anchorRef) => {
203
- const inputProps = useFormControlForwardedProps(props);
204
- const [labelText, setLabelText] = useState("");
205
- useEffect(() => {
206
- const label = document.querySelector(`[for='${inputProps.id}']`);
207
- if (label !== null && label !== void 0 && label.textContent) setLabelText(label.textContent);
208
- }, [inputProps.id]);
209
- if (labelText) return /* @__PURE__ */ jsx(ButtonComponent, {
210
- ref: anchorRef,
211
- "aria-label": `${anchorRef.current.textContent}, ${labelText}`,
212
- ...inputProps
213
- });
214
- else return /* @__PURE__ */ jsx(ButtonComponent, {
215
- ref: anchorRef,
216
- ...props
217
- });
266
+ const SelectPanelButton = /*#__PURE__*/React.forwardRef((props, anchorRef) => {
267
+ const inputProps = useFormControlForwardedProps(props);
268
+ const [labelText, setLabelText] = useState('');
269
+ useEffect(() => {
270
+ const label = document.querySelector(`[for='${inputProps.id}']`);
271
+ if (label !== null && label !== void 0 && label.textContent) {
272
+ // eslint-disable-next-line react-hooks/set-state-in-effect
273
+ setLabelText(label.textContent);
274
+ }
275
+ }, [inputProps.id]);
276
+ if (labelText) {
277
+ return /*#__PURE__*/jsx(ButtonComponent, {
278
+ ref: anchorRef
279
+ // eslint-disable-next-line react-hooks/refs
280
+ ,
281
+ "aria-label": `${anchorRef.current.textContent}, ${labelText}`,
282
+ ...inputProps
283
+ });
284
+ } else {
285
+ return /*#__PURE__*/jsx(ButtonComponent, {
286
+ ref: anchorRef,
287
+ ...props
288
+ });
289
+ }
218
290
  });
219
- SelectPanelButton.__SLOT__ = Symbol("SelectPanel.Button");
220
- const SelectPanelHeader = ({ children, onBack, className, ...props }) => {
221
- const [slots, childrenWithoutSlots] = useSlots(children, { searchInput: SelectPanelSearchInput });
222
- const { title, description, panelId, onCancel, onClearSelection } = React.useContext(SelectPanelContext);
223
- return /* @__PURE__ */ jsxs("div", {
224
- className: clsx(SelectPanel_module_css_default.Header, className),
225
- ...props,
226
- children: [
227
- /* @__PURE__ */ jsxs("div", {
228
- className: SelectPanel_module_css_default.HeaderContent,
229
- "data-description": description ? true : void 0,
230
- "data-search-input": slots.searchInput ? true : void 0,
231
- children: [/* @__PURE__ */ jsxs("div", {
232
- className: SelectPanel_module_css_default.FlexBox,
233
- children: [onBack ? /* @__PURE__ */ jsx(IconButton, {
234
- type: "button",
235
- variant: "invisible",
236
- icon: ArrowLeftIcon,
237
- "aria-label": "Back",
238
- onClick: () => onBack()
239
- }) : null, /* @__PURE__ */ jsxs("div", {
240
- className: SelectPanel_module_css_default.TitleWrapper,
241
- "data-description": description ? true : void 0,
242
- "data-on-back": onBack ? true : void 0,
243
- children: [/* @__PURE__ */ jsx(Heading, {
244
- as: "h1",
245
- id: `${panelId}--title`,
246
- className: SelectPanel_module_css_default.Title,
247
- children: title
248
- }), description ? /* @__PURE__ */ jsx("span", {
249
- id: `${panelId}--description`,
250
- className: SelectPanel_module_css_default.Description,
251
- children: description
252
- }) : null]
253
- })]
254
- }), /* @__PURE__ */ jsxs("div", { children: [onClearSelection ? /* @__PURE__ */ jsx(IconButton, {
255
- type: "button",
256
- variant: "invisible",
257
- icon: FilterRemoveIcon,
258
- "aria-label": "Clear selection",
259
- onClick: onClearSelection
260
- }) : null, /* @__PURE__ */ jsx(IconButton, {
261
- type: "button",
262
- variant: "invisible",
263
- icon: XIcon,
264
- "aria-label": "Close",
265
- onClick: () => onCancel()
266
- })] })]
267
- }),
268
- slots.searchInput,
269
- childrenWithoutSlots
270
- ]
271
- });
291
+ SelectPanelButton.__SLOT__ = Symbol('SelectPanel.Button');
292
+ const SelectPanelHeader = ({
293
+ children,
294
+ onBack,
295
+ className,
296
+ ...props
297
+ }) => {
298
+ const [slots, childrenWithoutSlots] = useSlots(children, {
299
+ searchInput: SelectPanelSearchInput
300
+ });
301
+ const {
302
+ title,
303
+ description,
304
+ panelId,
305
+ onCancel,
306
+ onClearSelection
307
+ } = React.useContext(SelectPanelContext);
308
+ return /*#__PURE__*/jsxs("div", {
309
+ className: clsx(classes.Header, className),
310
+ ...props,
311
+ children: [/*#__PURE__*/jsxs("div", {
312
+ className: classes.HeaderContent,
313
+ "data-description": description ? true : undefined,
314
+ "data-search-input": slots.searchInput ? true : undefined,
315
+ children: [/*#__PURE__*/jsxs("div", {
316
+ className: classes.FlexBox,
317
+ children: [onBack ? /*#__PURE__*/jsx(IconButton, {
318
+ type: "button",
319
+ variant: "invisible",
320
+ icon: ArrowLeftIcon,
321
+ "aria-label": "Back",
322
+ onClick: () => onBack()
323
+ }) : null, /*#__PURE__*/jsxs("div", {
324
+ className: classes.TitleWrapper,
325
+ "data-description": description ? true : undefined,
326
+ "data-on-back": onBack ? true : undefined,
327
+ children: [/*#__PURE__*/jsx(Heading, {
328
+ as: "h1",
329
+ id: `${panelId}--title`,
330
+ className: classes.Title,
331
+ children: title
332
+ }), description ? /*#__PURE__*/jsx("span", {
333
+ id: `${panelId}--description`,
334
+ className: classes.Description,
335
+ children: description
336
+ }) : null]
337
+ })]
338
+ }), /*#__PURE__*/jsxs("div", {
339
+ children: [onClearSelection ? /*#__PURE__*/jsx(IconButton, {
340
+ type: "button",
341
+ variant: "invisible",
342
+ icon: FilterRemoveIcon,
343
+ "aria-label": "Clear selection",
344
+ onClick: onClearSelection
345
+ }) : null, /*#__PURE__*/jsx(IconButton, {
346
+ type: "button",
347
+ variant: "invisible",
348
+ icon: XIcon,
349
+ "aria-label": "Close",
350
+ onClick: () => onCancel()
351
+ })]
352
+ })]
353
+ }), slots.searchInput, childrenWithoutSlots]
354
+ });
272
355
  };
273
356
  SelectPanelHeader.displayName = "SelectPanelHeader";
274
- SelectPanelHeader.__SLOT__ = Symbol("SelectPanel.Header");
275
- const SelectPanelSearchInput = ({ onChange: propsOnChange, onKeyDown: propsOnKeyDown, className, ...props }) => {
276
- const inputRef = /* @__PURE__ */ React.createRef();
277
- const { setSearchQuery, moveFocusToList } = React.useContext(SelectPanelContext);
278
- const internalOnChange = (event) => {
279
- if (typeof propsOnChange === "function") propsOnChange(event);
280
- else setSearchQuery(event.target.value);
281
- };
282
- const internalKeyDown = (event) => {
283
- if (event.key === "ArrowDown") {
284
- event.preventDefault();
285
- moveFocusToList();
286
- }
287
- if (typeof propsOnKeyDown === "function") propsOnKeyDown(event);
288
- };
289
- return /* @__PURE__ */ jsx(TextInput_default, {
290
- ref: inputRef,
291
- block: true,
292
- leadingVisual: SearchIcon,
293
- placeholder: "Search",
294
- trailingAction: /* @__PURE__ */ jsx(TextInput_default.Action, {
295
- icon: XCircleFillIcon,
296
- "aria-label": "Clear",
297
- tooltipDirection: "w",
298
- className: SelectPanel_module_css_default.ClearAction,
299
- onClick: () => {
300
- if (inputRef.current) inputRef.current.value = "";
301
- if (typeof propsOnChange === "function") propsOnChange({
302
- target: inputRef.current,
303
- currentTarget: inputRef.current
304
- });
305
- }
306
- }),
307
- className: clsx(SelectPanel_module_css_default.TextInput, className),
308
- onChange: internalOnChange,
309
- onKeyDown: internalKeyDown,
310
- ...props
311
- });
357
+ SelectPanelHeader.__SLOT__ = Symbol('SelectPanel.Header');
358
+ const SelectPanelSearchInput = ({
359
+ onChange: propsOnChange,
360
+ onKeyDown: propsOnKeyDown,
361
+ className,
362
+ ...props
363
+ }) => {
364
+ // TODO: use forwardedRef
365
+ const inputRef = /*#__PURE__*/React.createRef();
366
+ const {
367
+ setSearchQuery,
368
+ moveFocusToList
369
+ } = React.useContext(SelectPanelContext);
370
+ const internalOnChange = event => {
371
+ // If props.onChange is given, the application controls search,
372
+ // otherwise the component does
373
+ if (typeof propsOnChange === 'function') propsOnChange(event);else setSearchQuery(event.target.value);
374
+ };
375
+ const internalKeyDown = event => {
376
+ if (event.key === 'ArrowDown') {
377
+ event.preventDefault(); // prevent scroll
378
+ moveFocusToList();
379
+ }
380
+ if (typeof propsOnKeyDown === 'function') propsOnKeyDown(event);
381
+ };
382
+ return /*#__PURE__*/jsx(TextInput, {
383
+ ref: inputRef,
384
+ block: true,
385
+ leadingVisual: SearchIcon,
386
+ placeholder: "Search",
387
+ trailingAction: /*#__PURE__*/jsx(TextInput.Action, {
388
+ icon: XCircleFillIcon,
389
+ "aria-label": "Clear",
390
+ tooltipDirection: "w",
391
+ className: classes.ClearAction,
392
+ onClick: () => {
393
+ if (inputRef.current) inputRef.current.value = '';
394
+ if (typeof propsOnChange === 'function') {
395
+ // @ts-ignore TODO this is a hacky solution to clear
396
+ propsOnChange({
397
+ target: inputRef.current,
398
+ currentTarget: inputRef.current
399
+ });
400
+ }
401
+ }
402
+ }),
403
+ className: clsx(classes.TextInput, className),
404
+ onChange: internalOnChange,
405
+ onKeyDown: internalKeyDown,
406
+ ...props
407
+ });
312
408
  };
313
409
  SelectPanelSearchInput.displayName = "SelectPanelSearchInput";
314
- SelectPanelSearchInput.__SLOT__ = Symbol("SelectPanel.SearchInput");
315
- const FooterContext = /* @__PURE__ */ React.createContext(false);
316
- const SelectPanelFooter = ({ ...props }) => {
317
- const { onCancel, selectionVariant } = React.useContext(SelectPanelContext);
318
- const hidePrimaryActions = selectionVariant === "instant";
319
- const buttonSize = useResponsiveValue(responsiveButtonSizes, "small");
320
- if (hidePrimaryActions && !props.children) return null;
321
- return /* @__PURE__ */ jsx(FooterContext.Provider, {
322
- value: true,
323
- children: /* @__PURE__ */ jsxs("div", {
324
- className: SelectPanel_module_css_default.Footer,
325
- "data-hide-primary-actions": hidePrimaryActions || void 0,
326
- children: [/* @__PURE__ */ jsx("div", {
327
- className: SelectPanel_module_css_default.FooterContent,
328
- "data-hide-primary-actions": hidePrimaryActions || void 0,
329
- children: props.children
330
- }), hidePrimaryActions ? null : /* @__PURE__ */ jsxs("div", {
331
- className: SelectPanel_module_css_default.FooterActions,
332
- children: [/* @__PURE__ */ jsx(ButtonComponent, {
333
- type: "button",
334
- size: buttonSize,
335
- onClick: () => onCancel(),
336
- children: "Cancel"
337
- }), /* @__PURE__ */ jsx(ButtonComponent, {
338
- type: "submit",
339
- size: buttonSize,
340
- variant: "primary",
341
- children: "Save"
342
- })]
343
- })]
344
- })
345
- });
410
+ SelectPanelSearchInput.__SLOT__ = Symbol('SelectPanel.SearchInput');
411
+ const FooterContext = /*#__PURE__*/React.createContext(false);
412
+ const SelectPanelFooter = ({
413
+ ...props
414
+ }) => {
415
+ const {
416
+ onCancel,
417
+ selectionVariant
418
+ } = React.useContext(SelectPanelContext);
419
+ const hidePrimaryActions = selectionVariant === 'instant';
420
+ const buttonSize = useResponsiveValue(responsiveButtonSizes, 'small');
421
+ if (hidePrimaryActions && !props.children) {
422
+ // nothing to render
423
+ // todo: we can inform them the developer footer will render nothing
424
+ return null;
425
+ }
426
+ return /*#__PURE__*/jsx(FooterContext.Provider, {
427
+ value: true,
428
+ children: /*#__PURE__*/jsxs("div", {
429
+ className: classes.Footer,
430
+ "data-hide-primary-actions": hidePrimaryActions || undefined,
431
+ children: [/*#__PURE__*/jsx("div", {
432
+ className: classes.FooterContent,
433
+ "data-hide-primary-actions": hidePrimaryActions || undefined,
434
+ children: props.children
435
+ }), hidePrimaryActions ? null : /*#__PURE__*/jsxs("div", {
436
+ className: classes.FooterActions,
437
+ children: [/*#__PURE__*/jsx(ButtonComponent, {
438
+ type: "button",
439
+ size: buttonSize,
440
+ onClick: () => onCancel(),
441
+ children: "Cancel"
442
+ }), /*#__PURE__*/jsx(ButtonComponent, {
443
+ type: "submit",
444
+ size: buttonSize,
445
+ variant: "primary",
446
+ children: "Save"
447
+ })]
448
+ })]
449
+ })
450
+ });
346
451
  };
347
452
  SelectPanelFooter.displayName = "SelectPanelFooter";
348
- SelectPanelFooter.__SLOT__ = Symbol("SelectPanel.Footer");
349
- const SecondaryButton = (props) => {
350
- return /* @__PURE__ */ jsx(ButtonComponent, {
351
- type: "button",
352
- size: useResponsiveValue(responsiveButtonSizes, "small"),
353
- block: true,
354
- ...props
355
- });
453
+ SelectPanelFooter.__SLOT__ = Symbol('SelectPanel.Footer');
454
+ const SecondaryButton = props => {
455
+ const size = useResponsiveValue(responsiveButtonSizes, 'small');
456
+ return /*#__PURE__*/jsx(ButtonComponent, {
457
+ type: "button",
458
+ size: size,
459
+ block: true,
460
+ ...props
461
+ });
356
462
  };
357
463
  SecondaryButton.displayName = "SecondaryButton";
358
- const SecondaryLink = ({ className, ...props }) => {
359
- return /* @__PURE__ */ jsx(ButtonComponent, {
360
- as: Link,
361
- size: useResponsiveValue(responsiveButtonSizes, "small"),
362
- variant: "invisible",
363
- block: true,
364
- ...props,
365
- className: clsx(SelectPanel_module_css_default.SmallText, className),
366
- children: props.children
367
- });
464
+ const SecondaryLink = ({
465
+ className,
466
+ ...props
467
+ }) => {
468
+ const size = useResponsiveValue(responsiveButtonSizes, 'small');
469
+ return (
470
+ /*#__PURE__*/
471
+ // @ts-ignore TODO: is as prop is not recognised by button?
472
+ jsx(ButtonComponent, {
473
+ as: Link,
474
+ size: size,
475
+ variant: "invisible",
476
+ block: true,
477
+ ...props,
478
+ className: clsx(classes.SmallText, className),
479
+ children: props.children
480
+ })
481
+ );
368
482
  };
369
483
  SecondaryLink.displayName = "SecondaryLink";
370
- const SecondaryCheckbox = ({ id, children, className, ...props }) => {
371
- const checkboxId = useId$1(id);
372
- const { selectionVariant } = React.useContext(SelectPanelContext);
373
- !(selectionVariant !== "instant") && invariant(false, "Sorry! SelectPanel.SecondaryAction with variant=\"checkbox\" is not allowed inside selectionVariant=\"instant\"");
374
- return /* @__PURE__ */ jsxs("div", {
375
- className: SelectPanel_module_css_default.SecondaryCheckbox,
376
- children: [/* @__PURE__ */ jsx(Checkbox, {
377
- id: checkboxId,
378
- className: clsx(SelectPanel_module_css_default.Checkbox, className),
379
- ...props
380
- }), /* @__PURE__ */ jsx(InputLabel, {
381
- htmlFor: checkboxId,
382
- className: SelectPanel_module_css_default.SmallText,
383
- children
384
- })]
385
- });
484
+ const SecondaryCheckbox = ({
485
+ id,
486
+ children,
487
+ className,
488
+ ...props
489
+ }) => {
490
+ const checkboxId = useId(id);
491
+ const {
492
+ selectionVariant
493
+ } = React.useContext(SelectPanelContext);
494
+
495
+ // Checkbox should not be used with instant selection
496
+ !(selectionVariant !== 'instant') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Sorry! SelectPanel.SecondaryAction with variant="checkbox" is not allowed inside selectionVariant="instant"') : invariant(false) : void 0;
497
+ return /*#__PURE__*/jsxs("div", {
498
+ className: classes.SecondaryCheckbox,
499
+ children: [/*#__PURE__*/jsx(Checkbox, {
500
+ id: checkboxId,
501
+ className: clsx(classes.Checkbox, className),
502
+ ...props
503
+ }), /*#__PURE__*/jsx(InputLabel, {
504
+ htmlFor: checkboxId,
505
+ className: classes.SmallText,
506
+ children: children
507
+ })]
508
+ });
386
509
  };
387
510
  SecondaryCheckbox.displayName = "SecondaryCheckbox";
388
- const SelectPanelSecondaryAction = ({ variant, ...props }) => {
389
- !React.useContext(FooterContext) && invariant(false, "SelectPanel.SecondaryAction is only allowed inside SelectPanel.Footer");
390
- if (variant === "button") return /* @__PURE__ */ jsx(SecondaryButton, { ...props });
391
- else if (variant === "link") return /* @__PURE__ */ jsx(SecondaryLink, { ...props });
392
- else if (variant === "checkbox") return /* @__PURE__ */ jsx(SecondaryCheckbox, { ...props });
511
+ const SelectPanelSecondaryAction = ({
512
+ variant,
513
+ ...props
514
+ }) => {
515
+ const insideFooter = React.useContext(FooterContext);
516
+ !insideFooter ? process.env.NODE_ENV !== "production" ? invariant(false, 'SelectPanel.SecondaryAction is only allowed inside SelectPanel.Footer') : invariant(false) : void 0;
517
+
518
+ // @ts-ignore TODO
519
+ if (variant === 'button') return /*#__PURE__*/jsx(SecondaryButton, {
520
+ ...props
521
+ });
522
+ // @ts-ignore TODO
523
+ else if (variant === 'link') return /*#__PURE__*/jsx(SecondaryLink, {
524
+ ...props
525
+ });
526
+ // @ts-ignore TODO
527
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
528
+ else if (variant === 'checkbox') return /*#__PURE__*/jsx(SecondaryCheckbox, {
529
+ ...props
530
+ });
393
531
  };
394
- const SelectPanelLoading = ({ children = "Fetching items..." }) => {
395
- return /* @__PURE__ */ jsxs(AriaStatus, {
396
- announceOnShow: true,
397
- className: SelectPanel_module_css_default.SelectPanelLoading,
398
- children: [/* @__PURE__ */ jsx(Spinner, {
399
- size: "medium",
400
- srText: null
401
- }), /* @__PURE__ */ jsx("span", {
402
- className: SelectPanel_module_css_default.LoadingText,
403
- children
404
- })]
405
- });
532
+ const SelectPanelLoading = ({
533
+ children = 'Fetching items...'
534
+ }) => {
535
+ return /*#__PURE__*/jsxs(AriaStatus, {
536
+ announceOnShow: true,
537
+ className: classes.SelectPanelLoading,
538
+ children: [/*#__PURE__*/jsx(Spinner, {
539
+ size: "medium",
540
+ srText: null
541
+ }), /*#__PURE__*/jsx("span", {
542
+ className: classes.LoadingText,
543
+ children: children
544
+ })]
545
+ });
406
546
  };
407
547
  SelectPanelLoading.displayName = "SelectPanelLoading";
408
- const SelectPanelMessage = ({ variant = "warning", size = variant === "empty" ? "full" : "inline", title, children }) => {
409
- const MessageWrapper = variant === "empty" ? "div" : AriaStatus;
410
- if (size === "full") return /* @__PURE__ */ jsxs(MessageWrapper, {
411
- className: SelectPanel_module_css_default.MessageFull,
412
- children: [
413
- variant !== "empty" ? /* @__PURE__ */ jsx(Octicon, {
414
- icon: AlertIcon,
415
- className: clsx(SelectPanel_module_css_default.Octicon, variant === "error" ? SelectPanel_module_css_default.Error : void 0, variant === "warning" ? SelectPanel_module_css_default.Warning : void 0)
416
- }) : null,
417
- /* @__PURE__ */ jsx("span", {
418
- className: SelectPanel_module_css_default.MessageTitle,
419
- children: title
420
- }),
421
- /* @__PURE__ */ jsx("span", {
422
- className: SelectPanel_module_css_default.MessageContent,
423
- children
424
- })
425
- ]
426
- });
427
- else return /* @__PURE__ */ jsxs(MessageWrapper, {
428
- className: SelectPanel_module_css_default.MessageInline,
429
- "data-variant": variant,
430
- children: [/* @__PURE__ */ jsx(AlertIcon, { size: 16 }), /* @__PURE__ */ jsx("div", { children })]
431
- });
548
+ const SelectPanelMessage = ({
549
+ variant = 'warning',
550
+ size = variant === 'empty' ? 'full' : 'inline',
551
+ title,
552
+ children
553
+ }) => {
554
+ const MessageWrapper = variant === 'empty' ? 'div' : AriaStatus;
555
+ if (size === 'full') {
556
+ return /*#__PURE__*/jsxs(MessageWrapper, {
557
+ className: classes.MessageFull,
558
+ children: [variant !== 'empty' ? /*#__PURE__*/jsx(Octicon, {
559
+ icon: AlertIcon,
560
+ className: clsx(classes.Octicon, variant === 'error' ? classes.Error : undefined, variant === 'warning' ? classes.Warning : undefined)
561
+ }) : null, /*#__PURE__*/jsx("span", {
562
+ className: classes.MessageTitle,
563
+ children: title
564
+ }), /*#__PURE__*/jsx("span", {
565
+ className: classes.MessageContent,
566
+ children: children
567
+ })]
568
+ });
569
+ } else {
570
+ return /*#__PURE__*/jsxs(MessageWrapper, {
571
+ className: classes.MessageInline,
572
+ "data-variant": variant,
573
+ children: [/*#__PURE__*/jsx(AlertIcon, {
574
+ size: 16
575
+ }), /*#__PURE__*/jsx("div", {
576
+ children: children
577
+ })]
578
+ });
579
+ }
432
580
  };
433
581
  const SelectPanel = Object.assign(Panel, {
434
- Button: SelectPanelButton,
435
- Header: SelectPanelHeader,
436
- SearchInput: SelectPanelSearchInput,
437
- Footer: SelectPanelFooter,
438
- Loading: SelectPanelLoading,
439
- Message: SelectPanelMessage,
440
- SecondaryAction: SelectPanelSecondaryAction
582
+ Button: SelectPanelButton,
583
+ Header: SelectPanelHeader,
584
+ SearchInput: SelectPanelSearchInput,
585
+ Footer: SelectPanelFooter,
586
+ Loading: SelectPanelLoading,
587
+ Message: SelectPanelMessage,
588
+ SecondaryAction: SelectPanelSecondaryAction
441
589
  });
442
- //#endregion
590
+
443
591
  export { SelectPanel };