@zj-dynamics/components 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/NOTICE.react-is +21 -0
- package/NOTICE.tabbable +22 -0
- package/README.md +23 -2
- package/compatibility.css +2 -0
- package/dist/Button.d.ts +90 -0
- package/dist/Button.js +58 -0
- package/dist/ButtonDismiss.d.ts +6 -0
- package/dist/ButtonDismiss.js +5 -0
- package/dist/Dialog.d.ts +75 -0
- package/dist/Dialog.js +59 -0
- package/dist/Icon.d.ts +20 -0
- package/dist/Icon.js +11 -0
- package/dist/InputText.d.ts +26 -0
- package/dist/InputText.js +63 -0
- package/dist/Switch.d.ts +8 -0
- package/dist/Switch.js +19 -0
- package/dist/Toast.d.ts +21 -0
- package/dist/Toast.js +58 -0
- package/dist/browserFocus.d.ts +11 -0
- package/dist/browserFocus.js +85 -0
- package/dist/browserHooks.d.ts +5 -0
- package/dist/browserHooks.js +4 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +91 -0
- package/dist/legacyModalPortal.d.ts +1 -0
- package/dist/legacyModalPortal.js +2 -0
- package/dist/mockViewportWidth.d.ts +5 -0
- package/dist/mockViewportWidth.js +58 -0
- package/dist/slotChildren.d.ts +2 -0
- package/dist/slotChildren.js +6 -0
- package/dist/theme.d.ts +26 -0
- package/dist/theme.js +65 -0
- package/dist/unstyledPrimitives.d.ts +12 -0
- package/dist/unstyledPrimitives.js +12 -0
- package/dist/useBreakpoints.d.ts +3 -0
- package/dist/useBreakpoints.js +2 -0
- package/dist/useFocusTrap.d.ts +1 -0
- package/dist/useFocusTrap.js +1 -0
- package/dist/useInView.d.ts +1 -0
- package/dist/useInView.js +1 -0
- package/dist/useIsSmallScreen.d.ts +1 -0
- package/dist/useIsSmallScreen.js +1 -0
- package/dist/useLiveAnnounce.d.ts +1 -0
- package/dist/useLiveAnnounce.js +1 -0
- package/dist/useOnKeyDown.d.ts +1 -0
- package/dist/useOnKeyDown.js +1 -0
- package/dist/useRefocusOnActivator.d.ts +1 -0
- package/dist/useRefocusOnActivator.js +1 -0
- package/dist/useResizeObserver.d.ts +22 -0
- package/dist/useResizeObserver.js +47 -0
- package/dist/useWindowDimensions.d.ts +2 -0
- package/dist/useWindowDimensions.js +1 -0
- package/dist/viewport.d.ts +46 -0
- package/dist/viewport.js +141 -0
- package/foundation/ActivityIndicator/ActivityIndicator.d.ts +38 -0
- package/foundation/ActivityIndicator/index.d.mts +2 -0
- package/foundation/ActivityIndicator/index.mjs +6 -0
- package/foundation/ActivityIndicator-es.js +30 -0
- package/foundation/Autocomplete/Autocomplete.d.ts +8 -0
- package/foundation/Autocomplete/Autocomplete.types.d.ts +401 -0
- package/foundation/Autocomplete/hooks/useAutocompleteListNav.d.ts +30 -0
- package/foundation/Autocomplete/index.d.mts +3 -0
- package/foundation/Autocomplete/index.mjs +39 -0
- package/foundation/Autocomplete/utils/interactionUtils.d.ts +14 -0
- package/foundation/Autocomplete-es.js +1322 -0
- package/foundation/Avatar/Avatar.d.ts +77 -0
- package/foundation/Avatar/index.d.mts +1 -0
- package/foundation/Avatar/index.mjs +6 -0
- package/foundation/Avatar-es.js +80 -0
- package/foundation/Banner/Banner.d.ts +10 -0
- package/foundation/Banner/Banner.types.d.ts +165 -0
- package/foundation/Banner/index.d.mts +2 -0
- package/foundation/Banner/index.mjs +14 -0
- package/foundation/Banner-es.js +134 -0
- package/foundation/Body-es.js +45 -0
- package/foundation/BottomSheet-es.js +110 -0
- package/foundation/Box/Box.d.ts +3 -0
- package/foundation/Box/Box.types.d.ts +40 -0
- package/foundation/Box/index.d.mts +1 -0
- package/foundation/Box/index.mjs +4 -0
- package/foundation/Box-es.js +130 -0
- package/foundation/Button/Button.d.ts +17 -0
- package/foundation/Button/Button.types.d.ts +112 -0
- package/foundation/Button/ButtonInternals.d.ts +11 -0
- package/foundation/Button/ButtonProvider.d.ts +11 -0
- package/foundation/Button/index.d.mts +4 -0
- package/foundation/Button/useButtonStyles.d.ts +17 -0
- package/foundation/Button-es.js +122 -0
- package/foundation/ButtonDismiss/ButtonDismiss.d.ts +6 -0
- package/foundation/ButtonDismiss/index.d.mts +1 -0
- package/foundation/ButtonDismiss-es.js +9 -0
- package/foundation/Card/Card.d.ts +78 -0
- package/foundation/Card/cardcolors.module.d.ts +90 -0
- package/foundation/Card/index.d.mts +1 -0
- package/foundation/Card/index.mjs +37 -0
- package/foundation/Card/types.d.ts +63 -0
- package/foundation/Card-es.js +138 -0
- package/foundation/Checkbox/Checkbox.d.ts +7 -0
- package/foundation/Checkbox/Checkbox.types.d.ts +51 -0
- package/foundation/Checkbox/index.d.mts +2 -0
- package/foundation/Checkbox/index.mjs +8 -0
- package/foundation/Checkbox-es.js +57 -0
- package/foundation/Chip/Chip.d.ts +14 -0
- package/foundation/Chip/Chip.types.d.ts +70 -0
- package/foundation/Chip/components/ChipDismissible/ChipDismissible.d.ts +3 -0
- package/foundation/Chip/components/ChipPrefix/Chip.Prefix.d.ts +3 -0
- package/foundation/Chip/components/ChipSelectable/ChipSelectable.d.ts +3 -0
- package/foundation/Chip/components/ChipSuffix/Chip.Suffix.d.ts +9 -0
- package/foundation/Chip/index.d.mts +4 -0
- package/foundation/Chip/index.mjs +19 -0
- package/foundation/Chip-es.js +165 -0
- package/foundation/ChipDismissible-es.js +19 -0
- package/foundation/Chips/Chip.d.ts +9 -0
- package/foundation/Chips/ChipDismissible.d.ts +11 -0
- package/foundation/Chips/ChipTypes.d.ts +59 -0
- package/foundation/Chips/Chips.d.ts +8 -0
- package/foundation/Chips/ChipsTypes.d.ts +106 -0
- package/foundation/Chips/InternalChipButton.d.ts +11 -0
- package/foundation/Chips/index.d.mts +3 -0
- package/foundation/Chips/index.mjs +56 -0
- package/foundation/Chips-es.js +114 -0
- package/foundation/Cluster/Cluster.d.ts +3 -0
- package/foundation/Cluster/index.d.mts +2 -0
- package/foundation/Cluster/index.mjs +4 -0
- package/foundation/Cluster/types.d.ts +47 -0
- package/foundation/Cluster-es.js +12 -0
- package/foundation/Combobox/Combobox.d.ts +71 -0
- package/foundation/Combobox/Combobox.footer.d.ts +7 -0
- package/foundation/Combobox/Combobox.items.d.ts +25 -0
- package/foundation/Combobox/Combobox.selectAll.d.ts +4 -0
- package/foundation/Combobox/Combobox.slotFactory.d.ts +7 -0
- package/foundation/Combobox/Combobox.types.d.ts +168 -0
- package/foundation/Combobox/index.d.mts +2 -0
- package/foundation/Combobox/index.mjs +28 -0
- package/foundation/Combobox-es.js +782 -0
- package/foundation/ComboboxPrimitive-es.js +187 -0
- package/foundation/ComboboxSeparator-es.js +3541 -0
- package/foundation/ComponentSettingsContext/ComponentSettingsContext.d.ts +41 -0
- package/foundation/ComponentSettingsContext/index.d.mts +4 -0
- package/foundation/ComponentSettingsContext/index.mjs +5 -0
- package/foundation/ComponentSettingsContext-es.js +18 -0
- package/foundation/ConfirmationModal/ConfirmationModal.d.ts +79 -0
- package/foundation/ConfirmationModal/index.d.mts +1 -0
- package/foundation/ConfirmationModal/index.mjs +37 -0
- package/foundation/ConfirmationModal-es.js +111 -0
- package/foundation/Container/Container.d.ts +6 -0
- package/foundation/Container/index.d.mts +1 -0
- package/foundation/Container/index.mjs +3 -0
- package/foundation/Container/types.d.ts +22 -0
- package/foundation/Container-es.js +16 -0
- package/foundation/Content/Content.d.ts +22 -0
- package/foundation/Content/Spacing.module.d.ts +14 -0
- package/foundation/Content/index.d.mts +1 -0
- package/foundation/Content/index.mjs +3 -0
- package/foundation/Content-es.js +13 -0
- package/foundation/ContentBlock/ContentBlock.d.ts +3 -0
- package/foundation/ContentBlock/index.d.mts +2 -0
- package/foundation/ContentBlock/index.mjs +4 -0
- package/foundation/ContentBlock/types.d.ts +37 -0
- package/foundation/ContentBlock-es.js +29 -0
- package/foundation/Countdown/Countdown.d.ts +30 -0
- package/foundation/Countdown/index.d.mts +1 -0
- package/foundation/Countdown/index.mjs +4 -0
- package/foundation/Countdown-es.js +649 -0
- package/foundation/Cover/Cover.d.ts +6 -0
- package/foundation/Cover/index.d.mts +2 -0
- package/foundation/Cover/index.mjs +4 -0
- package/foundation/Cover/types.d.ts +34 -0
- package/foundation/Cover-es.js +14 -0
- package/foundation/DataDump/DataDump.d.ts +21 -0
- package/foundation/DataDump/index.d.mts +1 -0
- package/foundation/DataDump/index.mjs +40 -0
- package/foundation/DataDump-es.js +26 -0
- package/foundation/DataList/DataList.const.d.ts +22 -0
- package/foundation/DataList/DataList.d.ts +28 -0
- package/foundation/DataList/DataList.types.d.ts +323 -0
- package/foundation/DataList/components/DataListAction/DataListAction.d.ts +3 -0
- package/foundation/DataList/components/DataListAction/index.d.mts +1 -0
- package/foundation/DataList/components/DataListBulkActions/DataListBulkActions.d.ts +4 -0
- package/foundation/DataList/components/DataListBulkActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListEmptyState/DataListEmptyState.d.ts +4 -0
- package/foundation/DataList/components/DataListEmptyState/index.d.mts +1 -0
- package/foundation/DataList/components/DataListFilters/DataListFilters.d.ts +11 -0
- package/foundation/DataList/components/DataListFilters/index.d.mts +1 -0
- package/foundation/DataList/components/DataListItemActions/DataListItemActions.d.ts +9 -0
- package/foundation/DataList/components/DataListItemActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListLayout/DataListLayout.d.ts +3 -0
- package/foundation/DataList/components/DataListLayout/index.d.mts +1 -0
- package/foundation/DataList/components/DataListLayoutActions/DataListLayoutActions.d.ts +2 -0
- package/foundation/DataList/components/DataListLayoutActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListSearch/DataListSearch.d.ts +8 -0
- package/foundation/DataList/components/DataListSearch/index.d.mts +1 -0
- package/foundation/DataList/components/DataListStatusBar/DataListStatusBar.d.ts +11 -0
- package/foundation/DataList/components/DataListStatusBar/index.d.mts +1 -0
- package/foundation/DataList/index.d.mts +2 -0
- package/foundation/DataList/index.mjs +96 -0
- package/foundation/DataList-es.js +141 -0
- package/foundation/DataList.const-es.js +26 -0
- package/foundation/DataList.module-es.js +3 -0
- package/foundation/DataList.utils-es.js +167 -0
- package/foundation/DataListAction-es.js +43 -0
- package/foundation/DataListActions-es.js +53 -0
- package/foundation/DataListActionsMenu-es.js +52 -0
- package/foundation/DataListBulkActions-es.js +28 -0
- package/foundation/DataListContext-es.js +26 -0
- package/foundation/DataListEmptyState-es.js +54 -0
- package/foundation/DataListFilters-es.js +43 -0
- package/foundation/DataListHeader-es.js +130 -0
- package/foundation/DataListHeaderTile-es.js +86 -0
- package/foundation/DataListItem-es.js +118 -0
- package/foundation/DataListItemActions-es.js +29 -0
- package/foundation/DataListItemActionsOverflow-es.js +34 -0
- package/foundation/DataListItemClickable-es.js +45 -0
- package/foundation/DataListItems-es.js +19 -0
- package/foundation/DataListLayout-es.js +19 -0
- package/foundation/DataListLayoutActions-es.js +36 -0
- package/foundation/DataListLayoutContext-es.js +14 -0
- package/foundation/DataListLayoutContext-es2.js +8 -0
- package/foundation/DataListLoadMore-es.js +32 -0
- package/foundation/DataListLoadingState-es.js +22 -0
- package/foundation/DataListOverflowFade-es.js +22 -0
- package/foundation/DataListSearch-es.js +84 -0
- package/foundation/DataListSort-es.js +74 -0
- package/foundation/DataListSortingOptions-es.js +34 -0
- package/foundation/DataListStatusBar-es.js +22 -0
- package/foundation/DataListStickyHeader-es.js +23 -0
- package/foundation/DataListTags-es.js +62 -0
- package/foundation/DataListTotalCount-es.js +38 -0
- package/foundation/DataTable/DataTable.d.ts +74 -0
- package/foundation/DataTable/SortIcon.d.ts +11 -0
- package/foundation/DataTable/components/DataTableActions.d.ts +2 -0
- package/foundation/DataTable/components/DataTableBody.d.ts +2 -0
- package/foundation/DataTable/components/DataTableCell.d.ts +2 -0
- package/foundation/DataTable/components/DataTableContainer.d.ts +2 -0
- package/foundation/DataTable/components/DataTableFooter.d.ts +5 -0
- package/foundation/DataTable/components/DataTableHeader.d.ts +2 -0
- package/foundation/DataTable/components/DataTableHeaderCell.d.ts +5 -0
- package/foundation/DataTable/components/DataTablePagination.d.ts +5 -0
- package/foundation/DataTable/components/DataTablePaginationButton.d.ts +21 -0
- package/foundation/DataTable/components/DataTableRow.d.ts +2 -0
- package/foundation/DataTable/components/DataTableRowActions.d.ts +4 -0
- package/foundation/DataTable/components/DataTableSortableHeader.d.ts +24 -0
- package/foundation/DataTable/components/DataTableTable.d.ts +11 -0
- package/foundation/DataTable/components/index.d.mts +13 -0
- package/foundation/DataTable/index.d.mts +6 -0
- package/foundation/DataTable/index.mjs +29 -0
- package/foundation/DataTable/test-utilities/helpers.d.ts +1 -0
- package/foundation/DataTable/types.d.ts +83 -0
- package/foundation/DataTable-es.js +262 -0
- package/foundation/DataTableTable-es.js +117 -0
- package/foundation/DatePicker/DatePicker.d.ts +74 -0
- package/foundation/DatePicker/DatePickerActivator.d.ts +18 -0
- package/foundation/DatePicker/index.d.mts +1 -0
- package/foundation/DatePicker/index.mjs +26 -0
- package/foundation/DatePicker-es.js +13627 -0
- package/foundation/Dialog/dialogReturnFocus.d.ts +43 -0
- package/foundation/Disclosure/Disclosure.d.ts +68 -0
- package/foundation/Disclosure/index.d.mts +1 -0
- package/foundation/Disclosure/index.mjs +7 -0
- package/foundation/Disclosure-es.js +46 -0
- package/foundation/Divider/Divider.d.ts +39 -0
- package/foundation/Divider/DividerDirections.module.d.ts +6 -0
- package/foundation/Divider/DividerSizes.module.d.ts +8 -0
- package/foundation/Divider/index.d.mts +1 -0
- package/foundation/Divider/index.mjs +3 -0
- package/foundation/Divider-es.js +15 -0
- package/foundation/Drawer/Drawer.d.ts +14 -0
- package/foundation/Drawer/DrawerGrid.d.ts +7 -0
- package/foundation/Drawer/index.d.mts +2 -0
- package/foundation/Drawer/index.mjs +13 -0
- package/foundation/DrawerGrid-es.js +39 -0
- package/foundation/DrawerTitle-es.js +90 -0
- package/foundation/Emphasis/Emphasis.d.ts +12 -0
- package/foundation/Emphasis/index.d.mts +1 -0
- package/foundation/Emphasis/index.mjs +4 -0
- package/foundation/Emphasis-es.js +13 -0
- package/foundation/FeatureSwitch/FeatureSwitch.d.ts +52 -0
- package/foundation/FeatureSwitch/index.d.mts +1 -0
- package/foundation/FeatureSwitch/index.mjs +20 -0
- package/foundation/FeatureSwitch-es.js +66 -0
- package/foundation/FieldDescription-es.js +859 -0
- package/foundation/FilterPicker/FilterPicker.d.ts +11 -0
- package/foundation/FilterPicker/FilterPicker.types.d.ts +282 -0
- package/foundation/FilterPicker/FilterPickerProvider.d.ts +18 -0
- package/foundation/FilterPicker/components/FilterPickerAction/FilterPickerAction.d.ts +3 -0
- package/foundation/FilterPicker/components/FilterPickerAction/index.d.mts +1 -0
- package/foundation/FilterPicker/components/FilterPickerActivator/FilterPickerActivator.d.ts +3 -0
- package/foundation/FilterPicker/components/FilterPickerActivator/index.d.mts +1 -0
- package/foundation/FilterPicker/components/FilterPickerOption/FilterPickerOption.d.ts +3 -0
- package/foundation/FilterPicker/index.d.mts +3 -0
- package/foundation/FilterPicker/index.mjs +49 -0
- package/foundation/FilterPicker-es.js +110 -0
- package/foundation/FilterPicker.messages-es.js +56 -0
- package/foundation/FilterPickerAction-es.js +30 -0
- package/foundation/FilterPickerActivator-es.js +36 -0
- package/foundation/FilterPickerContent-es.js +180 -0
- package/foundation/FilterPickerContentHeader-es.js +23 -0
- package/foundation/FilterPickerContentList-es.js +74 -0
- package/foundation/FilterPickerContentSearch-es.js +35 -0
- package/foundation/FilterPickerLoadMore-es.js +14 -0
- package/foundation/FilterPickerOption-es.js +29 -0
- package/foundation/FilterPickerProvider-es.js +10 -0
- package/foundation/FilterPickerTrigger-es.js +19 -0
- package/foundation/Flex/Flex.d.ts +33 -0
- package/foundation/Flex/Flex.types.d.ts +6 -0
- package/foundation/Flex/index.d.mts +1 -0
- package/foundation/Flex/index.mjs +3 -0
- package/foundation/Flex-es.js +28 -0
- package/foundation/FormField/FormFieldAffix.d.ts +19 -0
- package/foundation/FormField/FormFieldTypes.d.ts +185 -0
- package/foundation/FormField/FormFieldWrapper.d.ts +57 -0
- package/foundation/FormField/hooks/useFormFieldName.d.ts +6 -0
- package/foundation/FormField/hooks/useFormFieldWrapperStyles.d.ts +35 -0
- package/foundation/FormField/index.d.mts +5 -0
- package/foundation/FormField/index.mjs +17 -0
- package/foundation/FormFieldPostFix-es.js +13 -0
- package/foundation/FormFieldWrapper-es.js +233 -0
- package/foundation/FormatFile/FormatFile.d.ts +42 -0
- package/foundation/FormatFile/index.d.mts +4 -0
- package/foundation/FormatFile/index.mjs +42 -0
- package/foundation/FormatFile/types.d.ts +27 -0
- package/foundation/FormatFile/useFormatFile.d.ts +5 -0
- package/foundation/FormatFile/useFormatFileStyles.d.ts +10 -0
- package/foundation/FormatFile-es.js +137 -0
- package/foundation/Frame/Frame.d.ts +3 -0
- package/foundation/Frame/index.d.mts +2 -0
- package/foundation/Frame/index.mjs +3 -0
- package/foundation/Frame/types.d.ts +24 -0
- package/foundation/Frame-es.js +10 -0
- package/foundation/Gallery/Gallery.d.ts +3 -0
- package/foundation/Gallery/GalleryTypes.d.ts +36 -0
- package/foundation/Gallery/index.d.mts +3 -0
- package/foundation/Gallery/index.mjs +64 -0
- package/foundation/Gallery-es.js +88 -0
- package/foundation/Glimmer/Glimmer.d.ts +71 -0
- package/foundation/Glimmer/index.d.mts +1 -0
- package/foundation/Glimmer/index.mjs +5 -0
- package/foundation/Glimmer/style/Shape.module.d.ts +9 -0
- package/foundation/Glimmer/style/Sizes.module.d.ts +10 -0
- package/foundation/Glimmer/style/Timing.module.d.ts +6 -0
- package/foundation/Glimmer-es.js +53 -0
- package/foundation/Grid/Grid.d.ts +32 -0
- package/foundation/Grid/GridAlign.module.d.ts +8 -0
- package/foundation/Grid/GridCell/GridCell.d.ts +23 -0
- package/foundation/Grid/GridCell/index.d.mts +1 -0
- package/foundation/Grid/index.d.mts +1 -0
- package/foundation/Grid/index.mjs +5 -0
- package/foundation/Grid-es.js +30 -0
- package/foundation/GridCell-es.js +34 -0
- package/foundation/Heading/Heading.d.ts +41 -0
- package/foundation/Heading/index.d.mts +2 -0
- package/foundation/Heading/index.mjs +4 -0
- package/foundation/Heading-es.js +55 -0
- package/foundation/HelperText-es.js +19 -0
- package/foundation/Icon/Icon.d.ts +47 -0
- package/foundation/Icon/index.d.mts +1 -0
- package/foundation/Icon-es.js +22 -0
- package/foundation/InlineLabel/InlineLabel.d.ts +18 -0
- package/foundation/InlineLabel/index.d.mts +1 -0
- package/foundation/InlineLabel/index.mjs +4 -0
- package/foundation/InlineLabel-es.js +19 -0
- package/foundation/InputAvatar/InputAvatar.d.ts +23 -0
- package/foundation/InputAvatar/index.d.mts +1 -0
- package/foundation/InputAvatar/index.mjs +22 -0
- package/foundation/InputAvatar-es.js +64 -0
- package/foundation/InputDate/InputDate.d.ts +3 -0
- package/foundation/InputDate/InputDate.types.d.ts +36 -0
- package/foundation/InputDate/index.d.mts +2 -0
- package/foundation/InputDate/index.mjs +39 -0
- package/foundation/InputDate-es.js +104 -0
- package/foundation/InputEmail/InputEmail.d.ts +3 -0
- package/foundation/InputEmail/InputEmail.types.d.ts +16 -0
- package/foundation/InputEmail/index.d.mts +2 -0
- package/foundation/InputEmail/index.mjs +22 -0
- package/foundation/InputEmail-es.js +105 -0
- package/foundation/InputFile/FileTypes.d.ts +17 -0
- package/foundation/InputFile/InputFile.d.ts +187 -0
- package/foundation/InputFile/InputFileButton.d.ts +6 -0
- package/foundation/InputFile/InputFileContentContext.d.ts +12 -0
- package/foundation/InputFile/InputFileDescription.d.ts +4 -0
- package/foundation/InputFile/InputFileDropzoneWrapper.d.ts +4 -0
- package/foundation/InputFile/InputFileHintText.d.ts +4 -0
- package/foundation/InputFile/index.d.mts +3 -0
- package/foundation/InputFile/index.mjs +16 -0
- package/foundation/InputFile-es.js +1780 -0
- package/foundation/InputGroup/InputGroup.d.ts +12 -0
- package/foundation/InputGroup/index.d.mts +1 -0
- package/foundation/InputGroup/index.mjs +3 -0
- package/foundation/InputGroup-es.js +26 -0
- package/foundation/InputNumber/InputNumber.d.ts +77 -0
- package/foundation/InputNumber/index.d.mts +2 -0
- package/foundation/InputNumber/index.mjs +33 -0
- package/foundation/InputNumber/types.d.ts +197 -0
- package/foundation/InputNumber-es.js +348 -0
- package/foundation/InputPhoneNumber/InputPhoneNumber.d.ts +3 -0
- package/foundation/InputPhoneNumber/InputPhoneNumber.types.d.ts +24 -0
- package/foundation/InputPhoneNumber/index.d.mts +2 -0
- package/foundation/InputPhoneNumber/index.mjs +22 -0
- package/foundation/InputPhoneNumber-es.js +188 -0
- package/foundation/InputText/InputText.d.ts +3 -0
- package/foundation/InputText/InputText.types.d.ts +58 -0
- package/foundation/InputText/index.d.mts +2 -0
- package/foundation/InputText/index.mjs +23 -0
- package/foundation/InputText-es.js +196 -0
- package/foundation/InputTime/InputTime.d.ts +3 -0
- package/foundation/InputTime/InputTime.types.d.ts +34 -0
- package/foundation/InputTime/index.d.mts +2 -0
- package/foundation/InputTime/index.mjs +23 -0
- package/foundation/InputTime-es.js +297 -0
- package/foundation/InputValidation/InputValidation.d.ts +10 -0
- package/foundation/InputValidation/index.d.mts +1 -0
- package/foundation/InputValidation/index.mjs +8 -0
- package/foundation/InputValidation-es.js +22 -0
- package/foundation/InternalChipDismissible-es.js +68 -0
- package/foundation/LICENSE +21 -0
- package/foundation/LegacySelect/LegacySelect.d.ts +7 -0
- package/foundation/LegacySelect/LegacySelect.types.d.ts +18 -0
- package/foundation/LegacySelect/Option.d.ts +18 -0
- package/foundation/LegacySelect/OptionGroup.d.ts +29 -0
- package/foundation/LegacySelect/index.d.mts +3 -0
- package/foundation/LegacySelect/index.mjs +23 -0
- package/foundation/LegacySelect-es.js +76 -0
- package/foundation/LegacyThemeContext/LegacyThemeContext.d.ts +5 -0
- package/foundation/LegacyThemeContext/index.d.mts +3 -0
- package/foundation/LegacyThemeContext/index.mjs +12 -0
- package/foundation/LegacyThemeContext/types.d.ts +59 -0
- package/foundation/LegacyThemeContext/updateTheme.d.ts +7 -0
- package/foundation/LegacyThemeContext-es.js +457 -0
- package/foundation/LightBox/LightBox.d.ts +165 -0
- package/foundation/LightBox/LightBox.types.d.ts +153 -0
- package/foundation/LightBox/LightBoxContext.d.ts +5 -0
- package/foundation/LightBox/index.d.mts +3 -0
- package/foundation/LightBox/index.mjs +50 -0
- package/foundation/LightBox-es.js +454 -0
- package/foundation/Link/Link.d.ts +9 -0
- package/foundation/Link/index.d.mts +2 -0
- package/foundation/Link/index.mjs +2 -0
- package/foundation/Link-es.js +12 -0
- package/foundation/List/List.d.ts +41 -0
- package/foundation/List/ListItem.d.ts +59 -0
- package/foundation/List/index.d.mts +2 -0
- package/foundation/List/index.mjs +22 -0
- package/foundation/List-es.js +199 -0
- package/foundation/Markdown/Markdown.d.ts +24 -0
- package/foundation/Markdown/index.d.mts +1 -0
- package/foundation/Markdown/index.mjs +10 -0
- package/foundation/Markdown-es.js +20558 -0
- package/foundation/Menu/Menu.d.ts +89 -0
- package/foundation/Menu/Menu.types.d.ts +105 -0
- package/foundation/Menu/index.d.mts +2 -0
- package/foundation/Menu/index.mjs +35 -0
- package/foundation/Menu/menuComposableTypes.d.ts +103 -0
- package/foundation/Menu-es.js +1033 -0
- package/foundation/MenuSubmenuTrigger-es.js +3088 -0
- package/foundation/Modal/Modal.rebuilt.d.ts +16 -0
- package/foundation/Modal/Modal.types.d.ts +138 -0
- package/foundation/Modal/ModalContext.rebuilt.d.ts +19 -0
- package/foundation/Modal/ModalSizes.module.d.ts +7 -0
- package/foundation/Modal/index.d.mts +17 -0
- package/foundation/Modal/index.mjs +302 -0
- package/foundation/Modal/useModalStyles.d.ts +12 -0
- package/foundation/MultiSelect/MultiSelect.d.ts +30 -0
- package/foundation/MultiSelect/index.d.mts +1 -0
- package/foundation/MultiSelect/index.mjs +9 -0
- package/foundation/MultiSelect/types.d.ts +13 -0
- package/foundation/MultiSelect-es.js +172 -0
- package/foundation/OverlaySeparator-es.js +13 -0
- package/foundation/Page/Page.d.ts +74 -0
- package/foundation/Page/index.d.mts +2 -0
- package/foundation/Page/index.mjs +42 -0
- package/foundation/Page/types.d.ts +123 -0
- package/foundation/Page-es.js +196 -0
- package/foundation/Popover/Popover.d.ts +9 -0
- package/foundation/Popover/Popover.types.d.ts +109 -0
- package/foundation/Popover/PopoverContext.d.ts +18 -0
- package/foundation/Popover/index.d.mts +4 -0
- package/foundation/Popover/index.mjs +27 -0
- package/foundation/Popover/usePopoverStyles.d.ts +5 -0
- package/foundation/Popover-es.js +166 -0
- package/foundation/ProgressBar/ProgressBar.d.ts +41 -0
- package/foundation/ProgressBar/ProgressBarSizes.module.d.ts +7 -0
- package/foundation/ProgressBar/index.d.mts +1 -0
- package/foundation/ProgressBar/index.mjs +5 -0
- package/foundation/ProgressBar-es.js +48 -0
- package/foundation/ProgressIndicator/ProgressIndicator.d.ts +60 -0
- package/foundation/ProgressIndicator/index.d.mts +1 -0
- package/foundation/ProgressIndicator/index.mjs +3 -0
- package/foundation/ProgressIndicator-es.js +41 -0
- package/foundation/RadioGroup/RadioGroup.d.ts +33 -0
- package/foundation/RadioGroup/RadioOption.d.ts +48 -0
- package/foundation/RadioGroup/index.d.mts +2 -0
- package/foundation/RadioGroup/index.mjs +5 -0
- package/foundation/RadioGroup-es.js +42 -0
- package/foundation/ResponsiveSwitcher/ResponsiveSwitcher.d.ts +3 -0
- package/foundation/ResponsiveSwitcher/index.d.mts +2 -0
- package/foundation/ResponsiveSwitcher/index.mjs +4 -0
- package/foundation/ResponsiveSwitcher/types.d.ts +26 -0
- package/foundation/ResponsiveSwitcher-es.js +11 -0
- package/foundation/RulnarPortalContent-es.js +1 -0
- package/foundation/ScrollAreaViewport-es.js +3959 -0
- package/foundation/SegmentedControl/SegmentedControl.d.ts +39 -0
- package/foundation/SegmentedControl/SegmentedControlBase.d.ts +7 -0
- package/foundation/SegmentedControl/SegmentedControlOption.d.ts +15 -0
- package/foundation/SegmentedControl/SegmentedControlProvider.d.ts +17 -0
- package/foundation/SegmentedControl/index.d.mts +2 -0
- package/foundation/SegmentedControl/index.mjs +3 -0
- package/foundation/SegmentedControl-es.js +64 -0
- package/foundation/Select/Select.d.ts +31 -0
- package/foundation/Select/Select.types.d.ts +145 -0
- package/foundation/Select/index.d.mts +2 -0
- package/foundation/Select/index.mjs +29 -0
- package/foundation/Select-es.js +227 -0
- package/foundation/SelectGroupLabel-es.js +1763 -0
- package/foundation/SelectPrimitive-es.js +126 -0
- package/foundation/Separator-es.js +33 -0
- package/foundation/SideDrawer/SideDrawer.d.ts +56 -0
- package/foundation/SideDrawer/SideDrawerActions.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerBackButton.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerFooter.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerTitle.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerToolbar.d.ts +2 -0
- package/foundation/SideDrawer/index.d.mts +1 -0
- package/foundation/SideDrawer/index.mjs +16 -0
- package/foundation/SideDrawer-es.js +198 -0
- package/foundation/SideKick/SideKick.d.ts +3 -0
- package/foundation/SideKick/index.d.mts +2 -0
- package/foundation/SideKick/index.mjs +4 -0
- package/foundation/SideKick/types.d.ts +35 -0
- package/foundation/SideKick-es.js +15 -0
- package/foundation/Spinner/Spinner.d.ts +22 -0
- package/foundation/Spinner/index.d.mts +1 -0
- package/foundation/Spinner/index.mjs +6 -0
- package/foundation/Spinner-es.js +21 -0
- package/foundation/Stack/Stack.d.ts +3 -0
- package/foundation/Stack/index.d.mts +2 -0
- package/foundation/Stack/index.mjs +4 -0
- package/foundation/Stack/types.d.ts +32 -0
- package/foundation/Stack-es.js +13 -0
- package/foundation/StatusIndicator/StatusIndicator.d.ts +7 -0
- package/foundation/StatusIndicator/StatusIndicator.type.d.ts +1 -0
- package/foundation/StatusIndicator/index.d.mts +2 -0
- package/foundation/StatusIndicator/index.mjs +2 -0
- package/foundation/StatusIndicator-es.js +9 -0
- package/foundation/StatusLabel/StatusLabel.d.ts +26 -0
- package/foundation/StatusLabel/index.d.mts +1 -0
- package/foundation/StatusLabel/index.mjs +5 -0
- package/foundation/StatusLabel-es.js +16 -0
- package/foundation/Table/Body.d.ts +7 -0
- package/foundation/Table/Cells/Cell.d.ts +8 -0
- package/foundation/Table/Cells/CellCurrency.d.ts +9 -0
- package/foundation/Table/Cells/CellNumeric.d.ts +5 -0
- package/foundation/Table/Footer.d.ts +7 -0
- package/foundation/Table/Header.d.ts +7 -0
- package/foundation/Table/Row.d.ts +7 -0
- package/foundation/Table/Table.d.ts +7 -0
- package/foundation/Table/index.d.mts +8 -0
- package/foundation/Table/index.mjs +4 -0
- package/foundation/Tabs/Tabs.d.ts +38 -0
- package/foundation/Tabs/index.d.mts +1 -0
- package/foundation/Tabs/index.mjs +8 -0
- package/foundation/Tabs-es.js +227 -0
- package/foundation/Text/Text.d.ts +29 -0
- package/foundation/Text/index.d.mts +2 -0
- package/foundation/Text/index.mjs +4 -0
- package/foundation/Text-es.js +25 -0
- package/foundation/Thumbnail/Thumbnail.d.ts +25 -0
- package/foundation/Thumbnail/index.d.mts +1 -0
- package/foundation/Thumbnail/index.mjs +9 -0
- package/foundation/Thumbnail-es.js +119 -0
- package/foundation/Tiles/Tiles.d.ts +3 -0
- package/foundation/Tiles/index.d.mts +2 -0
- package/foundation/Tiles/index.mjs +4 -0
- package/foundation/Tiles/types.d.ts +34 -0
- package/foundation/Tiles-es.js +11 -0
- package/foundation/Tooltip/Tooltip.d.ts +18 -0
- package/foundation/Tooltip/Tooltip.types.d.ts +1 -0
- package/foundation/Tooltip/index.d.mts +1 -0
- package/foundation/Tooltip/index.mjs +8 -0
- package/foundation/Tooltip-es.js +137 -0
- package/foundation/Typography/Typography.d.ts +64 -0
- package/foundation/Typography/css/Emphasis.module.d.ts +6 -0
- package/foundation/Typography/css/FontFamilies.module.d.ts +6 -0
- package/foundation/Typography/css/FontSizes.module.d.ts +12 -0
- package/foundation/Typography/css/FontWeights.module.d.ts +10 -0
- package/foundation/Typography/css/TextAlignment.module.d.ts +7 -0
- package/foundation/Typography/css/TextCases.module.d.ts +8 -0
- package/foundation/Typography/css/TextColors.module.d.ts +69 -0
- package/foundation/Typography/index.d.mts +1 -0
- package/foundation/Typography/index.mjs +3 -0
- package/foundation/Typography/types.d.ts +7 -0
- package/foundation/Typography-es.js +53 -0
- package/foundation/_baseAssignValue-es.js +29 -0
- package/foundation/_baseEach-es.js +1028 -0
- package/foundation/_baseFlatten-es.js +65 -0
- package/foundation/_baseFor-es.js +45 -0
- package/foundation/_commonjsHelpers-es.js +7 -0
- package/foundation/_getAllKeys-es.js +506 -0
- package/foundation/_getTag-es.js +133 -0
- package/foundation/_isIterateeCall-es.js +55 -0
- package/foundation/_setToString-es.js +168 -0
- package/foundation/buttonRenderAdapter-es.js +52 -0
- package/foundation/buttonStyles.d.mts +1 -0
- package/foundation/buttonStyles.mjs +1 -0
- package/foundation/clearable.d.ts +1 -0
- package/foundation/common.messages-es.js +18 -0
- package/foundation/compatHooks.mjs +2 -0
- package/foundation/constants-es.js +3 -0
- package/foundation/dateLocale-es.js +1142 -0
- package/foundation/debounce-es.js +329 -0
- package/foundation/dialogFocus.d.mts +1 -0
- package/foundation/dialogFocus.mjs +66 -0
- package/foundation/filterDataAttributes-es.js +24 -0
- package/foundation/floating-ui.react-es.js +6174 -0
- package/foundation/getMappedSpaceToken-es.js +18 -0
- package/foundation/helpers-es.js +15 -0
- package/foundation/identity-es.js +809 -0
- package/foundation/imageTypes.d.mts +1 -0
- package/foundation/imageTypes.mjs +1 -0
- package/foundation/index-es.js +1186 -0
- package/foundation/isObjectLike-es.js +190 -0
- package/foundation/isSymbol-es.js +33 -0
- package/foundation/isTypedArray-es.js +589 -0
- package/foundation/keysIn-es.js +385 -0
- package/foundation/linkEvents.d.mts +1 -0
- package/foundation/linkEvents.mjs +9 -0
- package/foundation/maxHeight-es.js +22 -0
- package/foundation/mergeClassName-es.js +10 -0
- package/foundation/mergeRefs-es.js +18 -0
- package/foundation/nestedEscape-es.js +91 -0
- package/foundation/noop-es.js +24 -0
- package/foundation/primitives/BottomSheet/BottomSheet.d.ts +37 -0
- package/foundation/primitives/BottomSheet/BottomSheet.types.d.ts +36 -0
- package/foundation/primitives/BottomSheet/index.d.mts +2 -0
- package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.d.ts +32 -0
- package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.types.d.ts +30 -0
- package/foundation/primitives/ComboboxPrimitive/index.d.mts +2 -0
- package/foundation/primitives/HelperText/HelperText.d.ts +25 -0
- package/foundation/primitives/HelperText/index.d.mts +1 -0
- package/foundation/primitives/OverlaySeparator/OverlaySeparator.d.ts +6 -0
- package/foundation/primitives/OverlaySeparator/index.d.mts +1 -0
- package/foundation/primitives/SelectPrimitive/SelectPrimitive.d.ts +74 -0
- package/foundation/primitives/SelectPrimitive/index.d.mts +2 -0
- package/foundation/primitives/SelectPrimitive/types.d.ts +31 -0
- package/foundation/primitives/index.d.mts +12 -0
- package/foundation/primitives/index.mjs +29 -0
- package/foundation/routerLink.d.mts +3 -0
- package/foundation/routerLink.mjs +1 -0
- package/foundation/scrollEdges-es.js +64 -0
- package/foundation/scrollable-es.js +54 -0
- package/foundation/sharedHelpers/getMappedBreakpointWidth.d.ts +8 -0
- package/foundation/sharedHelpers/types.d.ts +254 -0
- package/foundation/stringifyLocale-es.js +11 -0
- package/foundation/styles.css +16646 -0
- package/foundation/tslib.es6-es.js +97 -0
- package/foundation/unstyledPrimitives/index.d.mts +22 -0
- package/foundation/useActiveLayout-es.js +14 -0
- package/foundation/useBatchSelect-es.js +36 -0
- package/foundation/useChildComponent-es.js +15 -0
- package/foundation/useComponentMessages-es.js +86 -0
- package/foundation/useCompositeListItem-es.js +3955 -0
- package/foundation/useFormFieldFocus-es.js +37 -0
- package/foundation/useFormFieldName-es.js +11 -0
- package/foundation/useLabel-es.js +81 -0
- package/foundation/useRenderElement-es.js +628 -0
- package/foundation/useResponsiveSizing-es.js +8 -0
- package/foundation/useScrollLock-es.js +5746 -0
- package/foundation/useScrollToActive-es.js +581 -0
- package/foundation/utils/isNormalClick.d.ts +6 -0
- package/foundation/utils/isPreviewableImage.d.ts +1 -0
- package/foundation/utils/meta/meta.json +298 -0
- package/foundation.css +67 -0
- package/package.json +540 -4
- package/src/styles.css +181 -0
|
@@ -0,0 +1,1322 @@
|
|
|
1
|
+
import { ThemeBoundary } from "../dist/theme.js";
|
|
2
|
+
import React__default, { useState, useRef, useEffect, useCallback, useMemo, forwardRef } from 'react';
|
|
3
|
+
import { u as useFloating, b as autoUpdate, o as offset, f as flip, m as size, t as useClick, n as useListNavigation, e as useDismiss, g as useInteractions, F as FloatingPortal, q as FloatingFocusManager, v as useTransitionStyles } from './floating-ui.react-es.js';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { tokens } from '@zj-dynamics/design/foundation';
|
|
6
|
+
import { useCallbackRef, useDebounce } from './compatHooks.mjs';
|
|
7
|
+
import { c as calculateMaxHeight } from './maxHeight-es.js';
|
|
8
|
+
import { H as Heading } from './Heading-es.js';
|
|
9
|
+
import { T as Text } from './Text-es.js';
|
|
10
|
+
import { T as Typography } from './Typography-es.js';
|
|
11
|
+
import { I as Icon } from './Icon-es.js';
|
|
12
|
+
import { d as defineMessages, u as useComponentMessages } from './useComponentMessages-es.js';
|
|
13
|
+
import './ComponentSettingsContext-es.js';
|
|
14
|
+
import { G as Glimmer } from './Glimmer-es.js';
|
|
15
|
+
import { I as InputText } from './InputText-es.js';
|
|
16
|
+
import { c as FormFieldWrapper } from './FormFieldWrapper-es.js';
|
|
17
|
+
import './Button-es.js';
|
|
18
|
+
import { m as mergeRefs } from './mergeRefs-es.js';
|
|
19
|
+
import { f as filterDataAttributes } from './filterDataAttributes-es.js';
|
|
20
|
+
|
|
21
|
+
/** Stable empty array for cleared/empty selection state. Reuse to avoid reference churn. */
|
|
22
|
+
const EMPTY_SELECTED_VALUES = [];
|
|
23
|
+
|
|
24
|
+
var styles = {"list":"w5g7qggGrr4-","loadingList":"ELlB2Kio7q8-","option":"y9zhi8Wr8QA-","defaultOptionContent":"adJv-3bhYOQ-","icon":"K2phy6IC3TY-","optionActive":"p2CY3TGCdRc-","actionActive":"-tyLeCnCEUI-","action":"dXIHuZjqX84-","section":"gQ86NtBHt-Y-","emptyStateMessage":"uElGEScjH68-","stickyTop":"nXvoRgKgoz8-","scrollRegion":"Ey1zL5E-c74-","persistentHeader":"ei36u5racbA-","persistentFooter":"IDIz9ZHykRw-","textPersistent":"Wx--khA61eA-","multiSelectField":"COW3V1gDtwI-","chipArea":"_1iRpnGn3PaA-","inlineInput":"bHaScorkEaQ-","selectionChip":"sFMc1SJPOSM-","selectionChipActive":"_9Ljs17OW-QM-","selectionChipDisabled":"QYUKkbmNjLE-","chipDismiss":"Wv6D8g2MKPo-","limitText":"UAegmMck3-U-","spinning":"P9cQDL4MZ-s-"};
|
|
25
|
+
|
|
26
|
+
function flattenMenu(menu) {
|
|
27
|
+
const optionItems = [];
|
|
28
|
+
const sections = [];
|
|
29
|
+
const persistentsHeaders = [];
|
|
30
|
+
const persistentsFooters = [];
|
|
31
|
+
menu.forEach(item => {
|
|
32
|
+
if (item.type === "header") {
|
|
33
|
+
persistentsHeaders.push(item);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (item.type === "footer") {
|
|
37
|
+
persistentsFooters.push(item);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const group = item;
|
|
41
|
+
sections.push(group);
|
|
42
|
+
optionItems.push(...group.options);
|
|
43
|
+
});
|
|
44
|
+
return { optionItems, sections, persistentsHeaders, persistentsFooters };
|
|
45
|
+
}
|
|
46
|
+
function buildItemsForGroup(group, optionsFilter) {
|
|
47
|
+
var _a;
|
|
48
|
+
const isSection = group.type === "section";
|
|
49
|
+
const filtered = optionsFilter ? optionsFilter(group.options) : group.options;
|
|
50
|
+
const actions = (_a = group.actions) !== null && _a !== void 0 ? _a : [];
|
|
51
|
+
const result = [];
|
|
52
|
+
// Only render a section header when that section has at least one option after filtering
|
|
53
|
+
if (isSection && filtered.length > 0) {
|
|
54
|
+
result.push({
|
|
55
|
+
kind: "section",
|
|
56
|
+
section: group,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (filtered.length > 0) {
|
|
60
|
+
result.push(...filtered.map(o => ({
|
|
61
|
+
kind: "option",
|
|
62
|
+
value: o,
|
|
63
|
+
})));
|
|
64
|
+
}
|
|
65
|
+
// Only render actions for a group when that group has at least one option after filtering
|
|
66
|
+
if (actions.length > 0 && filtered.length > 0) {
|
|
67
|
+
result.push(...actions.map(action => ({
|
|
68
|
+
kind: "action",
|
|
69
|
+
action,
|
|
70
|
+
origin: "menu",
|
|
71
|
+
})));
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
function buildRenderableList(sections, optionsFilter) {
|
|
76
|
+
const items = [];
|
|
77
|
+
for (const group of sections) {
|
|
78
|
+
items.push(...buildItemsForGroup(group, optionsFilter));
|
|
79
|
+
}
|
|
80
|
+
return items;
|
|
81
|
+
}
|
|
82
|
+
function getNavigableItemAtIndex(activeIndex, renderable) {
|
|
83
|
+
if (activeIndex == null)
|
|
84
|
+
return null;
|
|
85
|
+
let navigableIndex = -1;
|
|
86
|
+
for (const item of renderable) {
|
|
87
|
+
// Ignore sections
|
|
88
|
+
if (item.kind === "section")
|
|
89
|
+
continue;
|
|
90
|
+
navigableIndex += 1;
|
|
91
|
+
if (navigableIndex === activeIndex)
|
|
92
|
+
return item;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function findNavigableIndexForValue(renderable, equals, selectedValue) {
|
|
97
|
+
let navigableIndex = -1;
|
|
98
|
+
for (const item of renderable) {
|
|
99
|
+
// Ignore sections
|
|
100
|
+
if (item.kind === "section")
|
|
101
|
+
continue;
|
|
102
|
+
navigableIndex += 1;
|
|
103
|
+
if (item.kind === "option" && equals(item.value, selectedValue)) {
|
|
104
|
+
return navigableIndex;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function invokeActiveItemOnEnter(event, activeIndex, renderable, onSelect, onAction) {
|
|
110
|
+
const activeItem = getNavigableItemAtIndex(activeIndex, renderable);
|
|
111
|
+
if (!activeItem)
|
|
112
|
+
return;
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
if (activeItem.kind === "option") {
|
|
115
|
+
onSelect(activeItem.value);
|
|
116
|
+
}
|
|
117
|
+
else if (activeItem.kind === "action") {
|
|
118
|
+
onAction({
|
|
119
|
+
run: activeItem.action.onClick,
|
|
120
|
+
closeOnRun: activeItem.action.shouldClose,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const MENU_OFFSET = tokens["space-small"];
|
|
126
|
+
const AUTOCOMPLETE_MAX_HEIGHT = 300;
|
|
127
|
+
function useStableSetReference(refs) {
|
|
128
|
+
const latestRefs = useRef(refs);
|
|
129
|
+
latestRefs.current = refs;
|
|
130
|
+
return useCallback((el) => latestRefs.current.setReference(el), []);
|
|
131
|
+
}
|
|
132
|
+
function useAutocompleteListNav({ navigableCount, shouldResetActiveIndexOnClose, onMenuOpen, onMenuClose, selectedIndex, readOnly = false, disabled = false, outsidePressExcludeSelector, }) {
|
|
133
|
+
const [open, setOpen] = useState(false);
|
|
134
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
135
|
+
const listRef = useRef([]);
|
|
136
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
137
|
+
placement: "bottom",
|
|
138
|
+
whileElementsMounted: autoUpdate,
|
|
139
|
+
open,
|
|
140
|
+
onOpenChange: (isOpen, _event, reason) => {
|
|
141
|
+
setOpen(isOpen);
|
|
142
|
+
if (isOpen) {
|
|
143
|
+
onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (shouldResetActiveIndexOnClose === null || shouldResetActiveIndexOnClose === void 0 ? void 0 : shouldResetActiveIndexOnClose()) {
|
|
147
|
+
setActiveIndex(null);
|
|
148
|
+
}
|
|
149
|
+
onMenuClose === null || onMenuClose === void 0 ? void 0 : onMenuClose(String(reason !== null && reason !== void 0 ? reason : ""));
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
middleware: [
|
|
153
|
+
offset(MENU_OFFSET),
|
|
154
|
+
flip({ fallbackPlacements: ["top"] }),
|
|
155
|
+
size({
|
|
156
|
+
apply({ availableHeight, rects, elements }) {
|
|
157
|
+
const maxHeight = calculateMaxHeight(availableHeight, {
|
|
158
|
+
maxHeight: AUTOCOMPLETE_MAX_HEIGHT,
|
|
159
|
+
});
|
|
160
|
+
Object.assign(elements.floating.style, {
|
|
161
|
+
maxHeight: `${maxHeight}px`,
|
|
162
|
+
width: `${rects.reference.width}px`,
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
const enabled = !readOnly && !disabled;
|
|
169
|
+
const click = useClick(context, {
|
|
170
|
+
enabled,
|
|
171
|
+
toggle: false, // Only open, never close on click
|
|
172
|
+
});
|
|
173
|
+
const listNav = useListNavigation(context, {
|
|
174
|
+
listRef,
|
|
175
|
+
activeIndex,
|
|
176
|
+
selectedIndex,
|
|
177
|
+
scrollItemIntoView: {
|
|
178
|
+
behavior: "smooth",
|
|
179
|
+
block: "end",
|
|
180
|
+
},
|
|
181
|
+
loop: true,
|
|
182
|
+
onNavigate: setActiveIndex,
|
|
183
|
+
virtual: true,
|
|
184
|
+
enabled: open,
|
|
185
|
+
openOnArrowKeyDown: false,
|
|
186
|
+
focusItemOnOpen: "auto",
|
|
187
|
+
focusItemOnHover: false,
|
|
188
|
+
});
|
|
189
|
+
const dismiss = useDismiss(context, {
|
|
190
|
+
outsidePress: outsidePressExcludeSelector
|
|
191
|
+
? (event) => {
|
|
192
|
+
var _a, _b, _c, _d;
|
|
193
|
+
const target = event.target;
|
|
194
|
+
const insideRef = (_b = (_a = context.elements.domReference) === null || _a === void 0 ? void 0 : _a.contains(target)) !== null && _b !== void 0 ? _b : false;
|
|
195
|
+
const insideFloating = (_d = (_c = context.elements.floating) === null || _c === void 0 ? void 0 : _c.contains(target)) !== null && _d !== void 0 ? _d : false;
|
|
196
|
+
const insideExclude = event.target.closest(outsidePressExcludeSelector);
|
|
197
|
+
return !(insideRef || insideFloating || insideExclude);
|
|
198
|
+
}
|
|
199
|
+
: true,
|
|
200
|
+
escapeKey: true,
|
|
201
|
+
outsidePressEvent: "click",
|
|
202
|
+
});
|
|
203
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([click, listNav, dismiss]);
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
listRef.current.length = navigableCount;
|
|
206
|
+
setActiveIndex(prev => {
|
|
207
|
+
if (navigableCount <= 0)
|
|
208
|
+
return null;
|
|
209
|
+
if (prev == null)
|
|
210
|
+
return null;
|
|
211
|
+
return prev >= navigableCount ? navigableCount - 1 : prev;
|
|
212
|
+
});
|
|
213
|
+
}, [navigableCount, setActiveIndex, listRef]);
|
|
214
|
+
const setReferenceElement = useStableSetReference(refs);
|
|
215
|
+
return {
|
|
216
|
+
refs,
|
|
217
|
+
floatingStyles,
|
|
218
|
+
context,
|
|
219
|
+
getReferenceProps,
|
|
220
|
+
getFloatingProps,
|
|
221
|
+
getItemProps,
|
|
222
|
+
activeIndex,
|
|
223
|
+
setActiveIndex,
|
|
224
|
+
listRef,
|
|
225
|
+
open,
|
|
226
|
+
setOpen,
|
|
227
|
+
setReferenceElement,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Handler that prevents default pointer behavior.
|
|
233
|
+
* Used to prevent blur/focus issues when clicking on non-interactive menu elements.
|
|
234
|
+
*/
|
|
235
|
+
function preventDefaultPointerDown(e) {
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates a handler for pointer down events on interactive menu items (options/actions).
|
|
240
|
+
* Prevents default to avoid blur and sets flag for focus management.
|
|
241
|
+
*
|
|
242
|
+
* @param isHandlingMenuInteractionRef - Ref to track if a menu interaction is in progress
|
|
243
|
+
* @returns A pointer down event handler
|
|
244
|
+
*/
|
|
245
|
+
function createInteractionPointerDownHandler(isHandlingMenuInteractionRef) {
|
|
246
|
+
return (e) => {
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
// Set flag to prevent blur/focus handlers from interfering
|
|
249
|
+
isHandlingMenuInteractionRef.current = true;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Keeping this hook cohesive improves readability by centralizing related
|
|
254
|
+
// interactions and state transitions.
|
|
255
|
+
// eslint-disable-next-line max-statements
|
|
256
|
+
function useAutocomplete(props, inputRef) {
|
|
257
|
+
const { menu, emptyActions, getOptionLabel: getOptionLabelProp, isOptionEqualToValue, inputValue, onInputChange, value, onChange, multiple, openOnFocus = true, readOnly = false, disabled = false, debounce: debounceMs = 300, } = props;
|
|
258
|
+
const isHandlingMenuInteractionRef = useRef(false);
|
|
259
|
+
// TODO: Clean up the types in these refs by enhancing the type system in useCallbackRef
|
|
260
|
+
const getOptionLabelPropRef = useCallbackRef((opt) => getOptionLabelProp === null || getOptionLabelProp === void 0 ? void 0 : getOptionLabelProp(opt));
|
|
261
|
+
const getOptionLabel = useCallback((opt) => {
|
|
262
|
+
const maybe = getOptionLabelPropRef(opt);
|
|
263
|
+
return maybe !== null && maybe !== void 0 ? maybe : opt.label;
|
|
264
|
+
}, [getOptionLabelPropRef]);
|
|
265
|
+
const isOptionEqualToValueRef = useCallbackRef((a, b) => isOptionEqualToValue === null || isOptionEqualToValue === void 0 ? void 0 : isOptionEqualToValue(a, b));
|
|
266
|
+
const equals = useCallback((a, b) => {
|
|
267
|
+
const custom = isOptionEqualToValueRef(a, b);
|
|
268
|
+
return custom != null ? custom : getOptionLabel(a) === getOptionLabel(b);
|
|
269
|
+
}, [isOptionEqualToValueRef, getOptionLabel]);
|
|
270
|
+
const isOptionSelected = useCallback((opt) => {
|
|
271
|
+
var _a;
|
|
272
|
+
if (multiple) {
|
|
273
|
+
const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
|
|
274
|
+
return current.some(v => equals(v, opt));
|
|
275
|
+
}
|
|
276
|
+
const current = value;
|
|
277
|
+
return current != null ? equals(current, opt) : false;
|
|
278
|
+
}, [multiple, value, equals]);
|
|
279
|
+
const flatInitial = useMemo(() => flattenMenu(menu), [menu]);
|
|
280
|
+
const sections = flatInitial.sections;
|
|
281
|
+
const optionItems = flatInitial.optionItems;
|
|
282
|
+
const persistentsHeaders = flatInitial.persistentsHeaders;
|
|
283
|
+
const persistentsFooters = flatInitial.persistentsFooters;
|
|
284
|
+
// Stable wrappers for function props
|
|
285
|
+
const inputEqualsOptionRef = useCallbackRef((text, o) => {
|
|
286
|
+
const fn = props.inputEqualsOption;
|
|
287
|
+
return fn ? fn(text, o) : undefined;
|
|
288
|
+
});
|
|
289
|
+
const inputEquals = useCallback((text, o) => {
|
|
290
|
+
const custom = inputEqualsOptionRef(text, o);
|
|
291
|
+
return custom != null ? custom : getOptionLabel(o) === text;
|
|
292
|
+
}, [inputEqualsOptionRef, getOptionLabel]);
|
|
293
|
+
// inputValue changes very often, is this worth memoizing?
|
|
294
|
+
const exactLabelMatch = useMemo(() => {
|
|
295
|
+
return optionItems.some(o => inputEquals(inputValue, o));
|
|
296
|
+
}, [optionItems, inputEquals, inputValue]);
|
|
297
|
+
const lastInputWasUser = useRef(false);
|
|
298
|
+
const [debouncedInputValue, setDebouncedInputValue] = useState(inputValue);
|
|
299
|
+
const debouncedSetter = useDebounce(setDebouncedInputValue, debounceMs);
|
|
300
|
+
useEffect(() => {
|
|
301
|
+
// Skip debounce when clearing input for immediate feedback, preventing flickering of last selected item
|
|
302
|
+
if (debounceMs === 0 || inputValue === "") {
|
|
303
|
+
setDebouncedInputValue(inputValue);
|
|
304
|
+
// Cancel any pending debounced call so a stale intermediate value
|
|
305
|
+
// (e.g. "P" while deleting "Pipe…") doesn't overwrite the immediate set.
|
|
306
|
+
debouncedSetter.cancel();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
debouncedSetter(inputValue);
|
|
310
|
+
}, [inputValue, debounceMs, debouncedSetter]);
|
|
311
|
+
const filterOptionsRef = useCallbackRef((opts, term) => {
|
|
312
|
+
const fn = (typeof props.filterOptions === "function"
|
|
313
|
+
? props.filterOptions
|
|
314
|
+
: undefined) || undefined;
|
|
315
|
+
return fn ? fn(opts, term) : undefined;
|
|
316
|
+
});
|
|
317
|
+
const applyFilter = useCallback((opts, term) => {
|
|
318
|
+
if (props.filterOptions === false)
|
|
319
|
+
return opts;
|
|
320
|
+
const override = filterOptionsRef(opts, term);
|
|
321
|
+
if (override)
|
|
322
|
+
return override;
|
|
323
|
+
const lowered = term.toLowerCase();
|
|
324
|
+
return opts.filter(opt => getOptionLabel(opt).toLowerCase().includes(lowered));
|
|
325
|
+
}, [props.filterOptions, filterOptionsRef, getOptionLabel]);
|
|
326
|
+
const renderable = useMemo(() => {
|
|
327
|
+
const filter = (opts) => {
|
|
328
|
+
if (exactLabelMatch && !lastInputWasUser.current)
|
|
329
|
+
return opts;
|
|
330
|
+
return applyFilter(opts, debouncedInputValue);
|
|
331
|
+
};
|
|
332
|
+
const items = buildRenderableList(sections, filter);
|
|
333
|
+
const hasAnyOptions = items.some(i => i.kind === "option");
|
|
334
|
+
if (!hasAnyOptions) {
|
|
335
|
+
if (emptyActions) {
|
|
336
|
+
const derived = typeof emptyActions === "function"
|
|
337
|
+
? emptyActions({ inputValue })
|
|
338
|
+
: emptyActions;
|
|
339
|
+
return derived.map(act => ({
|
|
340
|
+
kind: "action",
|
|
341
|
+
action: act,
|
|
342
|
+
origin: "empty",
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
// No options and no emptyActions: render empty state
|
|
346
|
+
return [];
|
|
347
|
+
}
|
|
348
|
+
return items;
|
|
349
|
+
}, [
|
|
350
|
+
sections,
|
|
351
|
+
applyFilter,
|
|
352
|
+
debouncedInputValue,
|
|
353
|
+
exactLabelMatch,
|
|
354
|
+
emptyActions,
|
|
355
|
+
inputValue,
|
|
356
|
+
]);
|
|
357
|
+
// This is only options
|
|
358
|
+
const optionCount = renderable.reduce((count, item) => count + (item.kind === "option" ? 1 : 0), 0);
|
|
359
|
+
const hasSelection = useMemo(() => {
|
|
360
|
+
var _a;
|
|
361
|
+
if (multiple) {
|
|
362
|
+
const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
|
|
363
|
+
return Array.isArray(current) && current.length > 0;
|
|
364
|
+
}
|
|
365
|
+
return value != null;
|
|
366
|
+
}, [multiple, value]);
|
|
367
|
+
const headerInteractivePersistents = persistentsHeaders.filter(p => Boolean(p.onClick));
|
|
368
|
+
const footerInteractivePersistents = persistentsFooters.filter(p => Boolean(p.onClick));
|
|
369
|
+
const mainNavigableCount = renderable.reduce((c, i) => c + (i.kind === "section" ? 0 : 1), 0);
|
|
370
|
+
const totalNavigableCount = headerInteractivePersistents.length +
|
|
371
|
+
mainNavigableCount +
|
|
372
|
+
footerInteractivePersistents.length;
|
|
373
|
+
// Compute the currently selected index in the global navigable list (header -> middle -> footer).
|
|
374
|
+
// In multiple mode this is always null — there is no single "selected" index, and
|
|
375
|
+
// floating-ui would otherwise jump the highlight whenever the value array changes.
|
|
376
|
+
const selectedIndex = useMemo(() => {
|
|
377
|
+
if (multiple)
|
|
378
|
+
return null;
|
|
379
|
+
const selectedValue = value;
|
|
380
|
+
if (!selectedValue)
|
|
381
|
+
return null;
|
|
382
|
+
const middleIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
|
|
383
|
+
if (middleIndex == null)
|
|
384
|
+
return null;
|
|
385
|
+
return headerInteractivePersistents.length + middleIndex;
|
|
386
|
+
}, [
|
|
387
|
+
multiple,
|
|
388
|
+
value,
|
|
389
|
+
renderable,
|
|
390
|
+
equals,
|
|
391
|
+
headerInteractivePersistents.length,
|
|
392
|
+
]);
|
|
393
|
+
const { refs, floatingStyles, context, getReferenceProps, getFloatingProps, getItemProps, activeIndex, setActiveIndex, listRef, open, setOpen, setReferenceElement, } = useAutocompleteListNav({
|
|
394
|
+
navigableCount: totalNavigableCount,
|
|
395
|
+
shouldResetActiveIndexOnClose: () => !hasSelection,
|
|
396
|
+
selectedIndex,
|
|
397
|
+
readOnly,
|
|
398
|
+
disabled,
|
|
399
|
+
outsidePressExcludeSelector: multiple
|
|
400
|
+
? "[data-testid='ATL-Autocomplete-chipArea']"
|
|
401
|
+
: undefined,
|
|
402
|
+
onMenuOpen: () => {
|
|
403
|
+
if (multiple)
|
|
404
|
+
return;
|
|
405
|
+
const selectedValue = value;
|
|
406
|
+
if (selectedValue) {
|
|
407
|
+
const selectedNavigableIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
|
|
408
|
+
if (selectedNavigableIndex != null) {
|
|
409
|
+
setActiveIndex(selectedNavigableIndex);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
setActiveIndex(null);
|
|
414
|
+
},
|
|
415
|
+
onMenuClose: () => {
|
|
416
|
+
if (props.allowFreeForm !== true) {
|
|
417
|
+
const hasText = inputValue.trim().length > 0;
|
|
418
|
+
if (hasText && !hasSelection) {
|
|
419
|
+
lastInputWasUser.current = false;
|
|
420
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
|
|
421
|
+
setActiveIndex(null);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
const prevOpenRef = useRef(false);
|
|
427
|
+
// TODO: Leverage FloatingUI useFocus, and onArrowKeyDown to manage open state and allow onOpenChange to be the source of truth
|
|
428
|
+
// JOB-154442
|
|
429
|
+
useEffect(() => {
|
|
430
|
+
var _a, _b;
|
|
431
|
+
if (open && !prevOpenRef.current) {
|
|
432
|
+
(_a = props.onOpen) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
433
|
+
}
|
|
434
|
+
else if (!open && prevOpenRef.current) {
|
|
435
|
+
(_b = props.onClose) === null || _b === void 0 ? void 0 : _b.call(props);
|
|
436
|
+
}
|
|
437
|
+
prevOpenRef.current = open;
|
|
438
|
+
}, [open, props.onOpen, props.onClose]);
|
|
439
|
+
function selectOption(option) {
|
|
440
|
+
var _a;
|
|
441
|
+
if (multiple) {
|
|
442
|
+
const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
|
|
443
|
+
const exists = current.some(v => equals(v, option));
|
|
444
|
+
const next = exists
|
|
445
|
+
? current.filter(v => !equals(v, option))
|
|
446
|
+
: [...current, option];
|
|
447
|
+
onChange((next.length === 0 ? EMPTY_SELECTED_VALUES : next));
|
|
448
|
+
lastInputWasUser.current = false;
|
|
449
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
onChange(option);
|
|
453
|
+
lastInputWasUser.current = false;
|
|
454
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(getOptionLabel(option));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function reHighlightSelectedItem() {
|
|
458
|
+
const selectedValue = value;
|
|
459
|
+
if (!selectedValue)
|
|
460
|
+
return;
|
|
461
|
+
const idx = findNavigableIndexForValue(renderable, equals, selectedValue);
|
|
462
|
+
if (idx != null)
|
|
463
|
+
setActiveIndex(idx);
|
|
464
|
+
}
|
|
465
|
+
function tryCommitFreeFormOnEnter() {
|
|
466
|
+
if (props.allowFreeForm !== true)
|
|
467
|
+
return false;
|
|
468
|
+
if (open && activeIndex != null)
|
|
469
|
+
return false;
|
|
470
|
+
const inputText = inputValue.trim();
|
|
471
|
+
if (inputText.length === 0)
|
|
472
|
+
return false;
|
|
473
|
+
commitFromInputText(inputText);
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
const onSelection = useCallback((option) => {
|
|
477
|
+
var _a;
|
|
478
|
+
selectOption(option);
|
|
479
|
+
if (!multiple) {
|
|
480
|
+
setOpen(false);
|
|
481
|
+
}
|
|
482
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
483
|
+
}, [selectOption, setOpen, multiple, inputRef]);
|
|
484
|
+
const onAction = useCallback((action) => {
|
|
485
|
+
var _a;
|
|
486
|
+
action.run();
|
|
487
|
+
setActiveIndex(null);
|
|
488
|
+
if (action.closeOnRun !== false)
|
|
489
|
+
setOpen(false);
|
|
490
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
491
|
+
}, [setOpen, setActiveIndex, inputRef]);
|
|
492
|
+
/**
|
|
493
|
+
* Handler for mousedown on interactive menu items (options/actions)
|
|
494
|
+
* Prevents default to avoid blur and sets flag for focus management
|
|
495
|
+
*/
|
|
496
|
+
const onInteractionPointerDown = useMemo(() => createInteractionPointerDownHandler(isHandlingMenuInteractionRef), []);
|
|
497
|
+
function applyFreeFormValue(freeFormCreated) {
|
|
498
|
+
var _a;
|
|
499
|
+
const nextValue = multiple
|
|
500
|
+
? [...((_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES), freeFormCreated]
|
|
501
|
+
: freeFormCreated;
|
|
502
|
+
props.onChange(nextValue);
|
|
503
|
+
if (multiple) {
|
|
504
|
+
lastInputWasUser.current = false;
|
|
505
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function commitFromInputText(inputText) {
|
|
509
|
+
var _a;
|
|
510
|
+
if (inputText.length === 0)
|
|
511
|
+
return false;
|
|
512
|
+
const match = optionItems.find(o => inputEquals(inputText, o));
|
|
513
|
+
if (match) {
|
|
514
|
+
onSelection(match);
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
setOpen(false);
|
|
518
|
+
if (props.allowFreeForm !== true)
|
|
519
|
+
return false;
|
|
520
|
+
const freeFormCreated = (_a = props.createFreeFormValue) === null || _a === void 0 ? void 0 : _a.call(props, inputText);
|
|
521
|
+
if (!freeFormCreated)
|
|
522
|
+
return false;
|
|
523
|
+
applyFreeFormValue(freeFormCreated);
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
const tryRestoreInputToSelectedLabel = useCallback(() => {
|
|
527
|
+
if (props.allowFreeForm === true)
|
|
528
|
+
return;
|
|
529
|
+
if (multiple) {
|
|
530
|
+
if (inputValue.trim().length > 0) {
|
|
531
|
+
lastInputWasUser.current = false;
|
|
532
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange("");
|
|
533
|
+
}
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const selectedValue = value;
|
|
537
|
+
if (!selectedValue)
|
|
538
|
+
return;
|
|
539
|
+
const selectedLabel = getOptionLabel(selectedValue);
|
|
540
|
+
if (inputValue === selectedLabel)
|
|
541
|
+
return;
|
|
542
|
+
lastInputWasUser.current = false;
|
|
543
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(selectedLabel);
|
|
544
|
+
}, [
|
|
545
|
+
props.allowFreeForm,
|
|
546
|
+
getOptionLabel,
|
|
547
|
+
inputValue,
|
|
548
|
+
onInputChange,
|
|
549
|
+
multiple,
|
|
550
|
+
value,
|
|
551
|
+
]);
|
|
552
|
+
const onInputFocus = useCallback((event) => {
|
|
553
|
+
var _a;
|
|
554
|
+
if (!readOnly && openOnFocus && !isHandlingMenuInteractionRef.current) {
|
|
555
|
+
setOpen(true);
|
|
556
|
+
}
|
|
557
|
+
// Only call user's onFocus for genuine focus events, not programmatic restorations
|
|
558
|
+
if (!isHandlingMenuInteractionRef.current) {
|
|
559
|
+
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
560
|
+
}
|
|
561
|
+
isHandlingMenuInteractionRef.current = false;
|
|
562
|
+
}, [props.onFocus, readOnly, openOnFocus, setOpen]);
|
|
563
|
+
const onInputBlur = useCallback((event) => {
|
|
564
|
+
var _a, _b;
|
|
565
|
+
if (isHandlingMenuInteractionRef.current) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
if (readOnly) {
|
|
569
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (props.allowFreeForm === true) {
|
|
573
|
+
const inputText = inputValue.trim();
|
|
574
|
+
if (inputText.length > 0)
|
|
575
|
+
commitFromInputText(inputText);
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
tryRestoreInputToSelectedLabel();
|
|
579
|
+
}
|
|
580
|
+
lastInputWasUser.current = false;
|
|
581
|
+
(_b = props.onBlur) === null || _b === void 0 ? void 0 : _b.call(props, event);
|
|
582
|
+
}, [
|
|
583
|
+
readOnly,
|
|
584
|
+
props.allowFreeForm,
|
|
585
|
+
inputValue,
|
|
586
|
+
props.onBlur,
|
|
587
|
+
tryRestoreInputToSelectedLabel,
|
|
588
|
+
setOpen,
|
|
589
|
+
]);
|
|
590
|
+
function getRegionByActiveIndex(index) {
|
|
591
|
+
const headerCount = headerInteractivePersistents.length;
|
|
592
|
+
const mainCount = mainNavigableCount;
|
|
593
|
+
if (index < headerCount)
|
|
594
|
+
return { region: "header", regionIndex: index };
|
|
595
|
+
const middleIndex = index - headerCount;
|
|
596
|
+
if (middleIndex < mainCount) {
|
|
597
|
+
return { region: "middle", regionIndex: middleIndex };
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
region: "footer",
|
|
601
|
+
regionIndex: middleIndex - mainCount,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
function computeInitialIndexForArrowUp() {
|
|
605
|
+
// If there are interactive footers, prefer the very last navigable item
|
|
606
|
+
if (footerInteractivePersistents.length > 0) {
|
|
607
|
+
return totalNavigableCount > 0 ? totalNavigableCount - 1 : null;
|
|
608
|
+
}
|
|
609
|
+
// Otherwise, prefer the last OPTION (not action), matching legacy behavior
|
|
610
|
+
let navigable = -1;
|
|
611
|
+
let lastOptionIdx = -1;
|
|
612
|
+
for (const item of renderable) {
|
|
613
|
+
if (item.kind === "section")
|
|
614
|
+
continue;
|
|
615
|
+
navigable += 1;
|
|
616
|
+
if (item.kind === "option")
|
|
617
|
+
lastOptionIdx = navigable;
|
|
618
|
+
}
|
|
619
|
+
if (lastOptionIdx >= 0) {
|
|
620
|
+
return headerInteractivePersistents.length + lastOptionIdx;
|
|
621
|
+
}
|
|
622
|
+
return totalNavigableCount > 0 ? totalNavigableCount - 1 : null;
|
|
623
|
+
}
|
|
624
|
+
function handleArrowNavigation(key, event) {
|
|
625
|
+
if (!open) {
|
|
626
|
+
setOpen(true);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (activeIndex == null) {
|
|
630
|
+
setActiveIndex(key === "ArrowDown" ? 0 : computeInitialIndexForArrowUp());
|
|
631
|
+
event.preventDefault();
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function handleEnterKey(event) {
|
|
635
|
+
if (tryCommitFreeFormOnEnter()) {
|
|
636
|
+
event.preventDefault();
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (!open || activeIndex == null)
|
|
640
|
+
return;
|
|
641
|
+
const { region, regionIndex } = getRegionByActiveIndex(activeIndex);
|
|
642
|
+
if (region === "middle") {
|
|
643
|
+
invokeActiveItemOnEnter(event, regionIndex, renderable, onSelection, onAction);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const persistent = region === "header"
|
|
647
|
+
? headerInteractivePersistents[regionIndex]
|
|
648
|
+
: footerInteractivePersistents[regionIndex];
|
|
649
|
+
if (persistent === null || persistent === void 0 ? void 0 : persistent.onClick) {
|
|
650
|
+
onAction({
|
|
651
|
+
run: persistent.onClick,
|
|
652
|
+
closeOnRun: persistent.shouldClose,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const removeLastSelection = useCallback(() => {
|
|
657
|
+
var _a;
|
|
658
|
+
if (!multiple || readOnly)
|
|
659
|
+
return;
|
|
660
|
+
const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
|
|
661
|
+
if (current.length > 0) {
|
|
662
|
+
const next = current.slice(0, -1);
|
|
663
|
+
onChange((next.length === 0 ? EMPTY_SELECTED_VALUES : next));
|
|
664
|
+
}
|
|
665
|
+
}, [multiple, readOnly, value, onChange]);
|
|
666
|
+
const removeSelection = useCallback((option) => {
|
|
667
|
+
var _a;
|
|
668
|
+
if (readOnly)
|
|
669
|
+
return;
|
|
670
|
+
if (multiple) {
|
|
671
|
+
const current = (_a = value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES;
|
|
672
|
+
const next = current.filter(v => !equals(v, option));
|
|
673
|
+
onChange((next.length === 0
|
|
674
|
+
? EMPTY_SELECTED_VALUES
|
|
675
|
+
: next));
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
const current = value;
|
|
679
|
+
if (current && equals(current, option)) {
|
|
680
|
+
onChange(undefined);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}, [readOnly, multiple, value, equals, onChange]);
|
|
684
|
+
const onInputKeyDown = useCallback((event) => {
|
|
685
|
+
const key = event.key;
|
|
686
|
+
if (key === "Backspace" && multiple && inputValue === "") {
|
|
687
|
+
removeLastSelection();
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (key !== "ArrowDown" && key !== "ArrowUp" && key !== "Enter")
|
|
691
|
+
return;
|
|
692
|
+
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
693
|
+
handleArrowNavigation(key, event);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
handleEnterKey(event);
|
|
697
|
+
}, [open, onSelection, onAction, multiple, inputValue, removeLastSelection]);
|
|
698
|
+
const onInputChangeFromUser = useCallback((val) => {
|
|
699
|
+
lastInputWasUser.current = true;
|
|
700
|
+
const isEmpty = val.trim().length === 0;
|
|
701
|
+
if (isEmpty) {
|
|
702
|
+
setActiveIndex(null);
|
|
703
|
+
if (!multiple && hasSelection) {
|
|
704
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
else if (val.length > inputValue.length) {
|
|
708
|
+
setActiveIndex(null);
|
|
709
|
+
}
|
|
710
|
+
else if (val.length < inputValue.length &&
|
|
711
|
+
!multiple &&
|
|
712
|
+
open &&
|
|
713
|
+
hasSelection) {
|
|
714
|
+
reHighlightSelectedItem();
|
|
715
|
+
}
|
|
716
|
+
if (!readOnly) {
|
|
717
|
+
setOpen((!isEmpty && !props.allowFreeForm) || openOnFocus);
|
|
718
|
+
}
|
|
719
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(val);
|
|
720
|
+
}, [
|
|
721
|
+
onInputChange,
|
|
722
|
+
inputValue,
|
|
723
|
+
setActiveIndex,
|
|
724
|
+
readOnly,
|
|
725
|
+
props.allowFreeForm,
|
|
726
|
+
openOnFocus,
|
|
727
|
+
setOpen,
|
|
728
|
+
multiple,
|
|
729
|
+
hasSelection,
|
|
730
|
+
onChange,
|
|
731
|
+
open,
|
|
732
|
+
]);
|
|
733
|
+
const clearAll = useCallback(() => {
|
|
734
|
+
if (multiple) {
|
|
735
|
+
onChange(EMPTY_SELECTED_VALUES);
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
onChange(undefined);
|
|
739
|
+
}
|
|
740
|
+
onInputChangeFromUser("");
|
|
741
|
+
}, [multiple, onChange, onInputChangeFromUser]);
|
|
742
|
+
return {
|
|
743
|
+
// rendering data
|
|
744
|
+
renderable,
|
|
745
|
+
optionCount,
|
|
746
|
+
persistentsHeaders,
|
|
747
|
+
persistentsFooters,
|
|
748
|
+
headerInteractiveCount: headerInteractivePersistents.length,
|
|
749
|
+
middleNavigableCount: mainNavigableCount,
|
|
750
|
+
getOptionLabel,
|
|
751
|
+
isOptionSelected,
|
|
752
|
+
// floating-ui
|
|
753
|
+
refs,
|
|
754
|
+
floatingStyles,
|
|
755
|
+
context,
|
|
756
|
+
getReferenceProps,
|
|
757
|
+
getFloatingProps,
|
|
758
|
+
getItemProps,
|
|
759
|
+
// state
|
|
760
|
+
open,
|
|
761
|
+
setOpen,
|
|
762
|
+
activeIndex,
|
|
763
|
+
setActiveIndex,
|
|
764
|
+
listRef,
|
|
765
|
+
// actions
|
|
766
|
+
onSelection,
|
|
767
|
+
onAction,
|
|
768
|
+
onInteractionPointerDown,
|
|
769
|
+
removeSelection,
|
|
770
|
+
clearAll,
|
|
771
|
+
// input handlers
|
|
772
|
+
onInputChangeFromUser,
|
|
773
|
+
onInputBlur,
|
|
774
|
+
onInputFocus,
|
|
775
|
+
onInputKeyDown,
|
|
776
|
+
// ref attachment
|
|
777
|
+
setReferenceElement,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function useChipNavigation({ selectedValues, inputValue, readOnly, removeSelection, onInputKeyDown, onInputBlur, }) {
|
|
782
|
+
const [rawActiveChipIndex, setRawActiveChipIndex] = useState(null);
|
|
783
|
+
const [previousInputValue, setPreviousInputValue] = useState(inputValue);
|
|
784
|
+
const activeChipIndex = clampActiveIndex(rawActiveChipIndex, selectedValues.length);
|
|
785
|
+
if (previousInputValue !== inputValue) {
|
|
786
|
+
setPreviousInputValue(inputValue);
|
|
787
|
+
if (inputValue !== "" && rawActiveChipIndex !== null) {
|
|
788
|
+
setRawActiveChipIndex(null);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
const handleActiveChipKey = useCallback(
|
|
792
|
+
// eslint-disable-next-line max-statements
|
|
793
|
+
(event) => {
|
|
794
|
+
if (activeChipIndex === null)
|
|
795
|
+
return false;
|
|
796
|
+
const { key } = event;
|
|
797
|
+
if (key === "ArrowLeft") {
|
|
798
|
+
event.preventDefault();
|
|
799
|
+
setRawActiveChipIndex(i => Math.max(0, (i !== null && i !== void 0 ? i : 0) - 1));
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
if (key === "ArrowRight") {
|
|
803
|
+
event.preventDefault();
|
|
804
|
+
setRawActiveChipIndex(activeChipIndex + 1 >= selectedValues.length
|
|
805
|
+
? null
|
|
806
|
+
: activeChipIndex + 1);
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
if (key === "Backspace" || key === "Delete") {
|
|
810
|
+
event.preventDefault();
|
|
811
|
+
const option = selectedValues[activeChipIndex];
|
|
812
|
+
const newLen = selectedValues.length - 1;
|
|
813
|
+
if (newLen === 0) {
|
|
814
|
+
setRawActiveChipIndex(null);
|
|
815
|
+
}
|
|
816
|
+
else if (activeChipIndex >= newLen) {
|
|
817
|
+
setRawActiveChipIndex(newLen - 1);
|
|
818
|
+
}
|
|
819
|
+
removeSelection(option);
|
|
820
|
+
return true;
|
|
821
|
+
}
|
|
822
|
+
if (key === "Escape") {
|
|
823
|
+
setRawActiveChipIndex(null);
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
setRawActiveChipIndex(null);
|
|
827
|
+
return false;
|
|
828
|
+
}, [activeChipIndex, selectedValues, removeSelection]);
|
|
829
|
+
const onKeyDown = useCallback((event) => {
|
|
830
|
+
if (handleActiveChipKey(event))
|
|
831
|
+
return;
|
|
832
|
+
if (event.key === "ArrowLeft" &&
|
|
833
|
+
!readOnly &&
|
|
834
|
+
inputValue === "" &&
|
|
835
|
+
selectedValues.length > 0) {
|
|
836
|
+
event.preventDefault();
|
|
837
|
+
setRawActiveChipIndex(selectedValues.length - 1);
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
onInputKeyDown(event);
|
|
841
|
+
}, [handleActiveChipKey, selectedValues, inputValue, readOnly, onInputKeyDown]);
|
|
842
|
+
const onBlur = useCallback((event) => {
|
|
843
|
+
setRawActiveChipIndex(null);
|
|
844
|
+
onInputBlur(event);
|
|
845
|
+
}, [onInputBlur]);
|
|
846
|
+
return { activeChipIndex, onKeyDown, onBlur };
|
|
847
|
+
}
|
|
848
|
+
function clampActiveIndex(index, length) {
|
|
849
|
+
if (index === null)
|
|
850
|
+
return null;
|
|
851
|
+
if (length === 0)
|
|
852
|
+
return null;
|
|
853
|
+
if (index >= length)
|
|
854
|
+
return length - 1;
|
|
855
|
+
return index;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
function MenuList({ items, activeIndex, indexOffset = 0, getItemProps, listRef, listboxId, customRenderOption, customRenderSection, customRenderAction, getOptionLabel, onSelect, onAction, onInteractionPointerDown, isOptionSelected, slotOverrides, }) {
|
|
859
|
+
let navigableIndex = -1;
|
|
860
|
+
function renderItemNode(item) {
|
|
861
|
+
var _a, _b, _c, _d, _e, _f;
|
|
862
|
+
if (item.kind === "section") {
|
|
863
|
+
return handleSectionRendering({
|
|
864
|
+
section: item.section,
|
|
865
|
+
customRenderSection,
|
|
866
|
+
sectionClassName: (_a = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.section) === null || _a === void 0 ? void 0 : _a.className,
|
|
867
|
+
sectionStyle: (_b = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.section) === null || _b === void 0 ? void 0 : _b.style,
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
if (item.kind === "option") {
|
|
871
|
+
const result = handleOptionRendering({
|
|
872
|
+
option: item.value,
|
|
873
|
+
activeIndex,
|
|
874
|
+
navigableIndex,
|
|
875
|
+
getItemProps,
|
|
876
|
+
listRef,
|
|
877
|
+
listboxId,
|
|
878
|
+
isOptionSelected,
|
|
879
|
+
customRenderOption,
|
|
880
|
+
getOptionLabel,
|
|
881
|
+
onSelect,
|
|
882
|
+
onInteractionPointerDown,
|
|
883
|
+
indexOffset,
|
|
884
|
+
optionClassName: (_c = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.option) === null || _c === void 0 ? void 0 : _c.className,
|
|
885
|
+
optionStyle: (_d = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.option) === null || _d === void 0 ? void 0 : _d.style,
|
|
886
|
+
});
|
|
887
|
+
navigableIndex = result.nextNavigableIndex;
|
|
888
|
+
return result.node;
|
|
889
|
+
}
|
|
890
|
+
const result = handleActionRendering({
|
|
891
|
+
action: item.action,
|
|
892
|
+
activeIndex,
|
|
893
|
+
navigableIndex,
|
|
894
|
+
getItemProps,
|
|
895
|
+
listRef,
|
|
896
|
+
listboxId,
|
|
897
|
+
customRenderAction,
|
|
898
|
+
onAction,
|
|
899
|
+
onInteractionPointerDown,
|
|
900
|
+
indexOffset,
|
|
901
|
+
actionClassName: (_e = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.action) === null || _e === void 0 ? void 0 : _e.className,
|
|
902
|
+
actionStyle: (_f = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.action) === null || _f === void 0 ? void 0 : _f.style,
|
|
903
|
+
origin: item.origin,
|
|
904
|
+
});
|
|
905
|
+
navigableIndex = result.nextNavigableIndex;
|
|
906
|
+
return result.node;
|
|
907
|
+
}
|
|
908
|
+
return React__default.createElement(React__default.Fragment, null, items.map(renderItemNode));
|
|
909
|
+
}
|
|
910
|
+
function handleSectionRendering({ customRenderSection, section, sectionClassName, sectionStyle, }) {
|
|
911
|
+
var _a;
|
|
912
|
+
const headerContent = customRenderSection ? (customRenderSection(section)) : (React__default.createElement(DefaultSectionContent, { section: section }));
|
|
913
|
+
return (React__default.createElement("div", { key: `section-${String((_a = section.key) !== null && _a !== void 0 ? _a : section.label)}`, role: "presentation", tabIndex: -1, "data-testid": "ATL-Autocomplete-Section", className: classnames(styles.section, styles.stickyTop, sectionClassName), style: sectionStyle, onPointerDown: preventDefaultPointerDown }, headerContent));
|
|
914
|
+
}
|
|
915
|
+
function DefaultSectionContent({ section, }) {
|
|
916
|
+
return React__default.createElement(Heading, { level: 5 }, section.label);
|
|
917
|
+
}
|
|
918
|
+
function handleOptionRendering({ option, activeIndex, navigableIndex, getItemProps, listRef, listboxId, isOptionSelected, customRenderOption, getOptionLabel, onSelect, onInteractionPointerDown, indexOffset = 0, optionClassName, optionStyle, }) {
|
|
919
|
+
var _a;
|
|
920
|
+
const nextNavigableIndex = navigableIndex + 1;
|
|
921
|
+
const isActive = activeIndex === nextNavigableIndex;
|
|
922
|
+
const isSelected = isOptionSelected(option);
|
|
923
|
+
const optionContent = customRenderOption ? (customRenderOption({ value: option, isActive, isSelected })) : (React__default.createElement(DefaultOptionContent, { isSelected: isSelected, text: getOptionLabel(option) }));
|
|
924
|
+
return {
|
|
925
|
+
node: (React__default.createElement("div", Object.assign({ key: `option-${String((_a = option.key) !== null && _a !== void 0 ? _a : getOptionLabel(option))}` }, getItemProps({
|
|
926
|
+
ref(node) {
|
|
927
|
+
const idx = nextNavigableIndex + indexOffset;
|
|
928
|
+
if (node)
|
|
929
|
+
listRef.current[idx] = node;
|
|
930
|
+
},
|
|
931
|
+
onClick: () => onSelect(option),
|
|
932
|
+
onPointerDown: onInteractionPointerDown,
|
|
933
|
+
className: classnames(styles.option, isActive && styles.optionActive, optionClassName),
|
|
934
|
+
style: optionStyle,
|
|
935
|
+
}), { role: "option", tabIndex: -1, "aria-selected": isSelected ? true : false, id: `${listboxId}-item-${nextNavigableIndex + indexOffset}`, "data-index": nextNavigableIndex + indexOffset, "data-active": isActive ? true : undefined }), optionContent)),
|
|
936
|
+
nextNavigableIndex,
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
function DefaultOptionContent({ isSelected, text, }) {
|
|
940
|
+
return (React__default.createElement("div", { className: styles.defaultOptionContent },
|
|
941
|
+
React__default.createElement("div", { className: styles.icon, style: isSelected ? undefined : { visibility: "hidden" } },
|
|
942
|
+
React__default.createElement(Icon, { name: "checkmark", size: "small" })),
|
|
943
|
+
React__default.createElement(Text, null, text)));
|
|
944
|
+
}
|
|
945
|
+
function handleActionRendering({ action, activeIndex, navigableIndex, getItemProps, listRef, listboxId, customRenderAction, onAction, onInteractionPointerDown, indexOffset = 0, actionClassName, actionStyle, origin, }) {
|
|
946
|
+
var _a;
|
|
947
|
+
const nextNavigableIndex = navigableIndex + 1;
|
|
948
|
+
const isActive = activeIndex === nextNavigableIndex;
|
|
949
|
+
const actionContent = customRenderAction ? (customRenderAction({ value: action, isActive, origin })) : (React__default.createElement(DefaultActionContent, { textContent: action.label }));
|
|
950
|
+
const computedIndex = nextNavigableIndex + indexOffset;
|
|
951
|
+
const itemProps = getItemProps({
|
|
952
|
+
ref(node) {
|
|
953
|
+
if (node) {
|
|
954
|
+
listRef.current[computedIndex] = node;
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
onClick: () => {
|
|
958
|
+
onAction({
|
|
959
|
+
run: action.onClick,
|
|
960
|
+
closeOnRun: action.shouldClose,
|
|
961
|
+
});
|
|
962
|
+
},
|
|
963
|
+
onPointerDown: onInteractionPointerDown,
|
|
964
|
+
className: classnames(styles.action, isActive && styles.actionActive, actionClassName),
|
|
965
|
+
style: actionStyle,
|
|
966
|
+
});
|
|
967
|
+
return {
|
|
968
|
+
node: (React__default.createElement("div", Object.assign({ key: `action-${String((origin !== null && origin !== void 0 ? origin : "menu") + "-" + ((_a = action.key) !== null && _a !== void 0 ? _a : action.label))}` }, itemProps, { role: "button", tabIndex: -1, "data-testid": "ATL-Autocomplete-Action", id: `${listboxId}-item-${computedIndex}`, "data-index": computedIndex, "data-origin": origin, "data-active": isActive ? true : undefined }), actionContent)),
|
|
969
|
+
nextNavigableIndex,
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
function DefaultActionContent({ textContent, }) {
|
|
973
|
+
return (React__default.createElement(Typography, { textColor: "interactive", fontWeight: "semiBold", underline: "solid color-interactive", UNSAFE_style: {
|
|
974
|
+
textStyle: {
|
|
975
|
+
textDecorationThickness: "var(--border-thick)",
|
|
976
|
+
textUnderlineOffset: "var(--space-smallest)",
|
|
977
|
+
},
|
|
978
|
+
} }, textContent));
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function PersistentRegion({ items, position, activeIndex, indexOffset, getItemProps, listRef, customRenderHeader, customRenderFooter, className, style, onAction, onInteractionPointerDown, }) {
|
|
982
|
+
if (!items || items.length === 0)
|
|
983
|
+
return null;
|
|
984
|
+
let navigableIndex = -1;
|
|
985
|
+
return (React__default.createElement("div", { className: className, style: style, "data-region": position, "data-testid": `ATL-Autocomplete-${position}` }, items.map(persistent => {
|
|
986
|
+
const result = handlePersistentRendering({
|
|
987
|
+
persistent,
|
|
988
|
+
position,
|
|
989
|
+
activeIndex,
|
|
990
|
+
indexOffset,
|
|
991
|
+
getItemProps,
|
|
992
|
+
customRenderHeader,
|
|
993
|
+
customRenderFooter,
|
|
994
|
+
listRef,
|
|
995
|
+
onAction,
|
|
996
|
+
onInteractionPointerDown,
|
|
997
|
+
navigableIndex,
|
|
998
|
+
});
|
|
999
|
+
navigableIndex = result.nextNavigableIndex;
|
|
1000
|
+
return result.node;
|
|
1001
|
+
})));
|
|
1002
|
+
}
|
|
1003
|
+
function handlePersistentRendering({ persistent, position, activeIndex, indexOffset, getItemProps, customRenderHeader, customRenderFooter, listRef, onAction, onInteractionPointerDown, navigableIndex, }) {
|
|
1004
|
+
const interactive = Boolean(persistent.onClick);
|
|
1005
|
+
if (!interactive) {
|
|
1006
|
+
const node = handleTextPersistentRendering({
|
|
1007
|
+
persistent,
|
|
1008
|
+
position,
|
|
1009
|
+
customRenderHeader,
|
|
1010
|
+
customRenderFooter,
|
|
1011
|
+
});
|
|
1012
|
+
return { node, nextNavigableIndex: navigableIndex };
|
|
1013
|
+
}
|
|
1014
|
+
return handleActionPersistentRendering({
|
|
1015
|
+
persistent,
|
|
1016
|
+
position,
|
|
1017
|
+
activeIndex,
|
|
1018
|
+
indexOffset,
|
|
1019
|
+
getItemProps,
|
|
1020
|
+
customRenderHeader,
|
|
1021
|
+
customRenderFooter,
|
|
1022
|
+
listRef,
|
|
1023
|
+
onAction,
|
|
1024
|
+
onInteractionPointerDown,
|
|
1025
|
+
navigableIndex,
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
function handleTextPersistentRendering({ persistent, position, customRenderHeader, customRenderFooter, }) {
|
|
1029
|
+
var _a;
|
|
1030
|
+
let content;
|
|
1031
|
+
if (position === "header" && customRenderHeader) {
|
|
1032
|
+
content = customRenderHeader({ value: persistent });
|
|
1033
|
+
}
|
|
1034
|
+
else if (position === "footer" && customRenderFooter) {
|
|
1035
|
+
content = customRenderFooter({ value: persistent });
|
|
1036
|
+
}
|
|
1037
|
+
else {
|
|
1038
|
+
content = React__default.createElement(DefaultTextPersistentContent, { persistent: persistent });
|
|
1039
|
+
}
|
|
1040
|
+
return (React__default.createElement("div", { key: `persistent-${position}-${String((_a = persistent.key) !== null && _a !== void 0 ? _a : persistent.label)}`, role: "presentation", tabIndex: -1, className: styles.textPersistent, onPointerDown: preventDefaultPointerDown }, content));
|
|
1041
|
+
}
|
|
1042
|
+
function handleActionPersistentRendering({ persistent, position, activeIndex, indexOffset, getItemProps, customRenderHeader, customRenderFooter, listRef, onAction, onInteractionPointerDown, navigableIndex, }) {
|
|
1043
|
+
var _a;
|
|
1044
|
+
const nextNavigableIndex = navigableIndex + 1;
|
|
1045
|
+
const isActive = activeIndex === indexOffset + nextNavigableIndex;
|
|
1046
|
+
let content;
|
|
1047
|
+
if (position === "header" && customRenderHeader) {
|
|
1048
|
+
content = customRenderHeader({
|
|
1049
|
+
value: persistent,
|
|
1050
|
+
isActive,
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
else if (position === "footer" && customRenderFooter) {
|
|
1054
|
+
content = customRenderFooter({
|
|
1055
|
+
value: persistent,
|
|
1056
|
+
isActive,
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
content = React__default.createElement(DefaultActionContent, { textContent: persistent.label });
|
|
1061
|
+
}
|
|
1062
|
+
return {
|
|
1063
|
+
node: (React__default.createElement("div", Object.assign({ key: `persistent-${position}-${String((_a = persistent.key) !== null && _a !== void 0 ? _a : persistent.label)}`, "data-index": indexOffset + nextNavigableIndex, id: `${position}-persistent-${indexOffset + nextNavigableIndex}`, "data-active": isActive ? true : undefined }, getItemProps({
|
|
1064
|
+
ref(persistNode) {
|
|
1065
|
+
const idx = indexOffset + nextNavigableIndex;
|
|
1066
|
+
if (persistNode)
|
|
1067
|
+
listRef.current[idx] = persistNode;
|
|
1068
|
+
},
|
|
1069
|
+
onClick: () => {
|
|
1070
|
+
onAction({
|
|
1071
|
+
run: () => {
|
|
1072
|
+
var _a;
|
|
1073
|
+
(_a = persistent.onClick) === null || _a === void 0 ? void 0 : _a.call(persistent);
|
|
1074
|
+
},
|
|
1075
|
+
closeOnRun: persistent.shouldClose,
|
|
1076
|
+
});
|
|
1077
|
+
},
|
|
1078
|
+
onPointerDown: onInteractionPointerDown,
|
|
1079
|
+
className: classnames(styles.action, isActive && styles.actionActive),
|
|
1080
|
+
}), { role: "button", tabIndex: -1 }), content)),
|
|
1081
|
+
nextNavigableIndex,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
function DefaultTextPersistentContent({ persistent, }) {
|
|
1085
|
+
return React__default.createElement("div", { className: styles.textPersistent }, persistent.label);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
const autocompleteMessages = defineMessages({
|
|
1089
|
+
"Remove {option}": {
|
|
1090
|
+
en: "Remove {option}",
|
|
1091
|
+
es: "Eliminar {option}",
|
|
1092
|
+
},
|
|
1093
|
+
noOptions: {
|
|
1094
|
+
en: "No options",
|
|
1095
|
+
es: "Sin opciones",
|
|
1096
|
+
},
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
function FloatingMenu({ context, getFloatingProps, refs, listboxId, className, floatingStyles, transitionStyles, menuStyle, renderable, persistentsHeaders, persistentsFooters, activeIndex, headerInteractiveCount, middleNavigableCount, getItemProps, listRef, onSelection, onAction, onInteractionPointerDown, getOptionLabel, isOptionSelected, loading, showEmptyStateMessage, emptyStateMessage, customRenderLoading, customRenderOption, customRenderSection, customRenderAction, customRenderHeader, customRenderFooter, slotOverrides, }) {
|
|
1100
|
+
var _a, _b, _c, _d;
|
|
1101
|
+
const activeIndexForMiddle = activeIndex != null ? activeIndex - headerInteractiveCount : null;
|
|
1102
|
+
return (React__default.createElement(ScopedPortal, null,
|
|
1103
|
+
React__default.createElement(FloatingFocusManager, { context: context, modal: false, initialFocus: -1, closeOnFocusOut: true, returnFocus: false },
|
|
1104
|
+
React__default.createElement("div", Object.assign({}, getFloatingProps({
|
|
1105
|
+
ref(node) {
|
|
1106
|
+
if (node)
|
|
1107
|
+
refs.setFloating(node);
|
|
1108
|
+
},
|
|
1109
|
+
id: listboxId,
|
|
1110
|
+
role: "listbox",
|
|
1111
|
+
className,
|
|
1112
|
+
style: Object.assign(Object.assign(Object.assign({}, floatingStyles), transitionStyles), menuStyle),
|
|
1113
|
+
})),
|
|
1114
|
+
React__default.createElement(PersistentRegion, { items: persistentsHeaders, position: "header", activeIndex: activeIndex, indexOffset: 0, listboxId: listboxId, getItemProps: getItemProps, listRef: listRef, customRenderHeader: customRenderHeader, customRenderFooter: customRenderFooter, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, className: classnames(styles.persistentHeader, (_a = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.header) === null || _a === void 0 ? void 0 : _a.className), style: (_b = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.header) === null || _b === void 0 ? void 0 : _b.style }),
|
|
1115
|
+
React__default.createElement("div", { className: styles.scrollRegion, onPointerDown: preventDefaultPointerDown, "data-testid": "ATL-Autocomplete-ScrollRegion" }, loading ? (customRenderLoading !== null && customRenderLoading !== void 0 ? customRenderLoading : React__default.createElement(LoadingContent, null)) : (React__default.createElement(React__default.Fragment, null,
|
|
1116
|
+
showEmptyStateMessage && (React__default.createElement(EmptyStateMessage, { emptyState: emptyStateMessage })),
|
|
1117
|
+
renderable.length > 0 && (React__default.createElement(MenuList, { items: renderable, activeIndex: activeIndexForMiddle, indexOffset: headerInteractiveCount, listboxId: listboxId, getItemProps: getItemProps, listRef: listRef, customRenderOption: customRenderOption, customRenderSection: customRenderSection, customRenderAction: customRenderAction, getOptionLabel: getOptionLabel, onSelect: onSelection, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, isOptionSelected: isOptionSelected, slotOverrides: slotOverrides }))))),
|
|
1118
|
+
React__default.createElement(PersistentRegion, { items: persistentsFooters, position: "footer", activeIndex: activeIndex, indexOffset: headerInteractiveCount + middleNavigableCount, listboxId: listboxId, getItemProps: getItemProps, listRef: listRef, customRenderHeader: customRenderHeader, customRenderFooter: customRenderFooter, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, className: classnames(styles.persistentFooter, (_c = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.footer) === null || _c === void 0 ? void 0 : _c.className), style: (_d = slotOverrides === null || slotOverrides === void 0 ? void 0 : slotOverrides.footer) === null || _d === void 0 ? void 0 : _d.style })))));
|
|
1119
|
+
}
|
|
1120
|
+
function LoadingContent() {
|
|
1121
|
+
return (React__default.createElement("div", { className: styles.loadingList, onPointerDown: preventDefaultPointerDown },
|
|
1122
|
+
React__default.createElement(Glimmer, { shape: "rectangle", size: "base" }),
|
|
1123
|
+
React__default.createElement(Glimmer, { shape: "rectangle", size: "base" }),
|
|
1124
|
+
React__default.createElement(Glimmer, { shape: "rectangle", size: "base" })));
|
|
1125
|
+
}
|
|
1126
|
+
function EmptyStateMessage({ emptyState, }) {
|
|
1127
|
+
const { t } = useComponentMessages(autocompleteMessages);
|
|
1128
|
+
const emptyStateContent = emptyState !== null && emptyState !== void 0 ? emptyState : t("noOptions");
|
|
1129
|
+
return (React__default.createElement("div", { className: styles.emptyStateMessage, onPointerDown: preventDefaultPointerDown }, emptyStateContent));
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
const Autocomplete = forwardRef(AutocompleteInternal);
|
|
1133
|
+
// eslint-disable-next-line max-statements
|
|
1134
|
+
function AutocompleteInternal(props, forwardedRef) {
|
|
1135
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
1136
|
+
const { inputValue, placeholder, disabled, error, invalid, description, size: sizeProp, loading = false, } = props;
|
|
1137
|
+
const formFieldRef = useRef(null);
|
|
1138
|
+
// Ref for the multi-select input element, where we cannot use refs.domReference
|
|
1139
|
+
// since it is not attached to the literal input element, whereas single + InputText only offers a
|
|
1140
|
+
// ref to the literal input element.
|
|
1141
|
+
const internalInputRef = useRef(null);
|
|
1142
|
+
const { renderable, optionCount, persistentsHeaders, persistentsFooters, headerInteractiveCount, middleNavigableCount, getOptionLabel, isOptionSelected, refs, floatingStyles, context, getReferenceProps, getFloatingProps, getItemProps, activeIndex, open, listRef, onSelection, onAction, onInteractionPointerDown, removeSelection, onInputChangeFromUser, onInputBlur, onInputFocus, onInputKeyDown, setReferenceElement, clearAll, } = useAutocomplete(props, internalInputRef);
|
|
1143
|
+
const listboxId = React__default.useId();
|
|
1144
|
+
// Provides mount/unmount-aware transition styles for the floating element
|
|
1145
|
+
const { isMounted, styles: transitionStyles } = useTransitionStyles(context, {
|
|
1146
|
+
initial: { opacity: 0 },
|
|
1147
|
+
open: { opacity: 1 },
|
|
1148
|
+
close: { opacity: 0 },
|
|
1149
|
+
duration: { open: tokens["timing-base"], close: tokens["timing-base"] },
|
|
1150
|
+
});
|
|
1151
|
+
const [positionRefEl, setPositionRefEl] = React__default.useState(null);
|
|
1152
|
+
const inputId = React__default.useId();
|
|
1153
|
+
const descriptionId = `descriptionUUID--${inputId}`;
|
|
1154
|
+
const selectedValues = props.multiple
|
|
1155
|
+
? ((_a = props.value) !== null && _a !== void 0 ? _a : EMPTY_SELECTED_VALUES)
|
|
1156
|
+
: EMPTY_SELECTED_VALUES;
|
|
1157
|
+
const { activeChipIndex, onKeyDown: chipKeyDown, onBlur: chipBlur, } = useChipNavigation({
|
|
1158
|
+
selectedValues,
|
|
1159
|
+
inputValue,
|
|
1160
|
+
readOnly: props.readOnly,
|
|
1161
|
+
removeSelection,
|
|
1162
|
+
onInputKeyDown,
|
|
1163
|
+
onInputBlur,
|
|
1164
|
+
});
|
|
1165
|
+
const focusInputOnPointerDown = useCallback((e) => {
|
|
1166
|
+
var _a;
|
|
1167
|
+
const target = e.target;
|
|
1168
|
+
if (target.closest("input, button"))
|
|
1169
|
+
return;
|
|
1170
|
+
e.preventDefault();
|
|
1171
|
+
(_a = internalInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1172
|
+
}, []);
|
|
1173
|
+
const composedReferenceProps = getReferenceProps(Object.assign({ onKeyDown: props.multiple ? chipKeyDown : onInputKeyDown, onFocus: onInputFocus, onBlur: props.multiple ? chipBlur : onInputBlur }, (props.multiple ? { onPointerDown: focusInputOnPointerDown } : {})));
|
|
1174
|
+
const dataAttrs = filterDataAttributes(props);
|
|
1175
|
+
const ariaProps = {
|
|
1176
|
+
role: "combobox",
|
|
1177
|
+
"aria-label": props["aria-label"],
|
|
1178
|
+
"aria-autocomplete": "list",
|
|
1179
|
+
"aria-expanded": open ? true : false,
|
|
1180
|
+
"aria-controls": listboxId,
|
|
1181
|
+
"aria-activedescendant": activeChipIndex === null && open && activeIndex != null
|
|
1182
|
+
? `${listboxId}-item-${activeIndex}`
|
|
1183
|
+
: undefined,
|
|
1184
|
+
};
|
|
1185
|
+
const inputProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ value: inputValue, onChange: props.readOnly ? undefined : onInputChangeFromUser }, (props.readOnly ? { onFocus: onInputFocus, onBlur: onInputBlur } : {})), { placeholder,
|
|
1186
|
+
disabled, readOnly: props.readOnly, error: error !== null && error !== void 0 ? error : undefined, name: props.name, invalid, clearable: props.clearable, autoComplete: "off", autoFocus: props.autoFocus, description, size: sizeProp ? sizeProp : undefined, prefix: props.prefix, suffix: props.suffix }), (props.readOnly ? {} : composedReferenceProps)), ariaProps), dataAttrs);
|
|
1187
|
+
const chipAreaRef = useCallback((node) => {
|
|
1188
|
+
if (!node)
|
|
1189
|
+
return;
|
|
1190
|
+
// In multiple mode, we use the input as the reference so floating-ui's
|
|
1191
|
+
// useListNavigation treats it as a typeable combobox and allows Space.
|
|
1192
|
+
// Only use chipArea for positioning/sizing.
|
|
1193
|
+
if (!props.multiple) {
|
|
1194
|
+
setReferenceElement(node);
|
|
1195
|
+
}
|
|
1196
|
+
const multiContainer = node.closest("[data-testid='ATL-Autocomplete-multiSelectContainer']");
|
|
1197
|
+
if (multiContainer) {
|
|
1198
|
+
setPositionRefEl(multiContainer);
|
|
1199
|
+
}
|
|
1200
|
+
}, [setReferenceElement, props.multiple]);
|
|
1201
|
+
const referenceInputRef = useCallback((node) => {
|
|
1202
|
+
setReferenceElement(node);
|
|
1203
|
+
if (!props.multiple) {
|
|
1204
|
+
// Workaround to get the visual InputText element, which is not the same
|
|
1205
|
+
// as the literal input reference element when props like suffix/prefix
|
|
1206
|
+
// are present. Used to set the position reference for the floating menu.
|
|
1207
|
+
const visualInputTextElement = node === null || node === void 0 ? void 0 : node.closest("[data-testid='Form-Field-Wrapper']");
|
|
1208
|
+
if (visualInputTextElement) {
|
|
1209
|
+
setPositionRefEl(visualInputTextElement);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}, [setReferenceElement, props.multiple]);
|
|
1213
|
+
const mergedInputRef = useMemo(() => mergeRefs([
|
|
1214
|
+
referenceInputRef,
|
|
1215
|
+
internalInputRef,
|
|
1216
|
+
forwardedRef,
|
|
1217
|
+
]), [referenceInputRef, forwardedRef]);
|
|
1218
|
+
useEffect(() => {
|
|
1219
|
+
if (!positionRefEl)
|
|
1220
|
+
return;
|
|
1221
|
+
refs.setPositionReference(positionRefEl);
|
|
1222
|
+
}, [positionRefEl, refs]);
|
|
1223
|
+
const menuClassName = classnames(styles.list, (_b = props.UNSAFE_className) === null || _b === void 0 ? void 0 : _b.menu);
|
|
1224
|
+
const showEmptyStateMessage = optionCount === 0 && props.emptyStateMessage !== false;
|
|
1225
|
+
const floatingMenu = isMounted && !props.readOnly && !disabled && (React__default.createElement(FloatingMenu, { context: context, getFloatingProps: getFloatingProps, refs: refs, listboxId: listboxId, className: menuClassName, floatingStyles: floatingStyles, transitionStyles: transitionStyles, menuStyle: (_c = props.UNSAFE_styles) === null || _c === void 0 ? void 0 : _c.menu, renderable: renderable, persistentsHeaders: persistentsHeaders, persistentsFooters: persistentsFooters, activeIndex: activeIndex, headerInteractiveCount: headerInteractiveCount, middleNavigableCount: middleNavigableCount, getItemProps: getItemProps, listRef: listRef, onSelection: onSelection, onAction: onAction, onInteractionPointerDown: onInteractionPointerDown, getOptionLabel: getOptionLabel, isOptionSelected: isOptionSelected, loading: loading, showEmptyStateMessage: showEmptyStateMessage, emptyStateMessage: props.emptyStateMessage, customRenderLoading: props.customRenderLoading, customRenderOption: props.customRenderOption, customRenderSection: props.customRenderSection, customRenderAction: props.customRenderAction, customRenderHeader: props.customRenderHeader, customRenderFooter: props.customRenderFooter, slotOverrides: {
|
|
1226
|
+
option: {
|
|
1227
|
+
className: (_d = props.UNSAFE_className) === null || _d === void 0 ? void 0 : _d.option,
|
|
1228
|
+
style: (_e = props.UNSAFE_styles) === null || _e === void 0 ? void 0 : _e.option,
|
|
1229
|
+
},
|
|
1230
|
+
action: {
|
|
1231
|
+
className: (_f = props.UNSAFE_className) === null || _f === void 0 ? void 0 : _f.action,
|
|
1232
|
+
style: (_g = props.UNSAFE_styles) === null || _g === void 0 ? void 0 : _g.action,
|
|
1233
|
+
},
|
|
1234
|
+
section: {
|
|
1235
|
+
className: (_h = props.UNSAFE_className) === null || _h === void 0 ? void 0 : _h.section,
|
|
1236
|
+
style: (_j = props.UNSAFE_styles) === null || _j === void 0 ? void 0 : _j.section,
|
|
1237
|
+
},
|
|
1238
|
+
header: {
|
|
1239
|
+
className: (_k = props.UNSAFE_className) === null || _k === void 0 ? void 0 : _k.header,
|
|
1240
|
+
style: (_l = props.UNSAFE_styles) === null || _l === void 0 ? void 0 : _l.header,
|
|
1241
|
+
},
|
|
1242
|
+
footer: {
|
|
1243
|
+
className: (_m = props.UNSAFE_className) === null || _m === void 0 ? void 0 : _m.footer,
|
|
1244
|
+
style: (_o = props.UNSAFE_styles) === null || _o === void 0 ? void 0 : _o.footer,
|
|
1245
|
+
},
|
|
1246
|
+
} }));
|
|
1247
|
+
if (props.customRenderInput) {
|
|
1248
|
+
return (React__default.createElement("div", { "data-testid": "ATL-Autocomplete" },
|
|
1249
|
+
props.customRenderInput({ inputRef: mergedInputRef, inputProps }),
|
|
1250
|
+
floatingMenu));
|
|
1251
|
+
}
|
|
1252
|
+
if (props.multiple) {
|
|
1253
|
+
return (React__default.createElement(MultipleSelectionLayout, { selectedValues: selectedValues, inputValue: inputValue, disabled: disabled, error: error, invalid: invalid, sizeProp: sizeProp, inputId: inputId, descriptionId: descriptionId, description: description, placeholder: placeholder, clearable: props.clearable, prefix: props.prefix, suffix: props.suffix, readOnly: props.readOnly, name: props.name, autoFocus: props.autoFocus, formFieldRef: formFieldRef, chipAreaRef: chipAreaRef, mergedInputRef: mergedInputRef, internalInputRef: internalInputRef, activeChipIndex: activeChipIndex, getOptionLabel: getOptionLabel, customRenderValue: props.customRenderValue, removeSelection: removeSelection, clearAll: clearAll, onInputChangeFromUser: onInputChangeFromUser, chipAreaEventProps: props.readOnly
|
|
1254
|
+
? { onFocus: onInputFocus, onBlur: chipBlur }
|
|
1255
|
+
: composedReferenceProps, inputAriaProps: ariaProps, inputDataAttrs: dataAttrs, limitVisibleSelections: props.limitVisibleSelections, limitSelectionText: props.limitSelectionText, unsafeClassName: (_p = props.UNSAFE_className) === null || _p === void 0 ? void 0 : _p.selection, unsafeStyle: (_q = props.UNSAFE_styles) === null || _q === void 0 ? void 0 : _q.selection }, floatingMenu));
|
|
1256
|
+
}
|
|
1257
|
+
return (React__default.createElement("div", { "data-testid": "ATL-Autocomplete" },
|
|
1258
|
+
React__default.createElement(InputText, Object.assign({ ref: mergedInputRef }, inputProps)),
|
|
1259
|
+
floatingMenu));
|
|
1260
|
+
}
|
|
1261
|
+
function SelectionChip({ value, active, disabled, getOptionLabel, customRenderValue, canDismiss, onDismiss, unsafeClassName, unsafeStyle, }) {
|
|
1262
|
+
const { t } = useComponentMessages(autocompleteMessages);
|
|
1263
|
+
return (React__default.createElement("span", { "data-selection-disabled": disabled, className: classnames(styles.selectionChip, {
|
|
1264
|
+
[styles.selectionChipActive]: active,
|
|
1265
|
+
[styles.selectionChipDisabled]: disabled,
|
|
1266
|
+
}, unsafeClassName), style: unsafeStyle, "data-testid": "ATL-Autocomplete-chip", onPointerDown: preventDefaultPointerDown },
|
|
1267
|
+
customRenderValue ? (customRenderValue({ value, getOptionLabel })) : (React__default.createElement(Typography, { size: "small" }, getOptionLabel(value))),
|
|
1268
|
+
canDismiss && (React__default.createElement("button", { type: "button", disabled: disabled, className: styles.chipDismiss, onClick: onDismiss, onPointerDown: preventDefaultPointerDown, "aria-label": t("Remove {option}", { option: getOptionLabel(value) }), tabIndex: -1 },
|
|
1269
|
+
React__default.createElement(Icon, { size: "small", name: "cross" })))));
|
|
1270
|
+
}
|
|
1271
|
+
function SelectionChipsList({ selectedValues, isFocused, limitVisibleSelections = 6, limitSelectionText = (count) => `+${count}`, activeChipIndex, disabled, getOptionLabel, customRenderValue, canDismiss, removeSelection, unsafeClassName, unsafeStyle, }) {
|
|
1272
|
+
const shouldLimit = !isFocused &&
|
|
1273
|
+
limitVisibleSelections !== -1 &&
|
|
1274
|
+
selectedValues.length > limitVisibleSelections;
|
|
1275
|
+
const visibleValues = shouldLimit
|
|
1276
|
+
? selectedValues.slice(0, limitVisibleSelections)
|
|
1277
|
+
: selectedValues;
|
|
1278
|
+
const hiddenCount = shouldLimit
|
|
1279
|
+
? selectedValues.length - limitVisibleSelections
|
|
1280
|
+
: 0;
|
|
1281
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
1282
|
+
visibleValues.map((v, i) => {
|
|
1283
|
+
var _a;
|
|
1284
|
+
return (React__default.createElement(SelectionChip, { key: (_a = v.key) !== null && _a !== void 0 ? _a : getOptionLabel(v), value: v, active: activeChipIndex === i, disabled: disabled, getOptionLabel: getOptionLabel, customRenderValue: customRenderValue, canDismiss: canDismiss, onDismiss: () => removeSelection(v), unsafeClassName: unsafeClassName, unsafeStyle: unsafeStyle }));
|
|
1285
|
+
}),
|
|
1286
|
+
hiddenCount > 0 && (React__default.createElement("span", { className: styles.limitText, "data-testid": "ATL-Autocomplete-limitText" },
|
|
1287
|
+
React__default.createElement(Typography, { size: "small", element: "span" }, limitSelectionText(hiddenCount))))));
|
|
1288
|
+
}
|
|
1289
|
+
function MultipleSelectionLayout({ selectedValues, inputValue, disabled, error, invalid, sizeProp, inputId, descriptionId, description, placeholder, clearable, prefix, suffix, readOnly, name, autoFocus, formFieldRef, chipAreaRef, mergedInputRef, internalInputRef, activeChipIndex, getOptionLabel, customRenderValue, removeSelection, clearAll, onInputChangeFromUser, chipAreaEventProps, inputAriaProps, inputDataAttrs, limitVisibleSelections, limitSelectionText, unsafeClassName, unsafeStyle, children, }) {
|
|
1290
|
+
var _a;
|
|
1291
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
1292
|
+
const hasValue = selectedValues.length > 0 || inputValue;
|
|
1293
|
+
const canDismissChip = !disabled && !readOnly;
|
|
1294
|
+
const handleFocusIn = useCallback(() => {
|
|
1295
|
+
setIsFocused(true);
|
|
1296
|
+
}, []);
|
|
1297
|
+
const handleFocusOut = useCallback((e) => {
|
|
1298
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
1299
|
+
setIsFocused(false);
|
|
1300
|
+
}
|
|
1301
|
+
}, []);
|
|
1302
|
+
return (React__default.createElement("div", { "data-testid": "ATL-Autocomplete", onFocus: handleFocusIn, onBlur: handleFocusOut },
|
|
1303
|
+
React__default.createElement("div", { className: styles.multiSelectField, "data-testid": "ATL-Autocomplete-multiSelectContainer" },
|
|
1304
|
+
React__default.createElement(FormFieldWrapper, { disabled: disabled, size: sizeProp ? sizeProp : undefined, error: (_a = error) !== null && _a !== void 0 ? _a : "", invalid: Boolean(error || invalid), identifier: inputId, descriptionIdentifier: descriptionId, description: description, clearable: clearable !== null && clearable !== void 0 ? clearable : "never", onClear: () => {
|
|
1305
|
+
var _a;
|
|
1306
|
+
clearAll();
|
|
1307
|
+
(_a = internalInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1308
|
+
}, type: "text", placeholder: placeholder, value: hasValue ? "has-value" : "", prefix: prefix, suffix: suffix, wrapperRef: formFieldRef },
|
|
1309
|
+
React__default.createElement("div", Object.assign({ ref: chipAreaRef, className: styles.chipArea, "data-testid": "ATL-Autocomplete-chipArea" }, chipAreaEventProps),
|
|
1310
|
+
React__default.createElement(SelectionChipsList, { selectedValues: selectedValues, isFocused: isFocused, limitVisibleSelections: limitVisibleSelections, limitSelectionText: limitSelectionText, activeChipIndex: activeChipIndex, disabled: disabled, getOptionLabel: getOptionLabel, customRenderValue: customRenderValue, canDismiss: canDismissChip, removeSelection: removeSelection, unsafeClassName: unsafeClassName, unsafeStyle: unsafeStyle }),
|
|
1311
|
+
React__default.createElement("input", Object.assign({ ref: mergedInputRef, className: styles.inlineInput, id: inputId, value: inputValue, onChange: readOnly
|
|
1312
|
+
? undefined
|
|
1313
|
+
: e => onInputChangeFromUser(e.target.value), disabled: disabled, readOnly: readOnly, name: name, autoComplete: "off", autoFocus: autoFocus }, inputAriaProps, inputDataAttrs))))),
|
|
1314
|
+
children));
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
export { Autocomplete as A };
|
|
1318
|
+
|
|
1319
|
+
function ScopedPortal({children}) {
|
|
1320
|
+
return React__default.createElement(FloatingPortal, null,
|
|
1321
|
+
React__default.createElement(ThemeBoundary, null, children));
|
|
1322
|
+
}
|