@primer/react 0.0.0-20260428150519 → 0.0.0-20260428192448

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 (371) hide show
  1. package/CHANGELOG.md +15 -3
  2. package/dist/ActionBar/ActionBar-3f7b52a3.css +2 -0
  3. package/dist/ActionBar/ActionBar-3f7b52a3.css.map +1 -0
  4. package/dist/ActionBar/ActionBar.d.ts +1 -1
  5. package/dist/ActionBar/ActionBar.d.ts.map +1 -1
  6. package/dist/ActionBar/ActionBar.js +630 -514
  7. package/dist/ActionBar/ActionBar.module.css.js +5 -10
  8. package/dist/ActionBar/index.d.ts +1 -1
  9. package/dist/ActionBar/index.js +8 -8
  10. package/dist/ActionList/{ActionList-53389912.css → ActionList-09f5c4a8.css} +2 -2
  11. package/dist/ActionList/ActionList-09f5c4a8.css.map +1 -0
  12. package/dist/ActionList/ActionList.module.css.js +5 -31
  13. package/dist/ActionList/ActionListContainerContext.js +5 -4
  14. package/dist/ActionList/Description.js +133 -117
  15. package/dist/ActionList/Divider.js +38 -31
  16. package/dist/ActionList/Group.js +349 -292
  17. package/dist/ActionList/Group.module.css.js +5 -10
  18. package/dist/ActionList/Heading.js +106 -88
  19. package/dist/ActionList/Heading.module.css.js +5 -5
  20. package/dist/ActionList/Item.js +811 -668
  21. package/dist/ActionList/LinkItem.js +56 -36
  22. package/dist/ActionList/List.js +210 -168
  23. package/dist/ActionList/Selection.d.ts +2 -3
  24. package/dist/ActionList/Selection.d.ts.map +1 -1
  25. package/dist/ActionList/Selection.js +112 -83
  26. package/dist/ActionList/TrailingAction.js +112 -97
  27. package/dist/ActionList/Visuals.js +191 -143
  28. package/dist/ActionList/index.d.ts +7 -0
  29. package/dist/ActionList/index.d.ts.map +1 -1
  30. package/dist/ActionList/index.js +38 -33
  31. package/dist/ActionList/shared.js +9 -5
  32. package/dist/ActionMenu/ActionMenu.js +310 -223
  33. package/dist/ActionMenu/ActionMenu.module.css.js +5 -5
  34. package/dist/AnchoredOverlay/AnchoredOverlay.js +280 -206
  35. package/dist/AnchoredOverlay/AnchoredOverlay.module.css.js +5 -9
  36. package/dist/Autocomplete/Autocomplete.js +141 -125
  37. package/dist/Autocomplete/AutocompleteContext.js +20 -18
  38. package/dist/Autocomplete/AutocompleteInput.js +146 -108
  39. package/dist/Autocomplete/AutocompleteMenu.js +238 -201
  40. package/dist/Autocomplete/AutocompleteMenu.module.css.js +5 -8
  41. package/dist/Autocomplete/AutocompleteOverlay.js +79 -54
  42. package/dist/Autocomplete/AutocompleteOverlay.module.css.js +5 -5
  43. package/dist/Avatar/Avatar.js +133 -106
  44. package/dist/Avatar/Avatar.module.css.js +5 -5
  45. package/dist/AvatarStack/AvatarStack.js +143 -102
  46. package/dist/AvatarStack/AvatarStack.module.css.js +5 -9
  47. package/dist/Banner/Banner.js +186 -133
  48. package/dist/Banner/Banner.module.css.js +5 -14
  49. package/dist/Banner/index.js +7 -7
  50. package/dist/BaseStyles.js +91 -74
  51. package/dist/BaseStyles.module.css.js +5 -5
  52. package/dist/Blankslate/Blankslate.js +328 -266
  53. package/dist/Blankslate/Blankslate.module.css.js +5 -12
  54. package/dist/Blankslate/BlankslateContext.js +9 -7
  55. package/dist/Blankslate/index.js +9 -9
  56. package/dist/BranchName/BranchName.js +59 -49
  57. package/dist/BranchName/BranchName.module.css.js +5 -5
  58. package/dist/Breadcrumbs/Breadcrumbs.js +431 -371
  59. package/dist/Breadcrumbs/Breadcrumbs.module.css.js +5 -15
  60. package/dist/Button/Button.js +18 -15
  61. package/dist/Button/ButtonBase.js +139 -76
  62. package/dist/Button/ButtonBase.module.css.js +5 -16
  63. package/dist/Button/IconButton.js +74 -42
  64. package/dist/Button/LinkButton.js +17 -13
  65. package/dist/ButtonGroup/ButtonGroup.js +97 -80
  66. package/dist/ButtonGroup/ButtonGroup.module.css.js +5 -5
  67. package/dist/Card/Card.js +491 -401
  68. package/dist/Card/Card.module.css.js +5 -18
  69. package/dist/Card/index.js +9 -9
  70. package/dist/Checkbox/Checkbox.d.ts.map +1 -1
  71. package/dist/Checkbox/Checkbox.js +75 -52
  72. package/dist/Checkbox/Checkbox.module.css.js +5 -9
  73. package/dist/Checkbox/shared.module.css.js +5 -5
  74. package/dist/CheckboxGroup/CheckboxGroup.js +132 -111
  75. package/dist/CheckboxGroup/CheckboxGroupContext.js +4 -4
  76. package/dist/CircleBadge/CircleBadge.js +90 -77
  77. package/dist/CircleBadge/CircleBadge.module.css.js +5 -8
  78. package/dist/ConfirmationDialog/ConfirmationDialog.js +92 -68
  79. package/dist/CounterLabel/CounterLabel.js +99 -83
  80. package/dist/CounterLabel/CounterLabel.module.css.js +5 -5
  81. package/dist/DataTable/DataTable.js +140 -100
  82. package/dist/DataTable/ErrorDialog.js +45 -33
  83. package/dist/DataTable/Pagination.js +592 -464
  84. package/dist/DataTable/Pagination.module.css.js +5 -13
  85. package/dist/DataTable/Table.js +710 -527
  86. package/dist/DataTable/Table.module.css.js +5 -26
  87. package/dist/DataTable/column.js +11 -10
  88. package/dist/DataTable/index.js +20 -22
  89. package/dist/DataTable/sorting.js +103 -65
  90. package/dist/DataTable/useTable.js +290 -207
  91. package/dist/Details/Details.js +126 -100
  92. package/dist/Details/Details.module.css.js +5 -5
  93. package/dist/Dialog/Dialog.js +351 -259
  94. package/dist/Dialog/Dialog.module.css.js +5 -22
  95. package/dist/FeatureFlags/DefaultFeatureFlags.js +7 -7
  96. package/dist/FeatureFlags/FeatureFlagContext.js +5 -5
  97. package/dist/FeatureFlags/FeatureFlagScope.js +44 -36
  98. package/dist/FeatureFlags/FeatureFlags.js +37 -29
  99. package/dist/FeatureFlags/useFeatureFlag.js +19 -17
  100. package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
  101. package/dist/FilteredActionList/FilteredActionList.js +559 -454
  102. package/dist/FilteredActionList/FilteredActionList.module.css.js +5 -15
  103. package/dist/FilteredActionList/FilteredActionListInput.d.ts +15 -0
  104. package/dist/FilteredActionList/FilteredActionListInput.d.ts.map +1 -0
  105. package/dist/FilteredActionList/FilteredActionListInput.js +119 -0
  106. package/dist/FilteredActionList/FilteredActionListLoaders.js +150 -119
  107. package/dist/FilteredActionList/FilteredActionListLoaders.module.css.js +5 -9
  108. package/dist/FilteredActionList/index.d.ts +9 -1
  109. package/dist/FilteredActionList/index.d.ts.map +1 -1
  110. package/dist/FilteredActionList/index.js +11 -0
  111. package/dist/FilteredActionList/useAnnouncements.js +180 -167
  112. package/dist/Flash/Flash.js +69 -57
  113. package/dist/Flash/Flash.module.css.js +5 -5
  114. package/dist/FormControl/FormControl.js +227 -211
  115. package/dist/FormControl/FormControl.module.css.js +5 -11
  116. package/dist/FormControl/FormControlCaption.js +49 -37
  117. package/dist/FormControl/FormControlCaption.module.css.js +5 -5
  118. package/dist/FormControl/FormControlLabel.js +115 -95
  119. package/dist/FormControl/FormControlLeadingVisual.js +37 -29
  120. package/dist/FormControl/FormControlLeadingVisual.module.css.js +5 -5
  121. package/dist/FormControl/_FormControlContext.js +48 -41
  122. package/dist/FormControl/_FormControlValidation.js +39 -29
  123. package/dist/Header/Header.js +165 -138
  124. package/dist/Header/Header.module.css.js +5 -9
  125. package/dist/Heading/Heading.js +37 -26
  126. package/dist/Heading/Heading.module.css.js +5 -5
  127. package/dist/Hidden/Hidden.js +77 -54
  128. package/dist/Hidden/Hidden.module.css.js +5 -5
  129. package/dist/InlineMessage/InlineMessage.js +116 -88
  130. package/dist/InlineMessage/InlineMessage.module.css.js +5 -8
  131. package/dist/KeybindingHint/KeybindingHint.js +88 -70
  132. package/dist/KeybindingHint/KeybindingHint.module.css.js +5 -5
  133. package/dist/KeybindingHint/components/Chord.js +93 -81
  134. package/dist/KeybindingHint/components/Chord.module.css.js +5 -11
  135. package/dist/KeybindingHint/components/Key.js +66 -49
  136. package/dist/KeybindingHint/components/Sequence.js +24 -12
  137. package/dist/KeybindingHint/key-names.js +114 -99
  138. package/dist/Label/Label.js +66 -56
  139. package/dist/Label/Label.module.css.js +5 -5
  140. package/dist/Label/index.js +5 -5
  141. package/dist/LabelGroup/LabelGroup.js +344 -260
  142. package/dist/LabelGroup/LabelGroup.module.css.js +5 -12
  143. package/dist/Link/Link.js +47 -31
  144. package/dist/Link/Link.module.css.js +5 -5
  145. package/dist/NavList/NavList.js +614 -424
  146. package/dist/NavList/NavList.module.css.js +5 -5
  147. package/dist/Octicon/Octicon.js +37 -35
  148. package/dist/Overlay/Overlay.js +318 -264
  149. package/dist/Overlay/Overlay.module.css.js +5 -8
  150. package/dist/PageHeader/PageHeader.js +823 -579
  151. package/dist/PageHeader/PageHeader.module.css.js +5 -21
  152. package/dist/PageLayout/PageLayout.js +913 -631
  153. package/dist/PageLayout/PageLayout.module.css.js +5 -31
  154. package/dist/PageLayout/paneUtils.js +29 -15
  155. package/dist/PageLayout/usePaneWidth.js +437 -334
  156. package/dist/Pagehead/Pagehead.js +14 -10
  157. package/dist/Pagehead/Pagehead.module.css.js +5 -5
  158. package/dist/Pagination/Pagination.js +114 -84
  159. package/dist/Pagination/Pagination.module.css.js +5 -9
  160. package/dist/Pagination/index.js +5 -5
  161. package/dist/Pagination/model.js +194 -118
  162. package/dist/Popover/Popover.js +151 -126
  163. package/dist/Popover/Popover.module.css.js +5 -8
  164. package/dist/Portal/Portal.js +85 -65
  165. package/dist/Portal/index.js +6 -5
  166. package/dist/ProgressBar/ProgressBar.js +255 -210
  167. package/dist/ProgressBar/ProgressBar.module.css.js +5 -9
  168. package/dist/ProgressBar/index.js +8 -6
  169. package/dist/Radio/Radio.js +115 -97
  170. package/dist/Radio/Radio.module.css.js +5 -5
  171. package/dist/RadioGroup/RadioGroup.js +118 -99
  172. package/dist/RelativeTime/RelativeTime.js +76 -64
  173. package/dist/ScrollableRegion/ScrollableRegion.js +79 -67
  174. package/dist/ScrollableRegion/ScrollableRegion.module.css.js +5 -5
  175. package/dist/SegmentedControl/SegmentedControl.js +287 -238
  176. package/dist/SegmentedControl/SegmentedControl.module.css.js +5 -15
  177. package/dist/SegmentedControl/SegmentedControlButton.js +187 -156
  178. package/dist/SegmentedControl/SegmentedControlIconButton.js +161 -133
  179. package/dist/Select/Select.js +234 -185
  180. package/dist/Select/Select.module.css.js +5 -10
  181. package/dist/SelectPanel/SelectPanel.d.ts +1 -0
  182. package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
  183. package/dist/SelectPanel/SelectPanel.js +829 -620
  184. package/dist/SelectPanel/SelectPanel.module.css.js +5 -27
  185. package/dist/SelectPanel/SelectPanelMessage.js +39 -37
  186. package/dist/SelectPanel/index.d.ts +1 -0
  187. package/dist/SelectPanel/index.d.ts.map +1 -1
  188. package/dist/SideNav.js +47 -24
  189. package/dist/SideNav.module.css.js +5 -12
  190. package/dist/Skeleton/SkeletonBox.js +111 -94
  191. package/dist/Skeleton/SkeletonBox.module.css.js +5 -8
  192. package/dist/SkeletonAvatar/SkeletonAvatar.js +120 -95
  193. package/dist/SkeletonAvatar/SkeletonAvatar.module.css.js +5 -5
  194. package/dist/SkeletonText/SkeletonText.js +137 -114
  195. package/dist/SkeletonText/SkeletonText.module.css.js +5 -8
  196. package/dist/Spinner/Spinner.js +211 -183
  197. package/dist/Spinner/Spinner.module.css.js +5 -9
  198. package/dist/SplitPageLayout/SplitPageLayout.js +276 -215
  199. package/dist/Stack/Stack.js +255 -207
  200. package/dist/Stack/Stack.module.css.js +5 -8
  201. package/dist/Stack/index.js +6 -4
  202. package/dist/StateLabel/StateLabel.js +123 -110
  203. package/dist/StateLabel/StateLabel.module.css.js +5 -8
  204. package/dist/SubNav/SubNav.js +197 -159
  205. package/dist/SubNav/SubNav.module.css.js +5 -11
  206. package/dist/TabNav/TabNav.js +199 -167
  207. package/dist/TabNav/TabNav.module.css.js +5 -10
  208. package/dist/Text/Text.js +67 -56
  209. package/dist/Text/Text.module.css.js +5 -5
  210. package/dist/TextInput/TextInput.js +228 -195
  211. package/dist/TextInput/TextInput.module.css.js +5 -8
  212. package/dist/TextInputWithTokens/TextInputWithTokens.js +673 -567
  213. package/dist/TextInputWithTokens/TextInputWithTokens.module.css.js +5 -14
  214. package/dist/Textarea/TextArea.module.css.js +5 -9
  215. package/dist/Textarea/Textarea.js +294 -264
  216. package/dist/ThemeProvider.js +257 -199
  217. package/dist/Timeline/Timeline.js +247 -204
  218. package/dist/Timeline/Timeline.module.css.js +5 -12
  219. package/dist/ToggleSwitch/ToggleSwitch.js +471 -403
  220. package/dist/ToggleSwitch/ToggleSwitch.module.css.js +5 -16
  221. package/dist/Token/IssueLabelToken.js +297 -256
  222. package/dist/Token/IssueLabelToken.module.css.js +5 -8
  223. package/dist/Token/Token.js +280 -232
  224. package/dist/Token/Token.module.css.js +5 -9
  225. package/dist/Token/TokenBase.js +126 -99
  226. package/dist/Token/TokenBase.module.css.js +5 -5
  227. package/dist/Token/_RemoveTokenButton.js +48 -27
  228. package/dist/Token/_RemoveTokenButton.module.css.js +5 -5
  229. package/dist/Token/_TokenTextContainer.js +65 -54
  230. package/dist/Token/_TokenTextContainer.module.css.js +5 -5
  231. package/dist/Tooltip/Tooltip.js +56 -49
  232. package/dist/Tooltip/Tooltip.module.css.js +5 -20
  233. package/dist/TooltipV2/Tooltip.js +305 -222
  234. package/dist/TooltipV2/Tooltip.module.css.js +5 -11
  235. package/dist/TopicTag/TopicTag.js +55 -46
  236. package/dist/TopicTag/TopicTag.module.css.js +5 -5
  237. package/dist/TopicTag/TopicTagGroup.js +48 -40
  238. package/dist/TopicTag/TopicTagGroup.module.css.js +5 -5
  239. package/dist/TopicTag/index.js +7 -5
  240. package/dist/TreeView/TreeView.js +1414 -1082
  241. package/dist/TreeView/TreeView.module.css.js +5 -24
  242. package/dist/TreeView/shared.js +9 -10
  243. package/dist/TreeView/useRovingTabIndex.js +203 -129
  244. package/dist/TreeView/useTreeItemCache.js +79 -64
  245. package/dist/TreeView/useTypeahead.js +112 -90
  246. package/dist/Truncate/Truncate.js +33 -21
  247. package/dist/Truncate/Truncate.module.css.js +5 -5
  248. package/dist/UnderlineNav/UnderlineNav.js +375 -278
  249. package/dist/UnderlineNav/UnderlineNav.module.css.js +5 -8
  250. package/dist/UnderlineNav/UnderlineNavContext.js +8 -8
  251. package/dist/UnderlineNav/UnderlineNavItem.js +72 -56
  252. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +5 -5
  253. package/dist/UnderlineNav/index.js +7 -5
  254. package/dist/UnderlineNav/styles.js +15 -11
  255. package/dist/VisuallyHidden/VisuallyHidden.js +49 -51
  256. package/dist/VisuallyHidden/VisuallyHidden.module.css.js +5 -5
  257. package/dist/_VisuallyHidden.js +62 -50
  258. package/dist/_VisuallyHidden.module.css.js +5 -5
  259. package/dist/deprecated/ActionList/Divider.js +23 -23
  260. package/dist/deprecated/ActionList/Divider.module.css.js +5 -5
  261. package/dist/deprecated/ActionList/Group.js +50 -43
  262. package/dist/deprecated/ActionList/Header.js +81 -69
  263. package/dist/deprecated/ActionList/Header.module.css.js +5 -5
  264. package/dist/deprecated/ActionList/Item.js +352 -308
  265. package/dist/deprecated/ActionList/Item.module.css.js +5 -18
  266. package/dist/deprecated/ActionList/List.js +196 -157
  267. package/dist/deprecated/ActionList/List.module.css.js +5 -5
  268. package/dist/deprecated/ActionList/index.js +14 -14
  269. package/dist/deprecated/ActionMenu.js +190 -159
  270. package/dist/deprecated/DialogV1/Dialog.js +200 -166
  271. package/dist/deprecated/DialogV1/Dialog.module.css.js +5 -11
  272. package/dist/deprecated/FilteredSearch/FilteredSearch.js +51 -43
  273. package/dist/deprecated/FilteredSearch/FilteredSearch.module.css.js +5 -5
  274. package/dist/deprecated/UnderlineNav/UnderlineNav.js +160 -132
  275. package/dist/deprecated/UnderlineNav/UnderlineNav.module.css.js +5 -14
  276. package/dist/deprecated/index.js +9 -20
  277. package/dist/experimental/IssueLabel/IssueLabel.js +158 -134
  278. package/dist/experimental/IssueLabel/IssueLabel.module.css.js +5 -5
  279. package/dist/experimental/SelectPanel2/SelectPanel.js +567 -419
  280. package/dist/experimental/SelectPanel2/SelectPanel.module.css.js +5 -32
  281. package/dist/experimental/Tabs/Tabs.js +297 -234
  282. package/dist/experimental/UnderlinePanels/UnderlinePanels.js +215 -165
  283. package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +5 -5
  284. package/dist/experimental/index.d.ts +2 -2
  285. package/dist/experimental/index.d.ts.map +1 -1
  286. package/dist/experimental/index.js +34 -44
  287. package/dist/hooks/useAnchoredPosition.js +144 -123
  288. package/dist/hooks/useControllableState.js +59 -34
  289. package/dist/hooks/useDetails.js +99 -84
  290. package/dist/hooks/useDialog.js +178 -140
  291. package/dist/hooks/useFocusTrap.js +71 -57
  292. package/dist/hooks/useFocusZone.js +38 -32
  293. package/dist/hooks/useId.js +16 -14
  294. package/dist/hooks/useIsMacOS.js +26 -21
  295. package/dist/hooks/useMedia.js +68 -54
  296. package/dist/hooks/useMenuInitialFocus.js +62 -65
  297. package/dist/hooks/useMenuKeyboardNavigation.js +126 -129
  298. package/dist/hooks/useMergedRefs.js +78 -63
  299. package/dist/hooks/useMnemonics.js +107 -77
  300. package/dist/hooks/useOnEscapePress.js +56 -45
  301. package/dist/hooks/useOnOutsideClick.js +63 -32
  302. package/dist/hooks/useOpenAndCloseFocus.js +43 -40
  303. package/dist/hooks/useOverflow.js +36 -32
  304. package/dist/hooks/useOverlay.js +75 -56
  305. package/dist/hooks/useProvidedRefOrCreate.js +24 -24
  306. package/dist/hooks/useProvidedStateOrCreate.js +39 -33
  307. package/dist/hooks/useRefObjectAsForwardedRef.js +32 -30
  308. package/dist/hooks/useRenderForcingRef.js +46 -42
  309. package/dist/hooks/useResizeObserver.js +43 -32
  310. package/dist/hooks/useResponsiveValue.js +57 -37
  311. package/dist/hooks/useSafeTimeout.js +29 -26
  312. package/dist/hooks/useScrollFlash.js +23 -16
  313. package/dist/hooks/useSlots.js +136 -102
  314. package/dist/hooks/useSyncedState.js +37 -31
  315. package/dist/index.d.ts +2 -2
  316. package/dist/index.d.ts.map +1 -1
  317. package/dist/index.js +86 -88
  318. package/dist/internal/components/ButtonReset.js +50 -45
  319. package/dist/internal/components/ButtonReset.module.css.js +5 -5
  320. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.js +105 -79
  321. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.module.css.js +5 -12
  322. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.js +21 -16
  323. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupContext.js +4 -4
  324. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.js +35 -26
  325. package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupValidation.js +19 -14
  326. package/dist/internal/components/ConditionalWrapper.js +51 -41
  327. package/dist/internal/components/InputLabel.js +113 -92
  328. package/dist/internal/components/InputLabel.module.css.js +5 -8
  329. package/dist/internal/components/InputValidation.js +87 -67
  330. package/dist/internal/components/InputValidation.module.css.js +5 -9
  331. package/dist/internal/components/TextInputInnerAction.js +173 -134
  332. package/dist/internal/components/TextInputInnerAction.module.css.js +5 -9
  333. package/dist/internal/components/TextInputInnerVisualSlot.js +110 -89
  334. package/dist/internal/components/TextInputInnerVisualSlot.module.css.js +5 -11
  335. package/dist/internal/components/TextInputWrapper.js +230 -187
  336. package/dist/internal/components/TextInputWrapper.module.css.js +5 -8
  337. package/dist/internal/components/UnderlineTabbedInterface.js +238 -191
  338. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +5 -11
  339. package/dist/internal/components/UnstyledTextInput.js +47 -40
  340. package/dist/internal/components/UnstyledTextInput.module.css.js +5 -5
  341. package/dist/internal/components/ValidationAnimationContainer.js +66 -55
  342. package/dist/internal/components/ValidationAnimationContainer.module.css.js +5 -8
  343. package/dist/internal/hooks/useEffectCallback.js +38 -35
  344. package/dist/internal/hooks/useEffectOnce.js +25 -23
  345. package/dist/internal/utils/getResponsiveAttributes.js +26 -23
  346. package/dist/internal/utils/hasInteractiveNodes.js +46 -34
  347. package/dist/legacy-theme/ts/color-schemes.js +4732 -4250
  348. package/dist/live-region/Announce.js +183 -144
  349. package/dist/live-region/AriaAlert.js +22 -20
  350. package/dist/live-region/AriaStatus.js +22 -20
  351. package/dist/next/index.js +1 -3
  352. package/dist/test-helpers.js +62 -40
  353. package/dist/theme.js +47 -83
  354. package/dist/utils/character-counter.js +63 -45
  355. package/dist/utils/create-component.js +16 -15
  356. package/dist/utils/descendant-registry.js +218 -182
  357. package/dist/utils/environment.js +7 -7
  358. package/dist/utils/getBreakpointDeclarations.js +10 -9
  359. package/dist/utils/invariant.js +23 -17
  360. package/dist/utils/is-slot.js +11 -10
  361. package/dist/utils/isNumeric.js +3 -3
  362. package/dist/utils/modern-polymorphic.js +20 -12
  363. package/dist/utils/scroll.js +11 -8
  364. package/dist/utils/theme.js +10 -5
  365. package/dist/utils/useIsomorphicLayoutEffect.js +9 -4
  366. package/dist/utils/warning.js +21 -14
  367. package/generated/components.json +1 -1
  368. package/package.json +10 -5
  369. package/dist/ActionBar/ActionBar-a41224b2.css +0 -2
  370. package/dist/ActionBar/ActionBar-a41224b2.css.map +0 -1
  371. 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 };