@dbcdk/react-components 0.0.102 → 0.0.104
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/dist/assets/logo.cjs +87 -0
- package/dist/assets/logo.js +85 -0
- package/dist/client.cjs +587 -0
- package/dist/client.d.ts +83 -0
- package/dist/client.js +84 -0
- package/dist/components/accordion/Accordion.cjs +103 -0
- package/dist/components/accordion/Accordion.js +97 -0
- package/dist/components/accordion/Accordion.module.css +41 -0
- package/dist/components/accordion/components/AccordionRow.cjs +115 -0
- package/dist/components/accordion/components/AccordionRow.js +109 -0
- package/dist/components/accordion/components/AccordionRow.module.css +99 -0
- package/dist/components/alert/Alert.cjs +52 -0
- package/dist/components/alert/Alert.d.ts +2 -1
- package/dist/components/alert/Alert.js +46 -0
- package/dist/components/alert/Alert.module.css +97 -0
- package/dist/components/app-header/AppHeader.cjs +14 -0
- package/dist/components/app-header/AppHeader.js +8 -0
- package/dist/components/app-header/AppHeader.module.css +74 -0
- package/dist/components/attribute-chip/AttributeChip.cjs +22 -0
- package/dist/components/attribute-chip/AttributeChip.js +16 -0
- package/dist/components/attribute-chip/AttributeChip.module.css +65 -0
- package/dist/components/avatar/Avatar.cjs +111 -0
- package/dist/components/avatar/Avatar.js +86 -0
- package/dist/components/avatar/Avatar.module.css +91 -0
- package/dist/components/breadcrumbs/Breadcrumbs.cjs +24 -0
- package/dist/components/breadcrumbs/Breadcrumbs.js +18 -0
- package/dist/components/breadcrumbs/Breadcrumbs.module.css +80 -0
- package/dist/components/button/Button.cjs +149 -0
- package/dist/components/button/Button.js +124 -0
- package/dist/components/button/Button.module.css +260 -0
- package/dist/components/button-select/ButtonSelect.cjs +35 -0
- package/dist/components/button-select/ButtonSelect.js +29 -0
- package/dist/components/button-select/ButtonSelect.module.css +40 -0
- package/dist/components/card/Card.cjs +112 -0
- package/dist/components/card/Card.d.ts +2 -1
- package/dist/components/card/Card.js +106 -0
- package/dist/components/card/Card.module.css +187 -0
- package/dist/components/card/components/CardMeta.cjs +62 -0
- package/dist/components/card/components/CardMeta.js +55 -0
- package/dist/components/card/components/CardMeta.module.css +55 -0
- package/dist/components/card-container/CardContainer.cjs +34 -0
- package/dist/components/card-container/CardContainer.js +28 -0
- package/dist/components/card-container/CardContainer.module.css +63 -0
- package/dist/components/chip/Chip.cjs +65 -0
- package/dist/components/chip/Chip.js +59 -0
- package/dist/components/chip/Chip.module.css +236 -0
- package/dist/components/circle/Circle.cjs +33 -0
- package/dist/components/circle/Circle.js +27 -0
- package/dist/components/circle/Circle.module.css +128 -0
- package/dist/components/clear-button/ClearButton.cjs +33 -0
- package/dist/components/clear-button/ClearButton.d.ts +2 -1
- package/dist/components/clear-button/ClearButton.js +27 -0
- package/dist/components/clear-button/ClearButton.module.css +26 -0
- package/dist/components/code-block/CodeBlock.cjs +97 -0
- package/dist/components/code-block/CodeBlock.js +91 -0
- package/dist/components/code-block/CodeBlock.module.css +124 -0
- package/dist/components/copy-button/CopyButton.cjs +139 -0
- package/dist/components/copy-button/CopyButton.js +133 -0
- package/dist/components/copy-button/CopyButton.module.css +22 -0
- package/dist/components/datetime-picker/DateTimePicker.cjs +559 -0
- package/dist/components/datetime-picker/DateTimePicker.js +553 -0
- package/dist/components/datetime-picker/DateTimePicker.module.css +155 -0
- package/dist/components/datetime-picker/dateTimeHelpers.cjs +179 -0
- package/dist/components/datetime-picker/dateTimeHelpers.js +160 -0
- package/dist/components/divider/Divider.cjs +22 -0
- package/dist/components/divider/Divider.js +20 -0
- package/dist/components/filter-field/FilterField.cjs +296 -0
- package/dist/components/filter-field/FilterField.js +289 -0
- package/dist/components/filter-field/FilterField.module.css +379 -0
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.cjs +115 -0
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.js +108 -0
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.module.css +59 -0
- package/dist/components/forms/checkbox/Checkbox.cjs +88 -0
- package/dist/components/forms/checkbox/Checkbox.js +82 -0
- package/dist/components/forms/checkbox/Checkbox.module.css +104 -0
- package/dist/components/forms/checkbox-group/CheckboxGroup.cjs +121 -0
- package/dist/components/forms/checkbox-group/CheckboxGroup.js +115 -0
- package/dist/components/forms/checkbox-group/CheckboxGroup.module.css +115 -0
- package/dist/components/forms/form-select/FormSelect.cjs +191 -0
- package/dist/components/forms/form-select/FormSelect.js +166 -0
- package/dist/components/forms/form-select/FormSelect.module.css +236 -0
- package/dist/components/forms/input/Input.cjs +188 -0
- package/dist/components/forms/input/Input.d.ts +1 -0
- package/dist/components/forms/input/Input.js +182 -0
- package/dist/components/forms/input/Input.module.css +468 -0
- package/dist/components/forms/input-container/InputContainer.cjs +72 -0
- package/dist/components/forms/input-container/InputContainer.js +66 -0
- package/dist/components/forms/input-container/InputContainer.module.css +59 -0
- package/dist/components/forms/multi-select/MultiSelect.cjs +227 -0
- package/dist/components/forms/multi-select/MultiSelect.js +225 -0
- package/dist/components/forms/radio-buttons/RadioButton.cjs +91 -0
- package/dist/components/forms/radio-buttons/RadioButton.js +85 -0
- package/dist/components/forms/radio-buttons/RadioButtonGroup.cjs +74 -0
- package/dist/components/forms/radio-buttons/RadioButtonGroup.js +72 -0
- package/dist/components/forms/radio-buttons/RadioButtons.module.css +118 -0
- package/dist/components/forms/select/Select.cjs +286 -0
- package/dist/components/forms/select/Select.js +280 -0
- package/dist/components/forms/select/Select.module.css +32 -0
- package/dist/components/forms/text-area/Textarea.cjs +116 -0
- package/dist/components/forms/text-area/Textarea.js +110 -0
- package/dist/components/forms/text-area/Textarea.module.css +70 -0
- package/dist/components/forms/typeahead/Typeahead.cjs +792 -0
- package/dist/components/forms/typeahead/Typeahead.js +768 -0
- package/dist/components/forms/typeahead/Typeahead.module.css +38 -0
- package/dist/components/grid/Grid.cjs +45 -0
- package/dist/components/grid/Grid.js +38 -0
- package/dist/components/grid/Grid.module.css +35 -0
- package/dist/components/headline/CollapsibleHeadline.cjs +80 -0
- package/dist/components/headline/CollapsibleHeadline.js +74 -0
- package/dist/components/headline/Headline.cjs +59 -0
- package/dist/components/headline/Headline.js +53 -0
- package/dist/components/headline/Headline.module.css +185 -0
- package/dist/components/hyperlink/Hyperlink.cjs +107 -0
- package/dist/components/hyperlink/Hyperlink.d.ts +1 -0
- package/dist/components/hyperlink/Hyperlink.js +82 -0
- package/dist/components/hyperlink/Hyperlink.module.css +121 -0
- package/dist/components/icon/Icon.cjs +27 -0
- package/dist/components/icon/Icon.js +20 -0
- package/dist/components/icon/Icon.module.css +36 -0
- package/dist/components/inline-status/InlineStatus.cjs +39 -0
- package/dist/components/inline-status/InlineStatus.js +33 -0
- package/dist/components/inline-status/InlineStatus.module.css +92 -0
- package/dist/components/interval-select/IntervalSelect.cjs +203 -0
- package/dist/components/interval-select/IntervalSelect.js +201 -0
- package/dist/components/json-viewer/HighlightedText.cjs +13 -0
- package/dist/components/json-viewer/HighlightedText.js +11 -0
- package/dist/components/json-viewer/JsonNode.cjs +124 -0
- package/dist/components/json-viewer/JsonNode.js +118 -0
- package/dist/components/json-viewer/JsonViewer.cjs +164 -0
- package/dist/components/json-viewer/JsonViewer.js +158 -0
- package/dist/components/json-viewer/JsonViewer.module.css +346 -0
- package/dist/components/json-viewer/types.cjs +2 -0
- package/dist/components/json-viewer/types.js +1 -0
- package/dist/components/json-viewer/useClipboardStatus.cjs +15 -0
- package/dist/components/json-viewer/useClipboardStatus.js +13 -0
- package/dist/components/json-viewer/utils.cjs +126 -0
- package/dist/components/json-viewer/utils.js +111 -0
- package/dist/components/media-card/MediaCard.cjs +60 -0
- package/dist/components/media-card/MediaCard.d.ts +19 -0
- package/dist/components/media-card/MediaCard.js +54 -0
- package/dist/components/media-card/MediaCard.module.css +92 -0
- package/dist/components/menu/Menu.cjs +287 -0
- package/dist/components/menu/Menu.js +262 -0
- package/dist/components/menu/Menu.module.css +220 -0
- package/dist/components/meta-bar/MetaBar.cjs +28 -0
- package/dist/components/meta-bar/MetaBar.js +22 -0
- package/dist/components/meta-bar/MetaBar.module.css +27 -0
- package/dist/components/nav-bar/NavBar.cjs +95 -0
- package/dist/components/nav-bar/NavBar.d.ts +1 -1
- package/dist/components/nav-bar/NavBar.js +89 -0
- package/dist/components/nav-bar/NavBar.module.css +225 -0
- package/dist/components/overlay/fade-overlay/FadeOverlay.cjs +30 -0
- package/dist/components/overlay/fade-overlay/FadeOverlay.js +24 -0
- package/dist/components/overlay/fade-overlay/FadeOverlay.module.css +54 -0
- package/dist/components/overlay/modal/Modal.cjs +189 -0
- package/dist/components/overlay/modal/Modal.d.ts +2 -1
- package/dist/components/overlay/modal/Modal.js +183 -0
- package/dist/components/overlay/modal/Modal.module.css +112 -0
- package/dist/components/overlay/modal/provider/ModalProvider.cjs +98 -0
- package/dist/components/overlay/modal/provider/ModalProvider.js +95 -0
- package/dist/components/overlay/side-panel/SidePanel.cjs +173 -0
- package/dist/components/overlay/side-panel/SidePanel.js +167 -0
- package/dist/components/overlay/side-panel/SidePanel.module.css +177 -0
- package/dist/components/overlay/side-panel/useSidePanel.cjs +16 -0
- package/dist/components/overlay/side-panel/useSidePanel.js +14 -0
- package/dist/components/overlay/tooltip/Tooltip.cjs +34 -0
- package/dist/components/overlay/tooltip/Tooltip.js +32 -0
- package/dist/components/overlay/tooltip/Tooltip.module.css +104 -0
- package/dist/components/overlay/tooltip/TooltipProvider.cjs +238 -0
- package/dist/components/overlay/tooltip/TooltipProvider.js +231 -0
- package/dist/components/overlay/tooltip/useTooltipTrigger.cjs +117 -0
- package/dist/components/overlay/tooltip/useTooltipTrigger.js +115 -0
- package/dist/components/page/Page.cjs +63 -0
- package/dist/components/page/Page.js +57 -0
- package/dist/components/page/Page.module.css +95 -0
- package/dist/components/page-layout/PageLayout.cjs +97 -0
- package/dist/components/page-layout/PageLayout.d.ts +0 -5
- package/dist/components/page-layout/PageLayout.js +91 -0
- package/dist/components/page-layout/PageLayout.module.css +236 -0
- package/dist/components/page-layout/components/footer/Footer.cjs +53 -0
- package/dist/components/page-layout/components/footer/Footer.js +47 -0
- package/dist/components/page-layout/components/footer/Footer.module.css +89 -0
- package/dist/components/pagination/Pagination.cjs +160 -0
- package/dist/components/pagination/Pagination.js +154 -0
- package/dist/components/pagination/Pagination.module.css +25 -0
- package/dist/components/panel/Panel.cjs +38 -0
- package/dist/components/panel/Panel.js +32 -0
- package/dist/components/panel/Panel.module.css +30 -0
- package/dist/components/popover/Popover.cjs +331 -0
- package/dist/components/popover/Popover.js +307 -0
- package/dist/components/popover/Popover.module.css +52 -0
- package/dist/components/search-box/SearchBox.cjs +274 -0
- package/dist/components/search-box/SearchBox.js +268 -0
- package/dist/components/search-box/SearchBox.module.css +27 -0
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.cjs +127 -0
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +121 -0
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +174 -0
- package/dist/components/sidebar/Sidebar.cjs +39 -0
- package/dist/components/sidebar/Sidebar.js +37 -0
- package/dist/components/sidebar/components/SidebarItem.cjs +29 -0
- package/dist/components/sidebar/components/SidebarItem.js +27 -0
- package/dist/components/sidebar/components/SidebarItem.module.css +0 -0
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +133 -0
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +127 -0
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +29 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.cjs +214 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +207 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +260 -0
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.cjs +54 -0
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +47 -0
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +106 -0
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.cjs +61 -0
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +55 -0
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.module.css +20 -0
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.cjs +97 -0
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +91 -0
- package/dist/components/sidebar/providers/SidebarProvider.cjs +223 -0
- package/dist/components/sidebar/providers/SidebarProvider.js +220 -0
- package/dist/components/skeleton-loader/SkeletonLoader.cjs +442 -0
- package/dist/components/skeleton-loader/SkeletonLoader.js +440 -0
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.cjs +42 -0
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +36 -0
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +51 -0
- package/dist/components/split-button/SplitButton.cjs +46 -0
- package/dist/components/split-button/SplitButton.js +40 -0
- package/dist/components/split-button/SplitButton.module.css +32 -0
- package/dist/components/split-pane/SplitPane.cjs +177 -0
- package/dist/components/split-pane/SplitPane.js +168 -0
- package/dist/components/split-pane/SplitPane.module.css +111 -0
- package/dist/components/split-pane/provider/SplitPaneContext.cjs +129 -0
- package/dist/components/split-pane/provider/SplitPaneContext.js +121 -0
- package/dist/components/stack/Stack.cjs +47 -0
- package/dist/components/stack/Stack.d.ts +1 -1
- package/dist/components/stack/Stack.js +41 -0
- package/dist/components/stack/Stack.module.css +61 -0
- package/dist/components/state-page/StatePage.cjs +48 -0
- package/dist/components/state-page/StatePage.js +42 -0
- package/dist/components/state-page/StatePage.module.css +9 -0
- package/dist/components/state-page/empty.cjs +664 -0
- package/dist/components/state-page/empty.js +662 -0
- package/dist/components/state-page/error.cjs +310 -0
- package/dist/components/state-page/error.js +308 -0
- package/dist/components/state-page/notFound.cjs +243 -0
- package/dist/components/state-page/notFound.js +241 -0
- package/dist/components/sticky-footer-layout/StickyFooterLayout.cjs +98 -0
- package/dist/components/sticky-footer-layout/StickyFooterLayout.js +96 -0
- package/dist/components/table/Table.cjs +216 -0
- package/dist/components/table/Table.js +210 -0
- package/dist/components/table/Table.module.css +534 -0
- package/dist/components/table/Table.types.cjs +2 -0
- package/dist/components/table/Table.types.js +1 -0
- package/dist/components/table/TanstackTable.cjs +172 -0
- package/dist/components/table/TanstackTable.js +147 -0
- package/dist/components/table/components/TableBody.cjs +50 -0
- package/dist/components/table/components/TableBody.js +44 -0
- package/dist/components/table/components/TableHeader.cjs +56 -0
- package/dist/components/table/components/TableHeader.js +50 -0
- package/dist/components/table/components/TableHeaderCell.cjs +69 -0
- package/dist/components/table/components/TableHeaderCell.js +63 -0
- package/dist/components/table/components/TableLoadingBody.cjs +35 -0
- package/dist/components/table/components/TableLoadingBody.js +29 -0
- package/dist/components/table/components/TablePagination.cjs +2 -0
- package/dist/components/table/components/TablePagination.js +1 -0
- package/dist/components/table/components/TableRow.cjs +151 -0
- package/dist/components/table/components/TableRow.js +145 -0
- package/dist/components/table/components/TableSelectionCell.cjs +41 -0
- package/dist/components/table/components/TableSelectionCell.js +35 -0
- package/dist/components/table/components/column-resizer/ColumnResizer.cjs +25 -0
- package/dist/components/table/components/column-resizer/ColumnResizer.js +19 -0
- package/dist/components/table/components/column-resizer/ColumnResizer.module.css +22 -0
- package/dist/components/table/components/empty-state/EmptyState.cjs +33 -0
- package/dist/components/table/components/empty-state/EmptyState.js +31 -0
- package/dist/components/table/components/empty-state/EmptyState.module.css +4 -0
- package/dist/components/table/components/table-settings/TableSettings.cjs +139 -0
- package/dist/components/table/components/table-settings/TableSettings.js +137 -0
- package/dist/components/table/hooks/useTableRowInteractions.cjs +46 -0
- package/dist/components/table/hooks/useTableRowInteractions.js +44 -0
- package/dist/components/table/table.classes.cjs +49 -0
- package/dist/components/table/table.classes.js +40 -0
- package/dist/components/table/table.utils.cjs +57 -0
- package/dist/components/table/table.utils.js +45 -0
- package/dist/components/table/tanstackTable.utils.cjs +166 -0
- package/dist/components/table/tanstackTable.utils.js +159 -0
- package/dist/components/tabs/Tabs.cjs +172 -0
- package/dist/components/tabs/Tabs.js +166 -0
- package/dist/components/tabs/Tabs.module.css +261 -0
- package/dist/components/theme-button/ThemeButton.cjs +78 -0
- package/dist/components/theme-button/ThemeButton.js +75 -0
- package/dist/components/toast/Toast.cjs +68 -0
- package/dist/components/toast/Toast.js +62 -0
- package/dist/components/toast/Toast.module.css +161 -0
- package/dist/components/toast/provider/ToastProvider.cjs +105 -0
- package/dist/components/toast/provider/ToastProvider.js +97 -0
- package/dist/components/user-display/UserDisplay.cjs +22 -0
- package/dist/components/user-display/UserDisplay.js +16 -0
- package/dist/components/user-display/UserDisplay.module.css +25 -0
- package/dist/constants/chart-colors.cjs +10 -0
- package/dist/constants/chart-colors.js +8 -0
- package/dist/constants/chart-colors.types.cjs +2 -0
- package/dist/constants/chart-colors.types.js +1 -0
- package/dist/constants/severity.cjs +30 -0
- package/dist/constants/severity.js +26 -0
- package/dist/constants/severity.types.cjs +2 -0
- package/dist/constants/severity.types.js +1 -0
- package/dist/constants/sizes.cjs +11 -0
- package/dist/constants/sizes.js +9 -0
- package/dist/hooks/useDeviceSize.cjs +35 -0
- package/dist/hooks/useDeviceSize.js +33 -0
- package/dist/hooks/useListNavigation.cjs +237 -0
- package/dist/hooks/useListNavigation.js +235 -0
- package/dist/hooks/usePagination.cjs +144 -0
- package/dist/hooks/usePagination.js +142 -0
- package/dist/hooks/useSorting.cjs +119 -0
- package/dist/hooks/useSorting.js +117 -0
- package/dist/hooks/useTableData.cjs +53 -0
- package/dist/hooks/useTableData.js +51 -0
- package/dist/hooks/useTableSelection.cjs +172 -0
- package/dist/hooks/useTableSelection.js +170 -0
- package/dist/hooks/useTableSettings.cjs +90 -0
- package/dist/hooks/useTableSettings.js +87 -0
- package/dist/hooks/useTheme.cjs +64 -0
- package/dist/hooks/useTheme.js +62 -0
- package/dist/hooks/useTimeDuration.cjs +72 -0
- package/dist/hooks/useTimeDuration.js +70 -0
- package/dist/hooks/useViewportFill.cjs +82 -0
- package/dist/hooks/useViewportFill.js +80 -0
- package/dist/index.cjs +161 -12901
- package/dist/index.css +67 -7228
- package/dist/index.d.ts +0 -58
- package/dist/index.js +24 -12802
- package/dist/styles/animation.cjs +9 -0
- package/dist/styles/animation.js +7 -0
- package/dist/styles/themes/dbc/colors.css +5 -0
- package/dist/styles/themes/types.cjs +2 -0
- package/dist/styles/themes/types.js +1 -0
- package/dist/tanstack.cjs +18 -2652
- package/dist/tanstack.js +3 -2636
- package/dist/types/a11y-props.types.cjs +2 -0
- package/dist/types/a11y-props.types.js +1 -0
- package/dist/types/assets.d.cjs +2 -0
- package/dist/types/assets.d.js +1 -0
- package/dist/types/css.d.cjs +2 -0
- package/dist/types/css.d.js +1 -0
- package/dist/types/sizes.types.cjs +2 -0
- package/dist/types/sizes.types.js +1 -0
- package/dist/utils/arrays/nested-filtering.cjs +40 -0
- package/dist/utils/arrays/nested-filtering.js +38 -0
- package/dist/utils/date/formatDate.cjs +35 -0
- package/dist/utils/date/formatDate.js +33 -0
- package/dist/utils/localStorage.utils.cjs +53 -0
- package/dist/utils/localStorage.utils.js +49 -0
- package/dist/utils/text/get-highlighted-segments.cjs +49 -0
- package/dist/utils/text/get-highlighted-segments.js +47 -0
- package/package.json +8 -3
- package/dist/tanstack.css +0 -1271
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useRef, useId, useMemo, useState, useLayoutEffect, useEffect } from 'react';
|
|
5
|
+
import { Chip } from '../../../components/chip/Chip';
|
|
6
|
+
import { Input } from '../../../components/forms/input/Input';
|
|
7
|
+
import { Menu } from '../../../components/menu/Menu';
|
|
8
|
+
import { Popover } from '../../../components/popover/Popover';
|
|
9
|
+
import styles from './Typeahead.module.css';
|
|
10
|
+
|
|
11
|
+
function parseLengthToPx(value, referenceFontSize = 16) {
|
|
12
|
+
if (!value) return 0;
|
|
13
|
+
const trimmed = value.trim();
|
|
14
|
+
if (!trimmed) return 0;
|
|
15
|
+
if (trimmed.endsWith("px")) {
|
|
16
|
+
const n2 = Number.parseFloat(trimmed);
|
|
17
|
+
return Number.isFinite(n2) ? n2 : 0;
|
|
18
|
+
}
|
|
19
|
+
if (trimmed.endsWith("rem")) {
|
|
20
|
+
const n2 = Number.parseFloat(trimmed);
|
|
21
|
+
if (!Number.isFinite(n2)) return 0;
|
|
22
|
+
const rootFont = Number.parseFloat(getComputedStyle(document.documentElement).fontSize || "16");
|
|
23
|
+
return n2 * (Number.isFinite(rootFont) ? rootFont : 16);
|
|
24
|
+
}
|
|
25
|
+
if (trimmed.endsWith("em")) {
|
|
26
|
+
const n2 = Number.parseFloat(trimmed);
|
|
27
|
+
return Number.isFinite(n2) ? n2 * referenceFontSize : 0;
|
|
28
|
+
}
|
|
29
|
+
const n = Number.parseFloat(trimmed);
|
|
30
|
+
return Number.isFinite(n) ? n : 0;
|
|
31
|
+
}
|
|
32
|
+
function getOuterWidthWithMargins(element) {
|
|
33
|
+
if (!(element instanceof HTMLElement)) return 0;
|
|
34
|
+
const rect = element.getBoundingClientRect();
|
|
35
|
+
const styles2 = window.getComputedStyle(element);
|
|
36
|
+
const marginLeft = Number.parseFloat(styles2.marginLeft || "0");
|
|
37
|
+
const marginRight = Number.parseFloat(styles2.marginRight || "0");
|
|
38
|
+
return Math.ceil(rect.width + marginLeft + marginRight);
|
|
39
|
+
}
|
|
40
|
+
function getInputFontShorthand(inputStyles) {
|
|
41
|
+
return inputStyles.font || [
|
|
42
|
+
inputStyles.fontStyle,
|
|
43
|
+
inputStyles.fontVariant,
|
|
44
|
+
inputStyles.fontWeight,
|
|
45
|
+
inputStyles.fontStretch,
|
|
46
|
+
inputStyles.fontSize,
|
|
47
|
+
inputStyles.lineHeight !== "normal" ? `/${inputStyles.lineHeight}` : "",
|
|
48
|
+
inputStyles.fontFamily
|
|
49
|
+
].filter(Boolean).join(" ");
|
|
50
|
+
}
|
|
51
|
+
function measureFitContentWidth(input, text, minWidth) {
|
|
52
|
+
const field = input.closest('[data-forminput="field"]');
|
|
53
|
+
if (!field) return null;
|
|
54
|
+
const inputStyles = window.getComputedStyle(input);
|
|
55
|
+
const fieldStyles = window.getComputedStyle(field);
|
|
56
|
+
const canvas = document.createElement("canvas");
|
|
57
|
+
const ctx = canvas.getContext("2d");
|
|
58
|
+
if (!ctx) return null;
|
|
59
|
+
ctx.font = getInputFontShorthand(inputStyles);
|
|
60
|
+
const textWidth = Math.ceil(ctx.measureText(text).width);
|
|
61
|
+
const inputFontSize = Number.parseFloat(inputStyles.fontSize || "16");
|
|
62
|
+
const inputPaddingLeft = Number.parseFloat(inputStyles.paddingLeft || "0");
|
|
63
|
+
const inputPaddingRight = Number.parseFloat(inputStyles.paddingRight || "0");
|
|
64
|
+
const borderLeft = Number.parseFloat(fieldStyles.borderLeftWidth || "0");
|
|
65
|
+
const borderRight = Number.parseFloat(fieldStyles.borderRightWidth || "0");
|
|
66
|
+
const startAdornmentWidth = getOuterWidthWithMargins(
|
|
67
|
+
field.querySelector('[data-input-role="start-adornment"]')
|
|
68
|
+
);
|
|
69
|
+
const endAdornmentWidth = getOuterWidthWithMargins(
|
|
70
|
+
field.querySelector('[data-input-role="end-adornment"]')
|
|
71
|
+
);
|
|
72
|
+
const iconWidth = getOuterWidthWithMargins(field.querySelector('[data-input-role="icon"]'));
|
|
73
|
+
const breathingRoom = 6;
|
|
74
|
+
const nextWidth = Math.ceil(
|
|
75
|
+
borderLeft + borderRight + iconWidth + startAdornmentWidth + inputPaddingLeft + textWidth + breathingRoom + inputPaddingRight + endAdornmentWidth
|
|
76
|
+
);
|
|
77
|
+
return Math.max(parseLengthToPx(minWidth, inputFontSize) || 120, nextWidth);
|
|
78
|
+
}
|
|
79
|
+
function Typeahead({
|
|
80
|
+
options,
|
|
81
|
+
mode = "single",
|
|
82
|
+
multiValueDisplayMode = "chips",
|
|
83
|
+
multiSelectedValuesDisplayMode = "hidden",
|
|
84
|
+
multiSelectedValueChipContent = "label",
|
|
85
|
+
selectedValue = null,
|
|
86
|
+
onChange,
|
|
87
|
+
placeholder,
|
|
88
|
+
variant = "outlined",
|
|
89
|
+
disabled = false,
|
|
90
|
+
fullWidth = false,
|
|
91
|
+
onClear,
|
|
92
|
+
emptyMessage = "Ingen resultater",
|
|
93
|
+
filterOptions,
|
|
94
|
+
inputProps,
|
|
95
|
+
inputSize,
|
|
96
|
+
width,
|
|
97
|
+
minWidth,
|
|
98
|
+
popoverWidth,
|
|
99
|
+
autoComplete,
|
|
100
|
+
autoCorrect,
|
|
101
|
+
autoCapitalize,
|
|
102
|
+
spellCheck,
|
|
103
|
+
popoverAnchorRef,
|
|
104
|
+
fitContent = false,
|
|
105
|
+
enableHotkey = false
|
|
106
|
+
}) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
const rootRef = useRef(null);
|
|
109
|
+
const triggerWrapperRef = useRef(null);
|
|
110
|
+
const inputRef = useRef(null);
|
|
111
|
+
const popoverContentRef = useRef(null);
|
|
112
|
+
const interactingWithOptionsRef = useRef(false);
|
|
113
|
+
const justClearedRef = useRef(false);
|
|
114
|
+
const locallyClearedRef = useRef(false);
|
|
115
|
+
const listboxId = useId();
|
|
116
|
+
const {
|
|
117
|
+
onFocus: inputPropsOnFocus,
|
|
118
|
+
onBlur: inputPropsOnBlur,
|
|
119
|
+
onKeyDown: inputPropsOnKeyDown,
|
|
120
|
+
onMouseDown: inputPropsOnMouseDown,
|
|
121
|
+
onClear: inputPropsOnClear,
|
|
122
|
+
startAdornment: inputPropsStartAdornment,
|
|
123
|
+
endAdornment: inputPropsEndAdornment,
|
|
124
|
+
...passthroughInputProps
|
|
125
|
+
} = inputProps != null ? inputProps : {};
|
|
126
|
+
const selectedOption = useMemo(() => {
|
|
127
|
+
var _a2;
|
|
128
|
+
if (mode === "multi") return null;
|
|
129
|
+
return (_a2 = options.find((option) => option.value === selectedValue)) != null ? _a2 : null;
|
|
130
|
+
}, [options, selectedValue, mode]);
|
|
131
|
+
const selectedOptions = useMemo(() => {
|
|
132
|
+
if (mode !== "multi" || !Array.isArray(selectedValue)) return [];
|
|
133
|
+
return options.filter((option) => selectedValue.includes(option.value));
|
|
134
|
+
}, [options, selectedValue, mode]);
|
|
135
|
+
const [open, setOpen] = useState(false);
|
|
136
|
+
const [inputValue, setInputValue] = useState(
|
|
137
|
+
mode === "multi" ? "" : (_a = selectedOption == null ? void 0 : selectedOption.label) != null ? _a : ""
|
|
138
|
+
);
|
|
139
|
+
const [query, setQuery] = useState("");
|
|
140
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
141
|
+
const [hideSelectedHighlight, setHideSelectedHighlight] = useState(false);
|
|
142
|
+
const clearJustClearedAfterEventCycle = React.useCallback(() => {
|
|
143
|
+
requestAnimationFrame(() => {
|
|
144
|
+
justClearedRef.current = false;
|
|
145
|
+
});
|
|
146
|
+
}, []);
|
|
147
|
+
const getSelectedValueChipLabel = React.useCallback(
|
|
148
|
+
(option) => {
|
|
149
|
+
switch (multiSelectedValueChipContent) {
|
|
150
|
+
case "value":
|
|
151
|
+
return String(option.value);
|
|
152
|
+
case "value-label":
|
|
153
|
+
return `${String(option.value)} - ${option.label}`;
|
|
154
|
+
case "label":
|
|
155
|
+
default:
|
|
156
|
+
return option.label;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[multiSelectedValueChipContent]
|
|
160
|
+
);
|
|
161
|
+
let filteredOptions;
|
|
162
|
+
if (filterOptions) {
|
|
163
|
+
filteredOptions = filterOptions(options, query);
|
|
164
|
+
} else {
|
|
165
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
166
|
+
if (!normalizedQuery) {
|
|
167
|
+
filteredOptions = options;
|
|
168
|
+
} else {
|
|
169
|
+
filteredOptions = options.filter(
|
|
170
|
+
(option) => option.label.toLocaleLowerCase().includes(normalizedQuery)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const commitSelection = React.useCallback(
|
|
175
|
+
(option) => {
|
|
176
|
+
var _a2, _b2;
|
|
177
|
+
locallyClearedRef.current = false;
|
|
178
|
+
setHideSelectedHighlight(false);
|
|
179
|
+
if (mode === "multi") {
|
|
180
|
+
if (!option) return;
|
|
181
|
+
const nextValues = Array.isArray(selectedValue) ? [...selectedValue] : [];
|
|
182
|
+
const idx = nextValues.indexOf(option.value);
|
|
183
|
+
if (idx > -1) {
|
|
184
|
+
nextValues.splice(idx, 1);
|
|
185
|
+
} else {
|
|
186
|
+
nextValues.push(option.value);
|
|
187
|
+
}
|
|
188
|
+
onChange(nextValues);
|
|
189
|
+
if (filteredOptions.length > 1) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
setInputValue("");
|
|
193
|
+
setQuery("");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
onChange((_a2 = option == null ? void 0 : option.value) != null ? _a2 : null);
|
|
197
|
+
setInputValue((_b2 = option == null ? void 0 : option.label) != null ? _b2 : "");
|
|
198
|
+
setQuery("");
|
|
199
|
+
setOpen(false);
|
|
200
|
+
setActiveIndex(-1);
|
|
201
|
+
},
|
|
202
|
+
[mode, selectedValue, onChange, filteredOptions.length]
|
|
203
|
+
);
|
|
204
|
+
const multiSelectionAdornment = mode === "multi" && selectedOptions.length > 0 ? multiValueDisplayMode === "count" ? /* @__PURE__ */ jsxs("span", { className: `dbc-muted-text dbc-sm-text ${styles.countAdornment}`, children: [
|
|
205
|
+
"(",
|
|
206
|
+
selectedOptions.length,
|
|
207
|
+
")"
|
|
208
|
+
] }) : (() => {
|
|
209
|
+
const MAX_CHIPS = 2;
|
|
210
|
+
const chipsToShow = selectedOptions.slice(0, MAX_CHIPS);
|
|
211
|
+
const extraCount = selectedOptions.length - MAX_CHIPS;
|
|
212
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.chipRow, children: [
|
|
213
|
+
chipsToShow.map((option) => /* @__PURE__ */ jsx(
|
|
214
|
+
Chip,
|
|
215
|
+
{
|
|
216
|
+
size: "sm",
|
|
217
|
+
type: "rounded",
|
|
218
|
+
onClose: () => commitSelection(option),
|
|
219
|
+
children: option.label
|
|
220
|
+
},
|
|
221
|
+
option.value
|
|
222
|
+
)),
|
|
223
|
+
extraCount > 0 && /* @__PURE__ */ jsxs("span", { className: "dbc-muted-text dbc-sm-text dbc-px-xxs", children: [
|
|
224
|
+
"+",
|
|
225
|
+
extraCount
|
|
226
|
+
] })
|
|
227
|
+
] });
|
|
228
|
+
})() : void 0;
|
|
229
|
+
const usesCountAdornment = mode === "multi" && multiValueDisplayMode === "count" && selectedOptions.length > 0;
|
|
230
|
+
const resolvedInputSize = (_b = inputSize != null ? inputSize : inputProps == null ? void 0 : inputProps.inputSize) != null ? _b : "md";
|
|
231
|
+
const shouldFitContent = fitContent && mode === "single";
|
|
232
|
+
const [fittedWidthPx, setFittedWidthPx] = useState(null);
|
|
233
|
+
const visibleSingleValueText = useMemo(() => {
|
|
234
|
+
if (!shouldFitContent) return "";
|
|
235
|
+
return inputValue || (selectedOption == null ? void 0 : selectedOption.label) || placeholder || "";
|
|
236
|
+
}, [shouldFitContent, inputValue, selectedOption, placeholder]);
|
|
237
|
+
useLayoutEffect(() => {
|
|
238
|
+
if (!shouldFitContent) return;
|
|
239
|
+
const input = inputRef.current;
|
|
240
|
+
if (!input) return;
|
|
241
|
+
let cancelled = false;
|
|
242
|
+
const frameId = requestAnimationFrame(() => {
|
|
243
|
+
const nextWidth = measureFitContentWidth(input, visibleSingleValueText, minWidth);
|
|
244
|
+
if (!cancelled && nextWidth != null) {
|
|
245
|
+
setFittedWidthPx((current) => current !== nextWidth ? nextWidth : current);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
const fonts = document.fonts;
|
|
249
|
+
if (fonts == null ? void 0 : fonts.ready) {
|
|
250
|
+
void fonts.ready.then(() => {
|
|
251
|
+
if (cancelled) return;
|
|
252
|
+
const liveInput = inputRef.current;
|
|
253
|
+
if (!liveInput) return;
|
|
254
|
+
const nextWidth = measureFitContentWidth(liveInput, visibleSingleValueText, minWidth);
|
|
255
|
+
if (nextWidth != null) {
|
|
256
|
+
setFittedWidthPx((current) => current !== nextWidth ? nextWidth : current);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return () => {
|
|
261
|
+
cancelled = true;
|
|
262
|
+
cancelAnimationFrame(frameId);
|
|
263
|
+
};
|
|
264
|
+
}, [
|
|
265
|
+
shouldFitContent,
|
|
266
|
+
visibleSingleValueText,
|
|
267
|
+
minWidth,
|
|
268
|
+
inputPropsStartAdornment,
|
|
269
|
+
inputPropsEndAdornment
|
|
270
|
+
]);
|
|
271
|
+
const measuredRootWidth = useMemo(() => {
|
|
272
|
+
if (!shouldFitContent) return void 0;
|
|
273
|
+
if (fittedWidthPx == null) return minWidth != null ? minWidth : "120px";
|
|
274
|
+
return `${fittedWidthPx}px`;
|
|
275
|
+
}, [shouldFitContent, fittedWidthPx, minWidth]);
|
|
276
|
+
const shouldStretchInput = fullWidth || shouldFitContent;
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (!enableHotkey) return;
|
|
279
|
+
function handleKeyDown2(event) {
|
|
280
|
+
var _a2;
|
|
281
|
+
if (event.key === "k" && (event.metaKey || event.ctrlKey)) {
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
window.addEventListener("keydown", handleKeyDown2);
|
|
287
|
+
return () => window.removeEventListener("keydown", handleKeyDown2);
|
|
288
|
+
}, [enableHotkey]);
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
var _a2;
|
|
291
|
+
if (justClearedRef.current || locallyClearedRef.current) return;
|
|
292
|
+
if (mode === "multi") {
|
|
293
|
+
setInputValue("");
|
|
294
|
+
setQuery("");
|
|
295
|
+
} else {
|
|
296
|
+
setInputValue((_a2 = selectedOption == null ? void 0 : selectedOption.label) != null ? _a2 : "");
|
|
297
|
+
}
|
|
298
|
+
}, [selectedOption, mode]);
|
|
299
|
+
const getSelectedIndex = React.useCallback(
|
|
300
|
+
(items) => {
|
|
301
|
+
if (items.length === 0) return -1;
|
|
302
|
+
if (locallyClearedRef.current) return 0;
|
|
303
|
+
if (mode === "multi") {
|
|
304
|
+
if (!Array.isArray(selectedValue) || selectedValue.length === 0) return 0;
|
|
305
|
+
const firstSelectedIndex = items.findIndex((option) => selectedValue.includes(option.value));
|
|
306
|
+
return firstSelectedIndex >= 0 ? firstSelectedIndex : 0;
|
|
307
|
+
}
|
|
308
|
+
const singleSelectedIndex = items.findIndex((option) => option.value === selectedValue);
|
|
309
|
+
return singleSelectedIndex >= 0 ? singleSelectedIndex : 0;
|
|
310
|
+
},
|
|
311
|
+
[mode, selectedValue]
|
|
312
|
+
);
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
setActiveIndex((current) => {
|
|
315
|
+
if (filteredOptions.length === 0) return -1;
|
|
316
|
+
if (locallyClearedRef.current) return 0;
|
|
317
|
+
if (current < 0) return getSelectedIndex(filteredOptions);
|
|
318
|
+
return Math.min(current, filteredOptions.length - 1);
|
|
319
|
+
});
|
|
320
|
+
}, [filteredOptions, getSelectedIndex]);
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
var _a2, _b2;
|
|
323
|
+
if (!open || activeIndex < 0) return;
|
|
324
|
+
const activeEl = (_a2 = document.getElementById(listboxId)) == null ? void 0 : _a2.querySelector(`#${CSS.escape(`${listboxId}-option-${activeIndex}`)}`);
|
|
325
|
+
(_b2 = activeEl == null ? void 0 : activeEl.scrollIntoView) == null ? void 0 : _b2.call(activeEl, { block: "nearest" });
|
|
326
|
+
}, [open, activeIndex, filteredOptions, listboxId]);
|
|
327
|
+
const getFocusableElements = React.useCallback(() => {
|
|
328
|
+
const selector = [
|
|
329
|
+
"a[href]",
|
|
330
|
+
"button:not([disabled])",
|
|
331
|
+
"input:not([disabled])",
|
|
332
|
+
"select:not([disabled])",
|
|
333
|
+
"textarea:not([disabled])",
|
|
334
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
335
|
+
].join(",");
|
|
336
|
+
const seen = /* @__PURE__ */ new Set();
|
|
337
|
+
const focusables = [];
|
|
338
|
+
for (const container of [rootRef.current, popoverContentRef.current]) {
|
|
339
|
+
if (!container) continue;
|
|
340
|
+
const elements = container.matches(selector) ? [container] : Array.from(container.querySelectorAll(selector));
|
|
341
|
+
for (const element of elements) {
|
|
342
|
+
if (seen.has(element) || element.getAttribute("aria-hidden") === "true" || element.tabIndex < 0) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
seen.add(element);
|
|
346
|
+
focusables.push(element);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return focusables;
|
|
350
|
+
}, []);
|
|
351
|
+
const isFocusWithinTypeahead = React.useCallback((target) => {
|
|
352
|
+
var _a2, _b2;
|
|
353
|
+
if (!(target instanceof Node)) return false;
|
|
354
|
+
return Boolean(((_a2 = rootRef.current) == null ? void 0 : _a2.contains(target)) || ((_b2 = popoverContentRef.current) == null ? void 0 : _b2.contains(target)));
|
|
355
|
+
}, []);
|
|
356
|
+
const handleTabKeyDown = React.useCallback(
|
|
357
|
+
(event) => {
|
|
358
|
+
var _a2, _b2, _c;
|
|
359
|
+
if (event.key !== "Tab" || !open) return;
|
|
360
|
+
const focusables = getFocusableElements();
|
|
361
|
+
if (focusables.length === 0) return;
|
|
362
|
+
const eventTarget = event.target instanceof HTMLElement ? event.target : document.activeElement;
|
|
363
|
+
const activeElement = eventTarget && focusables.includes(eventTarget) ? eventTarget : (_a2 = document.activeElement) != null ? _a2 : null;
|
|
364
|
+
const activeIndexInScope = activeElement ? focusables.indexOf(activeElement) : -1;
|
|
365
|
+
if (mode === "multi") {
|
|
366
|
+
if (activeIndexInScope === -1) {
|
|
367
|
+
event.preventDefault();
|
|
368
|
+
(_b2 = focusables[0]) == null ? void 0 : _b2.focus();
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
event.preventDefault();
|
|
372
|
+
const nextIndex = event.shiftKey ? (activeIndexInScope - 1 + focusables.length) % focusables.length : (activeIndexInScope + 1) % focusables.length;
|
|
373
|
+
(_c = focusables[nextIndex]) == null ? void 0 : _c.focus();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
setOpen(false);
|
|
377
|
+
setActiveIndex(-1);
|
|
378
|
+
},
|
|
379
|
+
[open, getFocusableElements, mode]
|
|
380
|
+
);
|
|
381
|
+
const handleInputChange = (nextValue) => {
|
|
382
|
+
if (justClearedRef.current) return;
|
|
383
|
+
locallyClearedRef.current = false;
|
|
384
|
+
setHideSelectedHighlight(false);
|
|
385
|
+
setInputValue(nextValue);
|
|
386
|
+
setQuery(nextValue);
|
|
387
|
+
if (!open) setOpen(true);
|
|
388
|
+
if (mode === "multi") return;
|
|
389
|
+
const exactMatch = options.find((option) => option.label === nextValue);
|
|
390
|
+
if (!exactMatch && selectedValue !== null) {
|
|
391
|
+
onChange(null);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
const handleBlur = (nextFocusedTarget) => {
|
|
395
|
+
if (justClearedRef.current || locallyClearedRef.current) {
|
|
396
|
+
setInputValue("");
|
|
397
|
+
setQuery("");
|
|
398
|
+
setOpen(false);
|
|
399
|
+
setActiveIndex(-1);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (isFocusWithinTypeahead(nextFocusedTarget)) return;
|
|
403
|
+
if (mode === "multi") {
|
|
404
|
+
if (interactingWithOptionsRef.current) {
|
|
405
|
+
interactingWithOptionsRef.current = false;
|
|
406
|
+
setInputValue("");
|
|
407
|
+
setQuery("");
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
setInputValue("");
|
|
411
|
+
setQuery("");
|
|
412
|
+
setOpen(false);
|
|
413
|
+
setActiveIndex(-1);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const exactLabelMatch = options.find((option) => option.label === inputValue);
|
|
417
|
+
if (exactLabelMatch) {
|
|
418
|
+
commitSelection(exactLabelMatch);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (selectedOption) {
|
|
422
|
+
setInputValue(selectedOption.label);
|
|
423
|
+
} else {
|
|
424
|
+
setInputValue("");
|
|
425
|
+
}
|
|
426
|
+
setQuery("");
|
|
427
|
+
setOpen(false);
|
|
428
|
+
setActiveIndex(-1);
|
|
429
|
+
};
|
|
430
|
+
const openWithAllOptions = React.useCallback(() => {
|
|
431
|
+
if (justClearedRef.current) return;
|
|
432
|
+
setQuery("");
|
|
433
|
+
setOpen(true);
|
|
434
|
+
setActiveIndex(getSelectedIndex(options));
|
|
435
|
+
}, [getSelectedIndex, options]);
|
|
436
|
+
const openWithCurrentFilter = React.useCallback(() => {
|
|
437
|
+
if (justClearedRef.current) return;
|
|
438
|
+
setOpen(true);
|
|
439
|
+
setActiveIndex(getSelectedIndex(filteredOptions));
|
|
440
|
+
}, [getSelectedIndex, filteredOptions]);
|
|
441
|
+
const prepareSingleSearchInput = React.useCallback(() => {
|
|
442
|
+
if (mode !== "single" || !selectedOption || justClearedRef.current) return;
|
|
443
|
+
setInputValue("");
|
|
444
|
+
setQuery("");
|
|
445
|
+
}, [mode, selectedOption]);
|
|
446
|
+
const handleOpen = React.useCallback(() => {
|
|
447
|
+
if (justClearedRef.current) return;
|
|
448
|
+
if (mode === "single" && selectedOption && !locallyClearedRef.current) {
|
|
449
|
+
prepareSingleSearchInput();
|
|
450
|
+
openWithAllOptions();
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
openWithCurrentFilter();
|
|
454
|
+
}, [mode, selectedOption, prepareSingleSearchInput, openWithAllOptions, openWithCurrentFilter]);
|
|
455
|
+
const handleTriggerMouseDown = React.useCallback(
|
|
456
|
+
(e) => {
|
|
457
|
+
var _a2;
|
|
458
|
+
inputPropsOnMouseDown == null ? void 0 : inputPropsOnMouseDown(e);
|
|
459
|
+
if (e.defaultPrevented) return;
|
|
460
|
+
if (justClearedRef.current) {
|
|
461
|
+
e.preventDefault();
|
|
462
|
+
e.stopPropagation();
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const isAlreadyFocused = document.activeElement === inputRef.current;
|
|
466
|
+
if (isAlreadyFocused && open) {
|
|
467
|
+
e.preventDefault();
|
|
468
|
+
setOpen(false);
|
|
469
|
+
setActiveIndex(-1);
|
|
470
|
+
setQuery("");
|
|
471
|
+
setInputValue(
|
|
472
|
+
mode === "single" && !locallyClearedRef.current ? (_a2 = selectedOption == null ? void 0 : selectedOption.label) != null ? _a2 : "" : ""
|
|
473
|
+
);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (isAlreadyFocused && mode === "single" && selectedOption && !locallyClearedRef.current) {
|
|
477
|
+
prepareSingleSearchInput();
|
|
478
|
+
setOpen(true);
|
|
479
|
+
setActiveIndex(getSelectedIndex(options));
|
|
480
|
+
} else if (isAlreadyFocused && !open) {
|
|
481
|
+
setOpen(true);
|
|
482
|
+
setActiveIndex(getSelectedIndex(filteredOptions));
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
[
|
|
486
|
+
inputPropsOnMouseDown,
|
|
487
|
+
open,
|
|
488
|
+
mode,
|
|
489
|
+
selectedOption,
|
|
490
|
+
prepareSingleSearchInput,
|
|
491
|
+
getSelectedIndex,
|
|
492
|
+
options,
|
|
493
|
+
filteredOptions
|
|
494
|
+
]
|
|
495
|
+
);
|
|
496
|
+
const handleChevronMouseDown = React.useCallback(
|
|
497
|
+
(e) => {
|
|
498
|
+
var _a2, _b2;
|
|
499
|
+
e.preventDefault();
|
|
500
|
+
e.stopPropagation();
|
|
501
|
+
if (justClearedRef.current) return;
|
|
502
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
503
|
+
if (open) {
|
|
504
|
+
setOpen(false);
|
|
505
|
+
setActiveIndex(-1);
|
|
506
|
+
setQuery("");
|
|
507
|
+
setInputValue(
|
|
508
|
+
mode === "single" && !locallyClearedRef.current ? (_b2 = selectedOption == null ? void 0 : selectedOption.label) != null ? _b2 : "" : ""
|
|
509
|
+
);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
handleOpen();
|
|
513
|
+
},
|
|
514
|
+
[open, mode, selectedOption, handleOpen]
|
|
515
|
+
);
|
|
516
|
+
const handleKeyDown = (e) => {
|
|
517
|
+
switch (e.key) {
|
|
518
|
+
case "ArrowDown":
|
|
519
|
+
e.preventDefault();
|
|
520
|
+
if (!open) {
|
|
521
|
+
handleOpen();
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
setActiveIndex((index) => {
|
|
525
|
+
if (filteredOptions.length === 0) return -1;
|
|
526
|
+
if (index < 0) return getSelectedIndex(filteredOptions);
|
|
527
|
+
return Math.min(index + 1, filteredOptions.length - 1);
|
|
528
|
+
});
|
|
529
|
+
return;
|
|
530
|
+
case "ArrowUp":
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
if (!open) {
|
|
533
|
+
handleOpen();
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
setActiveIndex((index) => {
|
|
537
|
+
if (filteredOptions.length === 0) return -1;
|
|
538
|
+
if (index < 0) return filteredOptions.length - 1;
|
|
539
|
+
return Math.max(index - 1, 0);
|
|
540
|
+
});
|
|
541
|
+
return;
|
|
542
|
+
case "Home":
|
|
543
|
+
if (!open || filteredOptions.length === 0) return;
|
|
544
|
+
e.preventDefault();
|
|
545
|
+
setActiveIndex(0);
|
|
546
|
+
return;
|
|
547
|
+
case "End":
|
|
548
|
+
if (!open || filteredOptions.length === 0) return;
|
|
549
|
+
e.preventDefault();
|
|
550
|
+
setActiveIndex(filteredOptions.length - 1);
|
|
551
|
+
return;
|
|
552
|
+
case "Enter":
|
|
553
|
+
if (!open) return;
|
|
554
|
+
e.preventDefault();
|
|
555
|
+
if (activeIndex >= 0 && filteredOptions[activeIndex]) {
|
|
556
|
+
commitSelection(filteredOptions[activeIndex]);
|
|
557
|
+
}
|
|
558
|
+
return;
|
|
559
|
+
case "Escape":
|
|
560
|
+
e.preventDefault();
|
|
561
|
+
e.stopPropagation();
|
|
562
|
+
setOpen(false);
|
|
563
|
+
setActiveIndex(-1);
|
|
564
|
+
setQuery("");
|
|
565
|
+
setInputValue(
|
|
566
|
+
mode === "single" && selectedOption && !locallyClearedRef.current ? selectedOption.label : ""
|
|
567
|
+
);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
return /* @__PURE__ */ jsxs(
|
|
572
|
+
"div",
|
|
573
|
+
{
|
|
574
|
+
ref: rootRef,
|
|
575
|
+
style: {
|
|
576
|
+
display: "flex",
|
|
577
|
+
flexDirection: "column",
|
|
578
|
+
gap: mode === "multi" && multiSelectedValuesDisplayMode === "below-input" && selectedOptions.length > 0 ? 8 : 0,
|
|
579
|
+
width: fullWidth ? "100%" : shouldFitContent ? measuredRootWidth : void 0,
|
|
580
|
+
flex: fullWidth || shouldFitContent ? "1 1 auto" : void 0,
|
|
581
|
+
minWidth: shouldFitContent ? measuredRootWidth : 0,
|
|
582
|
+
maxWidth: shouldFitContent ? "100%" : void 0
|
|
583
|
+
},
|
|
584
|
+
children: [
|
|
585
|
+
/* @__PURE__ */ jsx(
|
|
586
|
+
Popover,
|
|
587
|
+
{
|
|
588
|
+
open,
|
|
589
|
+
minWidth: popoverWidth != null ? popoverWidth : minWidth,
|
|
590
|
+
matchTriggerWidth: true,
|
|
591
|
+
fillTrigger: true,
|
|
592
|
+
anchorRef: popoverAnchorRef != null ? popoverAnchorRef : triggerWrapperRef,
|
|
593
|
+
onOpenChange: (nextOpen) => {
|
|
594
|
+
if (justClearedRef.current) {
|
|
595
|
+
setOpen(false);
|
|
596
|
+
setActiveIndex(-1);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
setOpen(nextOpen);
|
|
600
|
+
if (nextOpen) {
|
|
601
|
+
if (mode === "single" && selectedOption && !locallyClearedRef.current) {
|
|
602
|
+
setQuery("");
|
|
603
|
+
setActiveIndex(getSelectedIndex(options));
|
|
604
|
+
} else {
|
|
605
|
+
setActiveIndex(getSelectedIndex(filteredOptions));
|
|
606
|
+
}
|
|
607
|
+
} else {
|
|
608
|
+
setActiveIndex(-1);
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
fullWidth,
|
|
612
|
+
autoFocusContent: false,
|
|
613
|
+
returnFocus: false,
|
|
614
|
+
overlayRef: popoverContentRef,
|
|
615
|
+
trigger: (openPopover, icon) => {
|
|
616
|
+
var _a2, _b2, _c, _d;
|
|
617
|
+
return /* @__PURE__ */ jsx(
|
|
618
|
+
"div",
|
|
619
|
+
{
|
|
620
|
+
ref: triggerWrapperRef,
|
|
621
|
+
onMouseDown: (e) => {
|
|
622
|
+
const target = e.target;
|
|
623
|
+
if (justClearedRef.current) {
|
|
624
|
+
e.preventDefault();
|
|
625
|
+
e.stopPropagation();
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (target.closest('input, button, [data-input-role="clear"]')) return;
|
|
629
|
+
handleChevronMouseDown(e);
|
|
630
|
+
},
|
|
631
|
+
children: /* @__PURE__ */ jsx(
|
|
632
|
+
Input,
|
|
633
|
+
{
|
|
634
|
+
...passthroughInputProps,
|
|
635
|
+
ref: inputRef,
|
|
636
|
+
value: inputValue,
|
|
637
|
+
startAdornment: multiSelectionAdornment || inputPropsStartAdornment ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
638
|
+
multiSelectionAdornment,
|
|
639
|
+
inputPropsStartAdornment
|
|
640
|
+
] }) : void 0,
|
|
641
|
+
endAdornment: inputPropsEndAdornment || icon ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
642
|
+
inputPropsEndAdornment,
|
|
643
|
+
icon ? /* @__PURE__ */ jsx("span", { className: styles.chevronButton, onMouseDown: handleChevronMouseDown, children: icon }) : null
|
|
644
|
+
] }) : void 0,
|
|
645
|
+
onFocus: (e) => {
|
|
646
|
+
inputPropsOnFocus == null ? void 0 : inputPropsOnFocus(e);
|
|
647
|
+
if (e.defaultPrevented) return;
|
|
648
|
+
if (justClearedRef.current) return;
|
|
649
|
+
handleOpen();
|
|
650
|
+
openPopover(e);
|
|
651
|
+
},
|
|
652
|
+
onMouseDown: handleTriggerMouseDown,
|
|
653
|
+
onChange: (e) => handleInputChange(e.currentTarget.value),
|
|
654
|
+
onBlur: (e) => {
|
|
655
|
+
inputPropsOnBlur == null ? void 0 : inputPropsOnBlur(e);
|
|
656
|
+
if (e.defaultPrevented) return;
|
|
657
|
+
handleBlur(e.relatedTarget);
|
|
658
|
+
},
|
|
659
|
+
onKeyDown: (e) => {
|
|
660
|
+
inputPropsOnKeyDown == null ? void 0 : inputPropsOnKeyDown(e);
|
|
661
|
+
if (e.defaultPrevented) return;
|
|
662
|
+
handleTabKeyDown(e);
|
|
663
|
+
if (e.defaultPrevented) return;
|
|
664
|
+
handleKeyDown(e);
|
|
665
|
+
},
|
|
666
|
+
placeholder,
|
|
667
|
+
variant,
|
|
668
|
+
inputSize: resolvedInputSize,
|
|
669
|
+
width: shouldFitContent ? void 0 : width != null ? width : inputProps == null ? void 0 : inputProps.width,
|
|
670
|
+
autoComplete: (_a2 = autoComplete != null ? autoComplete : inputProps == null ? void 0 : inputProps.autoComplete) != null ? _a2 : "off",
|
|
671
|
+
autoCorrect: (_b2 = autoCorrect != null ? autoCorrect : inputProps == null ? void 0 : inputProps.autoCorrect) != null ? _b2 : "off",
|
|
672
|
+
autoCapitalize: (_c = autoCapitalize != null ? autoCapitalize : inputProps == null ? void 0 : inputProps.autoCapitalize) != null ? _c : "none",
|
|
673
|
+
spellCheck: (_d = spellCheck != null ? spellCheck : inputProps == null ? void 0 : inputProps.spellCheck) != null ? _d : false,
|
|
674
|
+
disabled,
|
|
675
|
+
fullWidth: shouldStretchInput,
|
|
676
|
+
inputClassName: [
|
|
677
|
+
inputProps == null ? void 0 : inputProps.inputClassName,
|
|
678
|
+
styles.typeaheadInput,
|
|
679
|
+
usesCountAdornment ? styles.inputWithoutStartPadding : ""
|
|
680
|
+
].filter(Boolean).join(" "),
|
|
681
|
+
onClear: (event) => {
|
|
682
|
+
var _a3, _b3;
|
|
683
|
+
(_a3 = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a3.call(event);
|
|
684
|
+
(_b3 = event == null ? void 0 : event.stopPropagation) == null ? void 0 : _b3.call(event);
|
|
685
|
+
justClearedRef.current = true;
|
|
686
|
+
locallyClearedRef.current = true;
|
|
687
|
+
setHideSelectedHighlight(true);
|
|
688
|
+
setOpen(false);
|
|
689
|
+
setInputValue("");
|
|
690
|
+
setQuery("");
|
|
691
|
+
setActiveIndex(-1);
|
|
692
|
+
inputPropsOnClear == null ? void 0 : inputPropsOnClear();
|
|
693
|
+
if (onClear) {
|
|
694
|
+
onClear();
|
|
695
|
+
} else {
|
|
696
|
+
onChange(mode === "multi" ? [] : null);
|
|
697
|
+
}
|
|
698
|
+
clearJustClearedAfterEventCycle();
|
|
699
|
+
},
|
|
700
|
+
role: "combobox",
|
|
701
|
+
"aria-expanded": open,
|
|
702
|
+
"aria-controls": listboxId,
|
|
703
|
+
"aria-autocomplete": "list",
|
|
704
|
+
"aria-activedescendant": open && activeIndex >= 0 ? `${listboxId}-option-${activeIndex}` : void 0
|
|
705
|
+
}
|
|
706
|
+
)
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
},
|
|
710
|
+
children: /* @__PURE__ */ jsx(Menu, { role: "listbox", id: listboxId, children: filteredOptions.length > 0 ? filteredOptions.map((option, index) => {
|
|
711
|
+
const isActive = index === activeIndex;
|
|
712
|
+
const isSelected = mode === "multi" ? Array.isArray(selectedValue) && selectedValue.includes(option.value) : option.value === selectedValue && !hideSelectedHighlight;
|
|
713
|
+
const optionId = `${listboxId}-option-${index}`;
|
|
714
|
+
return mode === "multi" ? /* @__PURE__ */ jsx(
|
|
715
|
+
Menu.CheckItem,
|
|
716
|
+
{
|
|
717
|
+
checked: isSelected,
|
|
718
|
+
active: isActive,
|
|
719
|
+
interactiveProps: {
|
|
720
|
+
id: optionId,
|
|
721
|
+
role: "option",
|
|
722
|
+
onMouseEnter: () => setActiveIndex(index),
|
|
723
|
+
onMouseDown: (e) => {
|
|
724
|
+
interactingWithOptionsRef.current = true;
|
|
725
|
+
e.preventDefault();
|
|
726
|
+
},
|
|
727
|
+
onKeyDown: (e) => handleTabKeyDown(e)
|
|
728
|
+
},
|
|
729
|
+
label: /* @__PURE__ */ jsx("span", { children: option.label }),
|
|
730
|
+
onCheckedChange: () => commitSelection(option)
|
|
731
|
+
},
|
|
732
|
+
option.value
|
|
733
|
+
) : /* @__PURE__ */ jsx(Menu.Item, { active: isActive, selected: isSelected, children: /* @__PURE__ */ jsx(
|
|
734
|
+
"button",
|
|
735
|
+
{
|
|
736
|
+
id: optionId,
|
|
737
|
+
type: "button",
|
|
738
|
+
role: "option",
|
|
739
|
+
"aria-selected": isSelected,
|
|
740
|
+
onMouseEnter: () => setActiveIndex(index),
|
|
741
|
+
onMouseDown: (e) => {
|
|
742
|
+
e.preventDefault();
|
|
743
|
+
},
|
|
744
|
+
onKeyDown: (e) => handleTabKeyDown(e),
|
|
745
|
+
onClick: () => commitSelection(option),
|
|
746
|
+
children: /* @__PURE__ */ jsx("span", { children: option.label })
|
|
747
|
+
}
|
|
748
|
+
) }, option.value);
|
|
749
|
+
}) : /* @__PURE__ */ jsx(Menu.Item, { disabled: true, children: emptyMessage }) })
|
|
750
|
+
}
|
|
751
|
+
),
|
|
752
|
+
mode === "multi" && multiSelectedValuesDisplayMode === "below-input" && selectedOptions.length > 0 && /* @__PURE__ */ jsx("div", { className: styles.selectedValues, children: selectedOptions.map((option) => /* @__PURE__ */ jsx(
|
|
753
|
+
Chip,
|
|
754
|
+
{
|
|
755
|
+
size: "sm",
|
|
756
|
+
type: "default",
|
|
757
|
+
severity: "neutral",
|
|
758
|
+
onClose: () => commitSelection(option),
|
|
759
|
+
children: getSelectedValueChipLabel(option)
|
|
760
|
+
},
|
|
761
|
+
option.value
|
|
762
|
+
)) })
|
|
763
|
+
]
|
|
764
|
+
}
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
export { Typeahead };
|