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,14 @@
1
+ /** An item typeahead can move to: list navigation's item (#97). */
2
+ export interface TypeaheadItem {
3
+ readonly element: Element;
4
+ /** The item's label, when its content is not; else its text content. */
5
+ readonly text?: string;
6
+ }
7
+ /**
8
+ * The item that `typed` moves to, from `active`, or `undefined`:
9
+ *
10
+ * ```ts
11
+ * const item = findMatch(list.items(), list.active(), "ba");
12
+ * ```
13
+ */
14
+ export declare function findMatch<T extends TypeaheadItem>(items: readonly T[], active: T | undefined, typed: string): T | undefined;
@@ -0,0 +1,32 @@
1
+ // Made on the first key, never at import time (PLAN.md section 6, rule 2),
2
+ // and kept for the page: it holds no state.
3
+ let collator;
4
+ /**
5
+ * The item that `typed` moves to, from `active`, or `undefined`:
6
+ *
7
+ * ```ts
8
+ * const item = findMatch(list.items(), list.active(), "ba");
9
+ * ```
10
+ */
11
+ export function findMatch(items, active, typed) {
12
+ const characters = [...typed];
13
+ // One character, or the same one repeated: the search cycles through
14
+ // the items that start with it.
15
+ const cycles = characters.every((character) => character === characters[0]);
16
+ const search = cycles ? characters[0] : typed;
17
+ const count = items.length;
18
+ const index = items.indexOf(active);
19
+ // One character searches after the active item, a longer string from it
20
+ // on, so the item the first character reached stays while it matches.
21
+ const start = index < 0 ? 0 : index + (cycles ? 1 : 0);
22
+ for (let offset = 0; offset < count; offset++) {
23
+ const item = items[(start + offset) % count];
24
+ // Read now, so a label that changed is matched as it is.
25
+ const text = (item.text ?? item.element.textContent ?? "").trimStart();
26
+ // Case and accents ignored.
27
+ collator ??= new Intl.Collator(undefined, { sensitivity: "base" });
28
+ if (!collator.compare(text.slice(0, search.length), search))
29
+ return item;
30
+ }
31
+ return undefined;
32
+ }
@@ -0,0 +1,41 @@
1
+ import { type TypeaheadItem } from "./match.ts";
2
+ /** What `createTypeahead` returns. */
3
+ export interface Typeahead {
4
+ /**
5
+ * A key from one of the items, or from the element that hands them over;
6
+ * returns whether it used the key.
7
+ */
8
+ onKeyDown(event: KeyboardEvent): boolean;
9
+ }
10
+ /**
11
+ * Typing characters moves to the item whose text starts with them
12
+ * (`findMatch`). Characters typed less than a second apart make one string;
13
+ * Space joins a string being typed. The component hands over list
14
+ * navigation's items, active item and move, and calls the handler from its
15
+ * items' key events, before its own Space activation:
16
+ *
17
+ * ```ts
18
+ * const typeahead = createTypeahead<Entry>({
19
+ * get open() { return open(); },
20
+ * get items() { return list.items(); },
21
+ * get active() { return list.active(); },
22
+ * move: (item) => list.move(item),
23
+ * });
24
+ * // In the item part:
25
+ * onKeyDown: (event) => {
26
+ * if (typeahead.onKeyDown(event) || list.onKeyDown(event)) return;
27
+ * if (event.key === " " || event.key === "Enter") activate(event);
28
+ * },
29
+ * ```
30
+ *
31
+ * The handler cancels each key it uses. Closing the popup (`open` turning
32
+ * false) and disposal clear the string and its timer; opening does not, so
33
+ * a closed Select's trigger may open on the first key and the string goes
34
+ * on. Nothing runs at import time, nor, until a key, on the server.
35
+ */
36
+ export declare function createTypeahead<T extends TypeaheadItem>(options: {
37
+ readonly open?: boolean;
38
+ readonly items: readonly T[];
39
+ readonly active: T | undefined;
40
+ move(item: T): void;
41
+ }): Typeahead;
@@ -0,0 +1,81 @@
1
+ import { createEffect, onCleanup } from "solid-js";
2
+ import { findMatch } from "./match.js";
3
+ // How long after the last key the typed string resets: what Chromium's
4
+ // native <select> waits (README.md, Decisions).
5
+ const resetDelay = 1000;
6
+ /**
7
+ * Typing characters moves to the item whose text starts with them
8
+ * (`findMatch`). Characters typed less than a second apart make one string;
9
+ * Space joins a string being typed. The component hands over list
10
+ * navigation's items, active item and move, and calls the handler from its
11
+ * items' key events, before its own Space activation:
12
+ *
13
+ * ```ts
14
+ * const typeahead = createTypeahead<Entry>({
15
+ * get open() { return open(); },
16
+ * get items() { return list.items(); },
17
+ * get active() { return list.active(); },
18
+ * move: (item) => list.move(item),
19
+ * });
20
+ * // In the item part:
21
+ * onKeyDown: (event) => {
22
+ * if (typeahead.onKeyDown(event) || list.onKeyDown(event)) return;
23
+ * if (event.key === " " || event.key === "Enter") activate(event);
24
+ * },
25
+ * ```
26
+ *
27
+ * The handler cancels each key it uses. Closing the popup (`open` turning
28
+ * false) and disposal clear the string and its timer; opening does not, so
29
+ * a closed Select's trigger may open on the first key and the string goes
30
+ * on. Nothing runs at import time, nor, until a key, on the server.
31
+ */
32
+ export function createTypeahead(options) {
33
+ let typed = "";
34
+ let timer;
35
+ const reset = () => {
36
+ clearTimeout(timer);
37
+ typed = "";
38
+ };
39
+ // Not on opening: a closed Select opens on the first key, and the string
40
+ // goes on.
41
+ createEffect(() => options.open, (open) => {
42
+ if (open === false)
43
+ reset();
44
+ });
45
+ onCleanup(reset);
46
+ return {
47
+ onKeyDown: (event) => {
48
+ const { key, target } = event;
49
+ const items = options.items;
50
+ // Only a key from one of its items, or from the element whose handler
51
+ // calls this, such as a closed Select's trigger: a nested list, such
52
+ // as a submenu in an item, takes its own keys, which bubble through
53
+ // it. As list navigation's check, except that `items` holds only the
54
+ // items the keys reach: a focused item they do not reach hands its
55
+ // key over from its own handler, as the target, and is taken all the
56
+ // same. A printable character is a key of one character, astral ones
57
+ // too; with Control, Alt or Meta it is a shortcut. Space is part of a
58
+ // string being typed, and else the part's. While an input method
59
+ // composes, its text arrives as events of its own.
60
+ if ((target !== event.currentTarget &&
61
+ !items.some((item) => item.element === target)) ||
62
+ event.isComposing ||
63
+ event.ctrlKey ||
64
+ event.altKey ||
65
+ event.metaKey ||
66
+ !/^.$/u.test(key) ||
67
+ (key === " " && !typed))
68
+ return false;
69
+ // So that a key typed into the string does nothing else.
70
+ event.preventDefault();
71
+ typed += key;
72
+ clearTimeout(timer);
73
+ timer = setTimeout(reset, resetDelay);
74
+ const active = options.active;
75
+ const match = findMatch(items, active, typed);
76
+ if (match && match !== active)
77
+ options.move(match);
78
+ return true;
79
+ },
80
+ };
81
+ }
@@ -0,0 +1,20 @@
1
+ import type { RenderProp } from "../../core/renderElement.tsx";
2
+ import type { MenuItemBaseProps } from "../item/menuItemProps.ts";
3
+ export interface MenuCheckboxItemProps extends MenuItemBaseProps {
4
+ /** Whether it is checked, when controlled. */
5
+ checked?: boolean;
6
+ /** Whether it is checked at first, when uncontrolled. */
7
+ defaultChecked?: boolean;
8
+ /**
9
+ * Called with the new value when the user checks or unchecks it. When
10
+ * controlled, it changes only if `checked` does.
11
+ */
12
+ onCheckedChange?: (checked: boolean) => void;
13
+ render?: RenderProp;
14
+ }
15
+ /**
16
+ * An option that is on or off: a `<div role="menuitemcheckbox">` with
17
+ * `aria-checked`. A click and Enter change it and close every open menu;
18
+ * Space changes it and keeps the menu open. Place it inside `Menu.Popup`.
19
+ */
20
+ export declare function MenuCheckboxItem(props: MenuCheckboxItemProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { omit } from "solid-js";
2
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { renderCheckedItem } from "../item/renderCheckedItem.jsx";
4
+ /**
5
+ * An option that is on or off: a `<div role="menuitemcheckbox">` with
6
+ * `aria-checked`. A click and Enter change it and close every open menu;
7
+ * Space changes it and keeps the menu open. Place it inside `Menu.Popup`.
8
+ */
9
+ export function MenuCheckboxItem(props) {
10
+ const [checked, setChecked] = createControllableSignal({
11
+ get value() {
12
+ return props.checked;
13
+ },
14
+ get defaultValue() {
15
+ return props.defaultChecked ?? false;
16
+ },
17
+ onChange: (value) => props.onCheckedChange?.(value),
18
+ });
19
+ return renderCheckedItem(props, omit(props, "render", "disabled", "label", "onClick", "checked", "defaultChecked", "onCheckedChange"), {
20
+ role: "menuitemcheckbox",
21
+ get checked() {
22
+ return checked();
23
+ },
24
+ onCheck: () => setChecked(!checked()),
25
+ });
26
+ }
@@ -0,0 +1,16 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface MenuGroupProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * Renders a group of items, `<div role="group">`, named by the GroupLabel
8
+ * inside it, for both `Menu.Group` and `Menu.RadioGroup`. `props` are the
9
+ * consumer's, less the group's own.
10
+ */
11
+ export declare function renderGroup(props: MenuGroupProps, rest: JSX.HTMLAttributes<HTMLElement>): JSX.Element;
12
+ /**
13
+ * Items that belong together: a `<div role="group">` named by its
14
+ * `Menu.GroupLabel`. Place it inside `Menu.Popup`.
15
+ */
16
+ export declare function MenuGroup(props: MenuGroupProps): JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { createIdSlot } from "../../core/slot.js";
5
+ import { MenuGroupContext } from "./MenuGroupContext.js";
6
+ /**
7
+ * Renders a group of items, `<div role="group">`, named by the GroupLabel
8
+ * inside it, for both `Menu.Group` and `Menu.RadioGroup`. `props` are the
9
+ * consumer's, less the group's own.
10
+ */
11
+ export function renderGroup(props, rest) {
12
+ const [labelId, registerLabelId] = createIdSlot();
13
+ const elementProps = mergeElementProps({
14
+ role: "group",
15
+ // The consumer's, else the GroupLabel's id, while one is rendered.
16
+ // Kept out of the merge ("`undefined` is a value", PLAN.md section 8).
17
+ get "aria-labelledby"() {
18
+ return props["aria-labelledby"] ?? labelId();
19
+ },
20
+ }, omit(rest, "aria-labelledby"));
21
+ return (<MenuGroupContext value={{ registerLabelId }}>
22
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
23
+ </MenuGroupContext>);
24
+ }
25
+ /**
26
+ * Items that belong together: a `<div role="group">` named by its
27
+ * `Menu.GroupLabel`. Place it inside `Menu.Popup`.
28
+ */
29
+ export function MenuGroup(props) {
30
+ return renderGroup(props, omit(props, "render"));
31
+ }
@@ -0,0 +1,10 @@
1
+ /** What a group shares with its label. */
2
+ export interface MenuGroupContextValue {
3
+ /**
4
+ * Registers the `id` of a mounted GroupLabel, as a getter. Returns what
5
+ * unregisters it, for the label's disposal.
6
+ */
7
+ registerLabelId(id: () => string | false): () => void;
8
+ }
9
+ export declare const MenuGroupContext: import("solid-js").Context<MenuGroupContextValue | null>;
10
+ export declare function useMenuGroupContext(): MenuGroupContextValue;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ // `null` outside a group, so that the part can name what is missing.
4
+ export const MenuGroupContext = createContext(null);
5
+ export function useMenuGroupContext() {
6
+ const context = useContext(MenuGroupContext);
7
+ // Production builds drop the check, and its message, with `isDev`.
8
+ if (isDev && !context) {
9
+ throw new Error("[menhir] Menu.GroupLabel must be placed within <Menu.Group> or <Menu.RadioGroup>.");
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 MenuGroupLabelProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The label of a group, which names it in `aria-labelledby`: a `<div>`,
8
+ * not reached by the keys. Place it inside `Menu.Group` or
9
+ * `Menu.RadioGroup`.
10
+ */
11
+ export declare function MenuGroupLabel(props: MenuGroupLabelProps): JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { createUniqueId, omit, onSettled } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useMenuGroupContext } from "../group/MenuGroupContext.js";
5
+ /**
6
+ * The label of a group, which names it in `aria-labelledby`: a `<div>`,
7
+ * not reached by the keys. Place it inside `Menu.Group` or
8
+ * `Menu.RadioGroup`.
9
+ */
10
+ export function MenuGroupLabel(props) {
11
+ const group = useMenuGroupContext();
12
+ const generated = createUniqueId();
13
+ // The consumer's `id`, else the generated one. Kept out of the merge,
14
+ // where a wrapper's `id={undefined}` would remove it.
15
+ const id = () => props.id ?? generated;
16
+ // Named once mounted, so the group names only a label that is rendered,
17
+ // and none in the server HTML, as a popup's Title.
18
+ onSettled(() => group.registerLabelId(id));
19
+ const elementProps = mergeElementProps({
20
+ get id() {
21
+ return id();
22
+ },
23
+ }, omit(props, "render", "id"));
24
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
25
+ }
@@ -0,0 +1 @@
1
+ export * as Menu from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Menu from "./index.parts.js";
@@ -0,0 +1,12 @@
1
+ export { MenuRoot as Root } from "./root/MenuRoot.tsx";
2
+ export { MenuTrigger as Trigger } from "./trigger/MenuTrigger.tsx";
3
+ export { MenuPopup as Popup } from "./popup/MenuPopup.tsx";
4
+ export { MenuItem as Item } from "./item/MenuItem.tsx";
5
+ export { MenuCheckboxItem as CheckboxItem } from "./checkbox-item/MenuCheckboxItem.tsx";
6
+ export { MenuItemIndicator as ItemIndicator } from "./item-indicator/MenuItemIndicator.tsx";
7
+ export { MenuGroup as Group } from "./group/MenuGroup.tsx";
8
+ export { MenuGroupLabel as GroupLabel } from "./group-label/MenuGroupLabel.tsx";
9
+ export { MenuRadioGroup as RadioGroup } from "./radio-group/MenuRadioGroup.tsx";
10
+ export { MenuRadioItem as RadioItem } from "./radio-item/MenuRadioItem.tsx";
11
+ export { MenuSubmenu as Submenu } from "./submenu/MenuSubmenu.tsx";
12
+ export { MenuSubmenuTrigger as SubmenuTrigger } from "./submenu-trigger/MenuSubmenuTrigger.tsx";
@@ -0,0 +1,12 @@
1
+ export { MenuRoot as Root } from "./root/MenuRoot.jsx";
2
+ export { MenuTrigger as Trigger } from "./trigger/MenuTrigger.jsx";
3
+ export { MenuPopup as Popup } from "./popup/MenuPopup.jsx";
4
+ export { MenuItem as Item } from "./item/MenuItem.jsx";
5
+ export { MenuCheckboxItem as CheckboxItem } from "./checkbox-item/MenuCheckboxItem.jsx";
6
+ export { MenuItemIndicator as ItemIndicator } from "./item-indicator/MenuItemIndicator.jsx";
7
+ export { MenuGroup as Group } from "./group/MenuGroup.jsx";
8
+ export { MenuGroupLabel as GroupLabel } from "./group-label/MenuGroupLabel.jsx";
9
+ export { MenuRadioGroup as RadioGroup } from "./radio-group/MenuRadioGroup.jsx";
10
+ export { MenuRadioItem as RadioItem } from "./radio-item/MenuRadioItem.jsx";
11
+ export { MenuSubmenu as Submenu } from "./submenu/MenuSubmenu.jsx";
12
+ export { MenuSubmenuTrigger as SubmenuTrigger } from "./submenu-trigger/MenuSubmenuTrigger.jsx";
@@ -0,0 +1,11 @@
1
+ import type { RenderProp } from "../../core/renderElement.tsx";
2
+ import type { MenuItemBaseProps } from "./menuItemProps.ts";
3
+ export interface MenuItemProps extends MenuItemBaseProps {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * An action in the menu: a `<div role="menuitem">`. A click, Enter or
8
+ * Space calls its `onClick` and closes every open menu; a disabled item
9
+ * does neither. Render a link with `render`. Place it inside `Menu.Popup`.
10
+ */
11
+ export declare function MenuItem(props: MenuItemProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useMenuContext } from "../root/MenuContext.js";
5
+ import { menuItemProps } from "./menuItemProps.js";
6
+ /**
7
+ * An action in the menu: a `<div role="menuitem">`. A click, Enter or
8
+ * Space calls its `onClick` and closes every open menu; a disabled item
9
+ * does neither. Render a link with `render`. Place it inside `Menu.Popup`.
10
+ */
11
+ export function MenuItem(props) {
12
+ const menu = useMenuContext();
13
+ const ownProps = menuItemProps(menu, props, {
14
+ role: "menuitem",
15
+ onActivate: (event, key) => menu.closeAll({ reason: "item-press", event: key ?? event }),
16
+ });
17
+ // The consumer's `onClick` is called by the item, not by the merge, so a
18
+ // disabled item does not call it.
19
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "disabled", "label", "onClick"));
20
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
21
+ }
@@ -0,0 +1,35 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { ElementProps } from "../../core/renderElement.tsx";
3
+ import type { Menu } from "../root/MenuContext.ts";
4
+ /** The props every kind of item takes. */
5
+ export interface MenuItemBaseProps extends JSX.HTMLAttributes<HTMLElement> {
6
+ /**
7
+ * Whether the item is disabled: still reached by the keys and the
8
+ * pointer, but not activated.
9
+ */
10
+ disabled?: boolean;
11
+ /**
12
+ * The text typeahead matches, when the item's content is not its label,
13
+ * such as an icon and a shortcut beside the text.
14
+ */
15
+ label?: string;
16
+ }
17
+ /** What kind of item `menuItemProps` makes, and what activating it does. */
18
+ export interface MenuItemOptions {
19
+ readonly role: "menuitem" | "menuitemcheckbox" | "menuitemradio";
20
+ /**
21
+ * Called on a click, Enter or Space, unless the item is disabled, with the
22
+ * key event that activated it, if any. It runs after the consumer's
23
+ * `onClick`, which a disabled item does not call.
24
+ */
25
+ onActivate(event: MouseEvent, key: KeyboardEvent | undefined): void;
26
+ /** The menu a SubmenuTrigger opens. */
27
+ readonly submenu?: Menu;
28
+ /** Receives the element, as the item's own ref does. */
29
+ ref?(element: HTMLElement): void;
30
+ }
31
+ /**
32
+ * The own props of an item of `menu`: its role, its place in the list's
33
+ * roving focus, typeahead, and activation.
34
+ */
35
+ export declare function menuItemProps(menu: Menu, props: MenuItemBaseProps, options: MenuItemOptions): ElementProps;
@@ -0,0 +1,78 @@
1
+ import { onSettled } from "solid-js";
2
+ import { callHandler } from "../../core/mergeElementProps.js";
3
+ /**
4
+ * The own props of an item of `menu`: its role, its place in the list's
5
+ * roving focus, typeahead, and activation.
6
+ */
7
+ export function menuItemProps(menu, props, options) {
8
+ let element;
9
+ const item = {
10
+ get element() {
11
+ return element;
12
+ },
13
+ get text() {
14
+ return props.label;
15
+ },
16
+ get disabled() {
17
+ return props.disabled;
18
+ },
19
+ submenu: options.submenu,
20
+ };
21
+ // A SubmenuTrigger is where Left Arrow in its submenu moves back to.
22
+ if (options.submenu)
23
+ options.submenu.triggerItem = item;
24
+ onSettled(() => menu.list.register(item));
25
+ // The key event whose click is under way, for `onActivate`.
26
+ let key;
27
+ return {
28
+ role: options.role,
29
+ get tabindex() {
30
+ return menu.list.isActive(item) ? 0 : -1;
31
+ },
32
+ get "data-active"() {
33
+ return menu.list.isActive(item) ? "" : undefined;
34
+ },
35
+ get "aria-disabled"() {
36
+ return props.disabled ? "true" : undefined;
37
+ },
38
+ get "data-disabled"() {
39
+ return props.disabled ? "" : undefined;
40
+ },
41
+ onKeyDown: (event) => {
42
+ // A key that moves through the menu, typed or Up, Down, Home or End,
43
+ // closes the submenu that was open.
44
+ const closeSubmenus = () => menu.closeSubmenus({ reason: "arrow-key", event });
45
+ if (menu.typeahead.onKeyDown(event)) {
46
+ closeSubmenus();
47
+ return;
48
+ }
49
+ if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key))
50
+ closeSubmenus();
51
+ if (menu.list.onKeyDown(event) || event.target !== element)
52
+ return;
53
+ if (event.key !== " " && event.key !== "Enter")
54
+ return;
55
+ // A link follows itself on Enter, with a click of its own.
56
+ if (event.key === "Enter" && element.matches("a[href]"))
57
+ return;
58
+ event.preventDefault();
59
+ key = event;
60
+ element.click();
61
+ key = undefined;
62
+ },
63
+ onPointerMove: (event) => menu.list.onPointerMove(item, event),
64
+ onClick: (event) => {
65
+ // Nor does a disabled link follow itself, by a click or Enter.
66
+ if (props.disabled) {
67
+ event.preventDefault();
68
+ return;
69
+ }
70
+ callHandler(props.onClick, event);
71
+ options.onActivate(event, key);
72
+ },
73
+ ref: (el) => {
74
+ element = el;
75
+ options.ref?.(el);
76
+ },
77
+ };
78
+ }
@@ -0,0 +1,22 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ import type { MenuItemBaseProps } from "./menuItemProps.ts";
4
+ /** What makes a checkbox or radio item, as getters and functions. */
5
+ export interface CheckedItemOptions {
6
+ readonly role: "menuitemcheckbox" | "menuitemradio";
7
+ /** Whether the item is checked. */
8
+ readonly checked: boolean;
9
+ /** Called when the item is activated: checks, or toggles, it. */
10
+ onCheck(): void;
11
+ }
12
+ /**
13
+ * Renders a checkbox or radio item, `Menu.CheckboxItem` and
14
+ * `Menu.RadioItem`: an item with `aria-checked`, `data-checked` or
15
+ * `data-unchecked`, which its `Menu.ItemIndicator` carries too. A click
16
+ * and Enter check it and close every open menu; Space checks it and keeps
17
+ * the menu open, as the menu pattern's optional Space does. `rest` is the
18
+ * consumer's props, less the item's own.
19
+ */
20
+ export declare function renderCheckedItem(props: MenuItemBaseProps & {
21
+ render?: RenderProp;
22
+ }, rest: JSX.HTMLAttributes<HTMLElement>, options: CheckedItemOptions): JSX.Element;
@@ -0,0 +1,41 @@
1
+ import { merge } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { MenuItemIndicatorContext } from "../item-indicator/MenuItemIndicatorContext.js";
5
+ import { useMenuContext } from "../root/MenuContext.js";
6
+ import { menuItemProps } from "./menuItemProps.js";
7
+ /**
8
+ * Renders a checkbox or radio item, `Menu.CheckboxItem` and
9
+ * `Menu.RadioItem`: an item with `aria-checked`, `data-checked` or
10
+ * `data-unchecked`, which its `Menu.ItemIndicator` carries too. A click
11
+ * and Enter check it and close every open menu; Space checks it and keeps
12
+ * the menu open, as the menu pattern's optional Space does. `rest` is the
13
+ * consumer's props, less the item's own.
14
+ */
15
+ export function renderCheckedItem(props, rest, options) {
16
+ const menu = useMenuContext();
17
+ const attributes = {
18
+ get "data-checked"() {
19
+ return options.checked ? "" : undefined;
20
+ },
21
+ get "data-unchecked"() {
22
+ return options.checked ? undefined : "";
23
+ },
24
+ };
25
+ const ownProps = merge(attributes, menuItemProps(menu, props, {
26
+ role: options.role,
27
+ onActivate: (event, key) => {
28
+ options.onCheck();
29
+ if (key?.key !== " ")
30
+ menu.closeAll({ reason: "item-press", event: key ?? event });
31
+ },
32
+ }), {
33
+ get "aria-checked"() {
34
+ return options.checked ? "true" : "false";
35
+ },
36
+ });
37
+ const elementProps = mergeElementProps(ownProps, rest);
38
+ return (<MenuItemIndicatorContext value={attributes}>
39
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
40
+ </MenuItemIndicatorContext>);
41
+ }
@@ -0,0 +1,12 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface MenuItemIndicatorProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The check mark of a checkbox or radio item: an `aria-hidden` `<span>`
8
+ * with its item's `data-checked` or `data-unchecked`, always rendered, so
9
+ * that CSS shows it by state. Place it inside `Menu.CheckboxItem` or
10
+ * `Menu.RadioItem`.
11
+ */
12
+ export declare function MenuItemIndicator(props: MenuItemIndicatorProps): JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useMenuItemIndicatorContext } from "./MenuItemIndicatorContext.js";
5
+ /**
6
+ * The check mark of a checkbox or radio item: an `aria-hidden` `<span>`
7
+ * with its item's `data-checked` or `data-unchecked`, always rendered, so
8
+ * that CSS shows it by state. Place it inside `Menu.CheckboxItem` or
9
+ * `Menu.RadioItem`.
10
+ */
11
+ export function MenuItemIndicator(props) {
12
+ const ownProps = merge(useMenuItemIndicatorContext(), {
13
+ "aria-hidden": "true",
14
+ });
15
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
16
+ return renderElement(props, elementProps, (p) => <span {...p}/>);
17
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A checkbox or radio item's state as `data-*` attributes, each `""` when
3
+ * it applies and absent otherwise: what the item and its
4
+ * `Menu.ItemIndicator` carry.
5
+ */
6
+ export type MenuItemIndicatorAttributes = {
7
+ readonly "data-checked": "" | undefined;
8
+ readonly "data-unchecked": "" | undefined;
9
+ };
10
+ export declare const MenuItemIndicatorContext: import("solid-js").Context<MenuItemIndicatorAttributes | null>;
11
+ export declare function useMenuItemIndicatorContext(): MenuItemIndicatorAttributes;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ // `null` outside a checkbox or radio item, so that the part can say so.
4
+ export const MenuItemIndicatorContext = createContext(null);
5
+ export function useMenuItemIndicatorContext() {
6
+ const context = useContext(MenuItemIndicatorContext);
7
+ // Production builds drop the check, and its message, with `isDev`.
8
+ if (isDev && !context) {
9
+ throw new Error("[menhir] Menu.ItemIndicator must be placed within <Menu.CheckboxItem> or <Menu.RadioItem>.");
10
+ }
11
+ return context;
12
+ }