menhir 0.1.3 → 0.1.5

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.
Files changed (158) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +9 -2
  3. package/dist/context-menu/index.js +2 -0
  4. package/dist/context-menu/index.parts.js +13 -0
  5. package/dist/context-menu/popup/ContextMenuPopup.js +30 -0
  6. package/dist/context-menu/root/ContextMenuContext.js +11 -0
  7. package/dist/context-menu/root/ContextMenuRoot.js +23 -0
  8. package/dist/context-menu/trigger/ContextMenuTrigger.js +47 -0
  9. package/dist/core/createControllableSignal.js +11 -2
  10. package/dist/core/listValue.js +2 -7
  11. package/dist/core/mergeElementProps.js +7 -1
  12. package/dist/floating/dismissal/escape.js +2 -1
  13. package/dist/floating/list-navigation/activeDescendant.js +29 -0
  14. package/dist/floating/list-navigation/listNavigation.js +108 -0
  15. package/dist/floating/list-navigation/roving.js +27 -0
  16. package/dist/floating/typeahead/match.js +24 -0
  17. package/dist/floating/typeahead/typeahead.js +56 -0
  18. package/dist/menu/checkbox-item/MenuCheckboxItem.js +28 -0
  19. package/dist/menu/group/MenuGroup.js +40 -0
  20. package/dist/menu/group/MenuGroupContext.js +10 -0
  21. package/dist/menu/group-label/MenuGroupLabel.js +27 -0
  22. package/dist/menu/index.js +2 -0
  23. package/dist/menu/index.parts.js +13 -0
  24. package/dist/menu/item/MenuItem.js +30 -0
  25. package/dist/menu/item/menuItemProps.js +77 -0
  26. package/dist/menu/item/renderCheckedItem.js +52 -0
  27. package/dist/menu/item-indicator/MenuItemIndicator.js +23 -0
  28. package/dist/menu/item-indicator/MenuItemIndicatorContext.js +10 -0
  29. package/dist/menu/popup/MenuPopup.js +123 -0
  30. package/dist/menu/radio-group/MenuRadioGroup.js +39 -0
  31. package/dist/menu/radio-item/MenuRadioItem.js +21 -0
  32. package/dist/menu/root/MenuContext.js +114 -0
  33. package/dist/menu/root/MenuRoot.js +19 -0
  34. package/dist/menu/submenu/MenuSubmenu.js +18 -0
  35. package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +114 -0
  36. package/dist/menu/trigger/MenuTrigger.js +67 -0
  37. package/dist/menubar/index.js +2 -0
  38. package/dist/menubar/index.parts.js +14 -0
  39. package/dist/menubar/menu/MenubarMenu.js +30 -0
  40. package/dist/menubar/root/MenubarContext.js +10 -0
  41. package/dist/menubar/root/MenubarRoot.js +68 -0
  42. package/dist/menubar/trigger/MenubarTrigger.js +73 -0
  43. package/dist/navigation-menu/index.js +2 -0
  44. package/dist/navigation-menu/index.parts.js +6 -0
  45. package/dist/navigation-menu/item/NavigationMenuItem.js +83 -0
  46. package/dist/navigation-menu/item/NavigationMenuItemContext.js +10 -0
  47. package/dist/navigation-menu/link/NavigationMenuLink.js +26 -0
  48. package/dist/navigation-menu/panel/NavigationMenuPanel.js +31 -0
  49. package/dist/navigation-menu/root/NavigationMenuRoot.js +100 -0
  50. package/dist/navigation-menu/root/NavigationMenuRootContext.js +10 -0
  51. package/dist/navigation-menu/trigger/NavigationMenuTrigger.js +36 -0
  52. package/dist/source/context-menu/index.d.ts +1 -0
  53. package/dist/source/context-menu/index.js +1 -0
  54. package/dist/source/context-menu/index.parts.d.ts +12 -0
  55. package/dist/source/context-menu/index.parts.js +13 -0
  56. package/dist/source/context-menu/popup/ContextMenuPopup.d.ts +12 -0
  57. package/dist/source/context-menu/popup/ContextMenuPopup.jsx +36 -0
  58. package/dist/source/context-menu/root/ContextMenuContext.d.ts +18 -0
  59. package/dist/source/context-menu/root/ContextMenuContext.js +12 -0
  60. package/dist/source/context-menu/root/ContextMenuRoot.d.ts +12 -0
  61. package/dist/source/context-menu/root/ContextMenuRoot.jsx +16 -0
  62. package/dist/source/context-menu/trigger/ContextMenuTrigger.d.ts +15 -0
  63. package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +46 -0
  64. package/dist/source/core/createControllableSignal.d.ts +9 -1
  65. package/dist/source/core/createControllableSignal.js +7 -2
  66. package/dist/source/core/listValue.js +4 -10
  67. package/dist/source/core/mergeElementProps.d.ts +8 -0
  68. package/dist/source/core/mergeElementProps.js +7 -1
  69. package/dist/source/floating/dismissal/escape.d.ts +2 -1
  70. package/dist/source/floating/dismissal/escape.js +2 -1
  71. package/dist/source/floating/dismissal/reason.d.ts +11 -2
  72. package/dist/source/floating/list-navigation/activeDescendant.d.ts +30 -0
  73. package/dist/source/floating/list-navigation/activeDescendant.js +24 -0
  74. package/dist/source/floating/list-navigation/listNavigation.d.ts +68 -0
  75. package/dist/source/floating/list-navigation/listNavigation.js +148 -0
  76. package/dist/source/floating/list-navigation/roving.d.ts +23 -0
  77. package/dist/source/floating/list-navigation/roving.js +25 -0
  78. package/dist/source/floating/typeahead/match.d.ts +14 -0
  79. package/dist/source/floating/typeahead/match.js +32 -0
  80. package/dist/source/floating/typeahead/typeahead.d.ts +41 -0
  81. package/dist/source/floating/typeahead/typeahead.js +81 -0
  82. package/dist/source/menu/checkbox-item/MenuCheckboxItem.d.ts +20 -0
  83. package/dist/source/menu/checkbox-item/MenuCheckboxItem.jsx +26 -0
  84. package/dist/source/menu/group/MenuGroup.d.ts +16 -0
  85. package/dist/source/menu/group/MenuGroup.jsx +31 -0
  86. package/dist/source/menu/group/MenuGroupContext.d.ts +10 -0
  87. package/dist/source/menu/group/MenuGroupContext.js +12 -0
  88. package/dist/source/menu/group-label/MenuGroupLabel.d.ts +11 -0
  89. package/dist/source/menu/group-label/MenuGroupLabel.jsx +25 -0
  90. package/dist/source/menu/index.d.ts +1 -0
  91. package/dist/source/menu/index.js +1 -0
  92. package/dist/source/menu/index.parts.d.ts +12 -0
  93. package/dist/source/menu/index.parts.js +12 -0
  94. package/dist/source/menu/item/MenuItem.d.ts +11 -0
  95. package/dist/source/menu/item/MenuItem.jsx +21 -0
  96. package/dist/source/menu/item/menuItemProps.d.ts +35 -0
  97. package/dist/source/menu/item/menuItemProps.js +78 -0
  98. package/dist/source/menu/item/renderCheckedItem.d.ts +22 -0
  99. package/dist/source/menu/item/renderCheckedItem.jsx +41 -0
  100. package/dist/source/menu/item-indicator/MenuItemIndicator.d.ts +12 -0
  101. package/dist/source/menu/item-indicator/MenuItemIndicator.jsx +17 -0
  102. package/dist/source/menu/item-indicator/MenuItemIndicatorContext.d.ts +11 -0
  103. package/dist/source/menu/item-indicator/MenuItemIndicatorContext.js +12 -0
  104. package/dist/source/menu/popup/MenuPopup.d.ts +41 -0
  105. package/dist/source/menu/popup/MenuPopup.jsx +156 -0
  106. package/dist/source/menu/radio-group/MenuRadioGroup.d.ts +27 -0
  107. package/dist/source/menu/radio-group/MenuRadioGroup.jsx +36 -0
  108. package/dist/source/menu/radio-item/MenuRadioItem.d.ts +14 -0
  109. package/dist/source/menu/radio-item/MenuRadioItem.jsx +19 -0
  110. package/dist/source/menu/root/MenuContext.d.ts +114 -0
  111. package/dist/source/menu/root/MenuContext.js +123 -0
  112. package/dist/source/menu/root/MenuRoot.d.ts +11 -0
  113. package/dist/source/menu/root/MenuRoot.jsx +9 -0
  114. package/dist/source/menu/submenu/MenuSubmenu.d.ts +22 -0
  115. package/dist/source/menu/submenu/MenuSubmenu.jsx +10 -0
  116. package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.d.ts +14 -0
  117. package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +121 -0
  118. package/dist/source/menu/trigger/MenuTrigger.d.ts +13 -0
  119. package/dist/source/menu/trigger/MenuTrigger.jsx +73 -0
  120. package/dist/source/menubar/index.d.ts +1 -0
  121. package/dist/source/menubar/index.js +1 -0
  122. package/dist/source/menubar/index.parts.d.ts +13 -0
  123. package/dist/source/menubar/index.parts.js +14 -0
  124. package/dist/source/menubar/menu/MenubarMenu.d.ts +11 -0
  125. package/dist/source/menubar/menu/MenubarMenu.jsx +24 -0
  126. package/dist/source/menubar/root/MenubarContext.d.ts +30 -0
  127. package/dist/source/menubar/root/MenubarContext.js +12 -0
  128. package/dist/source/menubar/root/MenubarRoot.d.ts +11 -0
  129. package/dist/source/menubar/root/MenubarRoot.jsx +77 -0
  130. package/dist/source/menubar/trigger/MenubarTrigger.d.ts +11 -0
  131. package/dist/source/menubar/trigger/MenubarTrigger.jsx +78 -0
  132. package/dist/source/navigation-menu/index.d.ts +1 -0
  133. package/dist/source/navigation-menu/index.js +1 -0
  134. package/dist/source/navigation-menu/index.parts.d.ts +5 -0
  135. package/dist/source/navigation-menu/index.parts.js +5 -0
  136. package/dist/source/navigation-menu/item/NavigationMenuItem.d.ts +16 -0
  137. package/dist/source/navigation-menu/item/NavigationMenuItem.jsx +85 -0
  138. package/dist/source/navigation-menu/item/NavigationMenuItemContext.d.ts +27 -0
  139. package/dist/source/navigation-menu/item/NavigationMenuItemContext.js +12 -0
  140. package/dist/source/navigation-menu/link/NavigationMenuLink.d.ts +12 -0
  141. package/dist/source/navigation-menu/link/NavigationMenuLink.jsx +18 -0
  142. package/dist/source/navigation-menu/panel/NavigationMenuPanel.d.ts +11 -0
  143. package/dist/source/navigation-menu/panel/NavigationMenuPanel.jsx +26 -0
  144. package/dist/source/navigation-menu/root/NavigationMenuRoot.d.ts +37 -0
  145. package/dist/source/navigation-menu/root/NavigationMenuRoot.jsx +103 -0
  146. package/dist/source/navigation-menu/root/NavigationMenuRootContext.d.ts +33 -0
  147. package/dist/source/navigation-menu/root/NavigationMenuRootContext.js +13 -0
  148. package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.d.ts +12 -0
  149. package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.jsx +32 -0
  150. package/package.json +23 -2
  151. package/skills/menhir-styling/SKILL.md +35 -0
  152. package/skills/menhir-styling/looks/shadcn/LICENSE +24 -0
  153. package/skills/menhir-styling/looks/shadcn/LOOK.md +106 -0
  154. package/skills/menhir-styling/looks/shadcn/dialog.md +63 -0
  155. package/skills/menhir-styling/looks/shadcn/popover.md +39 -0
  156. package/skills/menhir-styling/looks/shadcn/switch.md +26 -0
  157. package/skills/menhir-styling/looks/shadcn/tabs.md +62 -0
  158. package/skills/menhir-styling/looks/shadcn/tokens.css +80 -0
