@pixum/combobox 5.10.4-alpha.24 → 5.10.4-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +730 -0
- package/lib/ComboBox.d.ts +6 -28
- package/lib/ComboBox.js +78 -177
- package/lib/ComboBox.js.map +1 -1
- package/lib/hooks/index.d.ts +0 -2
- package/lib/hooks/index.js +0 -2
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useIsDesktopScreenWidth.d.ts +0 -5
- package/lib/hooks/useIsDesktopScreenWidth.js +24 -34
- package/lib/hooks/useIsDesktopScreenWidth.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/lib/partials/ComboBoxOptions.d.ts +4 -15
- package/lib/partials/ComboBoxOptions.js +21 -25
- package/lib/partials/ComboBoxOptions.js.map +1 -1
- package/lib/partials/ComboBoxOptionsItems.d.ts +17 -32
- package/lib/partials/ComboBoxOptionsItems.js +14 -46
- package/lib/partials/ComboBoxOptionsItems.js.map +1 -1
- package/lib/partials/ComboBoxOptionsSlot.d.ts +16 -17
- package/lib/partials/ComboBoxOptionsSlot.js +11 -26
- package/lib/partials/ComboBoxOptionsSlot.js.map +1 -1
- package/lib/partials/index.d.ts +1 -2
- package/lib/partials/index.js +1 -2
- package/lib/partials/index.js.map +1 -1
- package/lib/styles.css +1 -1
- package/lib/types.d.ts +51 -122
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +2 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +8 -8
- package/lib/ComboBox.module.css +0 -1
- package/lib/hooks/useComboBox.d.ts +0 -60
- package/lib/hooks/useComboBox.js +0 -226
- package/lib/hooks/useComboBox.js.map +0 -1
- package/lib/hooks/useComboBoxFocus.d.ts +0 -35
- package/lib/hooks/useComboBoxFocus.js +0 -49
- package/lib/hooks/useComboBoxFocus.js.map +0 -1
- package/lib/partials/ComboBoxNoResults.d.ts +0 -14
- package/lib/partials/ComboBoxNoResults.js +0 -18
- package/lib/partials/ComboBoxNoResults.js.map +0 -1
- package/lib/partials/ComboBoxOptionsGroup.d.ts +0 -15
- package/lib/partials/ComboBoxOptionsGroup.js +0 -31
- package/lib/partials/ComboBoxOptionsGroup.js.map +0 -1
- package/lib/utils/options.d.ts +0 -77
- package/lib/utils/options.js +0 -145
- package/lib/utils/options.js.map +0 -1
package/lib/ComboBox.d.ts
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
import type { ComboBoxProps } from './types';
|
|
2
|
+
import './styles.css';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* This file is the only client boundary of the package: all partials, hooks and
|
|
7
|
-
* utils are plain modules without a `'use client'` directive, so they can be
|
|
8
|
-
* imported from server components as well and only end up in the client bundle
|
|
9
|
-
* through this component.
|
|
10
|
-
*
|
|
11
|
-
* Focus choreography:
|
|
12
|
-
* - focusing the trigger opens the options,
|
|
13
|
-
* - with `withSearch` the focus moves into the search field as soon as it is
|
|
14
|
-
* mounted, and its content is selected so the first keystroke replaces it,
|
|
15
|
-
* - selecting an option, Escape, Alt+ArrowUp and closing the sheet move the
|
|
16
|
-
* focus back to the trigger without re-opening the list,
|
|
17
|
-
* - Tab closes the list and lets the focus move on.
|
|
18
|
-
*
|
|
19
|
-
* Keyboard: ArrowUp/ArrowDown navigate, Home/End jump, Enter selects. Space
|
|
20
|
-
* selects as well - unless an open search field needs it as a real space
|
|
21
|
-
* character, which is what the ARIA authoring practices ask for.
|
|
22
|
-
*
|
|
23
|
-
* Selection: pass a string for single select, or `multiple` plus an array of
|
|
24
|
-
* strings for a checkbox list. `onOptionItemClick` reports the toggled value;
|
|
25
|
-
* the selection itself stays fully controlled by the consumer. The value of an
|
|
26
|
-
* option is its `text`, so `value` can be compared against the visible label as
|
|
27
|
-
* before.
|
|
4
|
+
* ComboBox component that provides a searchable dropdown with options.
|
|
5
|
+
* Adapts to mobile (bottom sheet) and desktop (dropdown) viewports.
|
|
6
|
+
* Supports both flat and grouped options, search functionality, and keyboard navigation.
|
|
28
7
|
*
|
|
29
8
|
* @param props - The props for the ComboBox component
|
|
30
|
-
* @returns A responsive
|
|
9
|
+
* @returns A responsive combobox component with search and selection capabilities
|
|
31
10
|
*/
|
|
32
|
-
export declare function ComboBox({ className, name,
|
|
33
|
-
export default ComboBox;
|
|
11
|
+
export declare function ComboBox({ className, name, headline, label, searchPattern, isOpen, options, placeholder, value, inputMode, noResultsText, leadingType, optionDetails, withSearch, theme, optionsSlot, leadingIcon, disabled, loading, setIsOpen, onClick, onChange, onOutsideClick, onOptionItemClick, onSheetClose, }: ComboBoxProps): import("react/jsx-runtime").JSX.Element;
|
package/lib/ComboBox.js
CHANGED
|
@@ -1,209 +1,110 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx,
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState, } from 'react';
|
|
4
4
|
import BottomSheet from '@pixum/bottom-sheet';
|
|
5
|
-
import Text, {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
5
|
+
import Text, { TextVariant } from '@pixum/text';
|
|
6
|
+
import { useEscapeKeyPress } from '@pixum/utils';
|
|
7
|
+
import { ComboBoxOptions } from './partials';
|
|
8
|
+
import { SelectInput, SearchInput } from '@pixum/web-input';
|
|
9
|
+
import { useIsDesktopScreenWidth } from './hooks';
|
|
8
10
|
import clsx from 'clsx';
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import { getOptionLabel, normaliseOptions, toValueArray } from './utils';
|
|
12
|
-
import styles from './ComboBox.module.css';
|
|
11
|
+
import ThemeProvider, { DEFAULT_THEME } from '@pixum/theme-provider';
|
|
12
|
+
import './styles.css';
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* This file is the only client boundary of the package: all partials, hooks and
|
|
18
|
-
* utils are plain modules without a `'use client'` directive, so they can be
|
|
19
|
-
* imported from server components as well and only end up in the client bundle
|
|
20
|
-
* through this component.
|
|
21
|
-
*
|
|
22
|
-
* Focus choreography:
|
|
23
|
-
* - focusing the trigger opens the options,
|
|
24
|
-
* - with `withSearch` the focus moves into the search field as soon as it is
|
|
25
|
-
* mounted, and its content is selected so the first keystroke replaces it,
|
|
26
|
-
* - selecting an option, Escape, Alt+ArrowUp and closing the sheet move the
|
|
27
|
-
* focus back to the trigger without re-opening the list,
|
|
28
|
-
* - Tab closes the list and lets the focus move on.
|
|
29
|
-
*
|
|
30
|
-
* Keyboard: ArrowUp/ArrowDown navigate, Home/End jump, Enter selects. Space
|
|
31
|
-
* selects as well - unless an open search field needs it as a real space
|
|
32
|
-
* character, which is what the ARIA authoring practices ask for.
|
|
33
|
-
*
|
|
34
|
-
* Selection: pass a string for single select, or `multiple` plus an array of
|
|
35
|
-
* strings for a checkbox list. `onOptionItemClick` reports the toggled value;
|
|
36
|
-
* the selection itself stays fully controlled by the consumer. The value of an
|
|
37
|
-
* option is its `text`, so `value` can be compared against the visible label as
|
|
38
|
-
* before.
|
|
14
|
+
* ComboBox component that provides a searchable dropdown with options.
|
|
15
|
+
* Adapts to mobile (bottom sheet) and desktop (dropdown) viewports.
|
|
16
|
+
* Supports both flat and grouped options, search functionality, and keyboard navigation.
|
|
39
17
|
*
|
|
40
18
|
* @param props - The props for the ComboBox component
|
|
41
|
-
* @returns A responsive
|
|
19
|
+
* @returns A responsive combobox component with search and selection capabilities
|
|
42
20
|
*/
|
|
43
|
-
export function ComboBox({ className = '', name,
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const isDesktop = useIsDesktopScreenWidth();
|
|
21
|
+
export function ComboBox({ className = '', name, headline, label, searchPattern = '', isOpen, options, placeholder, value, inputMode, noResultsText, leadingType, optionDetails, withSearch = true, theme = DEFAULT_THEME, optionsSlot, leadingIcon, disabled = false, loading = false, setIsOpen, onClick, onChange, onOutsideClick, onOptionItemClick, onSheetClose, }) {
|
|
22
|
+
const comboBoxRef = useRef(null);
|
|
23
|
+
const bottomSheetRef = useRef(null);
|
|
47
24
|
const [searchQuery, setSearchQuery] = useState('');
|
|
25
|
+
const [inputPlaceholder, setPlaceholder] = useState(placeholder);
|
|
26
|
+
const isDesktop = useIsDesktopScreenWidth();
|
|
27
|
+
const optionsExist = Object.keys(options).length > 0;
|
|
28
|
+
const showSelectField = !withSearch || (isDesktop && !isOpen) || !isDesktop;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
!isOpen && (onSheetClose === null || onSheetClose === void 0 ? void 0 : onSheetClose());
|
|
31
|
+
}, [isOpen]);
|
|
48
32
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
33
|
+
* Handles changes to the search input field
|
|
34
|
+
*
|
|
35
|
+
* @param e - The change event from the input
|
|
52
36
|
*/
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
const handleChange = (e) => {
|
|
38
|
+
const { value: searchValue } = e.target;
|
|
39
|
+
setSearchQuery(searchValue);
|
|
40
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(searchValue);
|
|
41
|
+
};
|
|
57
42
|
/**
|
|
58
|
-
*
|
|
59
|
-
* options that render a custom node instead of a plain `text` and for values
|
|
60
|
-
* that have no matching option at all.
|
|
43
|
+
* Clears the search input field
|
|
61
44
|
*/
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.map(getOptionLabel);
|
|
66
|
-
const selectedLabels = labels.length > 0 ? labels : selectedValues;
|
|
67
|
-
return renderValue ? renderValue(selectedLabels) : selectedLabels.join(', ');
|
|
68
|
-
}, [normalisedOptions, selectedValues, renderValue]);
|
|
69
|
-
const open = useCallback(() => {
|
|
70
|
-
if (disabled || loading)
|
|
71
|
-
return;
|
|
72
|
-
setIsOpen(true);
|
|
73
|
-
}, [disabled, loading, setIsOpen]);
|
|
45
|
+
const handleClearInput = () => {
|
|
46
|
+
setSearchQuery('');
|
|
47
|
+
};
|
|
74
48
|
/**
|
|
75
|
-
*
|
|
76
|
-
* deliberately (Tab, outside click) - returns the focus to the trigger.
|
|
77
|
-
*
|
|
78
|
-
* @param restoreFocus - Whether the focus goes back to the trigger
|
|
49
|
+
* Clears the search input and closes the dropdown/bottom sheet
|
|
79
50
|
*/
|
|
80
|
-
const
|
|
51
|
+
const clearAndClose = () => {
|
|
81
52
|
setSearchQuery('');
|
|
82
|
-
setHasTyped(false);
|
|
83
|
-
onChange === null || onChange === void 0 ? void 0 : onChange('');
|
|
84
53
|
setIsOpen(false);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Applies a selection. Single select closes the list, multi select keeps it
|
|
90
|
-
* open so further checkboxes can be toggled.
|
|
91
|
-
*
|
|
92
|
-
* @param optionValue - Value of the selected option
|
|
93
|
-
*/
|
|
94
|
-
const handleSelect = useCallback((optionValue) => {
|
|
95
|
-
onOptionItemClick === null || onOptionItemClick === void 0 ? void 0 : onOptionItemClick(optionValue);
|
|
96
|
-
if (!multiple)
|
|
97
|
-
close();
|
|
98
|
-
}, [multiple, onOptionItemClick, close]);
|
|
99
|
-
const { comboboxAriaProps, listboxAriaProps, onKeyDown, activeOptionId } = useComboBox({
|
|
100
|
-
options: normalisedOptions,
|
|
101
|
-
isOpen,
|
|
102
|
-
open,
|
|
103
|
-
close,
|
|
104
|
-
selectedValues,
|
|
105
|
-
onSelect: handleSelect,
|
|
106
|
-
listboxId,
|
|
107
|
-
searchable: withSearch,
|
|
108
|
-
multiple,
|
|
109
|
-
openOnEnter,
|
|
110
|
-
});
|
|
111
|
-
/**
|
|
112
|
-
* While the search field is open it owns the `combobox` role: it is the
|
|
113
|
-
* element the focus lives in, so it has to carry the ARIA state.
|
|
114
|
-
*/
|
|
115
|
-
const showSearchField = withSearch && isOpen;
|
|
116
|
-
/** On desktop the search field replaces the trigger in place. */
|
|
117
|
-
const showTrigger = !isDesktop || !showSearchField;
|
|
118
|
-
/**
|
|
119
|
-
* There must never be two comboboxes at once: while the bottom sheet holds
|
|
120
|
-
* the search field, the trigger behind it is inert.
|
|
121
|
-
*/
|
|
122
|
-
const triggerAriaProps = showSearchField
|
|
123
|
-
? { 'aria-hidden': true, tabIndex: -1 }
|
|
124
|
-
: comboboxAriaProps;
|
|
125
|
-
/** Notifies the consumer once the bottom sheet has actually closed. */
|
|
126
|
-
const wasOpen = useRef(isOpen);
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
if (wasOpen.current && !isOpen)
|
|
129
|
-
onSheetClose === null || onSheetClose === void 0 ? void 0 : onSheetClose();
|
|
130
|
-
wasOpen.current = isOpen;
|
|
131
|
-
}, [isOpen, onSheetClose]);
|
|
132
|
-
/**
|
|
133
|
-
* State of the list at `mousedown` time. The subsequent `click` toggles based
|
|
134
|
-
* on this value - otherwise the focus handler would open the list and the
|
|
135
|
-
* click would close it again straight away.
|
|
136
|
-
*/
|
|
137
|
-
const wasOpenOnPointerDown = useRef(false);
|
|
138
|
-
const handleRootPointerDown = useCallback(() => {
|
|
139
|
-
wasOpenOnPointerDown.current = isOpen;
|
|
140
|
-
}, [isOpen]);
|
|
141
|
-
/**
|
|
142
|
-
* Outside clicks are checked against the root: label, trigger, arrow and
|
|
143
|
-
* popover all live inside it and therefore never count as "outside".
|
|
144
|
-
*/
|
|
54
|
+
};
|
|
55
|
+
useEscapeKeyPress(clearAndClose, isOpen);
|
|
56
|
+
// Handle outside clicks for desktop dropdown
|
|
145
57
|
useEffect(() => {
|
|
146
58
|
if (!isDesktop || !isOpen)
|
|
147
59
|
return;
|
|
148
|
-
const
|
|
60
|
+
const handleDocumentClick = (event) => {
|
|
149
61
|
var _a;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
62
|
+
const node = event.target;
|
|
63
|
+
const isOutside = !((_a = comboBoxRef.current) === null || _a === void 0 ? void 0 : _a.contains(node));
|
|
64
|
+
if (isOutside) {
|
|
65
|
+
clearAndClose();
|
|
66
|
+
onOutsideClick === null || onOutsideClick === void 0 ? void 0 : onOutsideClick();
|
|
67
|
+
}
|
|
155
68
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
69
|
+
// Add listener after a small delay to avoid closing immediately on open
|
|
70
|
+
const timeoutId = setTimeout(() => {
|
|
71
|
+
document.addEventListener('mousedown', handleDocumentClick);
|
|
72
|
+
}, 100);
|
|
73
|
+
return () => {
|
|
74
|
+
clearTimeout(timeoutId);
|
|
75
|
+
document.removeEventListener('mousedown', handleDocumentClick);
|
|
76
|
+
};
|
|
77
|
+
}, [isDesktop, isOpen, onOutsideClick]);
|
|
159
78
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
79
|
+
* Handles click on an option item
|
|
80
|
+
*
|
|
81
|
+
* @param optionValue - The value of the clicked option
|
|
162
82
|
*/
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
83
|
+
const handleOptionItemClick = (optionValue) => {
|
|
84
|
+
onOptionItemClick === null || onOptionItemClick === void 0 ? void 0 : onOptionItemClick(optionValue);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Handles click on the input field
|
|
88
|
+
*/
|
|
89
|
+
const handleOnClick = () => {
|
|
169
90
|
if (disabled)
|
|
170
91
|
return;
|
|
171
92
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
172
|
-
|
|
173
|
-
close();
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
open();
|
|
177
|
-
}, [disabled, onClick, open, close]);
|
|
178
|
-
const handleSearchChange = useCallback((event) => {
|
|
179
|
-
setHasTyped(true);
|
|
180
|
-
setSearchQuery(event.target.value);
|
|
181
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value);
|
|
182
|
-
}, [onChange]);
|
|
183
|
-
const handleSearchClear = useCallback(() => {
|
|
184
|
-
setHasTyped(true);
|
|
185
|
-
setSearchQuery('');
|
|
186
|
-
onChange === null || onChange === void 0 ? void 0 : onChange('');
|
|
187
|
-
}, [onChange]);
|
|
93
|
+
};
|
|
188
94
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
95
|
+
* Renders the "no results" message when no options match the search
|
|
96
|
+
*
|
|
97
|
+
* @returns A text component displaying the no results message
|
|
191
98
|
*/
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
value: hasTyped || multiple ? searchQuery : displayValue, pattern: searchPattern, placeholder,
|
|
196
|
-
inputMode,
|
|
197
|
-
// The mobile sheet has no visible label, so the field needs a name of its own.
|
|
198
|
-
'aria-label': label, displayLeadingIcon: true, blurOnOutsideClick: false, onChange: handleSearchChange, onClear: handleSearchClear, onKeyDown }, comboboxAriaProps);
|
|
99
|
+
const NoResultsTextComponent = () => {
|
|
100
|
+
return (_jsx(Text, { variant: TextVariant.SUBHEADLINE, className: "combobox--no-results-text", children: noResultsText }));
|
|
101
|
+
};
|
|
199
102
|
/**
|
|
200
|
-
*
|
|
201
|
-
* the bottom sheet.
|
|
103
|
+
* Removes the placeholder text from the input field
|
|
202
104
|
*/
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
105
|
+
const removePlaceholder = () => {
|
|
106
|
+
setPlaceholder('');
|
|
107
|
+
};
|
|
108
|
+
return (_jsxs(ThemeProvider, { theme: theme, children: [showSelectField && (_jsx(SelectInput, { className: clsx(isOpen && 'active', className), name: name, label: label, value: value, placeholder: placeholder, onClick: handleOnClick, disableTrailingIconButton: true, leadingIcon: leadingIcon, disabled: disabled, loading: loading, readOnly: true })), isDesktop && isOpen && (_jsxs("div", { className: "combobox", ref: comboBoxRef, children: [withSearch && (_jsx(SearchInput, { name: name, value: searchQuery, pattern: searchPattern, label: label, onChange: handleChange, onClear: handleClearInput, displayLeadingIcon: isOpen, isCompact: true, inputMode: inputMode, autoFocus: true })), optionsSlot !== null && optionsSlot !== void 0 ? optionsSlot : (optionsExist ? (_jsx(ComboBoxOptions, { options: options, onClick: handleOptionItemClick, selectedOption: value, leadingType: leadingType })) : (_jsx(NoResultsTextComponent, {}))), _jsx("div", {})] })), !isDesktop && isOpen && (_jsxs(BottomSheet, { className: "combobox__bottom-sheet", open: isOpen, onClose: clearAndClose, ref: bottomSheetRef, children: [_jsxs("div", { className: "combobox--header", children: [_jsx(Text, { variant: TextVariant.HEADLINE, className: "combobox--headline", children: headline }), withSearch && (_jsx(SearchInput, { name: name, value: searchQuery, pattern: searchPattern, onChange: handleChange, onClear: handleClearInput, onFocus: removePlaceholder, placeholder: inputPlaceholder, isCompact: true, inputMode: inputMode, displayLeadingIcon: isOpen }))] }), _jsx("div", { className: "combobox__options", children: optionsSlot !== null && optionsSlot !== void 0 ? optionsSlot : (optionsExist ? (_jsx(ComboBoxOptions, { options: options, onClick: handleOptionItemClick, selectedOption: value, leadingType: leadingType, optionDetails: optionDetails })) : (_jsx(NoResultsTextComponent, {}))) })] }))] }));
|
|
207
109
|
}
|
|
208
|
-
export default ComboBox;
|
|
209
110
|
//# sourceMappingURL=ComboBox.js.map
|
package/lib/ComboBox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBox.js","sourceRoot":"","sources":["../src/ComboBox.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,
|
|
1
|
+
{"version":3,"file":"ComboBox.js","sourceRoot":"","sources":["../src/ComboBox.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAIL,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,WAAW,MAAM,qBAAqB,CAAA;AAC7C,OAAO,IAAI,EAAE,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MA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ACN,cAAK,SAAS,EAAC,mBAAmB,YAC/B,WAAW,aAAX,WAAW,cAAX,WAAW,GACV,CAAC,YAAY,CAAC,CAAC,CAAC,CACd,KAAC,eAAe,IACd,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,qBAAqB,EAC9B,cAAc,EAAE,KAAK,EACrB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC,CAAC,CAAC,CACF,KAAC,sBAAsB,KAAG,CAC3B,CAAC,GACA,IACM,CACf,IACa,CACjB,CAAA;AACH,CAAC"}
|
package/lib/hooks/index.d.ts
CHANGED
package/lib/hooks/index.js
CHANGED
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA"}
|
|
@@ -1,46 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
import { useSyncExternalStore } from 'react';
|
|
3
|
-
const DESKTOP_MEDIA_QUERY = '(min-width: 960px)';
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param onStoreChange - Callback invoked when the breakpoint match changes
|
|
9
|
-
* @returns An unsubscribe function that removes the listener
|
|
10
|
-
*/
|
|
11
|
-
function subscribe(onStoreChange) {
|
|
12
|
-
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
13
|
-
return () => { };
|
|
14
|
-
}
|
|
15
|
-
const mediaQueryList = window.matchMedia(DESKTOP_MEDIA_QUERY);
|
|
16
|
-
mediaQueryList.addEventListener('change', onStoreChange);
|
|
17
|
-
return () => mediaQueryList.removeEventListener('change', onStoreChange);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Client snapshot: the current match state of the desktop breakpoint.
|
|
3
|
+
* Custom hook that detects whether the viewport width is desktop size (>= 960px).
|
|
4
|
+
* Listens to window resize events to update the state dynamically.
|
|
21
5
|
*
|
|
22
|
-
* @returns True if the
|
|
6
|
+
* @returns True if the viewport width is 960px or greater, false otherwise
|
|
23
7
|
*/
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
return false;
|
|
27
|
-
return window.matchMedia(DESKTOP_MEDIA_QUERY).matches;
|
|
8
|
+
function isBrowser() {
|
|
9
|
+
return typeof window !== 'undefined';
|
|
28
10
|
}
|
|
29
11
|
/**
|
|
30
|
-
*
|
|
31
|
-
* render and the first client render match deterministically.
|
|
12
|
+
* Checks if the current viewport width is desktop size (>= 960px).
|
|
32
13
|
*
|
|
33
|
-
* @returns
|
|
14
|
+
* @returns True if the viewport is desktop size, false otherwise or in non-browser environments
|
|
34
15
|
*/
|
|
35
|
-
function
|
|
16
|
+
function isInitialScreenDesktop() {
|
|
17
|
+
if (isBrowser()) {
|
|
18
|
+
return window.innerWidth >= 960;
|
|
19
|
+
}
|
|
36
20
|
return false;
|
|
37
21
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Custom hook that detects whether the viewport width is desktop size (>= 960px).
|
|
40
|
-
*
|
|
41
|
-
* @returns True if the viewport width is 960px or greater, false otherwise
|
|
42
|
-
*/
|
|
43
22
|
export function useIsDesktopScreenWidth() {
|
|
44
|
-
|
|
23
|
+
const [isDesktop, setIsDesktop] = useState(isInitialScreenDesktop);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const checkScreenSize = () => {
|
|
26
|
+
setIsDesktop(window.innerWidth >= 960);
|
|
27
|
+
};
|
|
28
|
+
checkScreenSize();
|
|
29
|
+
window.addEventListener('resize', checkScreenSize);
|
|
30
|
+
return () => {
|
|
31
|
+
window.removeEventListener('resize', checkScreenSize);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return isDesktop;
|
|
45
35
|
}
|
|
46
36
|
//# sourceMappingURL=useIsDesktopScreenWidth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsDesktopScreenWidth.js","sourceRoot":"","sources":["../../src/hooks/useIsDesktopScreenWidth.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useIsDesktopScreenWidth.js","sourceRoot":"","sources":["../../src/hooks/useIsDesktopScreenWidth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE3C;;;;;GAKG;AAEH,SAAS,SAAS;IAChB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAA;AACtC,CAAC;AAED;;;;GAIG;AACH,SAAS,sBAAsB;IAC7B,IAAI,SAAS,EAAE,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC,UAAU,IAAI,GAAG,CAAA;IACjC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAU,sBAAsB,CAAC,CAAA;IAE3E,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,eAAe,GAAG,GAAG,EAAE;YAC3B,YAAY,CAAC,MAAM,CAAC,UAAU,IAAI,GAAG,CAAC,CAAA;QACxC,CAAC,CAAA;QAED,eAAe,EAAE,CAAA;QACjB,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAElD,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QACvD,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
import { ComboBox } from './ComboBox';
|
|
2
|
+
export default ComboBox;
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { ComboBoxOptionsSlot } from './partials';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { ComboBox } from './ComboBox';
|
|
2
|
+
export default ComboBox;
|
|
3
|
+
export * from './types';
|
|
2
4
|
export { ComboBoxOptionsSlot } from './partials';
|
|
3
|
-
export { useComboBox, useIsDesktopScreenWidth } from './hooks';
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,eAAe,QAAQ,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import type { ComboBoxOptionsProps } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* The panel is split in two: the `Menu` provides the visible box, the element
|
|
6
|
-
* inside it carries the `listbox` role and is the only part that scrolls. That
|
|
7
|
-
* keeps `optionDetails` a real footer - it stays visible without
|
|
8
|
-
* `position: sticky` and can no longer cover the active option - and it keeps
|
|
9
|
-
* the listbox free of anything that is not an option or a group, as ARIA
|
|
10
|
-
* requires.
|
|
11
|
-
*
|
|
12
|
-
* Flat and grouped options share one render path: the options arrive already
|
|
13
|
-
* normalised, `groupOptions` only splits them into their visual groups again.
|
|
14
|
-
* The listbox is not focusable - the focus stays in the input field, the active
|
|
15
|
-
* option is announced through `aria-activedescendant`.
|
|
3
|
+
* ComboBoxOptions component that renders a list of options in a menu.
|
|
4
|
+
* Handles both grouped and ungrouped options and automatically scrolls to the selected option.
|
|
16
5
|
*
|
|
17
6
|
* @param props - The props for the ComboBoxOptions component
|
|
18
|
-
* @returns
|
|
7
|
+
* @returns A menu containing the combobox options
|
|
19
8
|
*/
|
|
20
|
-
export declare function ComboBoxOptions({ options,
|
|
9
|
+
export declare function ComboBoxOptions({ options, onClick, selectedOption, leadingType, optionDetails, }: ComboBoxOptionsProps): import("react/jsx-runtime").JSX.Element;
|
|
21
10
|
export default ComboBoxOptions;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
2
3
|
import Menu from '@pixum/menu';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import styles from '../ComboBox.module.css';
|
|
4
|
+
import { useIsDesktopScreenWidth } from '../hooks';
|
|
5
|
+
import { scrollOptionToViewport } from '../utils';
|
|
6
|
+
import { ComboxBoxOptionsWithGrouping } from './ComboBoxOptionsWithGrouping';
|
|
7
|
+
import { ComboBoxOptionsItems } from './ComboBoxOptionsItems';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* The panel is split in two: the `Menu` provides the visible box, the element
|
|
12
|
-
* inside it carries the `listbox` role and is the only part that scrolls. That
|
|
13
|
-
* keeps `optionDetails` a real footer - it stays visible without
|
|
14
|
-
* `position: sticky` and can no longer cover the active option - and it keeps
|
|
15
|
-
* the listbox free of anything that is not an option or a group, as ARIA
|
|
16
|
-
* requires.
|
|
17
|
-
*
|
|
18
|
-
* Flat and grouped options share one render path: the options arrive already
|
|
19
|
-
* normalised, `groupOptions` only splits them into their visual groups again.
|
|
20
|
-
* The listbox is not focusable - the focus stays in the input field, the active
|
|
21
|
-
* option is announced through `aria-activedescendant`.
|
|
9
|
+
* ComboBoxOptions component that renders a list of options in a menu.
|
|
10
|
+
* Handles both grouped and ungrouped options and automatically scrolls to the selected option.
|
|
22
11
|
*
|
|
23
12
|
* @param props - The props for the ComboBoxOptions component
|
|
24
|
-
* @returns
|
|
13
|
+
* @returns A menu containing the combobox options
|
|
25
14
|
*/
|
|
26
|
-
export function ComboBoxOptions({ options,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
export function ComboBoxOptions({ options, onClick, selectedOption, leadingType, optionDetails, }) {
|
|
16
|
+
const isDesktop = useIsDesktopScreenWidth();
|
|
17
|
+
const optionsWithoutGroup = Array.isArray(options);
|
|
18
|
+
const optionsWithGroup = Object.entries(options);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
// Wait for next browser frame to ensure DOM is fully rendered
|
|
21
|
+
const frameId = requestAnimationFrame(() => {
|
|
22
|
+
scrollOptionToViewport(isDesktop);
|
|
23
|
+
});
|
|
24
|
+
return () => cancelAnimationFrame(frameId);
|
|
25
|
+
}, [isDesktop, selectedOption]);
|
|
26
|
+
return (_jsxs(Menu, { className: "combobox__options scrollable", "data-tappable": "true", children: [optionsWithoutGroup ? (_jsx(ComboBoxOptionsItems, { items: options, selectedOption: selectedOption, onClick: onClick, leadingType: leadingType })) : (_jsx(_Fragment, { children: optionsWithGroup.map(([group, items]) => (_jsx(ComboxBoxOptionsWithGrouping, { group: group, items: items, selectedOption: selectedOption, onClick: onClick, leadingType: leadingType }, `combobox__options-group-${group}`))) })), optionDetails && (_jsx("div", { className: "combobox__option-details text--caption", children: optionDetails }))] }));
|
|
31
27
|
}
|
|
32
28
|
export default ComboBoxOptions;
|
|
33
29
|
//# sourceMappingURL=ComboBoxOptions.js.map
|