menhir 0.1.4 → 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/context-menu/index.js +2 -0
- package/dist/context-menu/index.parts.js +13 -0
- package/dist/context-menu/popup/ContextMenuPopup.js +30 -0
- package/dist/context-menu/root/ContextMenuContext.js +11 -0
- package/dist/context-menu/root/ContextMenuRoot.js +23 -0
- package/dist/context-menu/trigger/ContextMenuTrigger.js +47 -0
- package/dist/core/mergeElementProps.js +7 -1
- package/dist/menu/checkbox-item/MenuCheckboxItem.js +28 -0
- package/dist/menu/group/MenuGroup.js +40 -0
- package/dist/menu/group/MenuGroupContext.js +10 -0
- package/dist/menu/group-label/MenuGroupLabel.js +27 -0
- package/dist/menu/index.js +2 -0
- package/dist/menu/index.parts.js +13 -0
- package/dist/menu/item/MenuItem.js +30 -0
- package/dist/menu/item/menuItemProps.js +77 -0
- package/dist/menu/item/renderCheckedItem.js +52 -0
- package/dist/menu/item-indicator/MenuItemIndicator.js +23 -0
- package/dist/menu/item-indicator/MenuItemIndicatorContext.js +10 -0
- package/dist/menu/popup/MenuPopup.js +123 -0
- package/dist/menu/radio-group/MenuRadioGroup.js +39 -0
- package/dist/menu/radio-item/MenuRadioItem.js +21 -0
- package/dist/menu/root/MenuContext.js +114 -0
- package/dist/menu/root/MenuRoot.js +19 -0
- package/dist/menu/submenu/MenuSubmenu.js +18 -0
- package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +114 -0
- package/dist/menu/trigger/MenuTrigger.js +67 -0
- package/dist/menubar/index.js +2 -0
- package/dist/menubar/index.parts.js +14 -0
- package/dist/menubar/menu/MenubarMenu.js +30 -0
- package/dist/menubar/root/MenubarContext.js +10 -0
- package/dist/menubar/root/MenubarRoot.js +68 -0
- package/dist/menubar/trigger/MenubarTrigger.js +73 -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/context-menu/index.d.ts +1 -0
- package/dist/source/context-menu/index.js +1 -0
- package/dist/source/context-menu/index.parts.d.ts +12 -0
- package/dist/source/context-menu/index.parts.js +13 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.d.ts +12 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.jsx +36 -0
- package/dist/source/context-menu/root/ContextMenuContext.d.ts +18 -0
- package/dist/source/context-menu/root/ContextMenuContext.js +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.d.ts +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.jsx +16 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.d.ts +15 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +46 -0
- package/dist/source/core/mergeElementProps.d.ts +8 -0
- package/dist/source/core/mergeElementProps.js +7 -1
- package/dist/source/floating/dismissal/reason.d.ts +12 -2
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.d.ts +20 -0
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.jsx +26 -0
- package/dist/source/menu/group/MenuGroup.d.ts +16 -0
- package/dist/source/menu/group/MenuGroup.jsx +31 -0
- package/dist/source/menu/group/MenuGroupContext.d.ts +10 -0
- package/dist/source/menu/group/MenuGroupContext.js +12 -0
- package/dist/source/menu/group-label/MenuGroupLabel.d.ts +11 -0
- package/dist/source/menu/group-label/MenuGroupLabel.jsx +25 -0
- package/dist/source/menu/index.d.ts +1 -0
- package/dist/source/menu/index.js +1 -0
- package/dist/source/menu/index.parts.d.ts +12 -0
- package/dist/source/menu/index.parts.js +12 -0
- package/dist/source/menu/item/MenuItem.d.ts +11 -0
- package/dist/source/menu/item/MenuItem.jsx +21 -0
- package/dist/source/menu/item/menuItemProps.d.ts +35 -0
- package/dist/source/menu/item/menuItemProps.js +78 -0
- package/dist/source/menu/item/renderCheckedItem.d.ts +22 -0
- package/dist/source/menu/item/renderCheckedItem.jsx +41 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.d.ts +12 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.jsx +17 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.d.ts +11 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.js +12 -0
- package/dist/source/menu/popup/MenuPopup.d.ts +41 -0
- package/dist/source/menu/popup/MenuPopup.jsx +156 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.d.ts +27 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.jsx +36 -0
- package/dist/source/menu/radio-item/MenuRadioItem.d.ts +14 -0
- package/dist/source/menu/radio-item/MenuRadioItem.jsx +19 -0
- package/dist/source/menu/root/MenuContext.d.ts +114 -0
- package/dist/source/menu/root/MenuContext.js +123 -0
- package/dist/source/menu/root/MenuRoot.d.ts +11 -0
- package/dist/source/menu/root/MenuRoot.jsx +9 -0
- package/dist/source/menu/submenu/MenuSubmenu.d.ts +22 -0
- package/dist/source/menu/submenu/MenuSubmenu.jsx +10 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.d.ts +14 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +121 -0
- package/dist/source/menu/trigger/MenuTrigger.d.ts +13 -0
- package/dist/source/menu/trigger/MenuTrigger.jsx +73 -0
- package/dist/source/menubar/index.d.ts +1 -0
- package/dist/source/menubar/index.js +1 -0
- package/dist/source/menubar/index.parts.d.ts +13 -0
- package/dist/source/menubar/index.parts.js +14 -0
- package/dist/source/menubar/menu/MenubarMenu.d.ts +11 -0
- package/dist/source/menubar/menu/MenubarMenu.jsx +24 -0
- package/dist/source/menubar/root/MenubarContext.d.ts +30 -0
- package/dist/source/menubar/root/MenubarContext.js +12 -0
- package/dist/source/menubar/root/MenubarRoot.d.ts +11 -0
- package/dist/source/menubar/root/MenubarRoot.jsx +77 -0
- package/dist/source/menubar/trigger/MenubarTrigger.d.ts +11 -0
- package/dist/source/menubar/trigger/MenubarTrigger.jsx +78 -0
- 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 +26 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createRovingList } from "../../floating/list-navigation/roving.js";
|
|
4
|
+
import { createTypeahead } from "../../floating/typeahead/typeahead.js";
|
|
5
|
+
import { MenubarContext } from "./MenubarContext.js";
|
|
6
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
7
|
+
import { omit } from "solid-js";
|
|
8
|
+
// src/menubar/root/MenubarRoot.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
10
|
+
/**
|
|
11
|
+
* A row of menus: a `<div role="menubar">` around `Menubar.Menu`s, one tab
|
|
12
|
+
* stop, with Right and Left Arrow, Home, End and typed characters moving
|
|
13
|
+
* between its items. Name it with `aria-label` or `aria-labelledby`.
|
|
14
|
+
*/
|
|
15
|
+
function MenubarRoot(props) {
|
|
16
|
+
const list = createRovingList({
|
|
17
|
+
orientation: "horizontal",
|
|
18
|
+
wrap: true
|
|
19
|
+
});
|
|
20
|
+
const typeahead = createTypeahead({
|
|
21
|
+
get items() {
|
|
22
|
+
return list.items();
|
|
23
|
+
},
|
|
24
|
+
get active() {
|
|
25
|
+
return list.active();
|
|
26
|
+
},
|
|
27
|
+
move: (item) => list.move(item)
|
|
28
|
+
});
|
|
29
|
+
let claimed = false;
|
|
30
|
+
const bar = {
|
|
31
|
+
list,
|
|
32
|
+
typeahead,
|
|
33
|
+
claimTabStop: () => !claimed && (claimed = true),
|
|
34
|
+
openMenu: () => list.items().find((item) => item.menu.open())?.menu,
|
|
35
|
+
follow: (open, details) => {
|
|
36
|
+
const to = list.items().find((item) => item.element === document.activeElement)?.menu;
|
|
37
|
+
if (!open || !to || to === open) return;
|
|
38
|
+
open.close(details);
|
|
39
|
+
to.keepFocus = true;
|
|
40
|
+
to.setOpen(true, details);
|
|
41
|
+
setTimeout(() => to.keepFocus = false);
|
|
42
|
+
},
|
|
43
|
+
moveTo: (item, details) => {
|
|
44
|
+
const open = bar.openMenu();
|
|
45
|
+
list.move(item);
|
|
46
|
+
bar.follow(open, details);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const elementProps = mergeElementProps({
|
|
50
|
+
role: "menubar",
|
|
51
|
+
onKeyDown: (event) => {
|
|
52
|
+
if (event.key !== "Tab" || !event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
53
|
+
const open = bar.openMenu();
|
|
54
|
+
if (open?.popup?.contains(event.target)) open.trigger?.focus();
|
|
55
|
+
}
|
|
56
|
+
}, omit(props, "render"));
|
|
57
|
+
return createComponent(MenubarContext, {
|
|
58
|
+
value: bar,
|
|
59
|
+
get children() {
|
|
60
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
61
|
+
var _el$ = _tmpl$();
|
|
62
|
+
spread(_el$, p, false);
|
|
63
|
+
return _el$;
|
|
64
|
+
})());
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export { MenubarRoot };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { callHandler } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { useMenuContext } from "../../menu/root/MenuContext.js";
|
|
3
|
+
import { MenuTrigger } from "../../menu/trigger/MenuTrigger.js";
|
|
4
|
+
import { useMenubarContext } from "../root/MenubarContext.js";
|
|
5
|
+
import { merge, onSettled } from "solid-js";
|
|
6
|
+
// src/menubar/trigger/MenubarTrigger.tsx
|
|
7
|
+
/**
|
|
8
|
+
* An item of the bar, which opens its menu: Menu's `<button type="button"
|
|
9
|
+
* aria-haspopup="menu">`, with the `menuitem` role and the bar's roving
|
|
10
|
+
* `tabindex`. Down Arrow, Enter and Space open the menu with focus on its
|
|
11
|
+
* first item, Up Arrow on its last. While a menu of the bar is open, moving
|
|
12
|
+
* to another item, by a key or the pointer, opens that item's menu instead.
|
|
13
|
+
* Place it inside `Menubar.Menu`, right before `Menubar.Popup`.
|
|
14
|
+
*/
|
|
15
|
+
function MenubarTrigger(props) {
|
|
16
|
+
const bar = useMenubarContext();
|
|
17
|
+
const menu = useMenuContext();
|
|
18
|
+
const item = {
|
|
19
|
+
get element() {
|
|
20
|
+
return menu.trigger;
|
|
21
|
+
},
|
|
22
|
+
menu
|
|
23
|
+
};
|
|
24
|
+
const first = bar.claimTabStop();
|
|
25
|
+
onSettled(() => bar.list.register(item));
|
|
26
|
+
return MenuTrigger(merge(props, {
|
|
27
|
+
role: "menuitem",
|
|
28
|
+
get tabindex() {
|
|
29
|
+
const stop = bar.list.active() ?? bar.list.items()[0];
|
|
30
|
+
return (stop ? stop === item : first) ? 0 : -1;
|
|
31
|
+
},
|
|
32
|
+
onFocus: (event) => {
|
|
33
|
+
callHandler(props.onFocus, event);
|
|
34
|
+
if (bar.list.active() !== item) bar.list.move(item);
|
|
35
|
+
},
|
|
36
|
+
onKeyDown: (event) => {
|
|
37
|
+
callHandler(props.onKeyDown, event);
|
|
38
|
+
const open = bar.openMenu();
|
|
39
|
+
if (bar.typeahead.onKeyDown(event) || bar.list.onKeyDown(event)) {
|
|
40
|
+
bar.follow(open, {
|
|
41
|
+
reason: "arrow-key",
|
|
42
|
+
event
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { key } = event;
|
|
47
|
+
if (event.altKey || event.ctrlKey || event.metaKey || !menu.open()) return;
|
|
48
|
+
if (key === "Tab") menu.close({
|
|
49
|
+
reason: "focus-out",
|
|
50
|
+
event
|
|
51
|
+
});
|
|
52
|
+
if ((key === "Enter" || key === " ") && !event.shiftKey) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
menu.list.move(menu.list.items()[0]);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
onPointerMove: (event) => {
|
|
58
|
+
callHandler(props.onPointerMove, event);
|
|
59
|
+
const open = bar.openMenu();
|
|
60
|
+
if (event.pointerType === "touch" || !open || open === menu) return;
|
|
61
|
+
bar.moveTo(item, {
|
|
62
|
+
reason: "trigger-hover",
|
|
63
|
+
event
|
|
64
|
+
});
|
|
65
|
+
menu.hoverOpened = true;
|
|
66
|
+
},
|
|
67
|
+
onPointerLeave: (event) => {
|
|
68
|
+
callHandler(props.onPointerLeave, event);
|
|
69
|
+
menu.hoverOpened = false;
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
export { MenubarTrigger };
|
|
@@ -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 };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { createActiveDescendantList } from "../../floating/list-navigation/activeDescendant.js";
|
|
3
|
+
import { createTypeahead } from "../../floating/typeahead/typeahead.js";
|
|
4
|
+
import { isDev } from "@solidjs/web";
|
|
5
|
+
import { createContext, createMemo, createUniqueId, useContext } from "solid-js";
|
|
6
|
+
// src/select/root/SelectContext.ts
|
|
7
|
+
/** Creates a select's state, its list navigation and its typeahead. */
|
|
8
|
+
function createSelect(props) {
|
|
9
|
+
const [open, setOpen] = createControllableSignal({
|
|
10
|
+
get value() {
|
|
11
|
+
return props.open;
|
|
12
|
+
},
|
|
13
|
+
get defaultValue() {
|
|
14
|
+
return props.defaultOpen ?? false;
|
|
15
|
+
},
|
|
16
|
+
onChange: (value, details) => props.onOpenChange?.(value, details)
|
|
17
|
+
});
|
|
18
|
+
const [value, setValue, requested] = createControllableSignal({
|
|
19
|
+
get value() {
|
|
20
|
+
return props.value;
|
|
21
|
+
},
|
|
22
|
+
get defaultValue() {
|
|
23
|
+
return props.defaultValue ?? null;
|
|
24
|
+
},
|
|
25
|
+
onChange: (value) => props.onValueChange?.(value)
|
|
26
|
+
});
|
|
27
|
+
const list = createActiveDescendantList({ get open() {
|
|
28
|
+
return open();
|
|
29
|
+
} });
|
|
30
|
+
const typeahead = createTypeahead({
|
|
31
|
+
get open() {
|
|
32
|
+
return open();
|
|
33
|
+
},
|
|
34
|
+
get items() {
|
|
35
|
+
return list.items();
|
|
36
|
+
},
|
|
37
|
+
get active() {
|
|
38
|
+
return active();
|
|
39
|
+
},
|
|
40
|
+
move: (item) => list.move(item)
|
|
41
|
+
});
|
|
42
|
+
const selectedItem = createMemo(() => {
|
|
43
|
+
const selected = value();
|
|
44
|
+
return list.items().find((item) => item.value === selected);
|
|
45
|
+
});
|
|
46
|
+
const initial = createMemo(() => open() && !list.active() ? selectedItem() ?? list.items()[0] : void 0);
|
|
47
|
+
const active = () => list.active() ?? initial();
|
|
48
|
+
const select = {
|
|
49
|
+
open,
|
|
50
|
+
setOpen,
|
|
51
|
+
value,
|
|
52
|
+
setValue,
|
|
53
|
+
select: (item) => {
|
|
54
|
+
if (!item || item.disabled) return false;
|
|
55
|
+
const input = select.input;
|
|
56
|
+
if (item.value !== requested()) {
|
|
57
|
+
if (input) {
|
|
58
|
+
input.value = item.value;
|
|
59
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
60
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
61
|
+
} else setValue(item.value);
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
65
|
+
selectedItem,
|
|
66
|
+
active,
|
|
67
|
+
isActive: (item) => open() && (list.isActive(item) || initial() === item),
|
|
68
|
+
initial,
|
|
69
|
+
list,
|
|
70
|
+
typeahead,
|
|
71
|
+
popupId: createUniqueId(),
|
|
72
|
+
triggerId: () => void 0,
|
|
73
|
+
trigger: void 0,
|
|
74
|
+
input: void 0,
|
|
75
|
+
attributes: {
|
|
76
|
+
get "data-open"() {
|
|
77
|
+
return open() ? "" : void 0;
|
|
78
|
+
},
|
|
79
|
+
get "data-closed"() {
|
|
80
|
+
return open() ? void 0 : "";
|
|
81
|
+
},
|
|
82
|
+
get "data-disabled"() {
|
|
83
|
+
return props.disabled ? "" : void 0;
|
|
84
|
+
},
|
|
85
|
+
get "data-required"() {
|
|
86
|
+
return props.required ? "" : void 0;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
props
|
|
90
|
+
};
|
|
91
|
+
return select;
|
|
92
|
+
}
|
|
93
|
+
var SelectContext = createContext(null);
|
|
94
|
+
function useSelectContext() {
|
|
95
|
+
const context = useContext(SelectContext);
|
|
96
|
+
if (isDev && !context) throw new Error("[menhir] Select parts must be placed within <Select.Root>.");
|
|
97
|
+
return context;
|
|
98
|
+
}
|
|
99
|
+
export { SelectContext, createSelect, useSelectContext };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SelectContext, createSelect } from "./SelectContext.js";
|
|
2
|
+
import { createComponent } from "@solidjs/web";
|
|
3
|
+
// src/select/root/SelectRoot.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A value selected from a list that a button opens: holds the value and
|
|
6
|
+
* whether the list is open, and shares them with `Select.Trigger`,
|
|
7
|
+
* `Select.Value`, `Select.Popup` and the items inside it. Its form props
|
|
8
|
+
* go on the hidden input the Trigger renders. Renders no element of its
|
|
9
|
+
* own.
|
|
10
|
+
*/
|
|
11
|
+
function SelectRoot(props) {
|
|
12
|
+
return createComponent(SelectContext, {
|
|
13
|
+
get value() {
|
|
14
|
+
return createSelect(props);
|
|
15
|
+
},
|
|
16
|
+
get children() {
|
|
17
|
+
return props.children;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { SelectRoot };
|