@@ -0,0 +1,121 @@
1
+ import { createEffect, createUniqueId, merge, omit, onCleanup } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { trackSafeArea } from "../../floating/hover/safeArea.js";
5
+ import { menuItemProps } from "../item/menuItemProps.js";
6
+ import { useMenuContext } from "../root/MenuContext.js";
7
+ /**
8
+ * The item that opens a submenu: a `<div role="menuitem"
9
+ * aria-haspopup="menu">` with `aria-expanded`, an item of the menu around
10
+ * its `Menu.Submenu`. Right Arrow, Enter and Space open the submenu with
11
+ * focus on its first item; the pointer resting on it, or a click, opens it
12
+ * and leaves focus here. Place it inside `Menu.Submenu`, right before the
13
+ * submenu's `Menu.Popup`.
14
+ */
15
+ export function MenuSubmenuTrigger(props) {
16
+ const submenu = useMenuContext();
17
+ // An item of the menu around the submenu.
18
+ const parent = submenu.parent;
19
+ const generated = createUniqueId();
20
+ // The consumer's `id`, else the generated one, which labels the submenu's
21
+ // Popup rendered after it. Kept out of the merge ("`undefined` is a
22
+ // value", PLAN.md section 8).
23
+ const id = () => props.id ?? generated;
24
+ submenu.triggerId = id;
25
+ const itemProps = menuItemProps(parent, props, {
26
+ role: "menuitem",
27
+ onActivate: (event, key) => {
28
+ const details = { reason: "trigger-press", event: key ?? event };
29
+ // A key moves focus into the submenu; a click leaves it here.
30
+ if (key)
31
+ submenu.openFromKey(details);
32
+ else
33
+ submenu.setOpen(true, details);
34
+ },
35
+ submenu,
36
+ ref: (element) => {
37
+ submenu.trigger = element;
38
+ },
39
+ });
40
+ // The pointer resting on the trigger opens the submenu after `delay`;
41
+ // leaving the trigger and the submenu closes it, across the safe area
42
+ // between them. Only a pointer that moves counts: a menu that opens
43
+ // under a still pointer gets boundary events, and opens no submenu.
44
+ let timer;
45
+ let stopSafeArea;
46
+ const cancel = () => {
47
+ clearTimeout(timer);
48
+ timer = undefined;
49
+ stopSafeArea?.();
50
+ stopSafeArea = undefined;
51
+ };
52
+ onCleanup(cancel);
53
+ const close = (event) => {
54
+ const closeDelay = submenu.delays.closeDelay ?? 0;
55
+ const details = { reason: "trigger-hover", event };
56
+ if (closeDelay > 0)
57
+ timer = setTimeout(() => submenu.close(details), closeDelay);
58
+ else
59
+ submenu.close(details);
60
+ };
61
+ /** The pointer leaving `from` on its way to `to`, or elsewhere. */
62
+ const leave = (event, to) => {
63
+ cancel();
64
+ if (event.pointerType === "touch" || !submenu.open())
65
+ return;
66
+ if (to && event.relatedTarget)
67
+ stopSafeArea = trackSafeArea(event, to, close);
68
+ else
69
+ close(event);
70
+ };
71
+ const hoverProps = {
72
+ onPointerMove: (event) => {
73
+ // List navigation's move first: the trigger becomes the active item.
74
+ itemProps.onPointerMove(event);
75
+ if (event.pointerType === "touch" || props.disabled)
76
+ return;
77
+ if (submenu.open()) {
78
+ // Back on the trigger: no longer on its way anywhere.
79
+ cancel();
80
+ return;
81
+ }
82
+ if (timer)
83
+ return;
84
+ const details = { reason: "trigger-hover", event };
85
+ timer = setTimeout(() => {
86
+ timer = undefined;
87
+ submenu.setOpen(true, details);
88
+ }, submenu.delays.delay ?? 100);
89
+ },
90
+ onPointerLeave: (event) => leave(event, submenu.popup),
91
+ };
92
+ // While open, the pointer on the submenu keeps it open, and leaving it
93
+ // closes it, unless on its way back to the trigger.
94
+ createEffect(() => submenu.open(), (open) => {
95
+ // Opened or closed, from here or elsewhere: a pending delay is moot.
96
+ cancel();
97
+ const popup = submenu.popup;
98
+ if (!open || !popup)
99
+ return;
100
+ const enter = () => cancel();
101
+ const exit = (event) => leave(event, submenu.trigger);
102
+ popup.addEventListener("pointerenter", enter);
103
+ popup.addEventListener("pointerleave", exit);
104
+ return () => {
105
+ popup.removeEventListener("pointerenter", enter);
106
+ popup.removeEventListener("pointerleave", exit);
107
+ };
108
+ });
109
+ const ownProps = merge(submenu.attributes, itemProps, hoverProps, {
110
+ get id() {
111
+ return id();
112
+ },
113
+ "aria-haspopup": "menu",
114
+ get "aria-expanded"() {
115
+ return submenu.open() ? "true" : "false";
116
+ },
117
+ "aria-controls": submenu.popupId,
118
+ });
119
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "disabled", "label", "onClick", "id"));
120
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
121
+ }
@@ -0,0 +1,13 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface MenuTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that opens and closes the menu: a `<button type="button"
8
+ * aria-haspopup="menu">` with `aria-expanded`, naming the Popup in
9
+ * `popovertarget` and `aria-controls`. Enter, Space and Down Arrow open the
10
+ * menu with focus on its first item, Up Arrow on its last. Place it inside
11
+ * `Menu.Root`, right before `Menu.Popup`.
12
+ */
13
+ export declare function MenuTrigger(props: MenuTriggerProps): JSX.Element;
@@ -0,0 +1,73 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createUniqueId, merge, omit } from "solid-js";
3
+ import { warnUnlessButton } from "../../core/button.js";
4
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
5
+ import { renderElement } from "../../core/renderElement.jsx";
6
+ import { useMenuContext } from "../root/MenuContext.js";
7
+ /**
8
+ * The button that opens and closes the menu: a `<button type="button"
9
+ * aria-haspopup="menu">` with `aria-expanded`, naming the Popup in
10
+ * `popovertarget` and `aria-controls`. Enter, Space and Down Arrow open the
11
+ * menu with focus on its first item, Up Arrow on its last. Place it inside
12
+ * `Menu.Root`, right before `Menu.Popup`.
13
+ */
14
+ export function MenuTrigger(props) {
15
+ const menu = useMenuContext();
16
+ const generated = createUniqueId();
17
+ // The consumer's `id`, else the generated one, which labels the Popup
18
+ // rendered after it. Kept out of the merge, where a wrapper's
19
+ // `id={undefined}` would remove it ("`undefined` is a value", PLAN.md
20
+ // section 8).
21
+ const id = () => props.id ?? generated;
22
+ menu.triggerId = id;
23
+ const ownProps = merge(menu.attributes, {
24
+ type: "button",
25
+ get id() {
26
+ return id();
27
+ },
28
+ // So that the browser counts a press on the Trigger as one on the
29
+ // popover, which light dismiss leaves open (README, "Decisions").
30
+ popovertarget: menu.popupId,
31
+ "aria-haspopup": "menu",
32
+ get "aria-expanded"() {
33
+ return menu.open() ? "true" : "false";
34
+ },
35
+ "aria-controls": menu.popupId,
36
+ onClick: (event) => {
37
+ // The state shows and hides the popover, in the flush that places
38
+ // it: the browser's own toggle would show it a task before.
39
+ event.preventDefault();
40
+ const details = { reason: "trigger-press", event };
41
+ const { hoverOpened } = menu;
42
+ menu.hoverOpened = false;
43
+ if (!menu.open())
44
+ menu.setOpen(true, details);
45
+ else if (hoverOpened)
46
+ menu.list.move(menu.list.items()[0]);
47
+ else
48
+ menu.close(details);
49
+ },
50
+ onKeyDown: (event) => {
51
+ const { key } = event;
52
+ if ((key !== "ArrowDown" && key !== "ArrowUp") ||
53
+ event.altKey ||
54
+ event.ctrlKey ||
55
+ event.metaKey ||
56
+ event.shiftKey)
57
+ return;
58
+ event.preventDefault();
59
+ menu.setOpen(true, { reason: "trigger-press", event });
60
+ const items = menu.list.items();
61
+ menu.list.move(key === "ArrowUp" ? items[items.length - 1] : items[0]);
62
+ },
63
+ ref: (element) => {
64
+ menu.trigger = element;
65
+ // Production builds drop the check with `isDev`.
66
+ // Menubar's Trigger is this one, in a menu of the bar.
67
+ if (isDev)
68
+ warnUnlessButton(element, menu.along ? "Menubar.Trigger" : "Menu.Trigger");
69
+ },
70
+ });
71
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
72
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
73
+ }
@@ -0,0 +1 @@
1
+ export * as Menubar from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Menubar from "./index.parts.js";
@@ -0,0 +1,13 @@
1
+ export { MenubarRoot as Root } from "./root/MenubarRoot.tsx";
2
+ export { MenubarMenu as Menu } from "./menu/MenubarMenu.tsx";
3
+ export { MenubarTrigger as Trigger } from "./trigger/MenubarTrigger.tsx";
4
+ export { MenuPopup as Popup } from "../menu/popup/MenuPopup.tsx";
5
+ export { MenuItem as Item } from "../menu/item/MenuItem.tsx";
6
+ export { MenuCheckboxItem as CheckboxItem } from "../menu/checkbox-item/MenuCheckboxItem.tsx";
7
+ export { MenuItemIndicator as ItemIndicator } from "../menu/item-indicator/MenuItemIndicator.tsx";
8
+ export { MenuGroup as Group } from "../menu/group/MenuGroup.tsx";
9
+ export { MenuGroupLabel as GroupLabel } from "../menu/group-label/MenuGroupLabel.tsx";
10
+ export { MenuRadioGroup as RadioGroup } from "../menu/radio-group/MenuRadioGroup.tsx";
11
+ export { MenuRadioItem as RadioItem } from "../menu/radio-item/MenuRadioItem.tsx";
12
+ export { MenuSubmenu as Submenu } from "../menu/submenu/MenuSubmenu.tsx";
13
+ export { MenuSubmenuTrigger as SubmenuTrigger } from "../menu/submenu-trigger/MenuSubmenuTrigger.tsx";
@@ -0,0 +1,14 @@
1
+ // Menu's parts, but the Root, Menu and Trigger (README, "Decisions"; #101).
2
+ export { MenubarRoot as Root } from "./root/MenubarRoot.jsx";
3
+ export { MenubarMenu as Menu } from "./menu/MenubarMenu.jsx";
4
+ export { MenubarTrigger as Trigger } from "./trigger/MenubarTrigger.jsx";
5
+ export { MenuPopup as Popup } from "../menu/popup/MenuPopup.jsx";
6
+ export { MenuItem as Item } from "../menu/item/MenuItem.jsx";
7
+ export { MenuCheckboxItem as CheckboxItem } from "../menu/checkbox-item/MenuCheckboxItem.jsx";
8
+ export { MenuItemIndicator as ItemIndicator } from "../menu/item-indicator/MenuItemIndicator.jsx";
9
+ export { MenuGroup as Group } from "../menu/group/MenuGroup.jsx";
10
+ export { MenuGroupLabel as GroupLabel } from "../menu/group-label/MenuGroupLabel.jsx";
11
+ export { MenuRadioGroup as RadioGroup } from "../menu/radio-group/MenuRadioGroup.jsx";
12
+ export { MenuRadioItem as RadioItem } from "../menu/radio-item/MenuRadioItem.jsx";
13
+ export { MenuSubmenu as Submenu } from "../menu/submenu/MenuSubmenu.jsx";
14
+ export { MenuSubmenuTrigger as SubmenuTrigger } from "../menu/submenu-trigger/MenuSubmenuTrigger.jsx";
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { MenuStateProps } from "../../menu/root/MenuContext.ts";
3
+ export interface MenubarMenuProps extends MenuStateProps {
4
+ children?: JSX.Element;
5
+ }
6
+ /**
7
+ * One menu of the bar: holds whether it is open and shares it with its
8
+ * `Menubar.Trigger`, `Menubar.Popup` and the items inside it. Renders no
9
+ * element of its own. Place it inside `Menubar.Root`.
10
+ */
11
+ export declare function MenubarMenu(props: MenubarMenuProps): JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { createMenu, MenuContext } from "../../menu/root/MenuContext.js";
2
+ import { useMenubarContext } from "../root/MenubarContext.js";
3
+ /**
4
+ * One menu of the bar: holds whether it is open and shares it with its
5
+ * `Menubar.Trigger`, `Menubar.Popup` and the items inside it. Renders no
6
+ * element of its own. Place it inside `Menubar.Root`.
7
+ */
8
+ export function MenubarMenu(props) {
9
+ const bar = useMenubarContext();
10
+ const menu = createMenu(props);
11
+ // Right Arrow on an item with no submenu, and Left Arrow in this menu,
12
+ // open the next or previous item's menu, with focus on that item. In a
13
+ // bar of one menu they do nothing.
14
+ menu.along = (step, event) => {
15
+ const items = bar.list.items();
16
+ const index = items.findIndex((item) => item.menu === menu);
17
+ const to = items[(index + step + items.length) % items.length];
18
+ if (!to || to.menu === menu)
19
+ return;
20
+ event.preventDefault();
21
+ bar.moveTo(to, { reason: "arrow-key", event });
22
+ };
23
+ return <MenuContext value={menu}>{props.children}</MenuContext>;
24
+ }
@@ -0,0 +1,30 @@
1
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
2
+ import type { ListItem, ListNavigation } from "../../floating/list-navigation/listNavigation.ts";
3
+ import type { Typeahead } from "../../floating/typeahead/typeahead.ts";
4
+ import type { Menu } from "../../menu/root/MenuContext.ts";
5
+ /** An item of the bar, a menu's Trigger, as its list navigation knows it. */
6
+ export interface MenubarItem extends ListItem {
7
+ /** The menu the item opens. */
8
+ readonly menu: Menu;
9
+ }
10
+ /** The bar: its items, the keys along it, and which of its menus is open. */
11
+ export interface Menubar {
12
+ readonly list: ListNavigation<MenubarItem>;
13
+ readonly typeahead: Typeahead;
14
+ /**
15
+ * Whether the item being created is the first, which has the tab stop of
16
+ * the server HTML and of the first render.
17
+ */
18
+ claimTabStop(): boolean;
19
+ /** The bar's open menu, if any. */
20
+ openMenu(): Menu | undefined;
21
+ /**
22
+ * Once focus has moved to another item of the bar: if `open` was open,
23
+ * closes it and opens that item's menu, with focus staying on the item.
24
+ */
25
+ follow(open: Menu | undefined, details: OpenChangeDetails): void;
26
+ /** Moves focus to `item`, and opens its menu if another one was open. */
27
+ moveTo(item: MenubarItem, details: OpenChangeDetails): void;
28
+ }
29
+ export declare const MenubarContext: import("solid-js").Context<Menubar | null>;
30
+ export declare function useMenubarContext(): Menubar;
@@ -0,0 +1,12 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // `null` outside a Root, so that the part can name what is missing.
4
+ export const MenubarContext = createContext(null);
5
+ export function useMenubarContext() {
6
+ const context = useContext(MenubarContext);
7
+ // Production builds drop the check, and its message, with `isDev`.
8
+ if (isDev && !context) {
9
+ throw new Error("[menhir] Menubar parts must be placed within <Menubar.Root>.");
10
+ }
11
+ return context;
12
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface MenubarRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * A row of menus: a `<div role="menubar">` around `Menubar.Menu`s, one tab
8
+ * stop, with Right and Left Arrow, Home, End and typed characters moving
9
+ * between its items. Name it with `aria-label` or `aria-labelledby`.
10
+ */
11
+ export declare function MenubarRoot(props: MenubarRootProps): JSX.Element;
@@ -0,0 +1,77 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { createRovingList } from "../../floating/list-navigation/roving.js";
5
+ import { createTypeahead } from "../../floating/typeahead/typeahead.js";
6
+ import { MenubarContext } from "./MenubarContext.js";
7
+ /**
8
+ * A row of menus: a `<div role="menubar">` around `Menubar.Menu`s, one tab
9
+ * stop, with Right and Left Arrow, Home, End and typed characters moving
10
+ * between its items. Name it with `aria-label` or `aria-labelledby`.
11
+ */
12
+ export function MenubarRoot(props) {
13
+ // Always shown, so its active item lasts: it is the tab stop (README,
14
+ // "Decisions").
15
+ const list = createRovingList({
16
+ orientation: "horizontal",
17
+ wrap: true,
18
+ });
19
+ const typeahead = createTypeahead({
20
+ get items() {
21
+ return list.items();
22
+ },
23
+ get active() {
24
+ return list.active();
25
+ },
26
+ move: (item) => list.move(item),
27
+ });
28
+ // Whether an item has claimed the tab stop of the server HTML.
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
37
+ .items()
38
+ .find((item) => item.element === document.activeElement)?.menu;
39
+ if (!open || !to || to === open)
40
+ return;
41
+ open.close(details);
42
+ to.keepFocus = true;
43
+ to.setOpen(true, details);
44
+ // For this opening only. One that goes through has used it by the
45
+ // next task, after its flushes; a controlled menu that refused it
46
+ // must not keep focus on the bar when it opens later.
47
+ setTimeout(() => (to.keepFocus = false));
48
+ },
49
+ moveTo: (item, details) => {
50
+ const open = bar.openMenu();
51
+ list.move(item);
52
+ bar.follow(open, details);
53
+ },
54
+ };
55
+ const ownProps = {
56
+ role: "menubar",
57
+ // Shift+Tab from a menu goes out of the bar, not to the menu's item in
58
+ // it, which keeps the tab stop: focus moves to the item first, and the
59
+ // browser's own move then goes on from there. The menu closes as focus
60
+ // leaves it by Tab (README, "Decisions").
61
+ onKeyDown: (event) => {
62
+ if (event.key !== "Tab" ||
63
+ !event.shiftKey ||
64
+ event.altKey ||
65
+ event.ctrlKey ||
66
+ event.metaKey)
67
+ return;
68
+ const open = bar.openMenu();
69
+ if (open?.popup?.contains(event.target))
70
+ open.trigger?.focus();
71
+ },
72
+ };
73
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
74
+ return (<MenubarContext value={bar}>
75
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
76
+ </MenubarContext>);
77
+ }
@@ -0,0 +1,11 @@
1
+ import type { MenuTriggerProps } from "../../menu/trigger/MenuTrigger.tsx";
2
+ export type MenubarTriggerProps = MenuTriggerProps;
3
+ /**
4
+ * An item of the bar, which opens its menu: Menu's `<button type="button"
5
+ * aria-haspopup="menu">`, with the `menuitem` role and the bar's roving
6
+ * `tabindex`. Down Arrow, Enter and Space open the menu with focus on its
7
+ * first item, Up Arrow on its last. While a menu of the bar is open, moving
8
+ * to another item, by a key or the pointer, opens that item's menu instead.
9
+ * Place it inside `Menubar.Menu`, right before `Menubar.Popup`.
10
+ */
11
+ export declare function MenubarTrigger(props: MenubarTriggerProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,78 @@
1
+ import { merge, onSettled } from "solid-js";
2
+ import { callHandler } from "../../core/mergeElementProps.js";
3
+ import { useMenuContext } from "../../menu/root/MenuContext.js";
4
+ import { MenuTrigger } from "../../menu/trigger/MenuTrigger.jsx";
5
+ import { useMenubarContext } from "../root/MenubarContext.js";
6
+ /**
7
+ * An item of the bar, which opens its menu: Menu's `<button type="button"
8
+ * aria-haspopup="menu">`, with the `menuitem` role and the bar's roving
9
+ * `tabindex`. Down Arrow, Enter and Space open the menu with focus on its
10
+ * first item, Up Arrow on its last. While a menu of the bar is open, moving
11
+ * to another item, by a key or the pointer, opens that item's menu instead.
12
+ * Place it inside `Menubar.Menu`, right before `Menubar.Popup`.
13
+ */
14
+ export function MenubarTrigger(props) {
15
+ const bar = useMenubarContext();
16
+ const menu = useMenuContext();
17
+ // Its element is the menu's trigger, which Menu's Trigger sets.
18
+ const item = {
19
+ get element() {
20
+ return menu.trigger;
21
+ },
22
+ menu,
23
+ };
24
+ // Read once: the tab stop of the server HTML, and of the first render.
25
+ const first = bar.claimTabStop();
26
+ onSettled(() => bar.list.register(item));
27
+ return MenuTrigger(merge(props, {
28
+ role: "menuitem",
29
+ // The item that last had focus, else the first (README, "Decisions").
30
+ get tabindex() {
31
+ const stop = bar.list.active() ?? bar.list.items()[0];
32
+ return (stop ? stop === item : first) ? 0 : -1;
33
+ },
34
+ // Called here, not merged, so the consumer's handlers run too, first,
35
+ // as in a merge.
36
+ onFocus: (event) => {
37
+ callHandler(props.onFocus, event);
38
+ if (bar.list.active() !== item)
39
+ bar.list.move(item);
40
+ },
41
+ onKeyDown: (event) => {
42
+ callHandler(props.onKeyDown, event);
43
+ const open = bar.openMenu();
44
+ if (bar.typeahead.onKeyDown(event) || bar.list.onKeyDown(event)) {
45
+ bar.follow(open, { reason: "arrow-key", event });
46
+ return;
47
+ }
48
+ const { key } = event;
49
+ if (event.altKey || event.ctrlKey || event.metaKey || !menu.open())
50
+ return;
51
+ // Tab leaves the bar, and closes its menu.
52
+ if (key === "Tab")
53
+ menu.close({ reason: "focus-out", event });
54
+ // Enter and Space open the menu, which is open already: focus moves
55
+ // into it, where Menu's Trigger would close it.
56
+ if ((key === "Enter" || key === " ") && !event.shiftKey) {
57
+ event.preventDefault();
58
+ menu.list.move(menu.list.items()[0]);
59
+ }
60
+ },
61
+ // While another menu of the bar is open, the pointer moving onto this
62
+ // item opens its menu. Only a pointer that moves counts, and no touch.
63
+ onPointerMove: (event) => {
64
+ callHandler(props.onPointerMove, event);
65
+ const open = bar.openMenu();
66
+ if (event.pointerType === "touch" || !open || open === menu)
67
+ return;
68
+ bar.moveTo(item, { reason: "trigger-hover", event });
69
+ // A press it was on its way to keeps the menu open (README,
70
+ // "Decisions").
71
+ menu.hoverOpened = true;
72
+ },
73
+ onPointerLeave: (event) => {
74
+ callHandler(props.onPointerLeave, event);
75
+ menu.hoverOpened = false;
76
+ },
77
+ }));
78
+ }
@@ -0,0 +1 @@
1
+ export * as NavigationMenu from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as NavigationMenu from "./index.parts.js";
@@ -0,0 +1,5 @@
1
+ export { NavigationMenuRoot as Root } from "./root/NavigationMenuRoot.tsx";
2
+ export { NavigationMenuItem as Item } from "./item/NavigationMenuItem.tsx";
3
+ export { NavigationMenuTrigger as Trigger } from "./trigger/NavigationMenuTrigger.tsx";
4
+ export { NavigationMenuPanel as Panel } from "./panel/NavigationMenuPanel.tsx";
5
+ export { NavigationMenuLink as Link } from "./link/NavigationMenuLink.tsx";
@@ -0,0 +1,5 @@
1
+ export { NavigationMenuRoot as Root } from "./root/NavigationMenuRoot.jsx";
2
+ export { NavigationMenuItem as Item } from "./item/NavigationMenuItem.jsx";
3
+ export { NavigationMenuTrigger as Trigger } from "./trigger/NavigationMenuTrigger.jsx";
4
+ export { NavigationMenuPanel as Panel } from "./panel/NavigationMenuPanel.jsx";
5
+ export { NavigationMenuLink as Link } from "./link/NavigationMenuLink.jsx";
@@ -0,0 +1,16 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface NavigationMenuItemProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /**
5
+ * Identifies the Item in the Root's value. Without one, the Item uses a
6
+ * generated value, which no other code knows.
7
+ */
8
+ value?: string;
9
+ render?: RenderProp;
10
+ }
11
+ /**
12
+ * One entry of the bar: an `<li>` around a `NavigationMenu.Trigger` and its
13
+ * `NavigationMenu.Panel`. Place it inside `NavigationMenu.Root`, in the
14
+ * `<ul>` of the bar.
15
+ */
16
+ export declare function NavigationMenuItem(props: NavigationMenuItemProps): JSX.Element;
@@ -0,0 +1,85 @@
1
+ import { createUniqueId, merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { createEscape } from "../../floating/dismissal/escape.js";
5
+ import { createHover } from "../../floating/hover/hover.js";
6
+ import { useNavigationMenuRootContext } from "../root/NavigationMenuRootContext.js";
7
+ import { NavigationMenuItemContext } from "./NavigationMenuItemContext.js";
8
+ /**
9
+ * One entry of the bar: an `<li>` around a `NavigationMenu.Trigger` and its
10
+ * `NavigationMenu.Panel`. Place it inside `NavigationMenu.Root`, in the
11
+ * `<ul>` of the bar.
12
+ */
13
+ export function NavigationMenuItem(props) {
14
+ const root = useNavigationMenuRootContext("Item");
15
+ const panelId = createUniqueId();
16
+ // Without a value, the Panel's id serves as one, as on an Accordion Item.
17
+ const value = () => props.value ?? panelId;
18
+ const open = () => root.value() === value();
19
+ const attributes = {
20
+ get "data-open"() {
21
+ return open() ? "" : undefined;
22
+ },
23
+ get "data-closed"() {
24
+ return open() ? undefined : "";
25
+ },
26
+ };
27
+ const context = {
28
+ open,
29
+ toggle: (event) => root.toggle(value(), event),
30
+ panelId,
31
+ trigger: undefined,
32
+ panel: undefined,
33
+ attributes,
34
+ };
35
+ let element;
36
+ createHover({
37
+ get trigger() {
38
+ return context.trigger;
39
+ },
40
+ get popup() {
41
+ return context.panel;
42
+ },
43
+ get open() {
44
+ return open();
45
+ },
46
+ // Read as the pointer enters: 0 while another Item is open (README,
47
+ // "Moving along the bar").
48
+ get delay() {
49
+ return root.hoverDelay();
50
+ },
51
+ get closeDelay() {
52
+ return root.closeDelay();
53
+ },
54
+ // A Panel that holds focus stays open when the pointer leaves: closing
55
+ // it would drop focus to the page. One a press opened stays open too
56
+ // (`hoverClose`).
57
+ onOpenChange: (next, details) => {
58
+ if (next)
59
+ root.hoverOpen(value(), details);
60
+ else if (!context.panel?.contains(document.activeElement))
61
+ root.hoverClose(value(), details);
62
+ },
63
+ });
64
+ createEscape({
65
+ get open() {
66
+ return open();
67
+ },
68
+ onDismiss: (details) => {
69
+ // As the example does: focus inside the Item goes back to its
70
+ // Trigger, which stays in the page; focus elsewhere stays there.
71
+ if (element?.contains(document.activeElement))
72
+ context.trigger?.focus();
73
+ root.close(details);
74
+ },
75
+ });
76
+ const ownProps = merge(attributes, {
77
+ ref: (el) => {
78
+ element = el;
79
+ },
80
+ });
81
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value"));
82
+ return (<NavigationMenuItemContext value={context}>
83
+ {renderElement(props, elementProps, (p) => (<li {...p}/>))}
84
+ </NavigationMenuItemContext>);
85
+ }