@primer/react 0.0.0-20260428150519 → 0.0.0-20260428191209
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/dist/ActionBar/ActionBar.js +705 -502
- package/dist/ActionBar/ActionBar.module.css.js +5 -10
- package/dist/ActionBar/index.js +8 -8
- package/dist/ActionList/{ActionList-53389912.css → ActionList-09f5c4a8.css} +2 -2
- package/dist/ActionList/ActionList-09f5c4a8.css.map +1 -0
- package/dist/ActionList/ActionList.module.css.js +5 -31
- package/dist/ActionList/ActionListContainerContext.js +5 -4
- package/dist/ActionList/Description.js +133 -117
- package/dist/ActionList/Divider.js +38 -31
- package/dist/ActionList/Group.js +349 -292
- package/dist/ActionList/Group.module.css.js +5 -10
- package/dist/ActionList/Heading.js +106 -88
- package/dist/ActionList/Heading.module.css.js +5 -5
- package/dist/ActionList/Item.js +811 -668
- package/dist/ActionList/LinkItem.js +56 -36
- package/dist/ActionList/List.js +210 -168
- package/dist/ActionList/Selection.d.ts +2 -3
- package/dist/ActionList/Selection.d.ts.map +1 -1
- package/dist/ActionList/Selection.js +112 -83
- package/dist/ActionList/TrailingAction.js +112 -97
- package/dist/ActionList/Visuals.js +191 -143
- package/dist/ActionList/index.d.ts +7 -0
- package/dist/ActionList/index.d.ts.map +1 -1
- package/dist/ActionList/index.js +38 -33
- package/dist/ActionList/shared.js +9 -5
- package/dist/ActionMenu/ActionMenu.js +310 -223
- package/dist/ActionMenu/ActionMenu.module.css.js +5 -5
- package/dist/AnchoredOverlay/AnchoredOverlay.js +280 -206
- package/dist/AnchoredOverlay/AnchoredOverlay.module.css.js +5 -9
- package/dist/Autocomplete/Autocomplete.js +141 -125
- package/dist/Autocomplete/AutocompleteContext.js +20 -18
- package/dist/Autocomplete/AutocompleteInput.js +146 -108
- package/dist/Autocomplete/AutocompleteMenu.js +238 -201
- package/dist/Autocomplete/AutocompleteMenu.module.css.js +5 -8
- package/dist/Autocomplete/AutocompleteOverlay.js +79 -54
- package/dist/Autocomplete/AutocompleteOverlay.module.css.js +5 -5
- package/dist/Avatar/Avatar.js +133 -106
- package/dist/Avatar/Avatar.module.css.js +5 -5
- package/dist/AvatarStack/AvatarStack.js +143 -102
- package/dist/AvatarStack/AvatarStack.module.css.js +5 -9
- package/dist/Banner/Banner.js +186 -133
- package/dist/Banner/Banner.module.css.js +5 -14
- package/dist/Banner/index.js +7 -7
- package/dist/BaseStyles.js +91 -74
- package/dist/BaseStyles.module.css.js +5 -5
- package/dist/Blankslate/Blankslate.js +328 -266
- package/dist/Blankslate/Blankslate.module.css.js +5 -12
- package/dist/Blankslate/BlankslateContext.js +9 -7
- package/dist/Blankslate/index.js +9 -9
- package/dist/BranchName/BranchName.js +59 -49
- package/dist/BranchName/BranchName.module.css.js +5 -5
- package/dist/Breadcrumbs/Breadcrumbs.js +431 -371
- package/dist/Breadcrumbs/Breadcrumbs.module.css.js +5 -15
- package/dist/Button/Button.js +18 -15
- package/dist/Button/ButtonBase.js +139 -76
- package/dist/Button/ButtonBase.module.css.js +5 -16
- package/dist/Button/IconButton.js +74 -42
- package/dist/Button/LinkButton.js +17 -13
- package/dist/ButtonGroup/ButtonGroup.js +97 -80
- package/dist/ButtonGroup/ButtonGroup.module.css.js +5 -5
- package/dist/Card/Card.js +491 -401
- package/dist/Card/Card.module.css.js +5 -18
- package/dist/Card/index.js +9 -9
- package/dist/Checkbox/Checkbox.js +71 -52
- package/dist/Checkbox/Checkbox.module.css.js +5 -9
- package/dist/Checkbox/shared.module.css.js +5 -5
- package/dist/CheckboxGroup/CheckboxGroup.js +132 -111
- package/dist/CheckboxGroup/CheckboxGroupContext.js +4 -4
- package/dist/CircleBadge/CircleBadge.js +90 -77
- package/dist/CircleBadge/CircleBadge.module.css.js +5 -8
- package/dist/ConfirmationDialog/ConfirmationDialog.js +92 -68
- package/dist/CounterLabel/CounterLabel.js +99 -83
- package/dist/CounterLabel/CounterLabel.module.css.js +5 -5
- package/dist/DataTable/DataTable.js +140 -100
- package/dist/DataTable/ErrorDialog.js +45 -33
- package/dist/DataTable/Pagination.js +592 -464
- package/dist/DataTable/Pagination.module.css.js +5 -13
- package/dist/DataTable/Table.js +710 -527
- package/dist/DataTable/Table.module.css.js +5 -26
- package/dist/DataTable/column.js +11 -10
- package/dist/DataTable/index.js +20 -22
- package/dist/DataTable/sorting.js +103 -65
- package/dist/DataTable/useTable.js +290 -207
- package/dist/Details/Details.js +126 -100
- package/dist/Details/Details.module.css.js +5 -5
- package/dist/Dialog/Dialog.js +351 -259
- package/dist/Dialog/Dialog.module.css.js +5 -22
- package/dist/FeatureFlags/DefaultFeatureFlags.js +7 -7
- package/dist/FeatureFlags/FeatureFlagContext.js +5 -5
- package/dist/FeatureFlags/FeatureFlagScope.js +44 -36
- package/dist/FeatureFlags/FeatureFlags.js +37 -29
- package/dist/FeatureFlags/useFeatureFlag.js +19 -17
- package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
- package/dist/FilteredActionList/FilteredActionList.js +559 -454
- package/dist/FilteredActionList/FilteredActionList.module.css.js +5 -15
- package/dist/FilteredActionList/FilteredActionListInput.d.ts +15 -0
- package/dist/FilteredActionList/FilteredActionListInput.d.ts.map +1 -0
- package/dist/FilteredActionList/FilteredActionListInput.js +119 -0
- package/dist/FilteredActionList/FilteredActionListLoaders.js +150 -119
- package/dist/FilteredActionList/FilteredActionListLoaders.module.css.js +5 -9
- package/dist/FilteredActionList/index.d.ts +9 -1
- package/dist/FilteredActionList/index.d.ts.map +1 -1
- package/dist/FilteredActionList/index.js +11 -0
- package/dist/FilteredActionList/useAnnouncements.js +180 -167
- package/dist/Flash/Flash.js +69 -57
- package/dist/Flash/Flash.module.css.js +5 -5
- package/dist/FormControl/FormControl.js +227 -211
- package/dist/FormControl/FormControl.module.css.js +5 -11
- package/dist/FormControl/FormControlCaption.js +49 -37
- package/dist/FormControl/FormControlCaption.module.css.js +5 -5
- package/dist/FormControl/FormControlLabel.js +115 -95
- package/dist/FormControl/FormControlLeadingVisual.js +37 -29
- package/dist/FormControl/FormControlLeadingVisual.module.css.js +5 -5
- package/dist/FormControl/_FormControlContext.js +48 -41
- package/dist/FormControl/_FormControlValidation.js +39 -29
- package/dist/Header/Header.js +165 -138
- package/dist/Header/Header.module.css.js +5 -9
- package/dist/Heading/Heading.js +37 -26
- package/dist/Heading/Heading.module.css.js +5 -5
- package/dist/Hidden/Hidden.js +77 -54
- package/dist/Hidden/Hidden.module.css.js +5 -5
- package/dist/InlineMessage/InlineMessage.js +116 -88
- package/dist/InlineMessage/InlineMessage.module.css.js +5 -8
- package/dist/KeybindingHint/KeybindingHint.js +88 -70
- package/dist/KeybindingHint/KeybindingHint.module.css.js +5 -5
- package/dist/KeybindingHint/components/Chord.js +93 -81
- package/dist/KeybindingHint/components/Chord.module.css.js +5 -11
- package/dist/KeybindingHint/components/Key.js +66 -49
- package/dist/KeybindingHint/components/Sequence.js +24 -12
- package/dist/KeybindingHint/key-names.js +114 -99
- package/dist/Label/Label.js +66 -56
- package/dist/Label/Label.module.css.js +5 -5
- package/dist/Label/index.js +5 -5
- package/dist/LabelGroup/LabelGroup.js +344 -260
- package/dist/LabelGroup/LabelGroup.module.css.js +5 -12
- package/dist/Link/Link.js +47 -31
- package/dist/Link/Link.module.css.js +5 -5
- package/dist/NavList/NavList.js +614 -424
- package/dist/NavList/NavList.module.css.js +5 -5
- package/dist/Octicon/Octicon.js +37 -35
- package/dist/Overlay/Overlay.js +318 -264
- package/dist/Overlay/Overlay.module.css.js +5 -8
- package/dist/PageHeader/PageHeader.js +823 -579
- package/dist/PageHeader/PageHeader.module.css.js +5 -21
- package/dist/PageLayout/PageLayout.js +913 -631
- package/dist/PageLayout/PageLayout.module.css.js +5 -31
- package/dist/PageLayout/paneUtils.js +29 -15
- package/dist/PageLayout/usePaneWidth.js +437 -334
- package/dist/Pagehead/Pagehead.js +14 -10
- package/dist/Pagehead/Pagehead.module.css.js +5 -5
- package/dist/Pagination/Pagination.js +114 -84
- package/dist/Pagination/Pagination.module.css.js +5 -9
- package/dist/Pagination/index.js +5 -5
- package/dist/Pagination/model.js +194 -118
- package/dist/Popover/Popover.js +151 -126
- package/dist/Popover/Popover.module.css.js +5 -8
- package/dist/Portal/Portal.js +85 -65
- package/dist/Portal/index.js +6 -5
- package/dist/ProgressBar/ProgressBar.js +255 -210
- package/dist/ProgressBar/ProgressBar.module.css.js +5 -9
- package/dist/ProgressBar/index.js +8 -6
- package/dist/Radio/Radio.js +115 -97
- package/dist/Radio/Radio.module.css.js +5 -5
- package/dist/RadioGroup/RadioGroup.js +118 -99
- package/dist/RelativeTime/RelativeTime.js +76 -64
- package/dist/ScrollableRegion/ScrollableRegion.js +79 -67
- package/dist/ScrollableRegion/ScrollableRegion.module.css.js +5 -5
- package/dist/SegmentedControl/SegmentedControl.js +287 -238
- package/dist/SegmentedControl/SegmentedControl.module.css.js +5 -15
- package/dist/SegmentedControl/SegmentedControlButton.js +187 -156
- package/dist/SegmentedControl/SegmentedControlIconButton.js +161 -133
- package/dist/Select/Select.js +234 -185
- package/dist/Select/Select.module.css.js +5 -10
- package/dist/SelectPanel/SelectPanel.d.ts +1 -0
- package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +829 -620
- package/dist/SelectPanel/SelectPanel.module.css.js +5 -27
- package/dist/SelectPanel/SelectPanelMessage.js +39 -37
- package/dist/SelectPanel/index.d.ts +1 -0
- package/dist/SelectPanel/index.d.ts.map +1 -1
- package/dist/SideNav.js +47 -24
- package/dist/SideNav.module.css.js +5 -12
- package/dist/Skeleton/SkeletonBox.js +111 -94
- package/dist/Skeleton/SkeletonBox.module.css.js +5 -8
- package/dist/SkeletonAvatar/SkeletonAvatar.js +120 -95
- package/dist/SkeletonAvatar/SkeletonAvatar.module.css.js +5 -5
- package/dist/SkeletonText/SkeletonText.js +137 -114
- package/dist/SkeletonText/SkeletonText.module.css.js +5 -8
- package/dist/Spinner/Spinner.js +211 -183
- package/dist/Spinner/Spinner.module.css.js +5 -9
- package/dist/SplitPageLayout/SplitPageLayout.js +276 -215
- package/dist/Stack/Stack.js +255 -207
- package/dist/Stack/Stack.module.css.js +5 -8
- package/dist/Stack/index.js +6 -4
- package/dist/StateLabel/StateLabel.js +123 -110
- package/dist/StateLabel/StateLabel.module.css.js +5 -8
- package/dist/SubNav/SubNav.js +197 -159
- package/dist/SubNav/SubNav.module.css.js +5 -11
- package/dist/TabNav/TabNav.js +199 -167
- package/dist/TabNav/TabNav.module.css.js +5 -10
- package/dist/Text/Text.js +67 -56
- package/dist/Text/Text.module.css.js +5 -5
- package/dist/TextInput/TextInput.js +228 -195
- package/dist/TextInput/TextInput.module.css.js +5 -8
- package/dist/TextInputWithTokens/TextInputWithTokens.js +673 -567
- package/dist/TextInputWithTokens/TextInputWithTokens.module.css.js +5 -14
- package/dist/Textarea/TextArea.module.css.js +5 -9
- package/dist/Textarea/Textarea.js +294 -264
- package/dist/ThemeProvider.js +257 -199
- package/dist/Timeline/Timeline.js +247 -204
- package/dist/Timeline/Timeline.module.css.js +5 -12
- package/dist/ToggleSwitch/ToggleSwitch.js +471 -403
- package/dist/ToggleSwitch/ToggleSwitch.module.css.js +5 -16
- package/dist/Token/IssueLabelToken.js +297 -256
- package/dist/Token/IssueLabelToken.module.css.js +5 -8
- package/dist/Token/Token.js +280 -232
- package/dist/Token/Token.module.css.js +5 -9
- package/dist/Token/TokenBase.js +126 -99
- package/dist/Token/TokenBase.module.css.js +5 -5
- package/dist/Token/_RemoveTokenButton.js +48 -27
- package/dist/Token/_RemoveTokenButton.module.css.js +5 -5
- package/dist/Token/_TokenTextContainer.js +65 -54
- package/dist/Token/_TokenTextContainer.module.css.js +5 -5
- package/dist/Tooltip/Tooltip.js +56 -49
- package/dist/Tooltip/Tooltip.module.css.js +5 -20
- package/dist/TooltipV2/Tooltip.js +305 -222
- package/dist/TooltipV2/Tooltip.module.css.js +5 -11
- package/dist/TopicTag/TopicTag.js +55 -46
- package/dist/TopicTag/TopicTag.module.css.js +5 -5
- package/dist/TopicTag/TopicTagGroup.js +48 -40
- package/dist/TopicTag/TopicTagGroup.module.css.js +5 -5
- package/dist/TopicTag/index.js +7 -5
- package/dist/TreeView/TreeView.js +1414 -1082
- package/dist/TreeView/TreeView.module.css.js +5 -24
- package/dist/TreeView/shared.js +9 -10
- package/dist/TreeView/useRovingTabIndex.js +203 -129
- package/dist/TreeView/useTreeItemCache.js +79 -64
- package/dist/TreeView/useTypeahead.js +112 -90
- package/dist/Truncate/Truncate.js +33 -21
- package/dist/Truncate/Truncate.module.css.js +5 -5
- package/dist/UnderlineNav/UnderlineNav.js +375 -278
- package/dist/UnderlineNav/UnderlineNav.module.css.js +5 -8
- package/dist/UnderlineNav/UnderlineNavContext.js +8 -8
- package/dist/UnderlineNav/UnderlineNavItem.js +72 -56
- package/dist/UnderlineNav/UnderlineNavItem.module.css.js +5 -5
- package/dist/UnderlineNav/index.js +7 -5
- package/dist/UnderlineNav/styles.js +15 -11
- package/dist/VisuallyHidden/VisuallyHidden.js +49 -51
- package/dist/VisuallyHidden/VisuallyHidden.module.css.js +5 -5
- package/dist/_VisuallyHidden.js +62 -50
- package/dist/_VisuallyHidden.module.css.js +5 -5
- package/dist/deprecated/ActionList/Divider.js +23 -23
- package/dist/deprecated/ActionList/Divider.module.css.js +5 -5
- package/dist/deprecated/ActionList/Group.js +50 -43
- package/dist/deprecated/ActionList/Header.js +81 -69
- package/dist/deprecated/ActionList/Header.module.css.js +5 -5
- package/dist/deprecated/ActionList/Item.js +352 -308
- package/dist/deprecated/ActionList/Item.module.css.js +5 -18
- package/dist/deprecated/ActionList/List.js +196 -157
- package/dist/deprecated/ActionList/List.module.css.js +5 -5
- package/dist/deprecated/ActionList/index.js +14 -14
- package/dist/deprecated/ActionMenu.js +190 -159
- package/dist/deprecated/DialogV1/Dialog.js +200 -166
- package/dist/deprecated/DialogV1/Dialog.module.css.js +5 -11
- package/dist/deprecated/FilteredSearch/FilteredSearch.js +51 -43
- package/dist/deprecated/FilteredSearch/FilteredSearch.module.css.js +5 -5
- package/dist/deprecated/UnderlineNav/UnderlineNav.js +160 -132
- package/dist/deprecated/UnderlineNav/UnderlineNav.module.css.js +5 -14
- package/dist/deprecated/index.js +9 -20
- package/dist/experimental/IssueLabel/IssueLabel.js +158 -134
- package/dist/experimental/IssueLabel/IssueLabel.module.css.js +5 -5
- package/dist/experimental/SelectPanel2/SelectPanel.js +567 -419
- package/dist/experimental/SelectPanel2/SelectPanel.module.css.js +5 -32
- package/dist/experimental/Tabs/Tabs.js +297 -234
- package/dist/experimental/UnderlinePanels/UnderlinePanels.js +215 -165
- package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +5 -5
- package/dist/experimental/index.d.ts +2 -2
- package/dist/experimental/index.d.ts.map +1 -1
- package/dist/experimental/index.js +34 -44
- package/dist/hooks/useAnchoredPosition.js +144 -123
- package/dist/hooks/useControllableState.js +59 -34
- package/dist/hooks/useDetails.js +99 -84
- package/dist/hooks/useDialog.js +178 -140
- package/dist/hooks/useFocusTrap.js +71 -57
- package/dist/hooks/useFocusZone.js +38 -32
- package/dist/hooks/useId.js +16 -14
- package/dist/hooks/useIsMacOS.js +26 -21
- package/dist/hooks/useMedia.js +68 -54
- package/dist/hooks/useMenuInitialFocus.js +62 -65
- package/dist/hooks/useMenuKeyboardNavigation.js +126 -129
- package/dist/hooks/useMergedRefs.js +78 -63
- package/dist/hooks/useMnemonics.js +107 -77
- package/dist/hooks/useOnEscapePress.js +56 -45
- package/dist/hooks/useOnOutsideClick.js +63 -32
- package/dist/hooks/useOpenAndCloseFocus.js +43 -40
- package/dist/hooks/useOverflow.js +36 -32
- package/dist/hooks/useOverlay.js +75 -56
- package/dist/hooks/useProvidedRefOrCreate.js +24 -24
- package/dist/hooks/useProvidedStateOrCreate.js +39 -33
- package/dist/hooks/useRefObjectAsForwardedRef.js +32 -30
- package/dist/hooks/useRenderForcingRef.js +46 -42
- package/dist/hooks/useResizeObserver.js +43 -32
- package/dist/hooks/useResponsiveValue.js +57 -37
- package/dist/hooks/useSafeTimeout.js +29 -26
- package/dist/hooks/useScrollFlash.js +23 -16
- package/dist/hooks/useSlots.js +136 -102
- package/dist/hooks/useSyncedState.js +37 -31
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -88
- package/dist/internal/components/ButtonReset.js +50 -45
- package/dist/internal/components/ButtonReset.module.css.js +5 -5
- package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.js +105 -79
- package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.module.css.js +5 -12
- package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.js +21 -16
- package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupContext.js +4 -4
- package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.js +35 -26
- package/dist/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupValidation.js +19 -14
- package/dist/internal/components/ConditionalWrapper.js +51 -41
- package/dist/internal/components/InputLabel.js +113 -92
- package/dist/internal/components/InputLabel.module.css.js +5 -8
- package/dist/internal/components/InputValidation.js +87 -67
- package/dist/internal/components/InputValidation.module.css.js +5 -9
- package/dist/internal/components/TextInputInnerAction.js +173 -134
- package/dist/internal/components/TextInputInnerAction.module.css.js +5 -9
- package/dist/internal/components/TextInputInnerVisualSlot.js +110 -89
- package/dist/internal/components/TextInputInnerVisualSlot.module.css.js +5 -11
- package/dist/internal/components/TextInputWrapper.js +230 -187
- package/dist/internal/components/TextInputWrapper.module.css.js +5 -8
- package/dist/internal/components/UnderlineTabbedInterface.js +238 -191
- package/dist/internal/components/UnderlineTabbedInterface.module.css.js +5 -11
- package/dist/internal/components/UnstyledTextInput.js +47 -40
- package/dist/internal/components/UnstyledTextInput.module.css.js +5 -5
- package/dist/internal/components/ValidationAnimationContainer.js +66 -55
- package/dist/internal/components/ValidationAnimationContainer.module.css.js +5 -8
- package/dist/internal/hooks/useEffectCallback.js +38 -35
- package/dist/internal/hooks/useEffectOnce.js +25 -23
- package/dist/internal/utils/getResponsiveAttributes.js +26 -23
- package/dist/internal/utils/hasInteractiveNodes.js +46 -34
- package/dist/legacy-theme/ts/color-schemes.js +4732 -4250
- package/dist/live-region/Announce.js +183 -144
- package/dist/live-region/AriaAlert.js +22 -20
- package/dist/live-region/AriaStatus.js +22 -20
- package/dist/next/index.js +1 -3
- package/dist/test-helpers.js +62 -40
- package/dist/theme.js +47 -83
- package/dist/utils/character-counter.js +63 -45
- package/dist/utils/create-component.js +16 -15
- package/dist/utils/descendant-registry.js +218 -182
- package/dist/utils/environment.js +7 -7
- package/dist/utils/getBreakpointDeclarations.js +10 -9
- package/dist/utils/invariant.js +23 -17
- package/dist/utils/is-slot.js +11 -10
- package/dist/utils/isNumeric.js +3 -3
- package/dist/utils/modern-polymorphic.js +20 -12
- package/dist/utils/scroll.js +11 -8
- package/dist/utils/theme.js +10 -5
- package/dist/utils/useIsomorphicLayoutEffect.js +9 -4
- package/dist/utils/warning.js +21 -14
- package/package.json +10 -5
- package/dist/ActionList/ActionList-53389912.css.map +0 -1
|
@@ -1,644 +1,853 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
|
|
1
|
+
import { SearchIcon, XIcon, TriangleDownIcon } from '@primer/octicons-react';
|
|
2
|
+
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
3
|
+
import { FilteredActionList } from '../FilteredActionList/index.js';
|
|
4
|
+
import { SelectPanelMessage } from './SelectPanelMessage.js';
|
|
5
|
+
import { IconButton } from '../Button/IconButton.js';
|
|
6
|
+
import { LinkButton } from '../Button/LinkButton.js';
|
|
7
|
+
import { ButtonComponent } from '../Button/Button.js';
|
|
8
|
+
import { useId } from '../hooks/useId.js';
|
|
9
|
+
import { useProvidedStateOrCreate } from '../hooks/useProvidedStateOrCreate.js';
|
|
10
|
+
import useSafeTimeout from '../hooks/useSafeTimeout.js';
|
|
11
|
+
import { FilteredActionListLoadingTypes } from '../FilteredActionList/FilteredActionListLoaders.js';
|
|
12
|
+
import { announceFromElement, announce } from '@primer/live-region-element';
|
|
13
|
+
import classes from './SelectPanel.module.css.js';
|
|
14
|
+
import { clsx } from 'clsx';
|
|
15
|
+
import { debounce } from '@github/mini-throttle';
|
|
16
|
+
import { useResponsiveValue } from '../hooks/useResponsiveValue.js';
|
|
17
|
+
import { Banner } from '../Banner/index.js';
|
|
18
|
+
import { isAlphabetKey } from '../hooks/useMnemonics.js';
|
|
19
|
+
import { useFormControlContext } from '../FormControl/_FormControlContext.js';
|
|
20
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
21
|
+
import { useFeatureFlag } from '../FeatureFlags/useFeatureFlag.js';
|
|
22
|
+
import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
|
|
23
|
+
import { AnchoredOverlay } from '../AnchoredOverlay/AnchoredOverlay.js';
|
|
24
|
+
import Heading from '../Heading/Heading.js';
|
|
25
|
+
|
|
26
26
|
const SHORT_DELAY_MS = 500;
|
|
27
|
-
const LONG_DELAY_MS =
|
|
27
|
+
const LONG_DELAY_MS = 1000;
|
|
28
28
|
const EMPTY_MESSAGE = {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
title: 'No items available',
|
|
30
|
+
description: ''
|
|
31
31
|
};
|
|
32
|
-
const DefaultEmptyMessage =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const DefaultEmptyMessage = /*#__PURE__*/jsx(SelectPanelMessage, {
|
|
33
|
+
variant: "empty",
|
|
34
|
+
title: EMPTY_MESSAGE.title,
|
|
35
|
+
children: EMPTY_MESSAGE.description
|
|
36
36
|
}, "empty-message");
|
|
37
37
|
async function announceText(text, delayMs = SHORT_DELAY_MS) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const liveRegion = document.querySelector('live-region');
|
|
39
|
+
liveRegion === null || liveRegion === void 0 ? void 0 : liveRegion.clear(); // clear previous announcements
|
|
40
|
+
|
|
41
|
+
await announce(text, {
|
|
42
|
+
delayMs,
|
|
43
|
+
from: liveRegion ? liveRegion : undefined // announce will create a liveRegion if it doesn't find one
|
|
44
|
+
});
|
|
44
45
|
}
|
|
45
46
|
async function announceLoading() {
|
|
46
|
-
|
|
47
|
+
await announceText('Loading.');
|
|
47
48
|
}
|
|
49
|
+
|
|
50
|
+
// onCancel is optional with variant=anchored, but required with variant=modal
|
|
51
|
+
|
|
48
52
|
function isMultiSelectVariant(selected) {
|
|
49
|
-
|
|
53
|
+
return Array.isArray(selected);
|
|
50
54
|
}
|
|
51
|
-
const focusZoneSettings = {
|
|
52
|
-
|
|
55
|
+
const focusZoneSettings = {
|
|
56
|
+
// Let FilteredActionList handle focus zone
|
|
57
|
+
disabled: true
|
|
58
|
+
};
|
|
59
|
+
const closeButtonProps = {
|
|
60
|
+
'aria-label': 'Cancel and close'
|
|
61
|
+
};
|
|
53
62
|
const areItemsEqual = (itemA, itemB) => {
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
// prefer checking equivality by item.id
|
|
64
|
+
if (typeof itemA.id !== 'undefined') return itemA.id === itemB.id;else return itemA === itemB;
|
|
56
65
|
};
|
|
57
66
|
const doesItemsIncludeItem = (items, item) => {
|
|
58
|
-
|
|
67
|
+
return items.some(i => areItemsEqual(i, item));
|
|
59
68
|
};
|
|
60
|
-
const defaultRenderAnchor =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
const defaultRenderAnchor = props => {
|
|
70
|
+
const {
|
|
71
|
+
children,
|
|
72
|
+
...rest
|
|
73
|
+
} = props;
|
|
74
|
+
return /*#__PURE__*/jsx(ButtonComponent, {
|
|
75
|
+
trailingAction: TriangleDownIcon,
|
|
76
|
+
...rest,
|
|
77
|
+
children: children
|
|
78
|
+
});
|
|
67
79
|
};
|
|
68
80
|
defaultRenderAnchor.displayName = "defaultRenderAnchor";
|
|
69
|
-
function Panel({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
81
|
+
function Panel({
|
|
82
|
+
open,
|
|
83
|
+
onOpenChange,
|
|
84
|
+
renderAnchor = defaultRenderAnchor,
|
|
85
|
+
anchorRef: externalAnchorRef,
|
|
86
|
+
placeholder,
|
|
87
|
+
placeholderText = 'Filter items',
|
|
88
|
+
inputLabel = placeholderText,
|
|
89
|
+
selected,
|
|
90
|
+
title = isMultiSelectVariant(selected) ? 'Select items' : 'Select an item',
|
|
91
|
+
subtitle,
|
|
92
|
+
onSelectedChange,
|
|
93
|
+
filterValue: externalFilterValue,
|
|
94
|
+
onFilterChange: externalOnFilterChange,
|
|
95
|
+
items,
|
|
96
|
+
footer,
|
|
97
|
+
textInputProps,
|
|
98
|
+
overlayProps,
|
|
99
|
+
loading,
|
|
100
|
+
initialLoadingType = 'spinner',
|
|
101
|
+
className,
|
|
102
|
+
height,
|
|
103
|
+
width,
|
|
104
|
+
id,
|
|
105
|
+
message,
|
|
106
|
+
notice,
|
|
107
|
+
onCancel,
|
|
108
|
+
variant = 'anchored',
|
|
109
|
+
secondaryAction,
|
|
110
|
+
showSelectedOptionsFirst = true,
|
|
111
|
+
disableFullscreenOnNarrow,
|
|
112
|
+
align,
|
|
113
|
+
showSelectAll = false,
|
|
114
|
+
focusPrependedElements,
|
|
115
|
+
virtualized,
|
|
116
|
+
displayInViewport,
|
|
117
|
+
...listProps
|
|
118
|
+
}) {
|
|
119
|
+
var _listProps$groupMetad;
|
|
120
|
+
const titleId = useId();
|
|
121
|
+
const subtitleId = useId();
|
|
122
|
+
const [dataLoadedOnce, setDataLoadedOnce] = useState(false);
|
|
123
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
124
|
+
const [filterValue, setInternalFilterValue] = useProvidedStateOrCreate(externalFilterValue, undefined, '');
|
|
125
|
+
const {
|
|
126
|
+
safeSetTimeout,
|
|
127
|
+
safeClearTimeout
|
|
128
|
+
} = useSafeTimeout();
|
|
129
|
+
const loadingDelayTimeoutId = useRef(null);
|
|
130
|
+
const loadingManagedInternally = loading === undefined;
|
|
131
|
+
const loadingManagedExternally = !loadingManagedInternally;
|
|
132
|
+
const [inputRef, setInputRef] = React.useState(null);
|
|
133
|
+
const [listContainerElement, setListContainerElement] = useState(null);
|
|
134
|
+
const [needsNoItemsAnnouncement, setNeedsNoItemsAnnouncement] = useState(false);
|
|
135
|
+
const isNarrowScreenSize = useResponsiveValue({
|
|
136
|
+
narrow: true,
|
|
137
|
+
regular: false,
|
|
138
|
+
wide: false
|
|
139
|
+
}, false);
|
|
140
|
+
const [selectedOnSort, setSelectedOnSort] = useState([]);
|
|
141
|
+
const initialHeightRef = useRef(0);
|
|
142
|
+
const initialScaleRef = useRef(1);
|
|
143
|
+
const noticeRef = useRef(null);
|
|
144
|
+
const [isKeyboardVisible, setIsKeyboardVisible] = useState(false);
|
|
145
|
+
const [availablePanelHeight, setAvailablePanelHeight] = useState(undefined);
|
|
146
|
+
const KEYBOARD_VISIBILITY_THRESHOLD = 10;
|
|
147
|
+
const featureFlagFullScreenOnNarrow = useFeatureFlag('primer_react_select_panel_fullscreen_on_narrow');
|
|
148
|
+
const usingFullScreenOnNarrow = disableFullscreenOnNarrow ? false : featureFlagFullScreenOnNarrow;
|
|
149
|
+
const shouldOrderSelectedFirst = useFeatureFlag('primer_react_select_panel_order_selected_at_top') && showSelectedOptionsFirst;
|
|
150
|
+
const {
|
|
151
|
+
isReferenced,
|
|
152
|
+
labelId
|
|
153
|
+
} = useFormControlContext();
|
|
154
|
+
const selectedValueId = id ? `${id}-selected-value` : undefined;
|
|
155
|
+
|
|
156
|
+
// Single select modals work differently, they have an intermediate state where the user has selected an item but
|
|
157
|
+
// has not yet confirmed the selection. This is the only time the user can cancel the selection.
|
|
158
|
+
const isSingleSelectModal = variant === 'modal' && !isMultiSelectVariant(selected);
|
|
159
|
+
const [intermediateSelected, setIntermediateSelected] = useState(isSingleSelectModal ? selected : undefined);
|
|
160
|
+
|
|
161
|
+
// Reset the intermediate selected item when the panel is open/closed
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
164
|
+
setIntermediateSelected(isSingleSelectModal ? selected : undefined);
|
|
165
|
+
}, [isSingleSelectModal, open, selected]);
|
|
166
|
+
const onListContainerRefChanged = useCallback(node => {
|
|
167
|
+
setListContainerElement(node);
|
|
168
|
+
if (!node && needsNoItemsAnnouncement) {
|
|
169
|
+
setNeedsNoItemsAnnouncement(false);
|
|
170
|
+
}
|
|
171
|
+
}, [needsNoItemsAnnouncement]);
|
|
172
|
+
const onInputRefChanged = useCallback(ref => {
|
|
173
|
+
setInputRef(ref);
|
|
174
|
+
}, [setInputRef]);
|
|
175
|
+
const resetSort = useCallback(() => {
|
|
176
|
+
if (isMultiSelectVariant(selected)) {
|
|
177
|
+
setSelectedOnSort(selected);
|
|
178
|
+
} else if (selected) {
|
|
179
|
+
setSelectedOnSort([selected]);
|
|
180
|
+
} else {
|
|
181
|
+
setSelectedOnSort([]);
|
|
182
|
+
}
|
|
183
|
+
}, [selected]);
|
|
184
|
+
const onFilterChange = useCallback((value, e) => {
|
|
185
|
+
if (loadingManagedInternally) {
|
|
186
|
+
if (loadingDelayTimeoutId.current) {
|
|
187
|
+
safeClearTimeout(loadingDelayTimeoutId.current);
|
|
188
|
+
}
|
|
189
|
+
if (dataLoadedOnce) {
|
|
190
|
+
// If data has already been loaded once, delay the spinner a bit. This also helps
|
|
191
|
+
// not show and then immediately hide the spinner if items are loaded quickly, i.e.
|
|
192
|
+
// not async.
|
|
193
|
+
|
|
194
|
+
loadingDelayTimeoutId.current = safeSetTimeout(() => {
|
|
195
|
+
setIsLoading(true);
|
|
196
|
+
announceLoading();
|
|
197
|
+
}, LONG_DELAY_MS);
|
|
198
|
+
} else {
|
|
199
|
+
// If this is the first data load and there are no items, show the loading spinner
|
|
200
|
+
// immediately
|
|
201
|
+
|
|
202
|
+
if (items.length === 0) {
|
|
203
|
+
setIsLoading(true);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// We still want to announce if loading is taking too long
|
|
207
|
+
loadingDelayTimeoutId.current = safeSetTimeout(() => {
|
|
208
|
+
announceLoading();
|
|
209
|
+
}, LONG_DELAY_MS);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
externalOnFilterChange(value, e);
|
|
213
|
+
setInternalFilterValue(value);
|
|
214
|
+
if (!value) {
|
|
215
|
+
resetSort();
|
|
216
|
+
}
|
|
217
|
+
}, [loadingManagedInternally, externalOnFilterChange, setInternalFilterValue, dataLoadedOnce, safeSetTimeout, safeClearTimeout, items.length, resetSort]);
|
|
218
|
+
|
|
219
|
+
// Pre-compute a Set of item IDs in the current filtered view for O(1) lookups
|
|
220
|
+
const itemsInViewSet = useMemo(() => {
|
|
221
|
+
const set = new Set();
|
|
222
|
+
for (const item of items) {
|
|
223
|
+
if (item.id !== undefined) {
|
|
224
|
+
set.add(item.id);
|
|
225
|
+
} else {
|
|
226
|
+
set.add(item);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return set;
|
|
230
|
+
}, [items]);
|
|
231
|
+
const handleSelectAllChange = useCallback(checked => {
|
|
232
|
+
// Exit early if not in multi-select mode
|
|
233
|
+
if (!isMultiSelectVariant(selected)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const multiSelectOnChange = onSelectedChange;
|
|
237
|
+
const selectedArray = selected;
|
|
238
|
+
|
|
239
|
+
// Use Set for O(1) lookup instead of O(n) items.some()
|
|
240
|
+
const selectedItemsNotInFilteredView = selectedArray.filter(selectedItem => {
|
|
241
|
+
if (selectedItem.id !== undefined) {
|
|
242
|
+
return !itemsInViewSet.has(selectedItem.id);
|
|
243
|
+
}
|
|
244
|
+
return !itemsInViewSet.has(selectedItem);
|
|
245
|
+
});
|
|
246
|
+
if (checked) {
|
|
247
|
+
multiSelectOnChange([...selectedItemsNotInFilteredView, ...items]);
|
|
248
|
+
} else {
|
|
249
|
+
multiSelectOnChange(selectedItemsNotInFilteredView);
|
|
250
|
+
}
|
|
251
|
+
}, [items, itemsInViewSet, onSelectedChange, selected]);
|
|
252
|
+
|
|
253
|
+
// disable body scroll when the panel is open in modal mode or on narrow screens
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
if (open && (variant === 'modal' || isNarrowScreenSize && usingFullScreenOnNarrow)) {
|
|
256
|
+
const bodyOverflowStyle = document.body.style.overflow || '';
|
|
257
|
+
// If the body is already set to overflow: hidden, it likely means
|
|
258
|
+
// that there is already a modal open. In that case, we should bail
|
|
259
|
+
// so we don't re-enable scroll after the second dialog is closed.
|
|
260
|
+
if (bodyOverflowStyle === 'hidden') {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
document.body.style.overflow = 'hidden';
|
|
264
|
+
return () => {
|
|
265
|
+
document.body.style.overflow = bodyOverflowStyle;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}, [isNarrowScreenSize, open, usingFullScreenOnNarrow, variant]);
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
if (open) {
|
|
271
|
+
if (items.length === 0 && !(isLoading || loading)) {
|
|
272
|
+
// we need to wait for the listContainerElement to disappear before announcing no items, otherwise it will be interrupted
|
|
273
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
274
|
+
setNeedsNoItemsAnnouncement(true);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (loadingManagedExternally) {
|
|
278
|
+
if (items.length > 0) {
|
|
279
|
+
setDataLoadedOnce(true);
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (isLoading || items.length > 0) {
|
|
284
|
+
setIsLoading(false);
|
|
285
|
+
setDataLoadedOnce(true);
|
|
286
|
+
}
|
|
287
|
+
if (loadingDelayTimeoutId.current) {
|
|
288
|
+
safeClearTimeout(loadingDelayTimeoutId.current);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Only fire this effect if items have changed
|
|
292
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
293
|
+
}, [items]);
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
|
|
296
|
+
const ref = inputRef.current;
|
|
297
|
+
|
|
298
|
+
// We would normally expect AnchoredOverlay's focus trap to automatically focus the input,
|
|
299
|
+
// but for some reason the ref isn't populated until _after_ the panel is open, which is
|
|
300
|
+
// too late. So, we focus manually here.
|
|
301
|
+
if (open) {
|
|
302
|
+
ref.focus();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, [inputRef, open]);
|
|
306
|
+
|
|
307
|
+
// Manage loading announcements when loadingManagedExternally
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (loadingManagedExternally) {
|
|
310
|
+
if (isLoading) {
|
|
311
|
+
// Delay the announcement a bit, just in case the loading is quick
|
|
312
|
+
loadingDelayTimeoutId.current = safeSetTimeout(() => {
|
|
313
|
+
announceLoading();
|
|
314
|
+
}, LONG_DELAY_MS);
|
|
315
|
+
} else {
|
|
316
|
+
// If loading is done, we can clear the loading announcement
|
|
317
|
+
if (loadingDelayTimeoutId.current) {
|
|
318
|
+
safeClearTimeout(loadingDelayTimeoutId.current);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}, [isLoading, loadingManagedExternally, safeSetTimeout, safeClearTimeout]);
|
|
323
|
+
|
|
324
|
+
// Populate panel with items on first open
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
if (loadingManagedExternally) return;
|
|
327
|
+
|
|
328
|
+
// If data was already loaded once, do nothing
|
|
329
|
+
if (dataLoadedOnce) return;
|
|
330
|
+
|
|
331
|
+
// Only load data when the panel is open
|
|
332
|
+
if (open) {
|
|
333
|
+
// Only trigger filter change event if there are no items
|
|
334
|
+
if (items.length === 0) {
|
|
335
|
+
// Trigger filter event to populate panel on first open
|
|
336
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
337
|
+
onFilterChange(filterValue, null);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}, [open, dataLoadedOnce, onFilterChange, filterValue, items, loadingManagedExternally, listContainerElement]);
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
if (!window.visualViewport || !open || !isNarrowScreenSize) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
initialHeightRef.current = window.visualViewport.height;
|
|
346
|
+
initialScaleRef.current = window.visualViewport.scale;
|
|
347
|
+
const handleViewportChange = debounce(() => {
|
|
348
|
+
if (window.visualViewport) {
|
|
349
|
+
const currentScale = window.visualViewport.scale;
|
|
350
|
+
const isZooming = currentScale !== initialScaleRef.current;
|
|
351
|
+
if (!isZooming) {
|
|
352
|
+
const currentHeight = window.visualViewport.height;
|
|
353
|
+
const keyboardVisible = initialHeightRef.current - currentHeight > KEYBOARD_VISIBILITY_THRESHOLD;
|
|
354
|
+
setIsKeyboardVisible(keyboardVisible);
|
|
355
|
+
setAvailablePanelHeight(keyboardVisible ? currentHeight : undefined);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}, 100);
|
|
359
|
+
|
|
360
|
+
// keeping this check to satisfy typescript but need eslint to ignore redundancy rule
|
|
361
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
362
|
+
if (window.visualViewport) {
|
|
363
|
+
// Using visualViewport to more reliably detect viewport changes across different browsers, which specifically requires these listeners
|
|
364
|
+
// eslint-disable-next-line github/prefer-observers
|
|
365
|
+
window.visualViewport.addEventListener('resize', handleViewportChange);
|
|
366
|
+
// eslint-disable-next-line github/prefer-observers
|
|
367
|
+
window.visualViewport.addEventListener('scroll', handleViewportChange);
|
|
368
|
+
}
|
|
369
|
+
return () => {
|
|
370
|
+
if (window.visualViewport) {
|
|
371
|
+
window.visualViewport.removeEventListener('resize', handleViewportChange);
|
|
372
|
+
window.visualViewport.removeEventListener('scroll', handleViewportChange);
|
|
373
|
+
}
|
|
374
|
+
handleViewportChange.cancel();
|
|
375
|
+
};
|
|
376
|
+
}, [open, isNarrowScreenSize]);
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
const announceNotice = async () => {
|
|
379
|
+
if (!noticeRef.current) return;
|
|
380
|
+
const liveRegion = document.querySelector('live-region');
|
|
381
|
+
liveRegion === null || liveRegion === void 0 ? void 0 : liveRegion.clear();
|
|
382
|
+
await announceFromElement(noticeRef.current, {
|
|
383
|
+
from: liveRegion ? liveRegion : undefined
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
if (open && notice) {
|
|
387
|
+
announceNotice();
|
|
388
|
+
}
|
|
389
|
+
}, [notice, open]);
|
|
390
|
+
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
|
391
|
+
const onOpen = useCallback(gesture => onOpenChange(true, gesture), [onOpenChange]);
|
|
392
|
+
const onCancelRequested = useCallback(() => {
|
|
393
|
+
onOpenChange(false, 'cancel');
|
|
394
|
+
}, [onOpenChange]);
|
|
395
|
+
const onClose = useCallback(gesture => {
|
|
396
|
+
// Clicking outside should cancel the selection only on modals
|
|
397
|
+
if (variant === 'modal' && gesture === 'click-outside') {
|
|
398
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
399
|
+
}
|
|
400
|
+
if (gesture === 'close') {
|
|
401
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
402
|
+
onCancelRequested();
|
|
403
|
+
} else {
|
|
404
|
+
onOpenChange(false, gesture);
|
|
405
|
+
}
|
|
406
|
+
}, [onOpenChange, variant, onCancel, onCancelRequested]);
|
|
407
|
+
const renderMenuAnchor = useMemo(() => {
|
|
408
|
+
if (renderAnchor === null) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
const selectedItems = Array.isArray(selected) ? selected : [...(selected ? [selected] : [])];
|
|
412
|
+
const selectedValueText = selectedItems.length ? selectedItems.map(item => item.text).join(', ') : placeholder;
|
|
413
|
+
const shouldAutoWireLabel = isReferenced === false && Boolean(labelId) && Boolean(selectedValueId);
|
|
414
|
+
return props => {
|
|
415
|
+
return renderAnchor({
|
|
416
|
+
...props,
|
|
417
|
+
...(shouldAutoWireLabel ? {
|
|
418
|
+
'aria-labelledby': [labelId, selectedValueId].filter(Boolean).join(' ')
|
|
419
|
+
} : {}),
|
|
420
|
+
children: shouldAutoWireLabel ? /*#__PURE__*/jsx("span", {
|
|
421
|
+
id: selectedValueId,
|
|
422
|
+
children: selectedValueText
|
|
423
|
+
}) : selectedValueText
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
}, [placeholder, renderAnchor, selected, isReferenced, labelId, selectedValueId]);
|
|
427
|
+
|
|
428
|
+
// Pre-compute a Set of selected item IDs/references for O(1) lookups
|
|
429
|
+
// This optimizes isItemCurrentlySelected from O(m) to O(1) per call
|
|
430
|
+
const selectedItemsSet = useMemo(() => {
|
|
431
|
+
const set = new Set();
|
|
432
|
+
if (isMultiSelectVariant(selected)) {
|
|
433
|
+
for (const item of selected) {
|
|
434
|
+
if (item.id !== undefined) {
|
|
435
|
+
set.add(item.id);
|
|
436
|
+
} else {
|
|
437
|
+
set.add(item);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return set;
|
|
442
|
+
}, [selected]);
|
|
443
|
+
const isItemCurrentlySelected = useCallback(item => {
|
|
444
|
+
// For multi-select, use the pre-computed Set for O(1) lookup
|
|
445
|
+
if (isMultiSelectVariant(selected)) {
|
|
446
|
+
if (item.id !== undefined) {
|
|
447
|
+
return selectedItemsSet.has(item.id);
|
|
448
|
+
}
|
|
449
|
+
return selectedItemsSet.has(item);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// For single-select modal, there is an intermediate state when the user has selected
|
|
453
|
+
// an item but has not yet saved the selection. We need to check for this state.
|
|
454
|
+
if (isSingleSelectModal) {
|
|
455
|
+
return (intermediateSelected === null || intermediateSelected === void 0 ? void 0 : intermediateSelected.id) !== undefined ? intermediateSelected.id === item.id : intermediateSelected === item;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// For single-select anchored, we just need to check if the item is the selected item
|
|
459
|
+
return (selected === null || selected === void 0 ? void 0 : selected.id) !== undefined ? selected.id === item.id : selected === item;
|
|
460
|
+
}, [selected, selectedItemsSet, intermediateSelected, isSingleSelectModal]);
|
|
461
|
+
const itemsToRender = useMemo(() => {
|
|
462
|
+
// Pre-compute a Set of selected item IDs/references for O(1) lookups during sorting
|
|
463
|
+
// This avoids O(m * k) work per comparison in the sort function
|
|
464
|
+
const selectedOnSortSet = new Set();
|
|
465
|
+
for (const item of selectedOnSort) {
|
|
466
|
+
if (item.id !== undefined) {
|
|
467
|
+
selectedOnSortSet.add(item.id);
|
|
468
|
+
} else {
|
|
469
|
+
selectedOnSortSet.add(item);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const isSelectedForSort = item => {
|
|
473
|
+
if (item.id !== undefined) {
|
|
474
|
+
return selectedOnSortSet.has(item.id);
|
|
475
|
+
}
|
|
476
|
+
return selectedOnSortSet.has(item);
|
|
477
|
+
};
|
|
478
|
+
return items.map(item => {
|
|
479
|
+
return {
|
|
480
|
+
...item,
|
|
481
|
+
role: 'option',
|
|
482
|
+
id: item.id,
|
|
483
|
+
selected: 'selected' in item && item.selected === undefined ? undefined : isItemCurrentlySelected(item),
|
|
484
|
+
onAction: (itemFromAction, event) => {
|
|
485
|
+
var _item$onAction;
|
|
486
|
+
(_item$onAction = item.onAction) === null || _item$onAction === void 0 ? void 0 : _item$onAction.call(item, itemFromAction, event);
|
|
487
|
+
if (event.defaultPrevented) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (isMultiSelectVariant(selected)) {
|
|
491
|
+
const otherSelectedItems = selected.filter(selectedItem => !areItemsEqual(selectedItem, item));
|
|
492
|
+
const newSelectedItems = doesItemsIncludeItem(selected, item) ? otherSelectedItems : [...otherSelectedItems, item];
|
|
493
|
+
const multiSelectOnChange = onSelectedChange;
|
|
494
|
+
multiSelectOnChange(newSelectedItems);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (isSingleSelectModal) {
|
|
498
|
+
if ((intermediateSelected === null || intermediateSelected === void 0 ? void 0 : intermediateSelected.id) === item.id) {
|
|
499
|
+
// if the item is already selected, we need to unselect it
|
|
500
|
+
setIntermediateSelected(undefined);
|
|
501
|
+
} else {
|
|
502
|
+
setIntermediateSelected(item);
|
|
503
|
+
}
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
// single select anchored, direct save on click
|
|
507
|
+
const singleSelectOnChange = onSelectedChange;
|
|
508
|
+
singleSelectOnChange(item === selected ? undefined : item);
|
|
509
|
+
onClose('selection');
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
}).sort((itemA, itemB) => {
|
|
513
|
+
if (shouldOrderSelectedFirst) {
|
|
514
|
+
const itemASelected = isSelectedForSort(itemA);
|
|
515
|
+
const itemBSelected = isSelectedForSort(itemB);
|
|
516
|
+
|
|
517
|
+
// order selected items first
|
|
518
|
+
if (itemASelected && !itemBSelected) {
|
|
519
|
+
return -1;
|
|
520
|
+
} else if (!itemASelected && itemBSelected) {
|
|
521
|
+
return 1;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return 0;
|
|
525
|
+
});
|
|
526
|
+
}, [onClose, onSelectedChange, items, selected, isItemCurrentlySelected, isSingleSelectModal, intermediateSelected, shouldOrderSelectedFirst, selectedOnSort]);
|
|
527
|
+
|
|
528
|
+
// Track previous items and reset sort when items first load
|
|
529
|
+
const prevItemsRef = useRef(items);
|
|
530
|
+
useEffect(() => {
|
|
531
|
+
if (prevItemsRef.current !== items) {
|
|
532
|
+
if (prevItemsRef.current.length === 0 && items.length > 0) {
|
|
533
|
+
resetSort();
|
|
534
|
+
}
|
|
535
|
+
prevItemsRef.current = items;
|
|
536
|
+
}
|
|
537
|
+
}, [items, resetSort]);
|
|
538
|
+
|
|
539
|
+
// Reset sort when panel opens
|
|
540
|
+
const prevOpenRef = useRef(open);
|
|
541
|
+
useEffect(() => {
|
|
542
|
+
if (prevOpenRef.current !== open) {
|
|
543
|
+
resetSort();
|
|
544
|
+
prevOpenRef.current = open;
|
|
545
|
+
}
|
|
546
|
+
}, [open, resetSort]);
|
|
547
|
+
const focusTrapSettings = useMemo(() => ({
|
|
548
|
+
initialFocusRef: inputRef || undefined
|
|
549
|
+
}), [inputRef]);
|
|
550
|
+
const extendedTextInputProps = useMemo(() => {
|
|
551
|
+
return {
|
|
552
|
+
className: classes.TextInput,
|
|
553
|
+
contrast: true,
|
|
554
|
+
leadingVisual: SearchIcon,
|
|
555
|
+
'aria-label': inputLabel,
|
|
556
|
+
...textInputProps
|
|
557
|
+
};
|
|
558
|
+
}, [inputLabel, textInputProps]);
|
|
559
|
+
const loadingType = () => {
|
|
560
|
+
if (dataLoadedOnce) {
|
|
561
|
+
return FilteredActionListLoadingTypes.input;
|
|
562
|
+
} else {
|
|
563
|
+
if (initialLoadingType === 'spinner') {
|
|
564
|
+
return FilteredActionListLoadingTypes.bodySpinner;
|
|
565
|
+
} else {
|
|
566
|
+
return FilteredActionListLoadingTypes.bodySkeleton;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
function getMessage() {
|
|
571
|
+
if (items.length === 0 && !message) {
|
|
572
|
+
return DefaultEmptyMessage;
|
|
573
|
+
} else if (message) {
|
|
574
|
+
return /*#__PURE__*/jsx(SelectPanelMessage, {
|
|
575
|
+
title: message.title,
|
|
576
|
+
variant: message.variant,
|
|
577
|
+
icon: message.icon,
|
|
578
|
+
action: message.action,
|
|
579
|
+
children: message.body
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// We add permanent save and cancel buttons on:
|
|
585
|
+
// - modals
|
|
586
|
+
const showPermanentCancelSaveButtons = variant === 'modal';
|
|
587
|
+
|
|
588
|
+
// The next two could be collapsed, left them separate for readability
|
|
589
|
+
|
|
590
|
+
// We add a responsive save and cancel button on:
|
|
591
|
+
// - anchored panels with multi select if there is onCancel
|
|
592
|
+
const showResponsiveCancelSaveButtons = variant !== 'modal' && usingFullScreenOnNarrow && isMultiSelectVariant(selected) && onCancel !== undefined;
|
|
593
|
+
|
|
594
|
+
// The responsive save and close button is only covering a very specific case:
|
|
595
|
+
// - anchored panel with multi select if there is no onCancel.
|
|
596
|
+
// This variant should disappear in the future, once onCancel is required,
|
|
597
|
+
// but for now we need to support it so there is a user friendly way to close the panel.
|
|
598
|
+
const showResponsiveSaveAndCloseButton = variant !== 'modal' && usingFullScreenOnNarrow && isMultiSelectVariant(selected) && onCancel === undefined;
|
|
599
|
+
|
|
600
|
+
// If there is any element in the footer, we render it.
|
|
601
|
+
const renderFooter = secondaryAction !== undefined || showPermanentCancelSaveButtons || showResponsiveSaveAndCloseButton || showResponsiveCancelSaveButtons;
|
|
602
|
+
|
|
603
|
+
// If there's any permanent elements in the footer, we show it always.
|
|
604
|
+
// The save button is only shown on small screens.
|
|
605
|
+
const displayFooter = secondaryAction !== undefined || showPermanentCancelSaveButtons ? 'always' : showResponsiveSaveAndCloseButton || showResponsiveCancelSaveButtons ? 'only-small' : undefined;
|
|
606
|
+
const stretchSecondaryAction = showResponsiveSaveAndCloseButton || showResponsiveCancelSaveButtons ? 'only-big' : showPermanentCancelSaveButtons ? 'never' : 'always';
|
|
607
|
+
const stretchSaveButton = showResponsiveSaveAndCloseButton && secondaryAction === undefined ? 'only-small' : 'never';
|
|
608
|
+
|
|
609
|
+
/*
|
|
610
|
+
* SelectPanel uses two close button implementations for different use cases:
|
|
611
|
+
*
|
|
612
|
+
* 1. AnchoredOverlay close button - Enabled on narrow screens (showXCloseIcon logic)
|
|
613
|
+
*
|
|
614
|
+
* 2. SelectPanel modal close button - Used for modal variant on wider screens
|
|
615
|
+
* (variant === 'modal' && !isNarrowScreenSize logic below)
|
|
616
|
+
*
|
|
617
|
+
* The dual approach handles different responsive behaviors: AnchoredOverlay manages
|
|
618
|
+
* close functionality for narrow fullscreen, while SelectPanel handles modal close on desktop.
|
|
619
|
+
*/
|
|
620
|
+
const showXCloseIcon = (onCancel !== undefined || !isMultiSelectVariant(selected)) && usingFullScreenOnNarrow;
|
|
621
|
+
const currentResponsiveVariant = useResponsiveValue(usingFullScreenOnNarrow ? {
|
|
622
|
+
regular: 'anchored',
|
|
623
|
+
narrow: 'fullscreen'
|
|
624
|
+
} : undefined, 'anchored');
|
|
625
|
+
const preventBubbling = useCallback(event => {
|
|
626
|
+
var _overlayProps$onKeyDo;
|
|
627
|
+
overlayProps === null || overlayProps === void 0 ? void 0 : (_overlayProps$onKeyDo = overlayProps.onKeyDown) === null || _overlayProps$onKeyDo === void 0 ? void 0 : _overlayProps$onKeyDo.call(overlayProps, event);
|
|
628
|
+
|
|
629
|
+
// skip if a TextInput has focus
|
|
630
|
+
const activeElement = document.activeElement;
|
|
631
|
+
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') return;
|
|
632
|
+
|
|
633
|
+
// skip if used with modifier to preserve shortcuts like ⌘ + F
|
|
634
|
+
const hasModifier = event.ctrlKey || event.altKey || event.metaKey;
|
|
635
|
+
if (hasModifier) return;
|
|
636
|
+
|
|
637
|
+
// skip if it's not the forward slash or an alphabet key
|
|
638
|
+
if (event.key !== '/' && !isAlphabetKey(event.nativeEvent)) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// if this is a typeahead event, don't propagate outside of menu
|
|
643
|
+
event.stopPropagation();
|
|
644
|
+
}, [overlayProps]);
|
|
645
|
+
const mergedOverlayProps = useMemo(() => ({
|
|
646
|
+
role: 'dialog',
|
|
647
|
+
'aria-labelledby': titleId,
|
|
648
|
+
'aria-describedby': subtitle ? subtitleId : undefined,
|
|
649
|
+
...overlayProps,
|
|
650
|
+
...(variant === 'modal' ? {
|
|
651
|
+
top: '50vh',
|
|
652
|
+
left: '50vw',
|
|
653
|
+
anchorSide: undefined
|
|
654
|
+
} : {}),
|
|
655
|
+
style: {
|
|
656
|
+
transform: variant === 'modal' ? 'translate(-50%, -50%)' : undefined,
|
|
657
|
+
...(isKeyboardVisible ? {
|
|
658
|
+
maxHeight: availablePanelHeight !== undefined ? `${availablePanelHeight}px` : 'auto'
|
|
659
|
+
} : {})
|
|
660
|
+
},
|
|
661
|
+
onKeyDown: preventBubbling
|
|
662
|
+
}), [titleId, subtitle, subtitleId, overlayProps, variant, isKeyboardVisible, availablePanelHeight, preventBubbling]);
|
|
663
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
664
|
+
children: [/*#__PURE__*/jsx(AnchoredOverlay, {
|
|
665
|
+
renderAnchor: renderMenuAnchor,
|
|
666
|
+
anchorRef: anchorRef,
|
|
667
|
+
align: align,
|
|
668
|
+
open: open,
|
|
669
|
+
onOpen: onOpen,
|
|
670
|
+
onClose: onClose,
|
|
671
|
+
overlayProps: mergedOverlayProps,
|
|
672
|
+
focusTrapSettings: focusTrapSettings,
|
|
673
|
+
focusZoneSettings: focusZoneSettings,
|
|
674
|
+
height: height,
|
|
675
|
+
width: width,
|
|
676
|
+
anchorId: id,
|
|
677
|
+
variant: usingFullScreenOnNarrow ? {
|
|
678
|
+
regular: 'anchored',
|
|
679
|
+
narrow: 'fullscreen'
|
|
680
|
+
} : undefined,
|
|
681
|
+
pinPosition: !height,
|
|
682
|
+
className: classes.Overlay,
|
|
683
|
+
displayCloseButton: showXCloseIcon,
|
|
684
|
+
closeButtonProps: closeButtonProps,
|
|
685
|
+
displayInViewport: displayInViewport,
|
|
686
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
687
|
+
className: classes.Wrapper,
|
|
688
|
+
"data-variant": variant,
|
|
689
|
+
"data-component": "SelectPanel",
|
|
690
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
691
|
+
className: classes.Header,
|
|
692
|
+
"data-variant": currentResponsiveVariant,
|
|
693
|
+
"data-component": "SelectPanel.Header",
|
|
694
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
695
|
+
children: [/*#__PURE__*/jsx(Heading, {
|
|
696
|
+
as: "h1",
|
|
697
|
+
id: titleId,
|
|
698
|
+
className: classes.Title,
|
|
699
|
+
"data-component": "SelectPanel.Title",
|
|
700
|
+
children: title
|
|
701
|
+
}), subtitle ? /*#__PURE__*/jsx("div", {
|
|
702
|
+
id: subtitleId,
|
|
703
|
+
className: classes.Subtitle,
|
|
704
|
+
"data-component": "SelectPanel.Subtitle",
|
|
705
|
+
children: subtitle
|
|
706
|
+
}) : null]
|
|
707
|
+
}), variant === 'modal' && !isNarrowScreenSize ? /*#__PURE__*/jsx(IconButton, {
|
|
708
|
+
type: "button",
|
|
709
|
+
variant: "invisible",
|
|
710
|
+
icon: XIcon,
|
|
711
|
+
"aria-label": "Cancel and close",
|
|
712
|
+
className: classes.ResponsiveCloseButton,
|
|
713
|
+
"data-component": "SelectPanel.CloseButton",
|
|
714
|
+
onClick: () => {
|
|
715
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
716
|
+
onCancelRequested();
|
|
717
|
+
}
|
|
718
|
+
}) : null]
|
|
719
|
+
}), notice && /*#__PURE__*/jsx("div", {
|
|
720
|
+
ref: noticeRef,
|
|
721
|
+
"data-component": "SelectPanel.Notice",
|
|
722
|
+
children: /*#__PURE__*/jsx(Banner, {
|
|
723
|
+
variant: notice.variant === 'error' ? 'critical' : notice.variant,
|
|
724
|
+
description: notice.text,
|
|
725
|
+
title: "Notice",
|
|
726
|
+
hideTitle: true,
|
|
727
|
+
className: classes.Notice,
|
|
728
|
+
layout: "compact"
|
|
729
|
+
})
|
|
730
|
+
}), /*#__PURE__*/jsx(FilteredActionList, {
|
|
731
|
+
filterValue: filterValue,
|
|
732
|
+
onFilterChange: onFilterChange,
|
|
733
|
+
onListContainerRefChanged: onListContainerRefChanged
|
|
734
|
+
// @ts-expect-error it needs a non nullable ref
|
|
735
|
+
,
|
|
736
|
+
onInputRefChanged: onInputRefChanged,
|
|
737
|
+
placeholderText: placeholderText,
|
|
738
|
+
...listProps,
|
|
739
|
+
variant: (_listProps$groupMetad = listProps.groupMetadata) !== null && _listProps$groupMetad !== void 0 && _listProps$groupMetad.length ? 'horizontal-inset' : 'inset',
|
|
740
|
+
role: "listbox"
|
|
741
|
+
// browsers give aria-labelledby precedence over aria-label so we need to make sure
|
|
742
|
+
// we don't accidentally override props.aria-label
|
|
743
|
+
,
|
|
744
|
+
"aria-labelledby": listProps['aria-label'] ? undefined : titleId,
|
|
745
|
+
"aria-multiselectable": isMultiSelectVariant(selected) ? 'true' : 'false',
|
|
746
|
+
selectionVariant: isSingleSelectModal ? 'radio' : isMultiSelectVariant(selected) ? 'multiple' : 'single',
|
|
747
|
+
items: itemsToRender,
|
|
748
|
+
textInputProps: extendedTextInputProps,
|
|
749
|
+
loading: loading || isLoading && !message,
|
|
750
|
+
loadingType: loadingType(),
|
|
751
|
+
onSelectAllChange: showSelectAll ? handleSelectAllChange : undefined
|
|
752
|
+
// hack because the deprecated ActionList does not support this prop
|
|
753
|
+
,
|
|
754
|
+
message: getMessage(),
|
|
755
|
+
messageText: {
|
|
756
|
+
title: (message === null || message === void 0 ? void 0 : message.title) || EMPTY_MESSAGE.title,
|
|
757
|
+
description: typeof (message === null || message === void 0 ? void 0 : message.body) === 'string' ? message.body : EMPTY_MESSAGE.description
|
|
758
|
+
},
|
|
759
|
+
fullScreenOnNarrow: usingFullScreenOnNarrow,
|
|
760
|
+
className: clsx(className, classes.FilteredActionList),
|
|
761
|
+
focusPrependedElements: focusPrependedElements,
|
|
762
|
+
virtualized: virtualized
|
|
763
|
+
}), footer ? /*#__PURE__*/jsx("div", {
|
|
764
|
+
className: classes.Footer,
|
|
765
|
+
"data-component": "SelectPanel.Footer",
|
|
766
|
+
children: footer
|
|
767
|
+
}) : renderFooter ? /*#__PURE__*/jsxs("div", {
|
|
768
|
+
"data-display-footer": displayFooter,
|
|
769
|
+
"data-stretch-secondary-action": stretchSecondaryAction,
|
|
770
|
+
"data-stretch-save-button": stretchSaveButton,
|
|
771
|
+
className: clsx(classes.Footer, classes.ResponsiveFooter),
|
|
772
|
+
"data-component": "SelectPanel.Footer",
|
|
773
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
774
|
+
"data-stretch-secondary-action": stretchSecondaryAction,
|
|
775
|
+
className: classes.SecondaryAction,
|
|
776
|
+
"data-component": "SelectPanel.SecondaryAction",
|
|
777
|
+
children: secondaryAction
|
|
778
|
+
}), showPermanentCancelSaveButtons || showResponsiveCancelSaveButtons ? /*#__PURE__*/jsxs("div", {
|
|
779
|
+
"data-stretch-save-button": stretchSaveButton,
|
|
780
|
+
className: clsx(classes.CancelSaveButtons, {
|
|
781
|
+
[classes.ResponsiveSaveButton]: showResponsiveCancelSaveButtons
|
|
782
|
+
}),
|
|
783
|
+
children: [/*#__PURE__*/jsx(ButtonComponent, {
|
|
784
|
+
size: "medium",
|
|
785
|
+
"data-component": "SelectPanel.CancelButton",
|
|
786
|
+
onClick: () => {
|
|
787
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
788
|
+
onCancelRequested();
|
|
789
|
+
},
|
|
790
|
+
children: "Cancel"
|
|
791
|
+
}), /*#__PURE__*/jsx(ButtonComponent, {
|
|
792
|
+
block: onCancel === undefined,
|
|
793
|
+
variant: "primary",
|
|
794
|
+
size: "medium",
|
|
795
|
+
"data-component": "SelectPanel.SaveButton",
|
|
796
|
+
onClick: () => {
|
|
797
|
+
if (isSingleSelectModal) {
|
|
798
|
+
const singleSelectOnChange = onSelectedChange;
|
|
799
|
+
singleSelectOnChange(intermediateSelected);
|
|
800
|
+
}
|
|
801
|
+
onClose(variant === 'modal' ? 'selection' : 'click-outside');
|
|
802
|
+
},
|
|
803
|
+
children: "Save"
|
|
804
|
+
})]
|
|
805
|
+
}) : null, showResponsiveSaveAndCloseButton ? /*#__PURE__*/jsx("div", {
|
|
806
|
+
className: classes.ResponsiveSaveButton,
|
|
807
|
+
"data-stretch-save-button": stretchSaveButton,
|
|
808
|
+
children: /*#__PURE__*/jsx(ButtonComponent, {
|
|
809
|
+
block: true,
|
|
810
|
+
variant: "primary",
|
|
811
|
+
size: "medium",
|
|
812
|
+
"data-component": "SelectPanel.SaveAndCloseButton",
|
|
813
|
+
onClick: () => {
|
|
814
|
+
onClose('click-outside');
|
|
815
|
+
},
|
|
816
|
+
children: "Save and close"
|
|
817
|
+
})
|
|
818
|
+
}) : null]
|
|
819
|
+
}) : null]
|
|
820
|
+
})
|
|
821
|
+
}), variant === 'modal' && open ? /*#__PURE__*/jsx("div", {
|
|
822
|
+
className: classes.Backdrop,
|
|
823
|
+
"data-component": "SelectPanel.Backdrop"
|
|
824
|
+
}) : null]
|
|
825
|
+
});
|
|
618
826
|
}
|
|
619
|
-
const SecondaryButton =
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
827
|
+
const SecondaryButton = props => {
|
|
828
|
+
return /*#__PURE__*/jsx(ButtonComponent, {
|
|
829
|
+
block: true,
|
|
830
|
+
"data-component": "SelectPanel.SecondaryActionButton",
|
|
831
|
+
...props,
|
|
832
|
+
children: props.children
|
|
833
|
+
});
|
|
626
834
|
};
|
|
627
835
|
SecondaryButton.displayName = "SecondaryButton";
|
|
628
|
-
const SecondaryLink =
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
836
|
+
const SecondaryLink = props => {
|
|
837
|
+
return /*#__PURE__*/jsx(LinkButton, {
|
|
838
|
+
...props,
|
|
839
|
+
variant: "invisible",
|
|
840
|
+
block: true,
|
|
841
|
+
"data-component": "SelectPanel.SecondaryActionLink",
|
|
842
|
+
children: props.children
|
|
843
|
+
});
|
|
636
844
|
};
|
|
637
845
|
SecondaryLink.displayName = "SecondaryLink";
|
|
638
846
|
const SelectPanel = Object.assign(Panel, {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
847
|
+
__SLOT__: Symbol('SelectPanel'),
|
|
848
|
+
SecondaryActionButton: SecondaryButton,
|
|
849
|
+
SecondaryActionLink: SecondaryLink,
|
|
850
|
+
Message: SelectPanelMessage
|
|
642
851
|
});
|
|
643
|
-
|
|
852
|
+
|
|
644
853
|
export { SelectPanel };
|