menhir 0.1.5 → 0.1.6
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/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 +160 -0
- package/dist/combobox/item/ComboboxItem.js +98 -0
- package/dist/combobox/item/ComboboxItemContext.js +10 -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 +137 -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/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 +174 -0
- package/dist/source/combobox/item/ComboboxItem.d.ts +25 -0
- package/dist/source/combobox/item/ComboboxItem.jsx +93 -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-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 +132 -0
- package/dist/source/combobox/root/ComboboxContext.js +156 -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 +11 -1
package/README.md
CHANGED
|
@@ -60,9 +60,9 @@ For everything else, go to the docs:
|
|
|
60
60
|
|
|
61
61
|
## Status
|
|
62
62
|
|
|
63
|
-
Early 0.x versions: the API may change between minor versions.
|
|
63
|
+
Early 0.x versions: the API may change between minor versions. Autocomplete and the form components come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
|
|
64
64
|
|
|
65
|
-
- Components: Accordion, Alert Dialog, Checkbox, Collapsible, Context Menu, Dialog, Menu, Menubar, Meter, Navigation Menu, Popover, Progress, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
|
|
65
|
+
- Components: Accordion, Alert Dialog, Checkbox, Collapsible, Combobox, Context Menu, Dialog, Menu, Menubar, Meter, Navigation Menu, Popover, Progress, Select, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
|
|
66
66
|
- Utilities: color scheme and theme, each with local-storage and cookie storage.
|
|
67
67
|
|
|
68
68
|
## Licence
|
|
@@ -0,0 +1,39 @@
|
|
|
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/clear/ComboboxClear.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that empties the text and the value, for the pointer, as
|
|
11
|
+
* Escape on a closed list does from the keyboard: a `<button type="button"
|
|
12
|
+
* tabindex="-1">` that then focuses the input. Name it with `aria-label`.
|
|
13
|
+
* Place it inside `Combobox.Root`.
|
|
14
|
+
*/
|
|
15
|
+
function ComboboxClear(props) {
|
|
16
|
+
const combobox = useComboboxContext();
|
|
17
|
+
const ownProps = merge(combobox.attributes, {
|
|
18
|
+
type: "button",
|
|
19
|
+
tabindex: -1,
|
|
20
|
+
get disabled() {
|
|
21
|
+
return combobox.props.disabled;
|
|
22
|
+
},
|
|
23
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
24
|
+
onClick: (event) => {
|
|
25
|
+
combobox.clear(event, "clear-press");
|
|
26
|
+
combobox.input?.focus();
|
|
27
|
+
},
|
|
28
|
+
ref: (element) => {
|
|
29
|
+
if (isDev) warnUnlessButton(element, "Combobox.Clear");
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
33
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
34
|
+
var _el$ = _tmpl$();
|
|
35
|
+
spread(_el$, p, false);
|
|
36
|
+
return _el$;
|
|
37
|
+
})());
|
|
38
|
+
}
|
|
39
|
+
export { ComboboxClear };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/combobox/filter/includesText.ts
|
|
2
|
+
var collator;
|
|
3
|
+
/**
|
|
4
|
+
* Whether `text` contains `query`, case and accents ignored, with the
|
|
5
|
+
* built-in `Intl.Collator`; an empty query matches everything. The filter
|
|
6
|
+
* for a Combobox whose items match what the user types:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const shown = createMemo(() =>
|
|
10
|
+
* countries.filter((country) => includesText(country.name, query())),
|
|
11
|
+
* );
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function includesText(text, query) {
|
|
15
|
+
const haystack = text.normalize();
|
|
16
|
+
const needle = query.normalize();
|
|
17
|
+
collator ??= new Intl.Collator(void 0, { sensitivity: "base" });
|
|
18
|
+
for (let start = 0; start + needle.length <= haystack.length; start++) {
|
|
19
|
+
const slice = haystack.slice(start, start + needle.length);
|
|
20
|
+
if (!collator.compare(slice, needle)) return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
export { includesText };
|
|
@@ -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 { ComboboxGroupContext } from "./ComboboxGroupContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { omit } from "solid-js";
|
|
7
|
+
// src/combobox/group/ComboboxGroup.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* Items that belong together: a `<div role="group">` named by its
|
|
11
|
+
* `Combobox.GroupLabel`. Place it inside `Combobox.List`.
|
|
12
|
+
*/
|
|
13
|
+
function ComboboxGroup(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(ComboboxGroupContext, {
|
|
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 { ComboboxGroup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/combobox/group/ComboboxGroupContext.ts
|
|
4
|
+
var ComboboxGroupContext = createContext(null);
|
|
5
|
+
function useComboboxGroupContext() {
|
|
6
|
+
const context = useContext(ComboboxGroupContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Combobox.GroupLabel must be placed within <Combobox.Group>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { ComboboxGroupContext, useComboboxGroupContext };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxGroupContext } from "../group/ComboboxGroupContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId, omit, onSettled } from "solid-js";
|
|
6
|
+
// src/combobox/group-label/ComboboxGroupLabel.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 `Combobox.Group`.
|
|
11
|
+
*/
|
|
12
|
+
function ComboboxGroupLabel(props) {
|
|
13
|
+
const group = useComboboxGroupContext();
|
|
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 { ComboboxGroupLabel };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComboboxRoot } from "./root/ComboboxRoot.js";
|
|
2
|
+
import { ComboboxInput } from "./input/ComboboxInput.js";
|
|
3
|
+
import { ComboboxTrigger } from "./trigger/ComboboxTrigger.js";
|
|
4
|
+
import { ComboboxClear } from "./clear/ComboboxClear.js";
|
|
5
|
+
import { ComboboxPopup } from "./popup/ComboboxPopup.js";
|
|
6
|
+
import { ComboboxList } from "./list/ComboboxList.js";
|
|
7
|
+
import { ComboboxItem } from "./item/ComboboxItem.js";
|
|
8
|
+
import { ComboboxItemIndicator } from "./item-indicator/ComboboxItemIndicator.js";
|
|
9
|
+
import { ComboboxGroup } from "./group/ComboboxGroup.js";
|
|
10
|
+
import { ComboboxGroupLabel } from "./group-label/ComboboxGroupLabel.js";
|
|
11
|
+
import { ComboboxStatus } from "./status/ComboboxStatus.js";
|
|
12
|
+
export { ComboboxClear as Clear, ComboboxGroup as Group, ComboboxGroupLabel as GroupLabel, ComboboxInput as Input, ComboboxItem as Item, ComboboxItemIndicator as ItemIndicator, ComboboxList as List, ComboboxPopup as Popup, ComboboxRoot as Root, ComboboxStatus as Status, ComboboxTrigger as Trigger };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
+
import { effect, heldRead, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
5
|
+
import { createSignal, merge, omit, onFlush, onSettled, untrack } from "solid-js";
|
|
6
|
+
// src/combobox/input/ComboboxInput.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<input aria-hidden=true tabindex=-1 style=position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none>`);
|
|
8
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<input>`);
|
|
9
|
+
/**
|
|
10
|
+
* The combobox itself: an `<input type="text" role="combobox"
|
|
11
|
+
* aria-autocomplete="list">` with `aria-expanded`, naming the List in
|
|
12
|
+
* `aria-controls` and the active item in `aria-activedescendant`. It keeps
|
|
13
|
+
* focus while the list is open: typing opens and filters it, and the arrow
|
|
14
|
+
* keys, Enter and Escape act on it. A visually hidden `<input>` follows it,
|
|
15
|
+
* the form's view of the value. Name it with a `<label>`. Place it inside
|
|
16
|
+
* `Combobox.Root`.
|
|
17
|
+
*/
|
|
18
|
+
function ComboboxInput(props) {
|
|
19
|
+
const combobox = useComboboxContext();
|
|
20
|
+
const { list } = combobox;
|
|
21
|
+
let input;
|
|
22
|
+
let hiddenInput;
|
|
23
|
+
const details = (reason, event) => ({
|
|
24
|
+
reason,
|
|
25
|
+
event
|
|
26
|
+
});
|
|
27
|
+
const setOpen = (open, reason, event) => combobox.setOpen(open, details(reason, event));
|
|
28
|
+
const [draft, setDraft] = createSignal(() => combobox.inputValue());
|
|
29
|
+
const syncText = () => {
|
|
30
|
+
const text = untrack(combobox.inputValue);
|
|
31
|
+
setDraft(text);
|
|
32
|
+
if (input && input.value !== text) input.value = text;
|
|
33
|
+
};
|
|
34
|
+
const ownProps = merge(combobox.attributes, {
|
|
35
|
+
type: "text",
|
|
36
|
+
role: "combobox",
|
|
37
|
+
"aria-autocomplete": "list",
|
|
38
|
+
autocomplete: "off",
|
|
39
|
+
get value() {
|
|
40
|
+
return draft();
|
|
41
|
+
},
|
|
42
|
+
get disabled() {
|
|
43
|
+
return combobox.props.disabled;
|
|
44
|
+
},
|
|
45
|
+
get "aria-expanded"() {
|
|
46
|
+
return combobox.open() ? "true" : "false";
|
|
47
|
+
},
|
|
48
|
+
"aria-controls": combobox.listId,
|
|
49
|
+
get "aria-activedescendant"() {
|
|
50
|
+
return combobox.open() ? list.activeId() : void 0;
|
|
51
|
+
},
|
|
52
|
+
get "aria-required"() {
|
|
53
|
+
return combobox.props.required ? "true" : void 0;
|
|
54
|
+
},
|
|
55
|
+
onInput: (event) => {
|
|
56
|
+
setDraft(input.value);
|
|
57
|
+
combobox.setInputValue(input.value, details("input-change", event));
|
|
58
|
+
list.move(void 0);
|
|
59
|
+
setOpen(true, "input-change", event);
|
|
60
|
+
onFlush(syncText);
|
|
61
|
+
},
|
|
62
|
+
onKeyDown: (event) => {
|
|
63
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
64
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
65
|
+
const isOpen = combobox.open();
|
|
66
|
+
const { key, altKey } = event;
|
|
67
|
+
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
68
|
+
const down = key === "ArrowDown";
|
|
69
|
+
if (altKey) {
|
|
70
|
+
if (down === isOpen) return;
|
|
71
|
+
setOpen(down, "arrow-key", event);
|
|
72
|
+
} else if (!isOpen) {
|
|
73
|
+
setOpen(true, "arrow-key", event);
|
|
74
|
+
const items = list.items();
|
|
75
|
+
list.move(down ? items[0] : items[items.length - 1]);
|
|
76
|
+
} else if (!list.onKeyDown(event)) return;
|
|
77
|
+
} else if (key === "Enter" && !altKey) {
|
|
78
|
+
if (!isOpen) return;
|
|
79
|
+
const item = list.active();
|
|
80
|
+
if (!item) {
|
|
81
|
+
setOpen(false, "enter-key", event);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (combobox.select(item, event)) setOpen(false, "item-press", event);
|
|
85
|
+
} else if (key === "Escape" && !altKey) {
|
|
86
|
+
if (isOpen) setOpen(false, "escape-key", event);
|
|
87
|
+
else if (combobox.inputValue() || combobox.value() !== null) combobox.clear(event, "escape-key");
|
|
88
|
+
else return;
|
|
89
|
+
} else return;
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
},
|
|
92
|
+
onBlur: (event) => {
|
|
93
|
+
if (!document.hasFocus()) return;
|
|
94
|
+
setOpen(false, "focus-out", event);
|
|
95
|
+
combobox.revert(event);
|
|
96
|
+
},
|
|
97
|
+
ref: (element) => {
|
|
98
|
+
input = element;
|
|
99
|
+
combobox.input = input;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const onHiddenChange = () => {
|
|
103
|
+
combobox.setValue(hiddenInput.value || null);
|
|
104
|
+
onFlush(syncHidden);
|
|
105
|
+
};
|
|
106
|
+
const syncHidden = () => {
|
|
107
|
+
if (hiddenInput) hiddenInput.value = untrack(combobox.value) ?? "";
|
|
108
|
+
};
|
|
109
|
+
onSettled(() => {
|
|
110
|
+
const form = hiddenInput?.form;
|
|
111
|
+
if (!form) return;
|
|
112
|
+
const onReset = (event) => {
|
|
113
|
+
const value = combobox.props.defaultValue ?? null;
|
|
114
|
+
combobox.setValue(value);
|
|
115
|
+
combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", details("reset", event));
|
|
116
|
+
onFlush(() => {
|
|
117
|
+
syncHidden();
|
|
118
|
+
syncText();
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
form.addEventListener("reset", onReset);
|
|
122
|
+
return () => form.removeEventListener("reset", onReset);
|
|
123
|
+
});
|
|
124
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
125
|
+
return [memo(() => {
|
|
126
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
127
|
+
var _el$2 = _tmpl$2();
|
|
128
|
+
spread(_el$2, p, false);
|
|
129
|
+
return _el$2;
|
|
130
|
+
})());
|
|
131
|
+
}), (() => {
|
|
132
|
+
var _el$ = _tmpl$();
|
|
133
|
+
_el$.addEventListener("focus", () => combobox.input?.focus());
|
|
134
|
+
_el$.addEventListener("change", onHiddenChange);
|
|
135
|
+
ref(() => {
|
|
136
|
+
return (element) => {
|
|
137
|
+
hiddenInput = element;
|
|
138
|
+
combobox.hiddenInput = element;
|
|
139
|
+
};
|
|
140
|
+
}, _el$);
|
|
141
|
+
effect(() => {
|
|
142
|
+
return {
|
|
143
|
+
e: combobox.props.name,
|
|
144
|
+
t: combobox.props.form,
|
|
145
|
+
a: combobox.props.required,
|
|
146
|
+
o: combobox.props.disabled,
|
|
147
|
+
i: combobox.value() ?? "",
|
|
148
|
+
n: heldRead()
|
|
149
|
+
};
|
|
150
|
+
}, ({ e, t, a, o, i, n }, _p$) => {
|
|
151
|
+
e !== _p$?.e && setAttribute(_el$, "name", e);
|
|
152
|
+
t !== _p$?.t && setAttribute(_el$, "form", t);
|
|
153
|
+
a !== _p$?.a && setAttribute(_el$, "required", a);
|
|
154
|
+
o !== _p$?.o && setAttribute(_el$, "disabled", o);
|
|
155
|
+
(i !== _p$?.i || !n) && (_el$.value = i ?? "");
|
|
156
|
+
});
|
|
157
|
+
return _el$;
|
|
158
|
+
})()];
|
|
159
|
+
}
|
|
160
|
+
export { ComboboxInput };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
+
import { ComboboxItemContext } from "./ComboboxItemContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { createUniqueId, merge, omit, onSettled } from "solid-js";
|
|
7
|
+
// src/combobox/item/ComboboxItem.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, sets the input's text to its label and closes the list, and
|
|
12
|
+
* so does Enter while it is the active item; a disabled item is not
|
|
13
|
+
* selected. Render the items that match the text, and place them inside
|
|
14
|
+
* `Combobox.List`.
|
|
15
|
+
*/
|
|
16
|
+
function ComboboxItem(props) {
|
|
17
|
+
const combobox = useComboboxContext();
|
|
18
|
+
let element;
|
|
19
|
+
const generated = createUniqueId();
|
|
20
|
+
const id = () => props.id || generated;
|
|
21
|
+
const item = {
|
|
22
|
+
get element() {
|
|
23
|
+
return element;
|
|
24
|
+
},
|
|
25
|
+
get id() {
|
|
26
|
+
return id();
|
|
27
|
+
},
|
|
28
|
+
get text() {
|
|
29
|
+
return props.label ?? labelOf(element);
|
|
30
|
+
},
|
|
31
|
+
get value() {
|
|
32
|
+
return props.value;
|
|
33
|
+
},
|
|
34
|
+
get disabled() {
|
|
35
|
+
return props.disabled;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
onSettled(() => combobox.list.register(item));
|
|
39
|
+
const selected = () => combobox.value() === props.value;
|
|
40
|
+
const attributes = {
|
|
41
|
+
get "data-selected"() {
|
|
42
|
+
return selected() ? "" : void 0;
|
|
43
|
+
},
|
|
44
|
+
get "data-unselected"() {
|
|
45
|
+
return selected() ? void 0 : "";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const ownProps = merge(attributes, {
|
|
49
|
+
role: "option",
|
|
50
|
+
get id() {
|
|
51
|
+
return id();
|
|
52
|
+
},
|
|
53
|
+
get "aria-selected"() {
|
|
54
|
+
return selected() ? "true" : "false";
|
|
55
|
+
},
|
|
56
|
+
get "data-active"() {
|
|
57
|
+
return combobox.isActive(item) ? "" : void 0;
|
|
58
|
+
},
|
|
59
|
+
get "aria-disabled"() {
|
|
60
|
+
return props.disabled ? "true" : void 0;
|
|
61
|
+
},
|
|
62
|
+
get "data-disabled"() {
|
|
63
|
+
return props.disabled ? "" : void 0;
|
|
64
|
+
},
|
|
65
|
+
onPointerMove: (event) => combobox.list.onPointerMove(item, event),
|
|
66
|
+
onClick: (event) => {
|
|
67
|
+
if (combobox.select(item, event)) combobox.setOpen(false, {
|
|
68
|
+
reason: "item-press",
|
|
69
|
+
event
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
ref: (el) => {
|
|
73
|
+
element = el;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "label", "id"));
|
|
77
|
+
return createComponent(ComboboxItemContext, {
|
|
78
|
+
value: attributes,
|
|
79
|
+
get children() {
|
|
80
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
81
|
+
var _el$ = _tmpl$();
|
|
82
|
+
spread(_el$, p, false);
|
|
83
|
+
return _el$;
|
|
84
|
+
})());
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* An item's own text: its text content without what is `aria-hidden`, such
|
|
90
|
+
* as its ItemIndicator's check mark, which is no part of its name either.
|
|
91
|
+
*/
|
|
92
|
+
function labelOf(node) {
|
|
93
|
+
let text = "";
|
|
94
|
+
for (const child of node.childNodes) if (child.nodeType === 3) text += child.nodeValue;
|
|
95
|
+
else if (child.getAttribute?.("aria-hidden") !== "true") text += labelOf(child);
|
|
96
|
+
return text;
|
|
97
|
+
}
|
|
98
|
+
export { ComboboxItem };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/combobox/item/ComboboxItemContext.ts
|
|
4
|
+
var ComboboxItemContext = createContext(null);
|
|
5
|
+
function useComboboxItemContext() {
|
|
6
|
+
const context = useContext(ComboboxItemContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Combobox.ItemIndicator must be placed within <Combobox.Item>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { ComboboxItemContext, useComboboxItemContext };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxItemContext } from "../item/ComboboxItemContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { merge, omit } from "solid-js";
|
|
6
|
+
// src/combobox/item-indicator/ComboboxItemIndicator.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 `Combobox.Item`.
|
|
12
|
+
*/
|
|
13
|
+
function ComboboxItemIndicator(props) {
|
|
14
|
+
const ownProps = merge(useComboboxItemContext(), { "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 { ComboboxItemIndicator };
|
|
@@ -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 };
|