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