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
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. 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, Autocomplete, 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,11 @@
|
|
|
1
|
+
import { AutocompleteRoot } from "./root/AutocompleteRoot.js";
|
|
2
|
+
import { AutocompleteInput } from "./input/AutocompleteInput.js";
|
|
3
|
+
import { ComboboxTrigger } from "../combobox/trigger/ComboboxTrigger.js";
|
|
4
|
+
import { ComboboxClear } from "../combobox/clear/ComboboxClear.js";
|
|
5
|
+
import { ComboboxPopup } from "../combobox/popup/ComboboxPopup.js";
|
|
6
|
+
import { ComboboxList } from "../combobox/list/ComboboxList.js";
|
|
7
|
+
import { AutocompleteItem } from "./item/AutocompleteItem.js";
|
|
8
|
+
import { ComboboxGroup } from "../combobox/group/ComboboxGroup.js";
|
|
9
|
+
import { ComboboxGroupLabel } from "../combobox/group-label/ComboboxGroupLabel.js";
|
|
10
|
+
import { ComboboxStatus } from "../combobox/status/ComboboxStatus.js";
|
|
11
|
+
export { ComboboxClear as Clear, ComboboxGroup as Group, ComboboxGroupLabel as GroupLabel, AutocompleteInput as Input, AutocompleteItem as Item, ComboboxList as List, ComboboxPopup as Popup, AutocompleteRoot as Root, ComboboxStatus as Status, ComboboxTrigger as Trigger };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createComboboxInput, onFormReset } from "../../combobox/input/createComboboxInput.js";
|
|
4
|
+
import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
5
|
+
import { spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit, onFlush } from "solid-js";
|
|
7
|
+
// src/autocomplete/input/AutocompleteInput.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<input>`);
|
|
9
|
+
/**
|
|
10
|
+
* The autocomplete itself, and the form's control: an `<input type="text"
|
|
11
|
+
* role="combobox" aria-autocomplete="list">` that takes `name`, `form`,
|
|
12
|
+
* `required` and `disabled` from the Root, so the form receives its text.
|
|
13
|
+
* It keeps focus while the list is open: typing opens it, and the arrow
|
|
14
|
+
* keys, Enter and Escape act on it. Name it with a `<label>`. Place it
|
|
15
|
+
* inside `Autocomplete.Root`.
|
|
16
|
+
*/
|
|
17
|
+
function AutocompleteInput(props) {
|
|
18
|
+
const autocomplete = useComboboxContext("Autocomplete");
|
|
19
|
+
const input = createComboboxInput(autocomplete);
|
|
20
|
+
onFormReset(() => autocomplete.input, (event) => {
|
|
21
|
+
autocomplete.setInputValue(autocomplete.props.defaultValue ?? "", {
|
|
22
|
+
reason: "reset",
|
|
23
|
+
event
|
|
24
|
+
});
|
|
25
|
+
onFlush(input.syncText);
|
|
26
|
+
});
|
|
27
|
+
const ownProps = merge(input.props, {
|
|
28
|
+
get name() {
|
|
29
|
+
return autocomplete.props.name;
|
|
30
|
+
},
|
|
31
|
+
get form() {
|
|
32
|
+
return autocomplete.props.form;
|
|
33
|
+
},
|
|
34
|
+
get required() {
|
|
35
|
+
return autocomplete.props.required;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
39
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
40
|
+
var _el$ = _tmpl$();
|
|
41
|
+
spread(_el$, p, false);
|
|
42
|
+
return _el$;
|
|
43
|
+
})());
|
|
44
|
+
}
|
|
45
|
+
export { AutocompleteInput };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
4
|
+
import { createComboboxItem } from "../../combobox/item/createComboboxItem.js";
|
|
5
|
+
import { spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/autocomplete/item/AutocompleteItem.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* A suggestion: a `<div role="option">`, with `aria-selected="true"` while
|
|
11
|
+
* it is the active item. A click accepts it, sets the input's text to its
|
|
12
|
+
* `value` and closes the list, and so does Enter while it is active; a
|
|
13
|
+
* disabled item is not accepted. Render the suggestions that match the
|
|
14
|
+
* text, and place them inside `Autocomplete.List`.
|
|
15
|
+
*/
|
|
16
|
+
function AutocompleteItem(props) {
|
|
17
|
+
const autocomplete = useComboboxContext("Autocomplete");
|
|
18
|
+
const { item, props: itemProps } = createComboboxItem(autocomplete, props, () => props.value);
|
|
19
|
+
const ownProps = merge(itemProps, { get "aria-selected"() {
|
|
20
|
+
return autocomplete.isActive(item) ? "true" : void 0;
|
|
21
|
+
} });
|
|
22
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "id"));
|
|
23
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
24
|
+
var _el$ = _tmpl$();
|
|
25
|
+
spread(_el$, p, false);
|
|
26
|
+
return _el$;
|
|
27
|
+
})());
|
|
28
|
+
}
|
|
29
|
+
export { AutocompleteItem };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { createComboboxBase } from "../../combobox/root/ComboboxContext.js";
|
|
3
|
+
// src/autocomplete/root/AutocompleteContext.ts
|
|
4
|
+
/** Creates an autocomplete's state, on Combobox's shared state. */
|
|
5
|
+
function createAutocomplete(props) {
|
|
6
|
+
const [text, setText, requestedText] = createControllableSignal({
|
|
7
|
+
get value() {
|
|
8
|
+
return props.value;
|
|
9
|
+
},
|
|
10
|
+
get defaultValue() {
|
|
11
|
+
return props.defaultValue ?? "";
|
|
12
|
+
},
|
|
13
|
+
onChange: (text, details) => props.onValueChange?.(text, details)
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
...createComboboxBase(props),
|
|
17
|
+
component: "Autocomplete",
|
|
18
|
+
inputValue: text,
|
|
19
|
+
setInputValue: setText,
|
|
20
|
+
select: (item, event) => {
|
|
21
|
+
if (!item || item.disabled) return false;
|
|
22
|
+
setText(item.value, {
|
|
23
|
+
reason: "item-press",
|
|
24
|
+
event
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
clear: (event, reason) => {
|
|
29
|
+
if (!requestedText()) return false;
|
|
30
|
+
setText("", {
|
|
31
|
+
reason,
|
|
32
|
+
event
|
|
33
|
+
});
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
props
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export { createAutocomplete };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
2
|
+
import { createAutocomplete } from "./AutocompleteContext.js";
|
|
3
|
+
import { createComponent } from "@solidjs/web";
|
|
4
|
+
// src/autocomplete/root/AutocompleteRoot.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A text input with suggestions: holds the text, which is its value, and
|
|
7
|
+
* whether the list is open, and shares them with `Autocomplete.Input`,
|
|
8
|
+
* `Autocomplete.Trigger`, `Autocomplete.Clear`, `Autocomplete.Popup` and
|
|
9
|
+
* the parts inside it. Its form props go on the Input. Renders no element
|
|
10
|
+
* of its own.
|
|
11
|
+
*/
|
|
12
|
+
function AutocompleteRoot(props) {
|
|
13
|
+
return createComponent(ComboboxContext, {
|
|
14
|
+
get value() {
|
|
15
|
+
return createAutocomplete(props);
|
|
16
|
+
},
|
|
17
|
+
get children() {
|
|
18
|
+
return props.children;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export { AutocompleteRoot };
|
|
@@ -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,78 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
+
import { createComboboxInput, onFormReset } from "./createComboboxInput.js";
|
|
5
|
+
import { effect, heldRead, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
|
+
import { omit, onFlush, untrack } from "solid-js";
|
|
7
|
+
// src/combobox/input/ComboboxInput.tsx
|
|
8
|
+
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>`);
|
|
9
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<input>`);
|
|
10
|
+
/**
|
|
11
|
+
* The combobox itself: an `<input type="text" role="combobox"
|
|
12
|
+
* aria-autocomplete="list">` with `aria-expanded`, naming the List in
|
|
13
|
+
* `aria-controls` and the active item in `aria-activedescendant`. It keeps
|
|
14
|
+
* focus while the list is open: typing opens and filters it, and the arrow
|
|
15
|
+
* keys, Enter and Escape act on it. A visually hidden `<input>` follows it,
|
|
16
|
+
* the form's view of the value. Name it with a `<label>`. Place it inside
|
|
17
|
+
* `Combobox.Root`.
|
|
18
|
+
*/
|
|
19
|
+
function ComboboxInput(props) {
|
|
20
|
+
const combobox = useComboboxContext("Combobox");
|
|
21
|
+
const input = createComboboxInput(combobox, combobox.revert);
|
|
22
|
+
let hiddenInput;
|
|
23
|
+
const onHiddenChange = () => {
|
|
24
|
+
combobox.setValue(hiddenInput.value || null);
|
|
25
|
+
onFlush(syncHidden);
|
|
26
|
+
};
|
|
27
|
+
const syncHidden = () => {
|
|
28
|
+
if (hiddenInput) hiddenInput.value = untrack(combobox.value) ?? "";
|
|
29
|
+
};
|
|
30
|
+
onFormReset(() => hiddenInput, (event) => {
|
|
31
|
+
const value = combobox.props.defaultValue ?? null;
|
|
32
|
+
combobox.setValue(value);
|
|
33
|
+
combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", {
|
|
34
|
+
reason: "reset",
|
|
35
|
+
event
|
|
36
|
+
});
|
|
37
|
+
onFlush(() => {
|
|
38
|
+
syncHidden();
|
|
39
|
+
input.syncText();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const elementProps = mergeElementProps(input.props, omit(props, "render"));
|
|
43
|
+
return [memo(() => {
|
|
44
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
45
|
+
var _el$2 = _tmpl$2();
|
|
46
|
+
spread(_el$2, p, false);
|
|
47
|
+
return _el$2;
|
|
48
|
+
})());
|
|
49
|
+
}), (() => {
|
|
50
|
+
var _el$ = _tmpl$();
|
|
51
|
+
_el$.addEventListener("focus", () => combobox.input?.focus());
|
|
52
|
+
_el$.addEventListener("change", onHiddenChange);
|
|
53
|
+
ref(() => {
|
|
54
|
+
return (element) => {
|
|
55
|
+
hiddenInput = element;
|
|
56
|
+
combobox.hiddenInput = element;
|
|
57
|
+
};
|
|
58
|
+
}, _el$);
|
|
59
|
+
effect(() => {
|
|
60
|
+
return {
|
|
61
|
+
e: combobox.props.name,
|
|
62
|
+
t: combobox.props.form,
|
|
63
|
+
a: combobox.props.required,
|
|
64
|
+
o: combobox.props.disabled,
|
|
65
|
+
i: combobox.value() ?? "",
|
|
66
|
+
n: heldRead()
|
|
67
|
+
};
|
|
68
|
+
}, ({ e, t, a, o, i, n }, _p$) => {
|
|
69
|
+
e !== _p$?.e && setAttribute(_el$, "name", e);
|
|
70
|
+
t !== _p$?.t && setAttribute(_el$, "form", t);
|
|
71
|
+
a !== _p$?.a && setAttribute(_el$, "required", a);
|
|
72
|
+
o !== _p$?.o && setAttribute(_el$, "disabled", o);
|
|
73
|
+
(i !== _p$?.i || !n) && (_el$.value = i ?? "");
|
|
74
|
+
});
|
|
75
|
+
return _el$;
|
|
76
|
+
})()];
|
|
77
|
+
}
|
|
78
|
+
export { ComboboxInput };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createSignal, merge, onFlush, onSettled, untrack } from "solid-js";
|
|
2
|
+
// src/combobox/input/createComboboxInput.ts
|
|
3
|
+
/**
|
|
4
|
+
* The input of a combobox, the code `Combobox.Input` and
|
|
5
|
+
* `Autocomplete.Input` share: its attributes, typing, the keys, focus
|
|
6
|
+
* leaving, and the draft its `value` binds to. Focus leaving closes the
|
|
7
|
+
* list and then calls `onFocusOut`, which a Combobox puts its text back
|
|
8
|
+
* in; an Autocomplete keeps the text, and passes none. Returns its props
|
|
9
|
+
* and `syncText`, which puts the element back to the combobox's text once
|
|
10
|
+
* that has settled, as after a form reset.
|
|
11
|
+
*/
|
|
12
|
+
function createComboboxInput(combobox, onFocusOut) {
|
|
13
|
+
const { list } = combobox;
|
|
14
|
+
let input;
|
|
15
|
+
const details = (reason, event) => ({
|
|
16
|
+
reason,
|
|
17
|
+
event
|
|
18
|
+
});
|
|
19
|
+
const setOpen = (open, reason, event) => combobox.setOpen(open, details(reason, event));
|
|
20
|
+
const [draft, setDraft] = createSignal(() => combobox.inputValue());
|
|
21
|
+
const syncText = () => {
|
|
22
|
+
const text = untrack(combobox.inputValue);
|
|
23
|
+
setDraft(text);
|
|
24
|
+
if (input && input.value !== text) input.value = text;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
props: merge(combobox.attributes, {
|
|
28
|
+
type: "text",
|
|
29
|
+
role: "combobox",
|
|
30
|
+
"aria-autocomplete": "list",
|
|
31
|
+
autocomplete: "off",
|
|
32
|
+
get value() {
|
|
33
|
+
return draft();
|
|
34
|
+
},
|
|
35
|
+
get disabled() {
|
|
36
|
+
return combobox.props.disabled;
|
|
37
|
+
},
|
|
38
|
+
get "aria-expanded"() {
|
|
39
|
+
return combobox.open() ? "true" : "false";
|
|
40
|
+
},
|
|
41
|
+
"aria-controls": combobox.listId,
|
|
42
|
+
get "aria-activedescendant"() {
|
|
43
|
+
return combobox.open() ? list.activeId() : void 0;
|
|
44
|
+
},
|
|
45
|
+
get "aria-required"() {
|
|
46
|
+
return combobox.props.required ? "true" : void 0;
|
|
47
|
+
},
|
|
48
|
+
onInput: (event) => {
|
|
49
|
+
setDraft(input.value);
|
|
50
|
+
combobox.setInputValue(input.value, details("input-change", event));
|
|
51
|
+
list.move(void 0);
|
|
52
|
+
setOpen(true, "input-change", event);
|
|
53
|
+
onFlush(syncText);
|
|
54
|
+
},
|
|
55
|
+
onKeyDown: (event) => {
|
|
56
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
57
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
58
|
+
const isOpen = combobox.open();
|
|
59
|
+
const { key, altKey } = event;
|
|
60
|
+
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
61
|
+
const down = key === "ArrowDown";
|
|
62
|
+
if (altKey) {
|
|
63
|
+
if (down === isOpen) return;
|
|
64
|
+
setOpen(down, "arrow-key", event);
|
|
65
|
+
} else if (!isOpen) {
|
|
66
|
+
setOpen(true, "arrow-key", event);
|
|
67
|
+
const items = list.items();
|
|
68
|
+
list.move(down ? items[0] : items[items.length - 1]);
|
|
69
|
+
} else if (!list.onKeyDown(event)) return;
|
|
70
|
+
} else if (key === "Enter" && !altKey) {
|
|
71
|
+
if (!isOpen) return;
|
|
72
|
+
const item = list.active();
|
|
73
|
+
if (!item) {
|
|
74
|
+
setOpen(false, "enter-key", event);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (combobox.select(item, event)) setOpen(false, "item-press", event);
|
|
78
|
+
} else if (key === "Escape" && !altKey) {
|
|
79
|
+
if (isOpen) setOpen(false, "escape-key", event);
|
|
80
|
+
else if (!combobox.clear(event, "escape-key")) return;
|
|
81
|
+
} else return;
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
},
|
|
84
|
+
onBlur: (event) => {
|
|
85
|
+
if (!document.hasFocus()) return;
|
|
86
|
+
setOpen(false, "focus-out", event);
|
|
87
|
+
onFocusOut?.(event);
|
|
88
|
+
},
|
|
89
|
+
ref: (element) => {
|
|
90
|
+
input = element;
|
|
91
|
+
combobox.input = input;
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
syncText
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Calls `reset` when the form of `input()` is reset, from the time the
|
|
99
|
+
* part has settled: a form reset puts a control back to its default, and
|
|
100
|
+
* so it does a combobox, through its setters, so that a controlled one
|
|
101
|
+
* asks. The browser resets the form's inputs after the event, to their
|
|
102
|
+
* `value` attributes; an `onFlush` in `reset` runs after that.
|
|
103
|
+
*/
|
|
104
|
+
function onFormReset(input, reset) {
|
|
105
|
+
onSettled(() => {
|
|
106
|
+
const form = input()?.form;
|
|
107
|
+
if (!form) return;
|
|
108
|
+
form.addEventListener("reset", reset);
|
|
109
|
+
return () => form.removeEventListener("reset", reset);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
export { createComboboxInput, onFormReset };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
+
import { createComboboxItem } from "./createComboboxItem.js";
|
|
5
|
+
import { ComboboxItemContext } from "./ComboboxItemContext.js";
|
|
6
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
7
|
+
import { merge, omit } from "solid-js";
|
|
8
|
+
// src/combobox/item/ComboboxItem.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
10
|
+
/**
|
|
11
|
+
* A value to select: a `<div role="option">` with `aria-selected`. A click
|
|
12
|
+
* selects it, sets the input's text to its label and closes the list, and
|
|
13
|
+
* so does Enter while it is the active item; a disabled item is not
|
|
14
|
+
* selected. Render the items that match the text, and place them inside
|
|
15
|
+
* `Combobox.List`.
|
|
16
|
+
*/
|
|
17
|
+
function ComboboxItem(props) {
|
|
18
|
+
const combobox = useComboboxContext("Combobox");
|
|
19
|
+
const { props: itemProps } = createComboboxItem(combobox, props, (element) => props.label ?? labelOf(element));
|
|
20
|
+
const selected = () => combobox.value() === props.value;
|
|
21
|
+
const attributes = {
|
|
22
|
+
get "data-selected"() {
|
|
23
|
+
return selected() ? "" : void 0;
|
|
24
|
+
},
|
|
25
|
+
get "data-unselected"() {
|
|
26
|
+
return selected() ? void 0 : "";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const ownProps = merge(attributes, itemProps, { get "aria-selected"() {
|
|
30
|
+
return selected() ? "true" : "false";
|
|
31
|
+
} });
|
|
32
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "label", "id"));
|
|
33
|
+
return createComponent(ComboboxItemContext, {
|
|
34
|
+
value: attributes,
|
|
35
|
+
get children() {
|
|
36
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
37
|
+
var _el$ = _tmpl$();
|
|
38
|
+
spread(_el$, p, false);
|
|
39
|
+
return _el$;
|
|
40
|
+
})());
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* An item's own text: its text content without what is `aria-hidden`, such
|
|
46
|
+
* as its ItemIndicator's check mark, which is no part of its name either.
|
|
47
|
+
*/
|
|
48
|
+
function labelOf(node) {
|
|
49
|
+
let text = "";
|
|
50
|
+
for (const child of node.childNodes) if (child.nodeType === 3) text += child.nodeValue;
|
|
51
|
+
else if (child.getAttribute?.("aria-hidden") !== "true") text += labelOf(child);
|
|
52
|
+
return text;
|
|
53
|
+
}
|
|
54
|
+
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,62 @@
|
|
|
1
|
+
import { createUniqueId, onSettled } from "solid-js";
|
|
2
|
+
// src/combobox/item/createComboboxItem.ts
|
|
3
|
+
/**
|
|
4
|
+
* An item of a combobox, the code `Combobox.Item` and `Autocomplete.Item`
|
|
5
|
+
* share: its entry in the list navigation, registered once mounted, and
|
|
6
|
+
* the props of its `option` element, its `id`, `data-active`, the disabled
|
|
7
|
+
* state, the pointer and the click that selects or accepts it. `text` is
|
|
8
|
+
* what the input shows once it is: a Combobox's label, an Autocomplete's
|
|
9
|
+
* value. Each Item adds its own `aria-selected`.
|
|
10
|
+
*/
|
|
11
|
+
function createComboboxItem(combobox, props, text) {
|
|
12
|
+
let element;
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const id = () => props.id || generated;
|
|
15
|
+
const item = {
|
|
16
|
+
get element() {
|
|
17
|
+
return element;
|
|
18
|
+
},
|
|
19
|
+
get id() {
|
|
20
|
+
return id();
|
|
21
|
+
},
|
|
22
|
+
get text() {
|
|
23
|
+
return text(element);
|
|
24
|
+
},
|
|
25
|
+
get value() {
|
|
26
|
+
return props.value;
|
|
27
|
+
},
|
|
28
|
+
get disabled() {
|
|
29
|
+
return props.disabled;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
onSettled(() => combobox.list.register(item));
|
|
33
|
+
return {
|
|
34
|
+
item,
|
|
35
|
+
props: {
|
|
36
|
+
role: "option",
|
|
37
|
+
get id() {
|
|
38
|
+
return id();
|
|
39
|
+
},
|
|
40
|
+
get "data-active"() {
|
|
41
|
+
return combobox.isActive(item) ? "" : void 0;
|
|
42
|
+
},
|
|
43
|
+
get "aria-disabled"() {
|
|
44
|
+
return props.disabled ? "true" : void 0;
|
|
45
|
+
},
|
|
46
|
+
get "data-disabled"() {
|
|
47
|
+
return props.disabled ? "" : void 0;
|
|
48
|
+
},
|
|
49
|
+
onPointerMove: (event) => combobox.list.onPointerMove(item, event),
|
|
50
|
+
onClick: (event) => {
|
|
51
|
+
if (combobox.select(item, event)) combobox.setOpen(false, {
|
|
52
|
+
reason: "item-press",
|
|
53
|
+
event
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
ref: (el) => {
|
|
57
|
+
element = el;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export { createComboboxItem };
|
|
@@ -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 };
|