menhir 0.1.5 → 0.1.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/README.md +2 -2
- package/dist/autocomplete/index.js +3 -0
- package/dist/autocomplete/index.parts.js +11 -0
- package/dist/autocomplete/input/AutocompleteInput.js +45 -0
- package/dist/autocomplete/item/AutocompleteItem.js +29 -0
- package/dist/autocomplete/root/AutocompleteContext.js +39 -0
- package/dist/autocomplete/root/AutocompleteRoot.js +22 -0
- package/dist/combobox/clear/ComboboxClear.js +39 -0
- package/dist/combobox/filter/includesText.js +24 -0
- package/dist/combobox/group/ComboboxGroup.js +32 -0
- package/dist/combobox/group/ComboboxGroupContext.js +10 -0
- package/dist/combobox/group-label/ComboboxGroupLabel.js +26 -0
- package/dist/combobox/index.js +3 -0
- package/dist/combobox/index.parts.js +12 -0
- package/dist/combobox/input/ComboboxInput.js +78 -0
- package/dist/combobox/input/createComboboxInput.js +112 -0
- package/dist/combobox/item/ComboboxItem.js +54 -0
- package/dist/combobox/item/ComboboxItemContext.js +10 -0
- package/dist/combobox/item/createComboboxItem.js +62 -0
- package/dist/combobox/item-indicator/ComboboxItemIndicator.js +22 -0
- package/dist/combobox/list/ComboboxList.js +26 -0
- package/dist/combobox/popup/ComboboxPopup.js +78 -0
- package/dist/combobox/root/ComboboxContext.js +161 -0
- package/dist/combobox/root/ComboboxRoot.js +21 -0
- package/dist/combobox/status/ComboboxStatus.js +31 -0
- package/dist/combobox/trigger/ComboboxTrigger.js +47 -0
- package/dist/select/group/SelectGroup.js +32 -0
- package/dist/select/group/SelectGroupContext.js +10 -0
- package/dist/select/group-label/SelectGroupLabel.js +26 -0
- package/dist/select/index.js +2 -0
- package/dist/select/index.parts.js +9 -0
- package/dist/select/item/SelectItem.js +97 -0
- package/dist/select/item/SelectItemContext.js +10 -0
- package/dist/select/item-indicator/SelectItemIndicator.js +22 -0
- package/dist/select/popup/SelectPopup.js +92 -0
- package/dist/select/root/SelectContext.js +99 -0
- package/dist/select/root/SelectRoot.js +21 -0
- package/dist/select/trigger/SelectTrigger.js +163 -0
- package/dist/select/value/SelectValue.js +32 -0
- package/dist/source/autocomplete/index.d.ts +2 -0
- package/dist/source/autocomplete/index.js +4 -0
- package/dist/source/autocomplete/index.parts.d.ts +10 -0
- package/dist/source/autocomplete/index.parts.js +12 -0
- package/dist/source/autocomplete/input/AutocompleteInput.d.ts +18 -0
- package/dist/source/autocomplete/input/AutocompleteInput.jsx +37 -0
- package/dist/source/autocomplete/item/AutocompleteItem.d.ts +20 -0
- package/dist/source/autocomplete/item/AutocompleteItem.jsx +25 -0
- package/dist/source/autocomplete/root/AutocompleteContext.d.ts +59 -0
- package/dist/source/autocomplete/root/AutocompleteContext.js +33 -0
- package/dist/source/autocomplete/root/AutocompleteRoot.d.ts +13 -0
- package/dist/source/autocomplete/root/AutocompleteRoot.jsx +15 -0
- package/dist/source/combobox/clear/ComboboxClear.d.ts +12 -0
- package/dist/source/combobox/clear/ComboboxClear.jsx +36 -0
- package/dist/source/combobox/filter/includesText.d.ts +12 -0
- package/dist/source/combobox/filter/includesText.js +26 -0
- package/dist/source/combobox/group/ComboboxGroup.d.ts +10 -0
- package/dist/source/combobox/group/ComboboxGroup.jsx +23 -0
- package/dist/source/combobox/group/ComboboxGroupContext.d.ts +10 -0
- package/dist/source/combobox/group/ComboboxGroupContext.js +12 -0
- package/dist/source/combobox/group-label/ComboboxGroupLabel.d.ts +10 -0
- package/dist/source/combobox/group-label/ComboboxGroupLabel.jsx +24 -0
- package/dist/source/combobox/index.d.ts +2 -0
- package/dist/source/combobox/index.js +4 -0
- package/dist/source/combobox/index.parts.d.ts +11 -0
- package/dist/source/combobox/index.parts.js +11 -0
- package/dist/source/combobox/input/ComboboxInput.d.ts +19 -0
- package/dist/source/combobox/input/ComboboxInput.jsx +52 -0
- package/dist/source/combobox/input/createComboboxInput.d.ts +30 -0
- package/dist/source/combobox/input/createComboboxInput.js +140 -0
- package/dist/source/combobox/item/ComboboxItem.d.ts +25 -0
- package/dist/source/combobox/item/ComboboxItem.jsx +50 -0
- package/dist/source/combobox/item/ComboboxItemContext.d.ts +11 -0
- package/dist/source/combobox/item/ComboboxItemContext.js +12 -0
- package/dist/source/combobox/item/createComboboxItem.d.ts +21 -0
- package/dist/source/combobox/item/createComboboxItem.js +61 -0
- package/dist/source/combobox/item-indicator/ComboboxItemIndicator.d.ts +11 -0
- package/dist/source/combobox/item-indicator/ComboboxItemIndicator.jsx +16 -0
- package/dist/source/combobox/list/ComboboxList.d.ts +12 -0
- package/dist/source/combobox/list/ComboboxList.jsx +17 -0
- package/dist/source/combobox/popup/ComboboxPopup.d.ts +34 -0
- package/dist/source/combobox/popup/ComboboxPopup.jsx +76 -0
- package/dist/source/combobox/root/ComboboxContext.d.ts +179 -0
- package/dist/source/combobox/root/ComboboxContext.js +186 -0
- package/dist/source/combobox/root/ComboboxRoot.d.ts +13 -0
- package/dist/source/combobox/root/ComboboxRoot.jsx +13 -0
- package/dist/source/combobox/status/ComboboxStatus.d.ts +19 -0
- package/dist/source/combobox/status/ComboboxStatus.jsx +27 -0
- package/dist/source/combobox/trigger/ComboboxTrigger.d.ts +13 -0
- package/dist/source/combobox/trigger/ComboboxTrigger.jsx +40 -0
- package/dist/source/floating/dismissal/reason.d.ts +7 -2
- package/dist/source/select/group/SelectGroup.d.ts +10 -0
- package/dist/source/select/group/SelectGroup.jsx +23 -0
- package/dist/source/select/group/SelectGroupContext.d.ts +10 -0
- package/dist/source/select/group/SelectGroupContext.js +12 -0
- package/dist/source/select/group-label/SelectGroupLabel.d.ts +10 -0
- package/dist/source/select/group-label/SelectGroupLabel.jsx +24 -0
- package/dist/source/select/index.d.ts +1 -0
- package/dist/source/select/index.js +1 -0
- package/dist/source/select/index.parts.d.ts +8 -0
- package/dist/source/select/index.parts.js +8 -0
- package/dist/source/select/item/SelectItem.d.ts +24 -0
- package/dist/source/select/item/SelectItem.jsx +92 -0
- package/dist/source/select/item/SelectItemContext.d.ts +11 -0
- package/dist/source/select/item/SelectItemContext.js +12 -0
- package/dist/source/select/item-indicator/SelectItemIndicator.d.ts +11 -0
- package/dist/source/select/item-indicator/SelectItemIndicator.jsx +16 -0
- package/dist/source/select/popup/SelectPopup.d.ts +32 -0
- package/dist/source/select/popup/SelectPopup.jsx +97 -0
- package/dist/source/select/root/SelectContext.d.ts +106 -0
- package/dist/source/select/root/SelectContext.js +119 -0
- package/dist/source/select/root/SelectRoot.d.ts +13 -0
- package/dist/source/select/root/SelectRoot.jsx +11 -0
- package/dist/source/select/trigger/SelectTrigger.d.ts +15 -0
- package/dist/source/select/trigger/SelectTrigger.jsx +181 -0
- package/dist/source/select/value/SelectValue.d.ts +20 -0
- package/dist/source/select/value/SelectValue.jsx +27 -0
- package/package.json +16 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/combobox/list/ComboboxList.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The list of items: a `<div role="listbox">` with the `id` the Input
|
|
10
|
+
* names in `aria-controls`. Name it with `aria-labelledby`, such as the
|
|
11
|
+
* `id` of the input's `<label>`, or `aria-label`. Place it inside
|
|
12
|
+
* `Combobox.Popup`, around the items.
|
|
13
|
+
*/
|
|
14
|
+
function ComboboxList(props) {
|
|
15
|
+
const combobox = useComboboxContext();
|
|
16
|
+
const elementProps = mergeElementProps({
|
|
17
|
+
id: combobox.listId,
|
|
18
|
+
role: "listbox"
|
|
19
|
+
}, omit(props, "render", "id"));
|
|
20
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
21
|
+
var _el$ = _tmpl$();
|
|
22
|
+
spread(_el$, p, false);
|
|
23
|
+
return _el$;
|
|
24
|
+
})());
|
|
25
|
+
}
|
|
26
|
+
export { ComboboxList };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createPosition } from "../../floating/positioning/createPosition.js";
|
|
4
|
+
import { flip } from "../../floating/positioning/flip.js";
|
|
5
|
+
import { offset } from "../../floating/positioning/offset.js";
|
|
6
|
+
import { shift } from "../../floating/positioning/shift.js";
|
|
7
|
+
import { size } from "../../floating/positioning/size.js";
|
|
8
|
+
import { createPresence } from "../../floating/presence/presence.js";
|
|
9
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
10
|
+
import { spread, template } from "@solidjs/web";
|
|
11
|
+
import { merge, omit } from "solid-js";
|
|
12
|
+
// src/combobox/popup/ComboboxPopup.tsx
|
|
13
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
14
|
+
/**
|
|
15
|
+
* The box the list shows in: a `<div popover="manual">` in the top layer,
|
|
16
|
+
* placed against the Input. It takes no focus: the input keeps it, and a
|
|
17
|
+
* press in it moves none. Escape, focus leaving the input, the Trigger and
|
|
18
|
+
* selecting an item close it. Its CSS variables `--anchor-width` and
|
|
19
|
+
* `--available-height` are for its `min-width` and `max-height`. Place
|
|
20
|
+
* `Combobox.List` inside it, and `Combobox.Status` or a `<Loading>`
|
|
21
|
+
* fallback beside the List. Place it inside `Combobox.Root`.
|
|
22
|
+
*/
|
|
23
|
+
function ComboboxPopup(props) {
|
|
24
|
+
const combobox = useComboboxContext();
|
|
25
|
+
let popup;
|
|
26
|
+
createPresence({
|
|
27
|
+
get popup() {
|
|
28
|
+
return popup;
|
|
29
|
+
},
|
|
30
|
+
get open() {
|
|
31
|
+
return combobox.open();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
createPosition({
|
|
35
|
+
get anchor() {
|
|
36
|
+
const anchor = props.anchor;
|
|
37
|
+
return (typeof anchor === "function" ? anchor() : anchor) ?? combobox.input;
|
|
38
|
+
},
|
|
39
|
+
get popup() {
|
|
40
|
+
return popup;
|
|
41
|
+
},
|
|
42
|
+
get open() {
|
|
43
|
+
return combobox.open();
|
|
44
|
+
},
|
|
45
|
+
get side() {
|
|
46
|
+
return props.side ?? "bottom";
|
|
47
|
+
},
|
|
48
|
+
get align() {
|
|
49
|
+
return props.align ?? "start";
|
|
50
|
+
},
|
|
51
|
+
get middleware() {
|
|
52
|
+
const padding = props.collisionPadding ?? 5;
|
|
53
|
+
return [
|
|
54
|
+
offset({
|
|
55
|
+
mainAxis: props.sideOffset ?? 0,
|
|
56
|
+
alignmentAxis: props.alignOffset ?? 0
|
|
57
|
+
}),
|
|
58
|
+
flip({ padding }),
|
|
59
|
+
shift({ padding }),
|
|
60
|
+
size({ padding })
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const ownProps = merge(combobox.attributes, {
|
|
65
|
+
popover: "manual",
|
|
66
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
67
|
+
ref: (element) => {
|
|
68
|
+
popup = element;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "side", "align", "sideOffset", "alignOffset", "collisionPadding", "anchor"));
|
|
72
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
73
|
+
var _el$ = _tmpl$();
|
|
74
|
+
spread(_el$, p, false);
|
|
75
|
+
return _el$;
|
|
76
|
+
})());
|
|
77
|
+
}
|
|
78
|
+
export { ComboboxPopup };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { createActiveDescendantList } from "../../floating/list-navigation/activeDescendant.js";
|
|
3
|
+
import { isDev } from "@solidjs/web";
|
|
4
|
+
import { createContext, createMemo, createUniqueId, untrack, useContext } from "solid-js";
|
|
5
|
+
// src/combobox/root/ComboboxContext.ts
|
|
6
|
+
/**
|
|
7
|
+
* The state `Combobox.Root` and `Autocomplete.Root` share: whether the list
|
|
8
|
+
* is open, its list navigation, the List's `id` and the `data-*`
|
|
9
|
+
* attributes. Each Root spreads it into its own combobox, beside its text
|
|
10
|
+
* and what accepting an item does.
|
|
11
|
+
*/
|
|
12
|
+
function createComboboxBase(props) {
|
|
13
|
+
const [open, setOpen] = createControllableSignal({
|
|
14
|
+
get value() {
|
|
15
|
+
return props.open;
|
|
16
|
+
},
|
|
17
|
+
get defaultValue() {
|
|
18
|
+
return props.defaultOpen ?? false;
|
|
19
|
+
},
|
|
20
|
+
onChange: (value, details) => props.onOpenChange?.(value, details)
|
|
21
|
+
});
|
|
22
|
+
const list = createActiveDescendantList({
|
|
23
|
+
get open() {
|
|
24
|
+
return open();
|
|
25
|
+
},
|
|
26
|
+
wrap: true
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
open,
|
|
30
|
+
setOpen,
|
|
31
|
+
isActive: (item) => open() && list.isActive(item),
|
|
32
|
+
count: () => list.items().length,
|
|
33
|
+
list,
|
|
34
|
+
listId: createUniqueId(),
|
|
35
|
+
input: void 0,
|
|
36
|
+
attributes: {
|
|
37
|
+
get "data-open"() {
|
|
38
|
+
return open() ? "" : void 0;
|
|
39
|
+
},
|
|
40
|
+
get "data-closed"() {
|
|
41
|
+
return open() ? void 0 : "";
|
|
42
|
+
},
|
|
43
|
+
get "data-disabled"() {
|
|
44
|
+
return props.disabled ? "" : void 0;
|
|
45
|
+
},
|
|
46
|
+
get "data-required"() {
|
|
47
|
+
return props.required ? "" : void 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Creates a combobox's state and its list navigation. */
|
|
53
|
+
function createCombobox(props) {
|
|
54
|
+
const base = createComboboxBase(props);
|
|
55
|
+
const { list } = base;
|
|
56
|
+
const [value, setValue, requestedValue] = createControllableSignal({
|
|
57
|
+
get value() {
|
|
58
|
+
return props.value;
|
|
59
|
+
},
|
|
60
|
+
get defaultValue() {
|
|
61
|
+
return props.defaultValue ?? null;
|
|
62
|
+
},
|
|
63
|
+
onChange: (value) => props.onValueChange?.(value)
|
|
64
|
+
});
|
|
65
|
+
const [text, setText, requestedText] = createControllableSignal({
|
|
66
|
+
get value() {
|
|
67
|
+
return props.inputValue;
|
|
68
|
+
},
|
|
69
|
+
get defaultValue() {
|
|
70
|
+
return props.defaultInputValue ?? null;
|
|
71
|
+
},
|
|
72
|
+
onChange: (text, details) => props.onInputValueChange?.(text, details)
|
|
73
|
+
});
|
|
74
|
+
const labelOfValue = (selected) => {
|
|
75
|
+
return list.items().find((item) => item.value === selected)?.text.trim();
|
|
76
|
+
};
|
|
77
|
+
let labelled = null;
|
|
78
|
+
const selectedLabel = createMemo((previous) => {
|
|
79
|
+
const selected = value();
|
|
80
|
+
const label = labelOfValue(selected) ?? (selected === labelled ? previous : void 0);
|
|
81
|
+
labelled = selected;
|
|
82
|
+
return label;
|
|
83
|
+
});
|
|
84
|
+
const inputValue = createMemo(() => text() ?? selectedLabel() ?? "");
|
|
85
|
+
const requestedInputValue = () => requestedText() ?? untrack(selectedLabel) ?? "";
|
|
86
|
+
let edited = false;
|
|
87
|
+
const setInputValue = (next, details) => {
|
|
88
|
+
edited = details.reason === "input-change";
|
|
89
|
+
if (next !== requestedInputValue()) setText(next, details);
|
|
90
|
+
};
|
|
91
|
+
const commit = (next) => {
|
|
92
|
+
if (next === requestedValue()) return;
|
|
93
|
+
const input = combobox.hiddenInput;
|
|
94
|
+
if (!input) return setValue(next);
|
|
95
|
+
input.value = next ?? "";
|
|
96
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
97
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
98
|
+
};
|
|
99
|
+
const combobox = {
|
|
100
|
+
...base,
|
|
101
|
+
component: "Combobox",
|
|
102
|
+
value,
|
|
103
|
+
setValue,
|
|
104
|
+
inputValue,
|
|
105
|
+
setInputValue,
|
|
106
|
+
select: (item, event) => {
|
|
107
|
+
if (!item || item.disabled) return false;
|
|
108
|
+
commit(item.value);
|
|
109
|
+
setInputValue(item.text.trim(), {
|
|
110
|
+
reason: "item-press",
|
|
111
|
+
event
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
clear: (event, reason) => {
|
|
116
|
+
if (!requestedInputValue() && requestedValue() === null) return false;
|
|
117
|
+
commit(null);
|
|
118
|
+
setInputValue("", {
|
|
119
|
+
reason,
|
|
120
|
+
event
|
|
121
|
+
});
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
revert: (event) => {
|
|
125
|
+
if (!edited) return;
|
|
126
|
+
if (!requestedInputValue().trim()) {
|
|
127
|
+
commit(null);
|
|
128
|
+
setInputValue("", {
|
|
129
|
+
reason: "focus-out",
|
|
130
|
+
event
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const selected = requestedValue();
|
|
135
|
+
const label = selected === null ? "" : labelOfValue(selected) ?? selectedLabel() ?? "";
|
|
136
|
+
setInputValue(label, {
|
|
137
|
+
reason: "focus-out",
|
|
138
|
+
event
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
labelOfValue,
|
|
142
|
+
hiddenInput: void 0,
|
|
143
|
+
props
|
|
144
|
+
};
|
|
145
|
+
return combobox;
|
|
146
|
+
}
|
|
147
|
+
var ComboboxContext = createContext(null);
|
|
148
|
+
/**
|
|
149
|
+
* The combobox of the Root around the part. A shared part passes no
|
|
150
|
+
* `component` and takes either Root's; a part only one Root takes passes
|
|
151
|
+
* that Root's `component`, and its type, `Combobox` or an Autocomplete's.
|
|
152
|
+
*/
|
|
153
|
+
function useComboboxContext(component) {
|
|
154
|
+
const context = useContext(ComboboxContext);
|
|
155
|
+
if (isDev) {
|
|
156
|
+
if (!context) throw new Error(component ? `[menhir] ${component} parts must be placed within <${component}.Root>.` : "[menhir] Combobox parts must be placed within <Combobox.Root>, and Autocomplete parts within <Autocomplete.Root>.");
|
|
157
|
+
if (component && context.component !== component) throw new Error(`[menhir] ${component} parts must be placed within <${component}.Root>, not <${context.component}.Root>.`);
|
|
158
|
+
}
|
|
159
|
+
return context;
|
|
160
|
+
}
|
|
161
|
+
export { ComboboxContext, createCombobox, createComboboxBase, useComboboxContext };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComboboxContext, createCombobox } from "./ComboboxContext.js";
|
|
2
|
+
import { createComponent } from "@solidjs/web";
|
|
3
|
+
// src/combobox/root/ComboboxRoot.tsx
|
|
4
|
+
/**
|
|
5
|
+
* An input that picks a value from a list: holds the value, the text in
|
|
6
|
+
* the input and whether the list is open, and shares them with
|
|
7
|
+
* `Combobox.Input`, `Combobox.Trigger`, `Combobox.Clear`, `Combobox.Popup`
|
|
8
|
+
* and the parts inside it. Its form props go on the hidden input the Input
|
|
9
|
+
* renders. Renders no element of its own.
|
|
10
|
+
*/
|
|
11
|
+
function ComboboxRoot(props) {
|
|
12
|
+
return createComponent(ComboboxContext, {
|
|
13
|
+
get value() {
|
|
14
|
+
return createCombobox(props);
|
|
15
|
+
},
|
|
16
|
+
get children() {
|
|
17
|
+
return props.children;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { ComboboxRoot };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/combobox/status/ComboboxStatus.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The number of items, said in the app's words: a `<div role="status">`, a
|
|
10
|
+
* polite live region, with what its function returns while the list is
|
|
11
|
+
* open, and nothing while it is closed. In `Combobox.Popup`, beside the
|
|
12
|
+
* List, it is the message for an empty list; visually hidden beside the
|
|
13
|
+
* input, it tells a screen reader how many items match as the user types.
|
|
14
|
+
* Place it inside `Combobox.Root`.
|
|
15
|
+
*/
|
|
16
|
+
function ComboboxStatus(props) {
|
|
17
|
+
const combobox = useComboboxContext();
|
|
18
|
+
const elementProps = mergeElementProps({
|
|
19
|
+
role: "status",
|
|
20
|
+
get children() {
|
|
21
|
+
const said = props.children(combobox.count());
|
|
22
|
+
return combobox.open() ? said : void 0;
|
|
23
|
+
}
|
|
24
|
+
}, omit(props, "render", "children"));
|
|
25
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
26
|
+
var _el$ = _tmpl$();
|
|
27
|
+
spread(_el$, p, false);
|
|
28
|
+
return _el$;
|
|
29
|
+
})());
|
|
30
|
+
}
|
|
31
|
+
export { ComboboxStatus };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
5
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/combobox/trigger/ComboboxTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that opens and closes the list, for the pointer and touch: a
|
|
11
|
+
* `<button type="button" tabindex="-1">` with `aria-expanded` and
|
|
12
|
+
* `aria-controls` naming the List. Out of the tab order, since the input
|
|
13
|
+
* takes the keys, and a press leaves focus in the input. Name it with
|
|
14
|
+
* `aria-label`. Place it inside `Combobox.Root`.
|
|
15
|
+
*/
|
|
16
|
+
function ComboboxTrigger(props) {
|
|
17
|
+
const combobox = useComboboxContext();
|
|
18
|
+
const ownProps = merge(combobox.attributes, {
|
|
19
|
+
type: "button",
|
|
20
|
+
tabindex: -1,
|
|
21
|
+
get disabled() {
|
|
22
|
+
return combobox.props.disabled;
|
|
23
|
+
},
|
|
24
|
+
get "aria-expanded"() {
|
|
25
|
+
return combobox.open() ? "true" : "false";
|
|
26
|
+
},
|
|
27
|
+
"aria-controls": combobox.listId,
|
|
28
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
29
|
+
onClick: (event) => {
|
|
30
|
+
combobox.setOpen(!combobox.open(), {
|
|
31
|
+
reason: "trigger-press",
|
|
32
|
+
event
|
|
33
|
+
});
|
|
34
|
+
combobox.input?.focus();
|
|
35
|
+
},
|
|
36
|
+
ref: (element) => {
|
|
37
|
+
if (isDev) warnUnlessButton(element, "Combobox.Trigger");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
41
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
42
|
+
var _el$ = _tmpl$();
|
|
43
|
+
spread(_el$, p, false);
|
|
44
|
+
return _el$;
|
|
45
|
+
})());
|
|
46
|
+
}
|
|
47
|
+
export { ComboboxTrigger };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createIdSlot } from "../../core/slot.js";
|
|
4
|
+
import { SelectGroupContext } from "./SelectGroupContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { omit } from "solid-js";
|
|
7
|
+
// src/select/group/SelectGroup.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* Items that belong together: a `<div role="group">` named by its
|
|
11
|
+
* `Select.GroupLabel`. Place it inside `Select.Popup`.
|
|
12
|
+
*/
|
|
13
|
+
function SelectGroup(props) {
|
|
14
|
+
const [labelId, registerLabelId] = createIdSlot();
|
|
15
|
+
const elementProps = mergeElementProps({
|
|
16
|
+
role: "group",
|
|
17
|
+
get "aria-labelledby"() {
|
|
18
|
+
return props["aria-labelledby"] ?? labelId();
|
|
19
|
+
}
|
|
20
|
+
}, omit(props, "render", "aria-labelledby"));
|
|
21
|
+
return createComponent(SelectGroupContext, {
|
|
22
|
+
value: { registerLabelId },
|
|
23
|
+
get children() {
|
|
24
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
25
|
+
var _el$ = _tmpl$();
|
|
26
|
+
spread(_el$, p, false);
|
|
27
|
+
return _el$;
|
|
28
|
+
})());
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export { SelectGroup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/select/group/SelectGroupContext.ts
|
|
4
|
+
var SelectGroupContext = createContext(null);
|
|
5
|
+
function useSelectGroupContext() {
|
|
6
|
+
const context = useContext(SelectGroupContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Select.GroupLabel must be placed within <Select.Group>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { SelectGroupContext, useSelectGroupContext };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useSelectGroupContext } from "../group/SelectGroupContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId, omit, onSettled } from "solid-js";
|
|
6
|
+
// src/select/group-label/SelectGroupLabel.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The label of a group, which names it in `aria-labelledby`: a `<div>`,
|
|
10
|
+
* not reached by the keys. Place it inside `Select.Group`.
|
|
11
|
+
*/
|
|
12
|
+
function SelectGroupLabel(props) {
|
|
13
|
+
const group = useSelectGroupContext();
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const id = () => props.id ?? generated;
|
|
16
|
+
onSettled(() => group.registerLabelId(id));
|
|
17
|
+
const elementProps = mergeElementProps({ get id() {
|
|
18
|
+
return id();
|
|
19
|
+
} }, omit(props, "render", "id"));
|
|
20
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
21
|
+
var _el$ = _tmpl$();
|
|
22
|
+
spread(_el$, p, false);
|
|
23
|
+
return _el$;
|
|
24
|
+
})());
|
|
25
|
+
}
|
|
26
|
+
export { SelectGroupLabel };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SelectRoot } from "./root/SelectRoot.js";
|
|
2
|
+
import { SelectTrigger } from "./trigger/SelectTrigger.js";
|
|
3
|
+
import { SelectValue } from "./value/SelectValue.js";
|
|
4
|
+
import { SelectPopup } from "./popup/SelectPopup.js";
|
|
5
|
+
import { SelectItem } from "./item/SelectItem.js";
|
|
6
|
+
import { SelectItemIndicator } from "./item-indicator/SelectItemIndicator.js";
|
|
7
|
+
import { SelectGroup } from "./group/SelectGroup.js";
|
|
8
|
+
import { SelectGroupLabel } from "./group-label/SelectGroupLabel.js";
|
|
9
|
+
export { SelectGroup as Group, SelectGroupLabel as GroupLabel, SelectItem as Item, SelectItemIndicator as ItemIndicator, SelectPopup as Popup, SelectRoot as Root, SelectTrigger as Trigger, SelectValue as Value };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useSelectContext } from "../root/SelectContext.js";
|
|
4
|
+
import { SelectItemContext } from "./SelectItemContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { createUniqueId, merge, omit, onSettled } from "solid-js";
|
|
7
|
+
// src/select/item/SelectItem.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* A value to select: a `<div role="option">` with `aria-selected`. A click
|
|
11
|
+
* selects it and closes the list, and so do Enter, Space and Tab while it
|
|
12
|
+
* is the active item; a disabled item is not selected. Place it inside
|
|
13
|
+
* `Select.Popup`.
|
|
14
|
+
*/
|
|
15
|
+
function SelectItem(props) {
|
|
16
|
+
const select = useSelectContext();
|
|
17
|
+
let element;
|
|
18
|
+
const generated = createUniqueId();
|
|
19
|
+
const id = () => props.id || generated;
|
|
20
|
+
const item = {
|
|
21
|
+
get element() {
|
|
22
|
+
return element;
|
|
23
|
+
},
|
|
24
|
+
get id() {
|
|
25
|
+
return id();
|
|
26
|
+
},
|
|
27
|
+
get text() {
|
|
28
|
+
return props.label ?? labelOf(element);
|
|
29
|
+
},
|
|
30
|
+
get value() {
|
|
31
|
+
return props.value;
|
|
32
|
+
},
|
|
33
|
+
get disabled() {
|
|
34
|
+
return props.disabled;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
onSettled(() => select.list.register(item));
|
|
38
|
+
const selected = () => select.value() === props.value;
|
|
39
|
+
const attributes = {
|
|
40
|
+
get "data-selected"() {
|
|
41
|
+
return selected() ? "" : void 0;
|
|
42
|
+
},
|
|
43
|
+
get "data-unselected"() {
|
|
44
|
+
return selected() ? void 0 : "";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const ownProps = merge(attributes, {
|
|
48
|
+
role: "option",
|
|
49
|
+
get id() {
|
|
50
|
+
return id();
|
|
51
|
+
},
|
|
52
|
+
get "aria-selected"() {
|
|
53
|
+
return selected() ? "true" : "false";
|
|
54
|
+
},
|
|
55
|
+
get "data-active"() {
|
|
56
|
+
return select.isActive(item) ? "" : void 0;
|
|
57
|
+
},
|
|
58
|
+
get "aria-disabled"() {
|
|
59
|
+
return props.disabled ? "true" : void 0;
|
|
60
|
+
},
|
|
61
|
+
get "data-disabled"() {
|
|
62
|
+
return props.disabled ? "" : void 0;
|
|
63
|
+
},
|
|
64
|
+
onPointerMove: (event) => select.list.onPointerMove(item, event),
|
|
65
|
+
onClick: (event) => {
|
|
66
|
+
if (select.select(item)) select.setOpen(false, {
|
|
67
|
+
reason: "item-press",
|
|
68
|
+
event
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
ref: (el) => {
|
|
72
|
+
element = el;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "label", "id"));
|
|
76
|
+
return createComponent(SelectItemContext, {
|
|
77
|
+
value: attributes,
|
|
78
|
+
get children() {
|
|
79
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
80
|
+
var _el$ = _tmpl$();
|
|
81
|
+
spread(_el$, p, false);
|
|
82
|
+
return _el$;
|
|
83
|
+
})());
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* An item's own text: its text content without what is `aria-hidden`, such
|
|
89
|
+
* as its ItemIndicator's check mark, which is no part of its name either.
|
|
90
|
+
*/
|
|
91
|
+
function labelOf(node) {
|
|
92
|
+
let text = "";
|
|
93
|
+
for (const child of node.childNodes) if (child.nodeType === 3) text += child.nodeValue;
|
|
94
|
+
else if (child.getAttribute?.("aria-hidden") !== "true") text += labelOf(child);
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
export { SelectItem };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/select/item/SelectItemContext.ts
|
|
4
|
+
var SelectItemContext = createContext(null);
|
|
5
|
+
function useSelectItemContext() {
|
|
6
|
+
const context = useContext(SelectItemContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Select.ItemIndicator must be placed within <Select.Item>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { SelectItemContext, useSelectItemContext };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useSelectItemContext } from "../item/SelectItemContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { merge, omit } from "solid-js";
|
|
6
|
+
// src/select/item-indicator/SelectItemIndicator.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span>`);
|
|
8
|
+
/**
|
|
9
|
+
* The check mark of an item: an `aria-hidden` `<span>` with its item's
|
|
10
|
+
* `data-selected` or `data-unselected`, always rendered, so that CSS shows
|
|
11
|
+
* it by state. Place it inside `Select.Item`.
|
|
12
|
+
*/
|
|
13
|
+
function SelectItemIndicator(props) {
|
|
14
|
+
const ownProps = merge(useSelectItemContext(), { "aria-hidden": "true" });
|
|
15
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
16
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
17
|
+
var _el$ = _tmpl$();
|
|
18
|
+
spread(_el$, p, false);
|
|
19
|
+
return _el$;
|
|
20
|
+
})());
|
|
21
|
+
}
|
|
22
|
+
export { SelectItemIndicator };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createPopoverClose } from "../../floating/dismissal/popoverClose.js";
|
|
4
|
+
import { createPosition } from "../../floating/positioning/createPosition.js";
|
|
5
|
+
import { flip } from "../../floating/positioning/flip.js";
|
|
6
|
+
import { offset } from "../../floating/positioning/offset.js";
|
|
7
|
+
import { shift } from "../../floating/positioning/shift.js";
|
|
8
|
+
import { size } from "../../floating/positioning/size.js";
|
|
9
|
+
import { createPresence } from "../../floating/presence/presence.js";
|
|
10
|
+
import { useSelectContext } from "../root/SelectContext.js";
|
|
11
|
+
import { spread, template } from "@solidjs/web";
|
|
12
|
+
import { createEffect, merge, omit } from "solid-js";
|
|
13
|
+
// src/select/popup/SelectPopup.tsx
|
|
14
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
15
|
+
/**
|
|
16
|
+
* The list itself: a `<div popover="auto" role="listbox">` in the top
|
|
17
|
+
* layer, placed against the Trigger and labelled by it. It takes no focus:
|
|
18
|
+
* the Trigger keeps it. Escape, a press outside, Tab and selecting an item
|
|
19
|
+
* close it. Its CSS variables `--anchor-width` and `--available-height`
|
|
20
|
+
* are for its `min-width` and `max-height`. Place it inside `Select.Root`,
|
|
21
|
+
* right after `Select.Trigger`.
|
|
22
|
+
*/
|
|
23
|
+
function SelectPopup(props) {
|
|
24
|
+
const select = useSelectContext();
|
|
25
|
+
let popup;
|
|
26
|
+
const options = {
|
|
27
|
+
get popup() {
|
|
28
|
+
return popup;
|
|
29
|
+
},
|
|
30
|
+
get trigger() {
|
|
31
|
+
return select.trigger;
|
|
32
|
+
},
|
|
33
|
+
get open() {
|
|
34
|
+
return select.open();
|
|
35
|
+
},
|
|
36
|
+
onDismiss: (details) => select.setOpen(false, details)
|
|
37
|
+
};
|
|
38
|
+
createPresence(options);
|
|
39
|
+
createPopoverClose(options);
|
|
40
|
+
createEffect(() => select.initial(), (item) => {
|
|
41
|
+
if (item) queueMicrotask(() => item.element.scrollIntoView({ block: "nearest" }));
|
|
42
|
+
});
|
|
43
|
+
createPosition({
|
|
44
|
+
get anchor() {
|
|
45
|
+
const anchor = props.anchor;
|
|
46
|
+
return (typeof anchor === "function" ? anchor() : anchor) ?? select.trigger;
|
|
47
|
+
},
|
|
48
|
+
get popup() {
|
|
49
|
+
return popup;
|
|
50
|
+
},
|
|
51
|
+
get open() {
|
|
52
|
+
return select.open();
|
|
53
|
+
},
|
|
54
|
+
get side() {
|
|
55
|
+
return props.side ?? "bottom";
|
|
56
|
+
},
|
|
57
|
+
get align() {
|
|
58
|
+
return props.align ?? "start";
|
|
59
|
+
},
|
|
60
|
+
get middleware() {
|
|
61
|
+
const padding = props.collisionPadding ?? 5;
|
|
62
|
+
return [
|
|
63
|
+
offset({
|
|
64
|
+
mainAxis: props.sideOffset ?? 0,
|
|
65
|
+
alignmentAxis: props.alignOffset ?? 0
|
|
66
|
+
}),
|
|
67
|
+
flip({ padding }),
|
|
68
|
+
shift({ padding }),
|
|
69
|
+
size({ padding })
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const ownProps = merge(select.attributes, {
|
|
74
|
+
id: select.popupId,
|
|
75
|
+
popover: "auto",
|
|
76
|
+
role: "listbox",
|
|
77
|
+
get "aria-labelledby"() {
|
|
78
|
+
return props["aria-labelledby"] ?? select.triggerId();
|
|
79
|
+
},
|
|
80
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
81
|
+
ref: (element) => {
|
|
82
|
+
popup = element;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "side", "align", "sideOffset", "alignOffset", "collisionPadding", "anchor", "aria-labelledby", "id"));
|
|
86
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
87
|
+
var _el$ = _tmpl$();
|
|
88
|
+
spread(_el$, p, false);
|
|
89
|
+
return _el$;
|
|
90
|
+
})());
|
|
91
|
+
}
|
|
92
|
+
export { SelectPopup };
|