@primer/react 0.0.0-20260427204434 → 0.0.0-20260428150519

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