@proyecto-viviana/solidaria-components 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ActionBar.js +184 -0
- package/dist/ActionBar.js.map +1 -0
- package/dist/ActionBar.jsx +128 -0
- package/dist/ActionBar.jsx.map +1 -0
- package/dist/ActionGroup.js +179 -0
- package/dist/ActionGroup.js.map +1 -0
- package/dist/ActionGroup.jsx +129 -0
- package/dist/ActionGroup.jsx.map +1 -0
- package/dist/Alert.js +111 -0
- package/dist/Alert.js.map +1 -0
- package/dist/Alert.jsx +82 -0
- package/dist/Alert.jsx.map +1 -0
- package/dist/Autocomplete.js +130 -0
- package/dist/Autocomplete.js.map +1 -0
- package/dist/Autocomplete.jsx +116 -0
- package/dist/Autocomplete.jsx.map +1 -0
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Breadcrumbs.js +334 -0
- package/dist/Breadcrumbs.js.map +1 -0
- package/dist/Breadcrumbs.jsx +266 -0
- package/dist/Breadcrumbs.jsx.map +1 -0
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +348 -0
- package/dist/Button.js.map +1 -0
- package/dist/Button.jsx +314 -0
- package/dist/Button.jsx.map +1 -0
- package/dist/Calendar.d.ts +4 -4
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Calendar.js +538 -0
- package/dist/Calendar.js.map +1 -0
- package/dist/Calendar.jsx +333 -0
- package/dist/Calendar.jsx.map +1 -0
- package/dist/CalendarPicker.d.ts +33 -0
- package/dist/CalendarPicker.d.ts.map +1 -0
- package/dist/CalendarPicker.js +44 -0
- package/dist/CalendarPicker.js.map +1 -0
- package/dist/CalendarPicker.jsx +44 -0
- package/dist/CalendarPicker.jsx.map +1 -0
- package/dist/Checkbox.d.ts +83 -4
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Checkbox.js +923 -0
- package/dist/Checkbox.js.map +1 -0
- package/dist/Checkbox.jsx +707 -0
- package/dist/Checkbox.jsx.map +1 -0
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +202 -0
- package/dist/Collection.js.map +1 -0
- package/dist/Collection.jsx +152 -0
- package/dist/Collection.jsx.map +1 -0
- package/dist/Color.d.ts.map +1 -1
- package/dist/Color.js +1720 -0
- package/dist/Color.js.map +1 -0
- package/dist/Color.jsx +1344 -0
- package/dist/Color.jsx.map +1 -0
- package/dist/ColorEditor.js +208 -0
- package/dist/ColorEditor.js.map +1 -0
- package/dist/ColorEditor.jsx +120 -0
- package/dist/ColorEditor.jsx.map +1 -0
- package/dist/ComboBox.d.ts +4 -4
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ComboBox.js +992 -0
- package/dist/ComboBox.js.map +1 -0
- package/dist/ComboBox.jsx +714 -0
- package/dist/ComboBox.jsx.map +1 -0
- package/dist/ContextualHelpTrigger.js +146 -0
- package/dist/ContextualHelpTrigger.js.map +1 -0
- package/dist/ContextualHelpTrigger.jsx +109 -0
- package/dist/ContextualHelpTrigger.jsx.map +1 -0
- package/dist/DateField.d.ts +3 -3
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DateField.js +4 -0
- package/dist/DateField.jsx +4 -0
- package/dist/DateField2.js +499 -0
- package/dist/DateField2.js.map +1 -0
- package/dist/DateField2.jsx +317 -0
- package/dist/DateField2.jsx.map +1 -0
- package/dist/DatePicker.d.ts +4 -4
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DatePicker.js +991 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/DatePicker.jsx +682 -0
- package/dist/DatePicker.jsx.map +1 -0
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Dialog.js +337 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Dialog.jsx +192 -0
- package/dist/Dialog.jsx.map +1 -0
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/Disclosure.js +328 -0
- package/dist/Disclosure.js.map +1 -0
- package/dist/Disclosure.jsx +230 -0
- package/dist/Disclosure.jsx.map +1 -0
- package/dist/DragAndDrop.d.ts.map +1 -1
- package/dist/DragAndDrop.js +176 -0
- package/dist/DragAndDrop.js.map +1 -0
- package/dist/DragAndDrop.jsx +160 -0
- package/dist/DragAndDrop.jsx.map +1 -0
- package/dist/DropZone.d.ts.map +1 -1
- package/dist/DropZone.js +189 -0
- package/dist/DropZone.js.map +1 -0
- package/dist/DropZone.jsx +144 -0
- package/dist/DropZone.jsx.map +1 -0
- package/dist/FieldError.js +66 -0
- package/dist/FieldError.js.map +1 -0
- package/dist/FieldError.jsx +47 -0
- package/dist/FieldError.jsx.map +1 -0
- package/dist/FileTrigger.js +79 -0
- package/dist/FileTrigger.js.map +1 -0
- package/dist/FileTrigger.jsx +49 -0
- package/dist/FileTrigger.jsx.map +1 -0
- package/dist/Focusable.js +70 -0
- package/dist/Focusable.js.map +1 -0
- package/dist/Focusable.jsx +69 -0
- package/dist/Focusable.jsx.map +1 -0
- package/dist/Form.js +99 -0
- package/dist/Form.js.map +1 -0
- package/dist/Form.jsx +73 -0
- package/dist/Form.jsx.map +1 -0
- package/dist/GridList.d.ts +34 -2
- package/dist/GridList.d.ts.map +1 -1
- package/dist/GridList.js +723 -0
- package/dist/GridList.js.map +1 -0
- package/dist/GridList.jsx +552 -0
- package/dist/GridList.jsx.map +1 -0
- package/dist/HiddenTimeInput.js +104 -0
- package/dist/HiddenTimeInput.js.map +1 -0
- package/dist/HiddenTimeInput.jsx +69 -0
- package/dist/HiddenTimeInput.jsx.map +1 -0
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Icon.js +127 -0
- package/dist/Icon.js.map +1 -0
- package/dist/Icon.jsx +72 -0
- package/dist/Icon.jsx.map +1 -0
- package/dist/Keyboard.js +30 -0
- package/dist/Keyboard.js.map +1 -0
- package/dist/Keyboard.jsx +24 -0
- package/dist/Keyboard.jsx.map +1 -0
- package/dist/Landmark.js +134 -0
- package/dist/Landmark.js.map +1 -0
- package/dist/Landmark.jsx +118 -0
- package/dist/Landmark.jsx.map +1 -0
- package/dist/Link.d.ts.map +1 -1
- package/dist/Link.js +219 -0
- package/dist/Link.js.map +1 -0
- package/dist/Link.jsx +189 -0
- package/dist/Link.jsx.map +1 -0
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListBox.js +670 -0
- package/dist/ListBox.js.map +1 -0
- package/dist/ListBox.jsx +508 -0
- package/dist/ListBox.jsx.map +1 -0
- package/dist/Menu.d.ts +27 -9
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Menu.js +1254 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Menu.jsx +1042 -0
- package/dist/Menu.jsx.map +1 -0
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Meter.js +123 -0
- package/dist/Meter.js.map +1 -0
- package/dist/Meter.jsx +107 -0
- package/dist/Meter.jsx.map +1 -0
- package/dist/Modal.d.ts.map +1 -1
- package/dist/Modal.js +380 -0
- package/dist/Modal.js.map +1 -0
- package/dist/Modal.jsx +314 -0
- package/dist/Modal.jsx.map +1 -0
- package/dist/NumberField.d.ts +3 -3
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/NumberField.js +573 -0
- package/dist/NumberField.js.map +1 -0
- package/dist/NumberField.jsx +443 -0
- package/dist/NumberField.jsx.map +1 -0
- package/dist/Popover.d.ts +10 -2
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Popover.js +464 -0
- package/dist/Popover.js.map +1 -0
- package/dist/Popover.jsx +333 -0
- package/dist/Popover.jsx.map +1 -0
- package/dist/Pressable.js +69 -0
- package/dist/Pressable.js.map +1 -0
- package/dist/Pressable.jsx +68 -0
- package/dist/Pressable.jsx.map +1 -0
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/ProgressBar.js +130 -0
- package/dist/ProgressBar.js.map +1 -0
- package/dist/ProgressBar.jsx +114 -0
- package/dist/ProgressBar.jsx.map +1 -0
- package/dist/RadioGroup.d.ts +82 -4
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RadioGroup.js +931 -0
- package/dist/RadioGroup.js.map +1 -0
- package/dist/RadioGroup.jsx +681 -0
- package/dist/RadioGroup.jsx.map +1 -0
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RangeCalendar.js +410 -0
- package/dist/RangeCalendar.js.map +1 -0
- package/dist/RangeCalendar.jsx +253 -0
- package/dist/RangeCalendar.jsx.map +1 -0
- package/dist/RouterProvider.js +118 -0
- package/dist/RouterProvider.js.map +1 -0
- package/dist/RouterProvider.jsx +112 -0
- package/dist/RouterProvider.jsx.map +1 -0
- package/dist/SearchField.d.ts +2 -2
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/SearchField.js +643 -0
- package/dist/SearchField.js.map +1 -0
- package/dist/SearchField.jsx +526 -0
- package/dist/SearchField.jsx.map +1 -0
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +1031 -0
- package/dist/Select.js.map +1 -0
- package/dist/Select.jsx +744 -0
- package/dist/Select.jsx.map +1 -0
- package/dist/SelectionIndicator.d.ts.map +1 -1
- package/dist/SelectionIndicator.js +86 -0
- package/dist/SelectionIndicator.js.map +1 -0
- package/dist/SelectionIndicator.jsx +50 -0
- package/dist/SelectionIndicator.jsx.map +1 -0
- package/dist/Separator.js +97 -0
- package/dist/Separator.js.map +1 -0
- package/dist/Separator.jsx +85 -0
- package/dist/Separator.jsx.map +1 -0
- package/dist/SharedElementTransition.d.ts.map +1 -1
- package/dist/SharedElementTransition.js +165 -0
- package/dist/SharedElementTransition.js.map +1 -0
- package/dist/SharedElementTransition.jsx +138 -0
- package/dist/SharedElementTransition.jsx.map +1 -0
- package/dist/Slider.d.ts +33 -1
- package/dist/Slider.d.ts.map +1 -1
- package/dist/Slider.js +515 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Slider.jsx +403 -0
- package/dist/Slider.jsx.map +1 -0
- package/dist/StepList.js +198 -0
- package/dist/StepList.js.map +1 -0
- package/dist/StepList.jsx +141 -0
- package/dist/StepList.jsx.map +1 -0
- package/dist/Switch.d.ts +65 -2
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Switch.js +534 -0
- package/dist/Switch.js.map +1 -0
- package/dist/Switch.jsx +393 -0
- package/dist/Switch.jsx.map +1 -0
- package/dist/Table.d.ts +48 -0
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +1759 -0
- package/dist/Table.js.map +1 -0
- package/dist/Table.jsx +1348 -0
- package/dist/Table.jsx.map +1 -0
- package/dist/Tabs.d.ts +0 -4
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/Tabs.js +595 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Tabs.jsx +367 -0
- package/dist/Tabs.jsx.map +1 -0
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/TagGroup.js +378 -0
- package/dist/TagGroup.js.map +1 -0
- package/dist/TagGroup.jsx +270 -0
- package/dist/TagGroup.jsx.map +1 -0
- package/dist/Text.d.ts +18 -6
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +42 -0
- package/dist/Text.js.map +1 -0
- package/dist/Text.jsx +35 -0
- package/dist/Text.jsx.map +1 -0
- package/dist/TextField.d.ts +6 -6
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +436 -0
- package/dist/TextField.js.map +1 -0
- package/dist/TextField.jsx +403 -0
- package/dist/TextField.jsx.map +1 -0
- package/dist/TimeField.d.ts +3 -3
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/TimeField.js +372 -0
- package/dist/TimeField.js.map +1 -0
- package/dist/TimeField.jsx +224 -0
- package/dist/TimeField.jsx.map +1 -0
- package/dist/Toast.d.ts +14 -0
- package/dist/Toast.d.ts.map +1 -1
- package/dist/Toast.js +551 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Toast.jsx +361 -0
- package/dist/Toast.jsx.map +1 -0
- package/dist/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButton.js +123 -0
- package/dist/ToggleButton.js.map +1 -0
- package/dist/ToggleButton.jsx +88 -0
- package/dist/ToggleButton.jsx.map +1 -0
- package/dist/ToggleButtonGroup.d.ts.map +1 -1
- package/dist/ToggleButtonGroup.js +114 -0
- package/dist/ToggleButtonGroup.js.map +1 -0
- package/dist/ToggleButtonGroup.jsx +85 -0
- package/dist/ToggleButtonGroup.jsx.map +1 -0
- package/dist/Toolbar.js +112 -0
- package/dist/Toolbar.js.map +1 -0
- package/dist/Toolbar.jsx +92 -0
- package/dist/Toolbar.jsx.map +1 -0
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip.js +539 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/Tooltip.jsx +465 -0
- package/dist/Tooltip.jsx.map +1 -0
- package/dist/Tree.d.ts +14 -2
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Tree.js +1424 -0
- package/dist/Tree.js.map +1 -0
- package/dist/Tree.jsx +1172 -0
- package/dist/Tree.jsx.map +1 -0
- package/dist/Virtualizer.d.ts +16 -2
- package/dist/Virtualizer.d.ts.map +1 -1
- package/dist/Virtualizer.js +2 -0
- package/dist/Virtualizer.jsx +2 -0
- package/dist/Virtualizer2.js +751 -0
- package/dist/Virtualizer2.js.map +1 -0
- package/dist/Virtualizer2.jsx +730 -0
- package/dist/Virtualizer2.jsx.map +1 -0
- package/dist/VirtualizerLayouts.d.ts +18 -0
- package/dist/VirtualizerLayouts.d.ts.map +1 -1
- package/dist/VisuallyHidden.js +42 -0
- package/dist/VisuallyHidden.js.map +1 -0
- package/dist/VisuallyHidden.jsx +35 -0
- package/dist/VisuallyHidden.jsx.map +1 -0
- package/dist/contexts.js +33 -0
- package/dist/contexts.js.map +1 -0
- package/dist/contexts.jsx +33 -0
- package/dist/contexts.jsx.map +1 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -23932
- package/dist/index.jsx +70 -18337
- package/dist/useDragAndDrop.js +2 -0
- package/dist/useDragAndDrop.jsx +2 -0
- package/dist/useDragAndDrop2.js +395 -0
- package/dist/useDragAndDrop2.js.map +1 -0
- package/dist/useDragAndDrop2.jsx +395 -0
- package/dist/useDragAndDrop2.jsx.map +1 -0
- package/dist/utils.d.ts +83 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +285 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.jsx +277 -0
- package/dist/utils.jsx.map +1 -0
- package/dist/virtualizer/Layout.js +144 -0
- package/dist/virtualizer/Layout.js.map +1 -0
- package/dist/virtualizer/Layout.jsx +144 -0
- package/dist/virtualizer/Layout.jsx.map +1 -0
- package/package.json +401 -4
- package/src/Breadcrumbs.tsx +3 -1
- package/src/Button.tsx +22 -2
- package/src/Calendar.tsx +27 -10
- package/src/CalendarPicker.tsx +73 -0
- package/src/Checkbox.tsx +539 -3
- package/src/Collection.tsx +9 -3
- package/src/Color.tsx +42 -14
- package/src/ComboBox.tsx +50 -6
- package/src/DateField.tsx +20 -2
- package/src/DatePicker.tsx +57 -5
- package/src/Dialog.tsx +13 -5
- package/src/Disclosure.tsx +3 -1
- package/src/DragAndDrop.tsx +3 -1
- package/src/DropZone.tsx +3 -1
- package/src/GridList.tsx +125 -24
- package/src/Icon.tsx +3 -1
- package/src/Link.tsx +3 -1
- package/src/ListBox.tsx +31 -4
- package/src/Menu.tsx +252 -128
- package/src/Meter.tsx +3 -1
- package/src/Modal.tsx +100 -52
- package/src/NumberField.tsx +51 -8
- package/src/Popover.tsx +40 -10
- package/src/ProgressBar.tsx +3 -1
- package/src/RadioGroup.tsx +468 -4
- package/src/RangeCalendar.tsx +3 -1
- package/src/SearchField.tsx +27 -3
- package/src/Select.tsx +22 -7
- package/src/SelectionIndicator.tsx +3 -1
- package/src/SharedElementTransition.tsx +3 -1
- package/src/Slider.tsx +159 -13
- package/src/Switch.tsx +395 -2
- package/src/Table.tsx +409 -95
- package/src/Tabs.tsx +16 -45
- package/src/TagGroup.tsx +3 -1
- package/src/Text.tsx +31 -10
- package/src/TextField.tsx +43 -5
- package/src/TimeField.tsx +20 -2
- package/src/Toast.tsx +79 -14
- package/src/ToggleButton.tsx +3 -1
- package/src/ToggleButtonGroup.tsx +3 -1
- package/src/Tooltip.tsx +3 -1
- package/src/Tree.tsx +77 -9
- package/src/Virtualizer.tsx +180 -31
- package/src/VirtualizerLayouts.ts +45 -10
- package/src/index.ts +50 -0
- package/src/utils.tsx +243 -27
- package/dist/index.js.map +0 -1
- package/dist/index.jsx.map +0 -1
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
import { Provider, filterDOMProps, useRenderProps } from "./utils.jsx";
|
|
2
|
+
import { TextContext } from "./Text.jsx";
|
|
3
|
+
import { SelectionIndicatorContext } from "./SelectionIndicator.jsx";
|
|
4
|
+
import { For, Show, createContext, createEffect, createMemo, createSignal, onCleanup, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { createComboBox, createHover, createInteractOutside, createListBox, createOption, createScrollIntoViewOnFocus, getComboBoxData, mergeProps as mergeProps$1 } from "@proyecto-viviana/solidaria";
|
|
6
|
+
import { createComboBoxState, defaultContainsFilter } from "@proyecto-viviana/solid-stately";
|
|
7
|
+
//#region src/ComboBox.tsx
|
|
8
|
+
/**
|
|
9
|
+
* ComboBox component for solidaria-components
|
|
10
|
+
*
|
|
11
|
+
* A pre-wired headless combobox that combines state + aria hooks.
|
|
12
|
+
* Port of react-aria-components/src/ComboBox.tsx
|
|
13
|
+
*/
|
|
14
|
+
function assignRef(ref, el) {
|
|
15
|
+
if (!ref) return;
|
|
16
|
+
if (typeof ref === "function") ref(el);
|
|
17
|
+
else ref.current = el;
|
|
18
|
+
}
|
|
19
|
+
const ComboBoxContext = createContext(null);
|
|
20
|
+
const ComboBoxStateContext = createContext(null);
|
|
21
|
+
const ComboBoxValueContext = ComboBoxContext;
|
|
22
|
+
function callInputKeyDown(handler, event) {
|
|
23
|
+
if (typeof handler === "function") handler(event);
|
|
24
|
+
else if (handler) handler[0](handler[1], event);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A combobox combines a text input with a listbox, allowing users to filter a list of options.
|
|
28
|
+
*/
|
|
29
|
+
function ComboBox(props) {
|
|
30
|
+
const contextSlotProps = useContext(ComboBoxContext)?.slots?.[props.slot ?? "default"];
|
|
31
|
+
const [local, stateProps, ariaProps] = splitProps(contextSlotProps ? mergeProps$1(contextSlotProps, props) : props, [
|
|
32
|
+
"class",
|
|
33
|
+
"style",
|
|
34
|
+
"slot",
|
|
35
|
+
"children",
|
|
36
|
+
"ref",
|
|
37
|
+
"rootRef",
|
|
38
|
+
"slots"
|
|
39
|
+
], [
|
|
40
|
+
"items",
|
|
41
|
+
"defaultItems",
|
|
42
|
+
"getKey",
|
|
43
|
+
"getTextValue",
|
|
44
|
+
"getDisabled",
|
|
45
|
+
"disabledKeys",
|
|
46
|
+
"selectionMode",
|
|
47
|
+
"selectedKey",
|
|
48
|
+
"defaultSelectedKey",
|
|
49
|
+
"selectedKeys",
|
|
50
|
+
"defaultSelectedKeys",
|
|
51
|
+
"onSelectionChange",
|
|
52
|
+
"onSelectionChangeMultiple",
|
|
53
|
+
"inputValue",
|
|
54
|
+
"defaultInputValue",
|
|
55
|
+
"onInputChange",
|
|
56
|
+
"isOpen",
|
|
57
|
+
"defaultOpen",
|
|
58
|
+
"onOpenChange",
|
|
59
|
+
"defaultFilter",
|
|
60
|
+
"allowsCustomValue",
|
|
61
|
+
"allowsEmptyCollection",
|
|
62
|
+
"menuTrigger",
|
|
63
|
+
"name",
|
|
64
|
+
"formValue"
|
|
65
|
+
]);
|
|
66
|
+
let inputRef = null;
|
|
67
|
+
let buttonRef = null;
|
|
68
|
+
let triggerRef = null;
|
|
69
|
+
let listBoxRef = null;
|
|
70
|
+
const optionActions = /* @__PURE__ */ new Map();
|
|
71
|
+
const runOptionAction = (key) => {
|
|
72
|
+
optionActions.get(key)?.();
|
|
73
|
+
};
|
|
74
|
+
const state = createComboBoxState({
|
|
75
|
+
get items() {
|
|
76
|
+
return stateProps.items;
|
|
77
|
+
},
|
|
78
|
+
get defaultItems() {
|
|
79
|
+
return stateProps.defaultItems;
|
|
80
|
+
},
|
|
81
|
+
get getKey() {
|
|
82
|
+
return stateProps.getKey;
|
|
83
|
+
},
|
|
84
|
+
get getTextValue() {
|
|
85
|
+
return stateProps.getTextValue;
|
|
86
|
+
},
|
|
87
|
+
get getDisabled() {
|
|
88
|
+
return stateProps.getDisabled;
|
|
89
|
+
},
|
|
90
|
+
get disabledKeys() {
|
|
91
|
+
return stateProps.disabledKeys;
|
|
92
|
+
},
|
|
93
|
+
get selectionMode() {
|
|
94
|
+
return stateProps.selectionMode;
|
|
95
|
+
},
|
|
96
|
+
get selectedKey() {
|
|
97
|
+
return stateProps.selectedKey;
|
|
98
|
+
},
|
|
99
|
+
get defaultSelectedKey() {
|
|
100
|
+
return stateProps.defaultSelectedKey;
|
|
101
|
+
},
|
|
102
|
+
get selectedKeys() {
|
|
103
|
+
return stateProps.selectedKeys;
|
|
104
|
+
},
|
|
105
|
+
get defaultSelectedKeys() {
|
|
106
|
+
return stateProps.defaultSelectedKeys;
|
|
107
|
+
},
|
|
108
|
+
get onSelectionChange() {
|
|
109
|
+
return stateProps.onSelectionChange;
|
|
110
|
+
},
|
|
111
|
+
get onSelectionChangeMultiple() {
|
|
112
|
+
return stateProps.onSelectionChangeMultiple;
|
|
113
|
+
},
|
|
114
|
+
get inputValue() {
|
|
115
|
+
return stateProps.inputValue;
|
|
116
|
+
},
|
|
117
|
+
get defaultInputValue() {
|
|
118
|
+
return stateProps.defaultInputValue;
|
|
119
|
+
},
|
|
120
|
+
get onInputChange() {
|
|
121
|
+
return stateProps.onInputChange;
|
|
122
|
+
},
|
|
123
|
+
get isOpen() {
|
|
124
|
+
return stateProps.isOpen;
|
|
125
|
+
},
|
|
126
|
+
get defaultOpen() {
|
|
127
|
+
return stateProps.defaultOpen;
|
|
128
|
+
},
|
|
129
|
+
get onOpenChange() {
|
|
130
|
+
return stateProps.onOpenChange;
|
|
131
|
+
},
|
|
132
|
+
get defaultFilter() {
|
|
133
|
+
return stateProps.defaultFilter;
|
|
134
|
+
},
|
|
135
|
+
get allowsCustomValue() {
|
|
136
|
+
return stateProps.allowsCustomValue;
|
|
137
|
+
},
|
|
138
|
+
get allowsEmptyCollection() {
|
|
139
|
+
return stateProps.allowsEmptyCollection;
|
|
140
|
+
},
|
|
141
|
+
get menuTrigger() {
|
|
142
|
+
return stateProps.menuTrigger;
|
|
143
|
+
},
|
|
144
|
+
get isDisabled() {
|
|
145
|
+
return ariaProps.isDisabled;
|
|
146
|
+
},
|
|
147
|
+
get isReadOnly() {
|
|
148
|
+
return ariaProps.isReadOnly;
|
|
149
|
+
},
|
|
150
|
+
get isRequired() {
|
|
151
|
+
return ariaProps.isRequired;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const listState = createComboBoxListStateAdapter(state);
|
|
155
|
+
const effectiveFormValue = createMemo(() => {
|
|
156
|
+
if (stateProps.allowsCustomValue) return "text";
|
|
157
|
+
return stateProps.formValue ?? "key";
|
|
158
|
+
});
|
|
159
|
+
const comboBoxAriaProps = createMemo(() => {
|
|
160
|
+
const cleanProps = {};
|
|
161
|
+
for (const key in ariaProps) if (!key.startsWith("data-")) cleanProps[key] = ariaProps[key];
|
|
162
|
+
return cleanProps;
|
|
163
|
+
});
|
|
164
|
+
const comboBoxAria = createComboBox(() => ({
|
|
165
|
+
...comboBoxAriaProps(),
|
|
166
|
+
get name() {
|
|
167
|
+
return effectiveFormValue() === "text" ? stateProps.name : void 0;
|
|
168
|
+
}
|
|
169
|
+
}), state, () => inputRef, () => buttonRef, () => listBoxRef);
|
|
170
|
+
const getInputProps = () => {
|
|
171
|
+
const inputProps = comboBoxAria.inputProps;
|
|
172
|
+
const originalOnKeyDown = inputProps.onKeyDown;
|
|
173
|
+
return {
|
|
174
|
+
...inputProps,
|
|
175
|
+
onKeyDown: (event) => {
|
|
176
|
+
const focusedKey = state.focusedKey();
|
|
177
|
+
const optionAction = event.key === "Enter" && state.isOpen() && focusedKey != null && !state.isKeyDisabled(focusedKey) ? optionActions.get(focusedKey) : void 0;
|
|
178
|
+
callInputKeyDown(originalOnKeyDown, event);
|
|
179
|
+
optionAction?.();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const { isHovered, hoverProps } = createHover({ get isDisabled() {
|
|
184
|
+
return ariaProps.isDisabled;
|
|
185
|
+
} });
|
|
186
|
+
const renderValues = createMemo(() => ({
|
|
187
|
+
isOpen: comboBoxAria.isOpen(),
|
|
188
|
+
isFocused: comboBoxAria.isFocused(),
|
|
189
|
+
isFocusVisible: comboBoxAria.isFocusVisible(),
|
|
190
|
+
isDisabled: !!ariaProps.isDisabled,
|
|
191
|
+
isRequired: !!ariaProps.isRequired,
|
|
192
|
+
isInvalid: !!ariaProps.isInvalid,
|
|
193
|
+
isReadOnly: !!ariaProps.isReadOnly,
|
|
194
|
+
isSelected: state.selectedKey() != null,
|
|
195
|
+
inputValue: state.inputValue()
|
|
196
|
+
}));
|
|
197
|
+
const renderProps = useRenderProps({
|
|
198
|
+
class: local.class,
|
|
199
|
+
style: local.style,
|
|
200
|
+
defaultClassName: "solidaria-ComboBox"
|
|
201
|
+
}, renderValues);
|
|
202
|
+
const domProps = createMemo(() => {
|
|
203
|
+
return filterDOMProps(ariaProps, { global: true });
|
|
204
|
+
});
|
|
205
|
+
const cleanHoverProps = () => {
|
|
206
|
+
const { ref: _ref, ...rest } = hoverProps;
|
|
207
|
+
return rest;
|
|
208
|
+
};
|
|
209
|
+
const ComboBoxChildren = () => typeof local.children === "function" ? local.children(renderValues()) : local.children;
|
|
210
|
+
const textSlots = { slots: {
|
|
211
|
+
get description() {
|
|
212
|
+
return comboBoxAria.descriptionProps;
|
|
213
|
+
},
|
|
214
|
+
get errorMessage() {
|
|
215
|
+
return comboBoxAria.errorMessageProps;
|
|
216
|
+
}
|
|
217
|
+
} };
|
|
218
|
+
return <ComboBoxContext.Provider value={{
|
|
219
|
+
state,
|
|
220
|
+
listState,
|
|
221
|
+
inputProps: getInputProps,
|
|
222
|
+
buttonProps: () => comboBoxAria.buttonProps,
|
|
223
|
+
listBoxProps: () => ({
|
|
224
|
+
...comboBoxAria.listBoxProps,
|
|
225
|
+
onAction: void 0,
|
|
226
|
+
shouldUseVirtualFocus: true,
|
|
227
|
+
shouldSelectOnPressUp: true,
|
|
228
|
+
shouldFocusOnHover: true,
|
|
229
|
+
linkBehavior: "selection",
|
|
230
|
+
UNSTABLE_itemBehavior: "action"
|
|
231
|
+
}),
|
|
232
|
+
labelProps: () => comboBoxAria.labelProps,
|
|
233
|
+
descriptionProps: () => comboBoxAria.descriptionProps,
|
|
234
|
+
errorMessageProps: () => comboBoxAria.errorMessageProps,
|
|
235
|
+
isOpen: comboBoxAria.isOpen,
|
|
236
|
+
isFocused: comboBoxAria.isFocused,
|
|
237
|
+
isFocusVisible: comboBoxAria.isFocusVisible,
|
|
238
|
+
items: stateProps.items ?? stateProps.defaultItems ?? [],
|
|
239
|
+
inputRef: () => inputRef,
|
|
240
|
+
setInputRef: (el) => {
|
|
241
|
+
inputRef = el;
|
|
242
|
+
},
|
|
243
|
+
buttonRef: () => buttonRef,
|
|
244
|
+
setButtonRef: (el) => {
|
|
245
|
+
buttonRef = el;
|
|
246
|
+
},
|
|
247
|
+
triggerRef: () => triggerRef,
|
|
248
|
+
setTriggerRef: (el) => {
|
|
249
|
+
triggerRef = el;
|
|
250
|
+
},
|
|
251
|
+
listBoxRef: () => listBoxRef,
|
|
252
|
+
setListBoxRef: (el) => {
|
|
253
|
+
listBoxRef = el;
|
|
254
|
+
},
|
|
255
|
+
registerOptionAction: (key, action) => {
|
|
256
|
+
if (action) optionActions.set(key, action);
|
|
257
|
+
else optionActions.delete(key);
|
|
258
|
+
},
|
|
259
|
+
runOptionAction,
|
|
260
|
+
slots: local.slots
|
|
261
|
+
}}>
|
|
262
|
+
<ComboBoxStateContext.Provider value={state}>
|
|
263
|
+
<div {...domProps()} {...cleanHoverProps()} ref={(el) => {
|
|
264
|
+
assignRef(local.ref, el);
|
|
265
|
+
assignRef(local.rootRef, el);
|
|
266
|
+
}} class={renderProps.class()} style={renderProps.style()} data-open={comboBoxAria.isOpen() || void 0} data-focused={comboBoxAria.isFocused() || void 0} data-focus-visible={comboBoxAria.isFocusVisible() || void 0} data-disabled={ariaProps.isDisabled || void 0} data-required={ariaProps.isRequired || void 0} data-invalid={ariaProps.isInvalid || void 0} data-readonly={ariaProps.isReadOnly || void 0} data-hovered={isHovered() || void 0} slot={local.slot}>
|
|
267
|
+
{}
|
|
268
|
+
<Show when={stateProps.name && effectiveFormValue() === "key"}>
|
|
269
|
+
<input type="hidden" name={stateProps.name} form={ariaProps.form} value={state.selectedKey()?.toString() ?? ""} />
|
|
270
|
+
</Show>
|
|
271
|
+
<Provider values={[[TextContext, textSlots]]}>
|
|
272
|
+
<ComboBoxChildren />
|
|
273
|
+
</Provider>
|
|
274
|
+
</div>
|
|
275
|
+
</ComboBoxStateContext.Provider>
|
|
276
|
+
</ComboBoxContext.Provider>;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Label element for a combobox.
|
|
280
|
+
*/
|
|
281
|
+
function ComboBoxLabel(props) {
|
|
282
|
+
const [local, domProps] = splitProps(props, [
|
|
283
|
+
"class",
|
|
284
|
+
"style",
|
|
285
|
+
"slot",
|
|
286
|
+
"children"
|
|
287
|
+
]);
|
|
288
|
+
const context = useContext(ComboBoxContext);
|
|
289
|
+
if (!context) throw new Error("ComboBoxLabel must be used within a ComboBox");
|
|
290
|
+
const cleanLabelProps = () => {
|
|
291
|
+
const { ref: _ref, ...rest } = context.labelProps();
|
|
292
|
+
return rest;
|
|
293
|
+
};
|
|
294
|
+
return <label {...domProps} {...cleanLabelProps()} class={local.class} style={local.style}>
|
|
295
|
+
{local.children}
|
|
296
|
+
</label>;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Description element for a combobox.
|
|
300
|
+
*/
|
|
301
|
+
function ComboBoxDescription(props) {
|
|
302
|
+
const [local, domProps] = splitProps(props, [
|
|
303
|
+
"class",
|
|
304
|
+
"style",
|
|
305
|
+
"slot",
|
|
306
|
+
"children"
|
|
307
|
+
]);
|
|
308
|
+
const context = useContext(ComboBoxContext);
|
|
309
|
+
if (!context) throw new Error("ComboBoxDescription must be used within a ComboBox");
|
|
310
|
+
const cleanDescriptionProps = () => {
|
|
311
|
+
const { ref: _ref, ...rest } = context.descriptionProps();
|
|
312
|
+
return rest;
|
|
313
|
+
};
|
|
314
|
+
return <div {...domProps} {...cleanDescriptionProps()} class={local.class} style={local.style}>
|
|
315
|
+
{local.children}
|
|
316
|
+
</div>;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Error message element for a combobox.
|
|
320
|
+
*/
|
|
321
|
+
function ComboBoxErrorMessage(props) {
|
|
322
|
+
const [local, domProps] = splitProps(props, [
|
|
323
|
+
"class",
|
|
324
|
+
"style",
|
|
325
|
+
"slot",
|
|
326
|
+
"children"
|
|
327
|
+
]);
|
|
328
|
+
const context = useContext(ComboBoxContext);
|
|
329
|
+
if (!context) throw new Error("ComboBoxErrorMessage must be used within a ComboBox");
|
|
330
|
+
const cleanErrorMessageProps = () => {
|
|
331
|
+
const { ref: _ref, ...rest } = context.errorMessageProps();
|
|
332
|
+
return rest;
|
|
333
|
+
};
|
|
334
|
+
return <div {...domProps} {...cleanErrorMessageProps()} class={local.class} style={local.style}>
|
|
335
|
+
{local.children}
|
|
336
|
+
</div>;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The text input for a combobox.
|
|
340
|
+
*/
|
|
341
|
+
function ComboBoxInput(props) {
|
|
342
|
+
const [local, domProps] = splitProps(props, [
|
|
343
|
+
"class",
|
|
344
|
+
"style",
|
|
345
|
+
"slot",
|
|
346
|
+
"children"
|
|
347
|
+
]);
|
|
348
|
+
const context = useContext(ComboBoxContext);
|
|
349
|
+
if (!context) throw new Error("ComboBoxInput must be used within a ComboBox");
|
|
350
|
+
const { isOpen, isFocused, isFocusVisible, state, setInputRef } = context;
|
|
351
|
+
const { isHovered, hoverProps } = createHover({ get isDisabled() {
|
|
352
|
+
return state.isDisabled;
|
|
353
|
+
} });
|
|
354
|
+
const renderValues = createMemo(() => ({
|
|
355
|
+
isOpen: isOpen(),
|
|
356
|
+
isFocused: isFocused(),
|
|
357
|
+
isFocusVisible: isFocusVisible(),
|
|
358
|
+
isHovered: isHovered(),
|
|
359
|
+
isDisabled: state.isDisabled,
|
|
360
|
+
inputValue: state.inputValue()
|
|
361
|
+
}));
|
|
362
|
+
const renderProps = useRenderProps({
|
|
363
|
+
get children() {
|
|
364
|
+
return local.children;
|
|
365
|
+
},
|
|
366
|
+
class: local.class,
|
|
367
|
+
style: local.style,
|
|
368
|
+
defaultClassName: "solidaria-ComboBox-input"
|
|
369
|
+
}, renderValues);
|
|
370
|
+
const cleanInputProps = () => {
|
|
371
|
+
const { ref: _ref1, value: _value, ...rest } = context.inputProps();
|
|
372
|
+
return rest;
|
|
373
|
+
};
|
|
374
|
+
const cleanHoverProps = () => {
|
|
375
|
+
const { ref: _ref2, ...rest } = hoverProps;
|
|
376
|
+
return rest;
|
|
377
|
+
};
|
|
378
|
+
return <input {...domProps} ref={(el) => setInputRef(el)} {...cleanInputProps()} {...cleanHoverProps()} value={state.inputValue()} class={renderProps.class()} style={renderProps.style()} data-open={isOpen() || void 0} data-focused={isFocused() || void 0} data-focus-visible={isFocusVisible() || void 0} data-hovered={isHovered() || void 0} data-disabled={state.isDisabled || void 0} />;
|
|
379
|
+
}
|
|
380
|
+
function ComboBoxValue(props) {
|
|
381
|
+
const context = useContext(ComboBoxContext);
|
|
382
|
+
if (!context) throw new Error("ComboBoxValue must be used within a ComboBox");
|
|
383
|
+
const state = context.state;
|
|
384
|
+
const isMulti = createMemo(() => state.selectionMode() === "multiple");
|
|
385
|
+
const selectedItem = createMemo(() => state.selectedItem());
|
|
386
|
+
const selectedItems = createMemo(() => {
|
|
387
|
+
if (isMulti()) return state.selectedItems().map((node) => node.value ?? null);
|
|
388
|
+
const item = selectedItem();
|
|
389
|
+
return item ? [item.value ?? null] : [];
|
|
390
|
+
});
|
|
391
|
+
const selectedText = createMemo(() => {
|
|
392
|
+
if (isMulti()) return state.selectedItems().map((n) => n.textValue).join(", ");
|
|
393
|
+
return selectedItem()?.textValue ?? "";
|
|
394
|
+
});
|
|
395
|
+
const textValue = createMemo(() => selectedText() || state.inputValue() || "");
|
|
396
|
+
const isPlaceholder = createMemo(() => textValue().length === 0);
|
|
397
|
+
const renderProps = useRenderProps({
|
|
398
|
+
get children() {
|
|
399
|
+
return props.children;
|
|
400
|
+
},
|
|
401
|
+
class: props.class,
|
|
402
|
+
style: props.style,
|
|
403
|
+
defaultClassName: "solidaria-ComboBox-value"
|
|
404
|
+
}, () => ({
|
|
405
|
+
textValue: textValue(),
|
|
406
|
+
isPlaceholder: isPlaceholder(),
|
|
407
|
+
selectedItems: selectedItems(),
|
|
408
|
+
selectedText: selectedText(),
|
|
409
|
+
state
|
|
410
|
+
}));
|
|
411
|
+
return <span class={renderProps.class()} style={renderProps.style()} data-placeholder={isPlaceholder() || void 0}>
|
|
412
|
+
{props.children ? renderProps.renderChildren() : isPlaceholder() ? props.placeholder : textValue()}
|
|
413
|
+
</span>;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* The trigger button for a combobox.
|
|
417
|
+
*/
|
|
418
|
+
function ComboBoxButton(props) {
|
|
419
|
+
const [local, domProps] = splitProps(props, [
|
|
420
|
+
"class",
|
|
421
|
+
"style",
|
|
422
|
+
"slot",
|
|
423
|
+
"children"
|
|
424
|
+
]);
|
|
425
|
+
const context = useContext(ComboBoxContext);
|
|
426
|
+
if (!context) throw new Error("ComboBoxButton must be used within a ComboBox");
|
|
427
|
+
const { isOpen, isFocused, state, setButtonRef } = context;
|
|
428
|
+
const { isHovered, hoverProps } = createHover({ get isDisabled() {
|
|
429
|
+
return state.isDisabled;
|
|
430
|
+
} });
|
|
431
|
+
const renderValues = createMemo(() => ({
|
|
432
|
+
isOpen: isOpen(),
|
|
433
|
+
isFocused: isFocused(),
|
|
434
|
+
isHovered: isHovered(),
|
|
435
|
+
isPressed: isOpen(),
|
|
436
|
+
isDisabled: state.isDisabled
|
|
437
|
+
}));
|
|
438
|
+
const renderProps = useRenderProps({
|
|
439
|
+
get children() {
|
|
440
|
+
return local.children;
|
|
441
|
+
},
|
|
442
|
+
class: local.class,
|
|
443
|
+
style: local.style,
|
|
444
|
+
defaultClassName: "solidaria-ComboBox-button"
|
|
445
|
+
}, renderValues);
|
|
446
|
+
const cleanButtonProps = () => {
|
|
447
|
+
const { ref: _ref1, ...rest } = context.buttonProps();
|
|
448
|
+
return rest;
|
|
449
|
+
};
|
|
450
|
+
const cleanHoverProps = () => {
|
|
451
|
+
const { ref: _ref2, ...rest } = hoverProps;
|
|
452
|
+
return rest;
|
|
453
|
+
};
|
|
454
|
+
return <button {...domProps} ref={(el) => setButtonRef(el)} {...cleanButtonProps()} {...cleanHoverProps()} class={renderProps.class()} style={renderProps.style()} data-open={isOpen() || void 0} data-pressed={isOpen() || void 0} data-focused={isFocused() || void 0} data-hovered={isHovered() || void 0} data-disabled={state.isDisabled || void 0}>
|
|
455
|
+
{renderProps.renderChildren()}
|
|
456
|
+
</button>;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* The listbox popup for a combobox.
|
|
460
|
+
*/
|
|
461
|
+
function ComboBoxListBox(props) {
|
|
462
|
+
const [local, domProps] = splitProps(props, [
|
|
463
|
+
"class",
|
|
464
|
+
"style",
|
|
465
|
+
"slot",
|
|
466
|
+
"children"
|
|
467
|
+
]);
|
|
468
|
+
const rawContext = useContext(ComboBoxContext);
|
|
469
|
+
if (!rawContext) throw new Error("ComboBoxListBox must be used within a ComboBox");
|
|
470
|
+
const context = rawContext;
|
|
471
|
+
const { state: comboBoxState, listState, isOpen, inputRef, buttonRef, setListBoxRef } = context;
|
|
472
|
+
const state = comboBoxState;
|
|
473
|
+
let listBoxRef;
|
|
474
|
+
createScrollIntoViewOnFocus({
|
|
475
|
+
focusedKey: () => state.focusedKey(),
|
|
476
|
+
isActive: () => isOpen(),
|
|
477
|
+
ref: () => listBoxRef ?? null
|
|
478
|
+
});
|
|
479
|
+
createInteractOutside({
|
|
480
|
+
ref: () => listBoxRef ?? null,
|
|
481
|
+
onInteractOutside: (e) => {
|
|
482
|
+
const target = e.target;
|
|
483
|
+
const input = inputRef();
|
|
484
|
+
const button = buttonRef();
|
|
485
|
+
if (input?.contains(target)) return;
|
|
486
|
+
if (button?.contains(target)) return;
|
|
487
|
+
if (isOpen()) state.close();
|
|
488
|
+
},
|
|
489
|
+
get isDisabled() {
|
|
490
|
+
return !isOpen();
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
const { listBoxProps } = createListBox(context.listBoxProps, listState);
|
|
494
|
+
const renderValues = createMemo(() => ({ isFocused: state.isFocused() }));
|
|
495
|
+
const renderProps = useRenderProps({
|
|
496
|
+
class: local.class,
|
|
497
|
+
style: local.style,
|
|
498
|
+
defaultClassName: "solidaria-ComboBox-listbox"
|
|
499
|
+
}, renderValues);
|
|
500
|
+
const cleanContextProps = () => {
|
|
501
|
+
const { ref: _ref1, ...rest } = context.listBoxProps();
|
|
502
|
+
return rest;
|
|
503
|
+
};
|
|
504
|
+
const cleanListBoxProps = () => {
|
|
505
|
+
const { ref: _ref2, ...rest } = listBoxProps;
|
|
506
|
+
return rest;
|
|
507
|
+
};
|
|
508
|
+
const items = () => Array.from(state.collection());
|
|
509
|
+
const getNodeValue = (node) => {
|
|
510
|
+
if (node.value != null) return node.value;
|
|
511
|
+
return context.items.find((item, index) => {
|
|
512
|
+
const candidate = item;
|
|
513
|
+
return (candidate.key ?? candidate.id ?? index) === node.key;
|
|
514
|
+
}) ?? null;
|
|
515
|
+
};
|
|
516
|
+
const setListBoxElement = (el) => {
|
|
517
|
+
listBoxRef = el;
|
|
518
|
+
setListBoxRef(el);
|
|
519
|
+
};
|
|
520
|
+
onCleanup(() => {
|
|
521
|
+
setListBoxRef(null);
|
|
522
|
+
});
|
|
523
|
+
return <Show when={isOpen()}>
|
|
524
|
+
<ul {...domProps} ref={setListBoxElement} {...cleanContextProps()} {...cleanListBoxProps()} class={renderProps.class()} style={renderProps.style()} data-focused={state.isFocused() || void 0}>
|
|
525
|
+
<Show when={local.children} fallback={<For each={items()}>
|
|
526
|
+
{(node) => <ComboBoxOption id={node.key}>{node.textValue}</ComboBoxOption>}
|
|
527
|
+
</For>}>
|
|
528
|
+
<For each={items()}>
|
|
529
|
+
{(node) => {
|
|
530
|
+
const value = getNodeValue(node);
|
|
531
|
+
return value != null ? local.children(value) : null;
|
|
532
|
+
}}
|
|
533
|
+
</For>
|
|
534
|
+
</Show>
|
|
535
|
+
</ul>
|
|
536
|
+
</Show>;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* An option in a combobox listbox.
|
|
540
|
+
*/
|
|
541
|
+
function ComboBoxOption(props) {
|
|
542
|
+
const [local, ariaProps] = splitProps(props, [
|
|
543
|
+
"class",
|
|
544
|
+
"style",
|
|
545
|
+
"slot",
|
|
546
|
+
"id",
|
|
547
|
+
"item",
|
|
548
|
+
"textValue",
|
|
549
|
+
"onAction"
|
|
550
|
+
]);
|
|
551
|
+
const stateContext = useContext(ComboBoxStateContext);
|
|
552
|
+
const comboBoxContext = useContext(ComboBoxContext);
|
|
553
|
+
if (!stateContext || !comboBoxContext) throw new Error("ComboBoxOption must be used within a ComboBox");
|
|
554
|
+
const state = stateContext;
|
|
555
|
+
const listState = comboBoxContext.listState;
|
|
556
|
+
const [ref, setRef] = createSignal(null);
|
|
557
|
+
const optionId = () => {
|
|
558
|
+
const listBoxId = getComboBoxData(state)?.listBoxId;
|
|
559
|
+
return listBoxId ? `${listBoxId}-option-${local.id}` : String(local.id);
|
|
560
|
+
};
|
|
561
|
+
createEffect(() => {
|
|
562
|
+
const key = local.id;
|
|
563
|
+
comboBoxContext?.registerOptionAction(key, local.onAction);
|
|
564
|
+
onCleanup(() => {
|
|
565
|
+
comboBoxContext?.registerOptionAction(key, void 0);
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
const optionAria = createOption({
|
|
569
|
+
key: local.id,
|
|
570
|
+
get optionId() {
|
|
571
|
+
return optionId();
|
|
572
|
+
},
|
|
573
|
+
get isDisabled() {
|
|
574
|
+
return ariaProps.isDisabled;
|
|
575
|
+
},
|
|
576
|
+
get "aria-label"() {
|
|
577
|
+
return ariaProps["aria-label"];
|
|
578
|
+
},
|
|
579
|
+
shouldSelectOnPressUp: true,
|
|
580
|
+
shouldFocusOnHover: true,
|
|
581
|
+
shouldUseVirtualFocus: true,
|
|
582
|
+
allowsDifferentPressOrigin: true,
|
|
583
|
+
get onHoverStart() {
|
|
584
|
+
return ariaProps.onHoverStart;
|
|
585
|
+
},
|
|
586
|
+
get onHoverEnd() {
|
|
587
|
+
return ariaProps.onHoverEnd;
|
|
588
|
+
},
|
|
589
|
+
get onHoverChange() {
|
|
590
|
+
return ariaProps.onHoverChange;
|
|
591
|
+
},
|
|
592
|
+
get onAction() {
|
|
593
|
+
return local.onAction;
|
|
594
|
+
}
|
|
595
|
+
}, listState, () => ref());
|
|
596
|
+
const isOptionFocusVisible = () => optionAria.isFocusVisible() || optionAria.isFocused() && (comboBoxContext?.isFocusVisible() ?? false);
|
|
597
|
+
const renderValues = createMemo(() => ({
|
|
598
|
+
isSelected: optionAria.isSelected(),
|
|
599
|
+
isFocused: optionAria.isFocused(),
|
|
600
|
+
isFocusVisible: isOptionFocusVisible(),
|
|
601
|
+
isPressed: optionAria.isPressed(),
|
|
602
|
+
isHovered: optionAria.isHovered(),
|
|
603
|
+
isDisabled: optionAria.isDisabled()
|
|
604
|
+
}));
|
|
605
|
+
const renderProps = useRenderProps({
|
|
606
|
+
get children() {
|
|
607
|
+
return props.children;
|
|
608
|
+
},
|
|
609
|
+
class: local.class,
|
|
610
|
+
style: local.style,
|
|
611
|
+
defaultClassName: "solidaria-ComboBox-option"
|
|
612
|
+
}, renderValues);
|
|
613
|
+
const selectionIndicatorContext = createMemo(() => ({ isSelected: optionAria.isSelected }));
|
|
614
|
+
const cleanOptionProps = () => {
|
|
615
|
+
const { ref: _ref1, ...rest } = optionAria.optionProps;
|
|
616
|
+
return rest;
|
|
617
|
+
};
|
|
618
|
+
return <SelectionIndicatorContext.Provider value={selectionIndicatorContext()}>
|
|
619
|
+
<li ref={setRef} {...cleanOptionProps()} class={renderProps.class()} style={renderProps.style()} data-selected={optionAria.isSelected() || void 0} data-focused={optionAria.isFocused() || void 0} data-focus-visible={isOptionFocusVisible() || void 0} data-pressed={optionAria.isPressed() || void 0} data-hovered={optionAria.isHovered() || void 0} data-disabled={optionAria.isDisabled() || void 0}>
|
|
620
|
+
{renderProps.renderChildren()}
|
|
621
|
+
</li>
|
|
622
|
+
</SelectionIndicatorContext.Provider>;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Renders selected items as tags in multi-select mode.
|
|
626
|
+
*/
|
|
627
|
+
function ComboBoxTagGroup(props) {
|
|
628
|
+
const context = useContext(ComboBoxContext);
|
|
629
|
+
if (!context) throw new Error("ComboBoxTagGroup must be used within a ComboBox");
|
|
630
|
+
const state = context.state;
|
|
631
|
+
const items = createMemo(() => state.selectedItems().map((node) => ({
|
|
632
|
+
key: node.key,
|
|
633
|
+
label: node.textValue
|
|
634
|
+
})));
|
|
635
|
+
return <Show when={items().length > 0}>
|
|
636
|
+
<div class={props.class ?? "solidaria-ComboBox-tagGroup"} style={props.style} role="group" aria-label="Selected items">
|
|
637
|
+
<For each={items()}>{(item) => props.children(item)}</For>
|
|
638
|
+
</div>
|
|
639
|
+
</Show>;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* A tag representing a selected item in a multi-select combobox.
|
|
643
|
+
*/
|
|
644
|
+
function ComboBoxTag(props) {
|
|
645
|
+
const context = useContext(ComboBoxContext);
|
|
646
|
+
if (!context) throw new Error("ComboBoxTag must be used within a ComboBox");
|
|
647
|
+
const state = context.state;
|
|
648
|
+
const handleRemove = () => {
|
|
649
|
+
if (props.onRemove) props.onRemove();
|
|
650
|
+
else state.removeSelectedKey(props.item.key);
|
|
651
|
+
};
|
|
652
|
+
return <span class={props.class ?? "solidaria-ComboBox-tag"} style={props.style} data-key={String(props.item.key)}>
|
|
653
|
+
{props.children ?? props.item.label}
|
|
654
|
+
<button type="button" aria-label={`Remove ${props.item.label}`} onClick={handleRemove} class="solidaria-ComboBox-tag-remove" tabIndex={-1}>
|
|
655
|
+
×
|
|
656
|
+
</button>
|
|
657
|
+
</span>;
|
|
658
|
+
}
|
|
659
|
+
ComboBox.Input = ComboBoxInput;
|
|
660
|
+
ComboBox.Button = ComboBoxButton;
|
|
661
|
+
ComboBox.ListBox = ComboBoxListBox;
|
|
662
|
+
ComboBox.Option = ComboBoxOption;
|
|
663
|
+
ComboBox.Label = ComboBoxLabel;
|
|
664
|
+
ComboBox.Description = ComboBoxDescription;
|
|
665
|
+
ComboBox.ErrorMessage = ComboBoxErrorMessage;
|
|
666
|
+
ComboBox.TagGroup = ComboBoxTagGroup;
|
|
667
|
+
ComboBox.Tag = ComboBoxTag;
|
|
668
|
+
function createComboBoxListStateAdapter(state) {
|
|
669
|
+
const selectedKeys = createMemo(() => {
|
|
670
|
+
if (state.selectionMode() === "multiple") return state.selectedKeys();
|
|
671
|
+
const key = state.selectedKey();
|
|
672
|
+
return key != null ? new Set([key]) : /* @__PURE__ */ new Set();
|
|
673
|
+
});
|
|
674
|
+
const disabledKeys = createMemo(() => {
|
|
675
|
+
const keys = /* @__PURE__ */ new Set();
|
|
676
|
+
for (const node of state.collection()) if (node.isDisabled) keys.add(node.key);
|
|
677
|
+
return keys;
|
|
678
|
+
});
|
|
679
|
+
return {
|
|
680
|
+
collection: state.collection,
|
|
681
|
+
selectionManager: state.selectionManager,
|
|
682
|
+
isFocused: state.isFocused,
|
|
683
|
+
setFocused: state.setFocused,
|
|
684
|
+
focusedKey: state.focusedKey,
|
|
685
|
+
setFocusedKey: (key) => state.setFocusedKey(key ?? null),
|
|
686
|
+
childFocusStrategy: () => null,
|
|
687
|
+
selectionMode: state.selectionMode,
|
|
688
|
+
selectionBehavior: () => "replace",
|
|
689
|
+
disallowEmptySelection: () => true,
|
|
690
|
+
selectedKeys,
|
|
691
|
+
disabledKeys,
|
|
692
|
+
disabledBehavior: () => "all",
|
|
693
|
+
isEmpty: () => selectedKeys().size === 0,
|
|
694
|
+
isSelectAll: () => false,
|
|
695
|
+
isSelected: state.isSelected,
|
|
696
|
+
isDisabled: state.isKeyDisabled,
|
|
697
|
+
setSelectionBehavior: () => {},
|
|
698
|
+
toggleSelection: (key) => state.select(key),
|
|
699
|
+
replaceSelection: (key) => state.select(key),
|
|
700
|
+
setSelectedKeys: (keys) => {
|
|
701
|
+
const first = keys[Symbol.iterator]().next().value;
|
|
702
|
+
state.setSelectedKey(first ?? null);
|
|
703
|
+
},
|
|
704
|
+
selectAll: () => {},
|
|
705
|
+
clearSelection: () => state.setSelectedKey(null),
|
|
706
|
+
toggleSelectAll: () => {},
|
|
707
|
+
extendSelection: (toKey) => state.select(toKey),
|
|
708
|
+
select: (key) => state.select(key)
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
//#endregion
|
|
712
|
+
export { ComboBox, ComboBoxButton, ComboBoxContext, ComboBoxDescription, ComboBoxErrorMessage, ComboBoxInput, ComboBoxLabel, ComboBoxListBox, ComboBoxOption, ComboBoxStateContext, ComboBoxTag, ComboBoxTagGroup, ComboBoxValue, ComboBoxValueContext, defaultContainsFilter };
|
|
713
|
+
|
|
714
|
+
//# sourceMappingURL=ComboBox.jsx.map
|