menhir 0.1.2 → 0.1.4

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 (208) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +9 -2
  3. package/dist/alert-dialog/index.js +2 -0
  4. package/dist/alert-dialog/index.parts.js +7 -0
  5. package/dist/alert-dialog/popup/AlertDialogPopup.js +13 -0
  6. package/dist/core/createControllableSignal.js +15 -5
  7. package/dist/core/listValue.js +2 -7
  8. package/dist/core/slot.js +30 -0
  9. package/dist/dialog/close/DialogClose.js +33 -0
  10. package/dist/dialog/description/DialogDescription.js +27 -0
  11. package/dist/dialog/index.js +2 -0
  12. package/dist/dialog/index.parts.js +7 -0
  13. package/dist/dialog/popup/DialogPopup.js +13 -0
  14. package/dist/dialog/popup/renderDialogPopup.js +71 -0
  15. package/dist/dialog/root/DialogRoot.js +46 -0
  16. package/dist/dialog/root/DialogRootContext.js +10 -0
  17. package/dist/dialog/title/DialogTitle.js +27 -0
  18. package/dist/dialog/trigger/DialogTrigger.js +33 -0
  19. package/dist/floating/dismissal/dialogClose.js +67 -0
  20. package/dist/floating/dismissal/escape.js +44 -0
  21. package/dist/floating/dismissal/outsidePress.js +52 -0
  22. package/dist/floating/dismissal/popoverClose.js +74 -0
  23. package/dist/floating/dismissal/reason.js +0 -0
  24. package/dist/floating/focus/initialFocus.js +33 -0
  25. package/dist/floating/focus/returnFocus.js +65 -0
  26. package/dist/floating/focus/tabWrap.js +55 -0
  27. package/dist/floating/focus/tabbable.js +50 -0
  28. package/dist/floating/focus/target.js +0 -0
  29. package/dist/floating/hover/group.js +36 -0
  30. package/dist/floating/hover/hover.js +105 -0
  31. package/dist/floating/hover/safeArea.js +64 -0
  32. package/dist/floating/list-navigation/activeDescendant.js +29 -0
  33. package/dist/floating/list-navigation/listNavigation.js +108 -0
  34. package/dist/floating/list-navigation/roving.js +27 -0
  35. package/dist/floating/presence/presence.js +57 -0
  36. package/dist/floating/scroll-lock/scrollLock.js +125 -0
  37. package/dist/floating/typeahead/match.js +24 -0
  38. package/dist/floating/typeahead/typeahead.js +56 -0
  39. package/dist/navigation-menu/index.js +2 -0
  40. package/dist/navigation-menu/index.parts.js +6 -0
  41. package/dist/navigation-menu/item/NavigationMenuItem.js +83 -0
  42. package/dist/navigation-menu/item/NavigationMenuItemContext.js +10 -0
  43. package/dist/navigation-menu/link/NavigationMenuLink.js +26 -0
  44. package/dist/navigation-menu/panel/NavigationMenuPanel.js +31 -0
  45. package/dist/navigation-menu/root/NavigationMenuRoot.js +100 -0
  46. package/dist/navigation-menu/root/NavigationMenuRootContext.js +10 -0
  47. package/dist/navigation-menu/trigger/NavigationMenuTrigger.js +36 -0
  48. package/dist/popover/arrow/PopoverArrow.js +39 -0
  49. package/dist/popover/close/PopoverClose.js +33 -0
  50. package/dist/popover/description/PopoverDescription.js +27 -0
  51. package/dist/popover/index.js +2 -0
  52. package/dist/popover/index.parts.js +8 -0
  53. package/dist/popover/popup/PopoverPopup.js +116 -0
  54. package/dist/popover/popup/PopoverPopupContext.js +10 -0
  55. package/dist/popover/root/PopoverRoot.js +50 -0
  56. package/dist/popover/root/PopoverRootContext.js +10 -0
  57. package/dist/popover/title/PopoverTitle.js +27 -0
  58. package/dist/popover/trigger/PopoverTrigger.js +44 -0
  59. package/dist/source/alert-dialog/index.d.ts +1 -0
  60. package/dist/source/alert-dialog/index.js +1 -0
  61. package/dist/source/alert-dialog/index.parts.d.ts +6 -0
  62. package/dist/source/alert-dialog/index.parts.js +7 -0
  63. package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
  64. package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
  65. package/dist/source/core/createControllableSignal.d.ts +13 -4
  66. package/dist/source/core/createControllableSignal.js +11 -5
  67. package/dist/source/core/listValue.js +4 -10
  68. package/dist/source/core/slot.d.ts +21 -0
  69. package/dist/source/core/slot.js +28 -0
  70. package/dist/source/dialog/close/DialogClose.d.ts +11 -0
  71. package/dist/source/dialog/close/DialogClose.jsx +25 -0
  72. package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
  73. package/dist/source/dialog/description/DialogDescription.jsx +26 -0
  74. package/dist/source/dialog/index.d.ts +1 -0
  75. package/dist/source/dialog/index.js +1 -0
  76. package/dist/source/dialog/index.parts.d.ts +6 -0
  77. package/dist/source/dialog/index.parts.js +6 -0
  78. package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
  79. package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
  80. package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
  81. package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
  82. package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
  83. package/dist/source/dialog/root/DialogRoot.jsx +39 -0
  84. package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
  85. package/dist/source/dialog/root/DialogRootContext.js +14 -0
  86. package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
  87. package/dist/source/dialog/title/DialogTitle.jsx +26 -0
  88. package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
  89. package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
  90. package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
  91. package/dist/source/floating/dismissal/dialogClose.js +69 -0
  92. package/dist/source/floating/dismissal/escape.d.ts +24 -0
  93. package/dist/source/floating/dismissal/escape.js +48 -0
  94. package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
  95. package/dist/source/floating/dismissal/outsidePress.js +50 -0
  96. package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
  97. package/dist/source/floating/dismissal/popoverClose.js +82 -0
  98. package/dist/source/floating/dismissal/reason.d.ts +34 -0
  99. package/dist/source/floating/dismissal/reason.js +1 -0
  100. package/dist/source/floating/focus/initialFocus.d.ts +24 -0
  101. package/dist/source/floating/focus/initialFocus.js +38 -0
  102. package/dist/source/floating/focus/returnFocus.d.ts +27 -0
  103. package/dist/source/floating/focus/returnFocus.js +81 -0
  104. package/dist/source/floating/focus/tabWrap.d.ts +21 -0
  105. package/dist/source/floating/focus/tabWrap.js +69 -0
  106. package/dist/source/floating/focus/tabbable.d.ts +16 -0
  107. package/dist/source/floating/focus/tabbable.js +69 -0
  108. package/dist/source/floating/focus/target.d.ts +8 -0
  109. package/dist/source/floating/focus/target.js +1 -0
  110. package/dist/source/floating/hover/group.d.ts +39 -0
  111. package/dist/source/floating/hover/group.js +38 -0
  112. package/dist/source/floating/hover/hover.d.ts +35 -0
  113. package/dist/source/floating/hover/hover.js +130 -0
  114. package/dist/source/floating/hover/safeArea.d.ts +23 -0
  115. package/dist/source/floating/hover/safeArea.js +67 -0
  116. package/dist/source/floating/list-navigation/activeDescendant.d.ts +30 -0
  117. package/dist/source/floating/list-navigation/activeDescendant.js +24 -0
  118. package/dist/source/floating/list-navigation/listNavigation.d.ts +68 -0
  119. package/dist/source/floating/list-navigation/listNavigation.js +148 -0
  120. package/dist/source/floating/list-navigation/roving.d.ts +23 -0
  121. package/dist/source/floating/list-navigation/roving.js +25 -0
  122. package/dist/source/floating/presence/presence.d.ts +24 -0
  123. package/dist/source/floating/presence/presence.js +73 -0
  124. package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
  125. package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
  126. package/dist/source/floating/typeahead/match.d.ts +14 -0
  127. package/dist/source/floating/typeahead/match.js +32 -0
  128. package/dist/source/floating/typeahead/typeahead.d.ts +41 -0
  129. package/dist/source/floating/typeahead/typeahead.js +81 -0
  130. package/dist/source/navigation-menu/index.d.ts +1 -0
  131. package/dist/source/navigation-menu/index.js +1 -0
  132. package/dist/source/navigation-menu/index.parts.d.ts +5 -0
  133. package/dist/source/navigation-menu/index.parts.js +5 -0
  134. package/dist/source/navigation-menu/item/NavigationMenuItem.d.ts +16 -0
  135. package/dist/source/navigation-menu/item/NavigationMenuItem.jsx +85 -0
  136. package/dist/source/navigation-menu/item/NavigationMenuItemContext.d.ts +27 -0
  137. package/dist/source/navigation-menu/item/NavigationMenuItemContext.js +12 -0
  138. package/dist/source/navigation-menu/link/NavigationMenuLink.d.ts +12 -0
  139. package/dist/source/navigation-menu/link/NavigationMenuLink.jsx +18 -0
  140. package/dist/source/navigation-menu/panel/NavigationMenuPanel.d.ts +11 -0
  141. package/dist/source/navigation-menu/panel/NavigationMenuPanel.jsx +26 -0
  142. package/dist/source/navigation-menu/root/NavigationMenuRoot.d.ts +37 -0
  143. package/dist/source/navigation-menu/root/NavigationMenuRoot.jsx +103 -0
  144. package/dist/source/navigation-menu/root/NavigationMenuRootContext.d.ts +33 -0
  145. package/dist/source/navigation-menu/root/NavigationMenuRootContext.js +13 -0
  146. package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.d.ts +12 -0
  147. package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.jsx +32 -0
  148. package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
  149. package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
  150. package/dist/source/popover/close/PopoverClose.d.ts +11 -0
  151. package/dist/source/popover/close/PopoverClose.jsx +25 -0
  152. package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
  153. package/dist/source/popover/description/PopoverDescription.jsx +26 -0
  154. package/dist/source/popover/index.d.ts +1 -0
  155. package/dist/source/popover/index.js +1 -0
  156. package/dist/source/popover/index.parts.d.ts +7 -0
  157. package/dist/source/popover/index.parts.js +7 -0
  158. package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
  159. package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
  160. package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
  161. package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
  162. package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
  163. package/dist/source/popover/root/PopoverRoot.jsx +42 -0
  164. package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
  165. package/dist/source/popover/root/PopoverRootContext.js +13 -0
  166. package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
  167. package/dist/source/popover/title/PopoverTitle.jsx +26 -0
  168. package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
  169. package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
  170. package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
  171. package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
  172. package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
  173. package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
  174. package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
  175. package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
  176. package/dist/source/tooltip/index.d.ts +1 -0
  177. package/dist/source/tooltip/index.js +1 -0
  178. package/dist/source/tooltip/index.parts.d.ts +5 -0
  179. package/dist/source/tooltip/index.parts.js +5 -0
  180. package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
  181. package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
  182. package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
  183. package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
  184. package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
  185. package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
  186. package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
  187. package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
  188. package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
  189. package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
  190. package/dist/tooltip/arrow/TooltipArrow.js +39 -0
  191. package/dist/tooltip/group/TooltipGroup.js +26 -0
  192. package/dist/tooltip/group/TooltipGroupContext.js +4 -0
  193. package/dist/tooltip/index.js +2 -0
  194. package/dist/tooltip/index.parts.js +6 -0
  195. package/dist/tooltip/popup/TooltipPopup.js +86 -0
  196. package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
  197. package/dist/tooltip/root/TooltipRoot.js +79 -0
  198. package/dist/tooltip/root/TooltipRootContext.js +10 -0
  199. package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
  200. package/package.json +28 -2
  201. package/skills/menhir-styling/SKILL.md +35 -0
  202. package/skills/menhir-styling/looks/shadcn/LICENSE +24 -0
  203. package/skills/menhir-styling/looks/shadcn/LOOK.md +106 -0
  204. package/skills/menhir-styling/looks/shadcn/dialog.md +63 -0
  205. package/skills/menhir-styling/looks/shadcn/popover.md +39 -0
  206. package/skills/menhir-styling/looks/shadcn/switch.md +26 -0
  207. package/skills/menhir-styling/looks/shadcn/tabs.md +62 -0
  208. package/skills/menhir-styling/looks/shadcn/tokens.css +80 -0
@@ -0,0 +1,40 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { ElementProps } from "../../core/renderElement.tsx";
3
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
4
+ import type { FocusTarget } from "../../floating/focus/target.ts";
5
+ type DialogElementProps = Omit<ElementProps, "tabindex">;
6
+ export interface DialogPopupProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "tabindex"> {
7
+ /**
8
+ * Where focus goes once the dialog has opened, instead of the browser's
9
+ * choice: the element with `autofocus`, else the first focusable one. An
10
+ * element, or a function called on each opening with the browser's
11
+ * choice, such as `() => input` for an element reached through a ref.
12
+ */
13
+ initialFocus?: FocusTarget;
14
+ /**
15
+ * Where focus goes once the dialog has closed, instead of the browser's
16
+ * choice: the element focused before it opened. An element, or a function
17
+ * called with the browser's choice, or `null` when it found none, such as
18
+ * `(focused) => focused ?? fallback`.
19
+ */
20
+ returnFocus?: FocusTarget;
21
+ /** Must render a `<dialog>`, which the Popup opens with `showModal()`. */
22
+ render?: (props: DialogElementProps) => JSX.Element;
23
+ }
24
+ /** What the Popup hands to `outsidePress`, as getters. */
25
+ export interface DialogPopupOptions {
26
+ readonly dialog: HTMLDialogElement | undefined;
27
+ readonly open: boolean;
28
+ onDismiss(details: OpenChangeDetails): void;
29
+ }
30
+ /**
31
+ * What a modal dialog's Popup does, for `Dialog.Popup` and
32
+ * `AlertDialog.Popup` (#32): a `<dialog>` opened with `showModal()`, closed
33
+ * by a close request, with Tab wrapping inside, the focus props, the page's
34
+ * scroll locked, and named by its Title and Description. `outsidePress`
35
+ * adds Dialog's press on the backdrop, so that Alert Dialog does not bundle
36
+ * it; `role` is Alert Dialog's `alertdialog`. Two arguments, not an
37
+ * options object, which measured 14 B more in `menhir/dialog`.
38
+ */
39
+ export declare function renderDialogPopup(props: DialogPopupProps, outsidePress?: (options: DialogPopupOptions) => void, role?: "alertdialog"): JSX.Element;
40
+ export {};
@@ -0,0 +1,73 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { merge, omit } from "solid-js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.jsx";
5
+ import { createDialogClose } from "../../floating/dismissal/dialogClose.js";
6
+ import { createInitialFocus } from "../../floating/focus/initialFocus.js";
7
+ import { createReturnFocus } from "../../floating/focus/returnFocus.js";
8
+ import { createTabWrap } from "../../floating/focus/tabWrap.js";
9
+ import { createPresence } from "../../floating/presence/presence.js";
10
+ import { createScrollLock } from "../../floating/scroll-lock/scrollLock.js";
11
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
12
+ /**
13
+ * What a modal dialog's Popup does, for `Dialog.Popup` and
14
+ * `AlertDialog.Popup` (#32): a `<dialog>` opened with `showModal()`, closed
15
+ * by a close request, with Tab wrapping inside, the focus props, the page's
16
+ * scroll locked, and named by its Title and Description. `outsidePress`
17
+ * adds Dialog's press on the backdrop, so that Alert Dialog does not bundle
18
+ * it; `role` is Alert Dialog's `alertdialog`. Two arguments, not an
19
+ * options object, which measured 14 B more in `menhir/dialog`.
20
+ */
21
+ export function renderDialogPopup(props, outsidePress, role) {
22
+ const root = useDialogRootContext();
23
+ let dialog;
24
+ // What every module of the `floating` layer takes, as getters.
25
+ const options = {
26
+ get dialog() {
27
+ return dialog;
28
+ },
29
+ get popup() {
30
+ return dialog;
31
+ },
32
+ get open() {
33
+ return root.open();
34
+ },
35
+ onDismiss: (details) => root.setOpen(false, details),
36
+ get initialFocus() {
37
+ return props.initialFocus;
38
+ },
39
+ get returnFocus() {
40
+ return props.returnFocus;
41
+ },
42
+ };
43
+ createPresence(options);
44
+ createDialogClose(options);
45
+ outsidePress?.(options);
46
+ createScrollLock(options);
47
+ createTabWrap(options);
48
+ createInitialFocus(options);
49
+ createReturnFocus(options);
50
+ const ownProps = merge(root.attributes, {
51
+ role,
52
+ // The consumer's, else the Title's and Description's ids. Kept out of
53
+ // the merge, where a wrapper's `aria-labelledby={undefined}` would
54
+ // remove the Title's ("`undefined` is a value", PLAN.md section 8);
55
+ // `false` removes it.
56
+ get "aria-labelledby"() {
57
+ return props["aria-labelledby"] ?? root.titleId();
58
+ },
59
+ get "aria-describedby"() {
60
+ return props["aria-describedby"] ?? root.descriptionId();
61
+ },
62
+ ref: (element) => {
63
+ // Production builds drop the check, and the part's name, with `isDev`.
64
+ if (isDev && !(element instanceof HTMLDialogElement)) {
65
+ console.warn(`[menhir] ${role ? "AlertDialog" : "Dialog"}.Popup's render function rendered a <${element.tagName.toLowerCase()}>. ` +
66
+ "Render a <dialog>, which the Popup opens with showModal().");
67
+ }
68
+ dialog = element;
69
+ },
70
+ });
71
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby"));
72
+ return renderElement(props, elementProps, (p) => (<dialog {...p}/>));
73
+ }
@@ -0,0 +1,20 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
3
+ export interface DialogRootProps {
4
+ /** Whether the dialog is open, when controlled. */
5
+ open?: boolean;
6
+ /** Whether the dialog is open at first, when uncontrolled. */
7
+ defaultOpen?: boolean;
8
+ /**
9
+ * Called with the new value, and why, when the user opens or closes the
10
+ * dialog. When controlled, the dialog changes only if `open` does.
11
+ */
12
+ onOpenChange?: (open: boolean, details: OpenChangeDetails) => void;
13
+ children?: JSX.Element;
14
+ }
15
+ /**
16
+ * A modal dialog: holds whether it is open and shares it with
17
+ * `Dialog.Trigger`, `Dialog.Popup` and the parts inside it. Renders no
18
+ * element of its own.
19
+ */
20
+ export declare function DialogRoot(props: DialogRootProps): JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
2
+ import { createIdSlot } from "../../core/slot.js";
3
+ import { DialogRootContext } from "./DialogRootContext.js";
4
+ /**
5
+ * A modal dialog: holds whether it is open and shares it with
6
+ * `Dialog.Trigger`, `Dialog.Popup` and the parts inside it. Renders no
7
+ * element of its own.
8
+ */
9
+ export function DialogRoot(props) {
10
+ const [open, setOpen] = createControllableSignal({
11
+ get value() {
12
+ return props.open;
13
+ },
14
+ get defaultValue() {
15
+ return props.defaultOpen ?? false;
16
+ },
17
+ onChange: (value, details) => props.onOpenChange?.(value, details),
18
+ });
19
+ const attributes = {
20
+ get "data-open"() {
21
+ return open() ? "" : undefined;
22
+ },
23
+ get "data-closed"() {
24
+ return open() ? undefined : "";
25
+ },
26
+ };
27
+ const [titleId, registerTitleId] = createIdSlot();
28
+ const [descriptionId, registerDescriptionId] = createIdSlot();
29
+ const context = {
30
+ open,
31
+ setOpen,
32
+ titleId,
33
+ registerTitleId,
34
+ descriptionId,
35
+ registerDescriptionId,
36
+ attributes,
37
+ };
38
+ return (<DialogRootContext value={context}>{props.children}</DialogRootContext>);
39
+ }
@@ -0,0 +1,32 @@
1
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
2
+ /**
3
+ * The dialog's state as `data-*` attributes, each `""` when it applies and
4
+ * absent otherwise: one of `data-open` and `data-closed`. Every part merges
5
+ * the same object, so its getters are read where each element uses them.
6
+ */
7
+ export type DialogStateAttributes = {
8
+ readonly "data-open": "" | undefined;
9
+ readonly "data-closed": "" | undefined;
10
+ };
11
+ /** What the Root shares with its parts. */
12
+ export interface DialogRootContextValue {
13
+ /** Whether the dialog is open. */
14
+ open(): boolean;
15
+ /** Asks to open or close the dialog, saying why. */
16
+ setOpen(open: boolean, details: OpenChangeDetails): void;
17
+ /** The `id` of the rendered Title, which the Popup names, if any. */
18
+ titleId(): string | undefined;
19
+ /**
20
+ * Registers the `id` of a mounted Title, as a getter. Returns what
21
+ * unregisters it, for the Title's disposal.
22
+ */
23
+ registerTitleId(id: () => string | false): () => void;
24
+ /** The `id` of the rendered Description, which the Popup names, if any. */
25
+ descriptionId(): string | undefined;
26
+ /** As `registerTitleId`, for the Description. */
27
+ registerDescriptionId(id: () => string | false): () => void;
28
+ /** The `data-*` attributes every part carries. */
29
+ readonly attributes: DialogStateAttributes;
30
+ }
31
+ export declare const DialogRootContext: import("solid-js").Context<DialogRootContextValue | null>;
32
+ export declare function useDialogRootContext(): DialogRootContextValue;
@@ -0,0 +1,14 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ // `null` outside a Root, so that the part can name what is missing. Solid's
4
+ // own error for a context with no provider and no default does not.
5
+ export const DialogRootContext = createContext(null);
6
+ export function useDialogRootContext() {
7
+ const context = useContext(DialogRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ // Alert Dialog's parts are Dialog's (#32), and cannot tell which.
11
+ throw new Error("[menhir] Dialog parts must be placed within <Dialog.Root>, and Alert Dialog parts within <AlertDialog.Root>.");
12
+ }
13
+ return context;
14
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface DialogTitleProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The dialog's title, which names the Popup in `aria-labelledby`: an
8
+ * `<h2>`. Place it inside `Dialog.Popup`.
9
+ */
10
+ export declare function DialogTitle(props: DialogTitleProps): JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { createUniqueId, merge, omit, onSettled } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
5
+ /**
6
+ * The dialog's title, which names the Popup in `aria-labelledby`: an
7
+ * `<h2>`. Place it inside `Dialog.Popup`.
8
+ */
9
+ export function DialogTitle(props) {
10
+ const root = useDialogRootContext();
11
+ const generated = createUniqueId();
12
+ // The consumer's `id`, else the generated one. Kept out of the merge,
13
+ // where a wrapper's `id={undefined}` would remove it ("`undefined` is a
14
+ // value", PLAN.md section 8).
15
+ const id = () => props.id ?? generated;
16
+ // Named once mounted, so the Popup names only a Title that is rendered,
17
+ // and none in the server HTML (README, "Decisions").
18
+ onSettled(() => root.registerTitleId(id));
19
+ const ownProps = merge(root.attributes, {
20
+ get id() {
21
+ return id();
22
+ },
23
+ });
24
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
25
+ return renderElement(props, elementProps, (p) => <h2 {...p}/>);
26
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface DialogTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that opens the dialog: a `<button type="button"
8
+ * aria-haspopup="dialog">`. Place it inside `Dialog.Root`.
9
+ */
10
+ export declare function DialogTrigger(props: DialogTriggerProps): JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { 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 { useDialogRootContext } from "../root/DialogRootContext.js";
7
+ /**
8
+ * The button that opens the dialog: a `<button type="button"
9
+ * aria-haspopup="dialog">`. Place it inside `Dialog.Root`.
10
+ */
11
+ export function DialogTrigger(props) {
12
+ const root = useDialogRootContext();
13
+ // No `aria-expanded`: the Trigger is inert while the dialog is open. No
14
+ // `aria-controls`: the closed dialog is not shown (README, "Decisions").
15
+ const ownProps = merge(root.attributes, {
16
+ type: "button",
17
+ "aria-haspopup": "dialog",
18
+ onClick: (event) => root.setOpen(true, { reason: "trigger-press", event }),
19
+ ref: (element) => {
20
+ // Production builds drop the check with `isDev`.
21
+ if (isDev)
22
+ warnUnlessButton(element, "Dialog.Trigger");
23
+ },
24
+ });
25
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
26
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
27
+ }
@@ -0,0 +1,26 @@
1
+ import type { OpenChangeDetails } from "./reason.ts";
2
+ /**
3
+ * Reports a modal `<dialog>` that the browser closes, while `open`: Escape
4
+ * and other close requests (`cancel`), and a `<form method="dialog">`
5
+ * (`close`). The popup closes through its own state:
6
+ *
7
+ * ```ts
8
+ * createDialogClose({
9
+ * get dialog() { return dialog; },
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * `cancel` is always prevented, so the state decides. The browser closes
16
+ * the dialog anyway when `cancel` cannot be prevented, such as on a second
17
+ * Escape: that close is reported once, and if the state still says open
18
+ * once it has settled, the dialog is opened again with `showModal()`. A
19
+ * close the popup made itself, after its state turned false, is not
20
+ * reported.
21
+ */
22
+ export declare function createDialogClose(options: {
23
+ readonly dialog: HTMLDialogElement | undefined;
24
+ readonly open: boolean;
25
+ onDismiss(details: OpenChangeDetails): void;
26
+ }): void;
@@ -0,0 +1,69 @@
1
+ import { createEffect, onFlush } from "solid-js";
2
+ /**
3
+ * Reports a modal `<dialog>` that the browser closes, while `open`: Escape
4
+ * and other close requests (`cancel`), and a `<form method="dialog">`
5
+ * (`close`). The popup closes through its own state:
6
+ *
7
+ * ```ts
8
+ * createDialogClose({
9
+ * get dialog() { return dialog; },
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * `cancel` is always prevented, so the state decides. The browser closes
16
+ * the dialog anyway when `cancel` cannot be prevented, such as on a second
17
+ * Escape: that close is reported once, and if the state still says open
18
+ * once it has settled, the dialog is opened again with `showModal()`. A
19
+ * close the popup made itself, after its state turned false, is not
20
+ * reported.
21
+ */
22
+ export function createDialogClose(options) {
23
+ createEffect(() => options.open, (open) => {
24
+ const dialog = options.dialog;
25
+ if (!open || !dialog)
26
+ return;
27
+ // The browser fires `cancel` while it handles the key, in the same
28
+ // task, so an Escape of this task is the reason. A timer forgets it.
29
+ let escapeKey;
30
+ const keydown = (event) => {
31
+ if (event.key !== "Escape")
32
+ return;
33
+ escapeKey = event;
34
+ setTimeout(() => {
35
+ if (escapeKey === event)
36
+ escapeKey = undefined;
37
+ });
38
+ };
39
+ // Set when the `close` that follows a `cancel` that could not be
40
+ // prevented has been reported already.
41
+ let reported = false;
42
+ const cancel = (event) => {
43
+ event.preventDefault();
44
+ reported = !event.cancelable;
45
+ options.onDismiss(escapeKey
46
+ ? { reason: "escape-key", event: escapeKey }
47
+ : { reason: "close-request", event });
48
+ };
49
+ const close = (event) => {
50
+ if (!reported)
51
+ options.onDismiss({ reason: "close-request", event });
52
+ reported = false;
53
+ // After the popup's own write (`createControllableSignal` defers it
54
+ // with `onFlush` too), so a refused close is the only one left open.
55
+ onFlush(() => {
56
+ if (options.open && !dialog.open)
57
+ dialog.showModal();
58
+ });
59
+ };
60
+ document.addEventListener("keydown", keydown, true);
61
+ dialog.addEventListener("cancel", cancel);
62
+ dialog.addEventListener("close", close);
63
+ return () => {
64
+ document.removeEventListener("keydown", keydown, true);
65
+ dialog.removeEventListener("cancel", cancel);
66
+ dialog.removeEventListener("close", close);
67
+ };
68
+ });
69
+ }
@@ -0,0 +1,24 @@
1
+ import type { OpenChangeDetails } from "./reason.ts";
2
+ /**
3
+ * Escape for a popup the browser does not close on Escape, a `manual`
4
+ * popover such as Tooltip's, or for content in the page's flow, such as
5
+ * Navigation Menu's Panels. While `open`, an Escape key calls `onDismiss`
6
+ * with the reason `escape-key`:
7
+ *
8
+ * ```ts
9
+ * createEscape({
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * Only the popup opened last closes, one per key. The key is marked
16
+ * handled (`preventDefault()`), so the browser does not also close a dialog
17
+ * or popover below, and carries on to the page's own listeners. A key
18
+ * already handled, or one pressed while an input method is composing, does
19
+ * nothing.
20
+ */
21
+ export declare function createEscape(options: {
22
+ readonly open: boolean;
23
+ onDismiss(details: OpenChangeDetails): void;
24
+ }): void;
@@ -0,0 +1,48 @@
1
+ import { createEffect } from "solid-js";
2
+ /**
3
+ * Escape for a popup the browser does not close on Escape, a `manual`
4
+ * popover such as Tooltip's, or for content in the page's flow, such as
5
+ * Navigation Menu's Panels. While `open`, an Escape key calls `onDismiss`
6
+ * with the reason `escape-key`:
7
+ *
8
+ * ```ts
9
+ * createEscape({
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * Only the popup opened last closes, one per key. The key is marked
16
+ * handled (`preventDefault()`), so the browser does not also close a dialog
17
+ * or popover below, and carries on to the page's own listeners. A key
18
+ * already handled, or one pressed while an input method is composing, does
19
+ * nothing.
20
+ */
21
+ export function createEscape(options) {
22
+ createEffect(() => options.open, (open) => {
23
+ if (!open)
24
+ return;
25
+ // Listeners of one target and phase run in the order they were
26
+ // added, and each popup adds its own when it opens. In the capture
27
+ // phase, the one opened last claims the key last; in the bubble
28
+ // phase, after the page's listeners, only the claim holder closes.
29
+ const claim = (event) => {
30
+ event.menhirEscapeClaim = claim;
31
+ };
32
+ const close = (event) => {
33
+ if (event.key !== "Escape" ||
34
+ event.isComposing ||
35
+ event.defaultPrevented ||
36
+ event.menhirEscapeClaim !== claim)
37
+ return;
38
+ event.preventDefault();
39
+ options.onDismiss({ reason: "escape-key", event });
40
+ };
41
+ document.addEventListener("keydown", claim, true);
42
+ document.addEventListener("keydown", close);
43
+ return () => {
44
+ document.removeEventListener("keydown", claim, true);
45
+ document.removeEventListener("keydown", close);
46
+ };
47
+ });
48
+ }
@@ -0,0 +1,26 @@
1
+ import type { OpenChangeDetails } from "./reason.ts";
2
+ /**
3
+ * Reports a press on a modal `<dialog>`'s backdrop, while `open`, with the
4
+ * reason `outside-press`. The popup closes through its own state:
5
+ *
6
+ * ```ts
7
+ * createOutsidePress({
8
+ * get dialog() { return dialog; },
9
+ * get open() { return open(); },
10
+ * onDismiss: (details) => setOpen(false, details),
11
+ * });
12
+ * ```
13
+ *
14
+ * A press on the backdrop targets the `<dialog>` itself, as one on its
15
+ * padding or its own scrollbar does, so the backdrop is where the target is
16
+ * the dialog and the point is outside its border box. It closes on release,
17
+ * as the browser's light dismiss does: on the `click` of a primary-button
18
+ * press that also started on the backdrop. So a press dragged out of the
19
+ * dialog, a secondary button (no `click`) and a touch that scrolls
20
+ * (`pointercancel`, no `click`) do not close it.
21
+ */
22
+ export declare function createOutsidePress(options: {
23
+ readonly dialog: HTMLDialogElement | undefined;
24
+ readonly open: boolean;
25
+ onDismiss(details: OpenChangeDetails): void;
26
+ }): void;
@@ -0,0 +1,50 @@
1
+ import { createEffect } from "solid-js";
2
+ /**
3
+ * Reports a press on a modal `<dialog>`'s backdrop, while `open`, with the
4
+ * reason `outside-press`. The popup closes through its own state:
5
+ *
6
+ * ```ts
7
+ * createOutsidePress({
8
+ * get dialog() { return dialog; },
9
+ * get open() { return open(); },
10
+ * onDismiss: (details) => setOpen(false, details),
11
+ * });
12
+ * ```
13
+ *
14
+ * A press on the backdrop targets the `<dialog>` itself, as one on its
15
+ * padding or its own scrollbar does, so the backdrop is where the target is
16
+ * the dialog and the point is outside its border box. It closes on release,
17
+ * as the browser's light dismiss does: on the `click` of a primary-button
18
+ * press that also started on the backdrop. So a press dragged out of the
19
+ * dialog, a secondary button (no `click`) and a touch that scrolls
20
+ * (`pointercancel`, no `click`) do not close it.
21
+ */
22
+ export function createOutsidePress(options) {
23
+ createEffect(() => options.open, (open) => {
24
+ const dialog = options.dialog;
25
+ if (!open || !dialog)
26
+ return;
27
+ const onBackdrop = (event) => {
28
+ if (event.target !== dialog)
29
+ return false;
30
+ const { left, top, right, bottom } = dialog.getBoundingClientRect();
31
+ const { clientX: x, clientY: y } = event;
32
+ return x < left || x > right || y < top || y > bottom;
33
+ };
34
+ let pressed = false;
35
+ const pointerdown = (event) => {
36
+ pressed = event.button === 0 && onBackdrop(event);
37
+ };
38
+ const click = (event) => {
39
+ if (pressed && onBackdrop(event))
40
+ options.onDismiss({ reason: "outside-press", event });
41
+ pressed = false;
42
+ };
43
+ dialog.addEventListener("pointerdown", pointerdown);
44
+ dialog.addEventListener("click", click);
45
+ return () => {
46
+ dialog.removeEventListener("pointerdown", pointerdown);
47
+ dialog.removeEventListener("click", click);
48
+ };
49
+ });
50
+ }
@@ -0,0 +1,28 @@
1
+ import type { OpenChangeDetails } from "./reason.ts";
2
+ /**
3
+ * Reports an `auto` popover that the browser closes, while `open`, with the
4
+ * reason. The popup closes through its own state:
5
+ *
6
+ * ```ts
7
+ * createPopoverClose({
8
+ * get popup() { return popup; },
9
+ * get trigger() { return trigger; },
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * The reason is the input event of the same task: an Escape key
16
+ * (`escape-key`), a pointer released outside the popover (`outside-press`,
17
+ * the browser's light dismiss) or a release or click on the trigger
18
+ * (`trigger-press`, its `popovertarget`); else `close-request`. The
19
+ * browser's close cannot be refused, so if the state still says open once
20
+ * it has settled, the popover is shown again. A close the popup made
21
+ * itself, after its state turned false, is not reported.
22
+ */
23
+ export declare function createPopoverClose(options: {
24
+ readonly popup: HTMLElement | undefined;
25
+ readonly trigger: Element | undefined;
26
+ readonly open: boolean;
27
+ onDismiss(details: OpenChangeDetails): void;
28
+ }): void;
@@ -0,0 +1,82 @@
1
+ import { createEffect } from "solid-js";
2
+ /**
3
+ * Reports an `auto` popover that the browser closes, while `open`, with the
4
+ * reason. The popup closes through its own state:
5
+ *
6
+ * ```ts
7
+ * createPopoverClose({
8
+ * get popup() { return popup; },
9
+ * get trigger() { return trigger; },
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * The reason is the input event of the same task: an Escape key
16
+ * (`escape-key`), a pointer released outside the popover (`outside-press`,
17
+ * the browser's light dismiss) or a release or click on the trigger
18
+ * (`trigger-press`, its `popovertarget`); else `close-request`. The
19
+ * browser's close cannot be refused, so if the state still says open once
20
+ * it has settled, the popover is shown again. A close the popup made
21
+ * itself, after its state turned false, is not reported.
22
+ */
23
+ export function createPopoverClose(options) {
24
+ createEffect(() => options.open, (open) => {
25
+ const popup = options.popup;
26
+ if (!open || !popup)
27
+ return;
28
+ // The browser fires `beforetoggle` while it handles the key or press
29
+ // that closes the popover, in the same task, so the input event of
30
+ // this task is the reason. A timer forgets it.
31
+ let cause;
32
+ const note = (reason, event) => {
33
+ const noted = { reason, event };
34
+ cause = noted;
35
+ setTimeout(() => {
36
+ if (cause === noted)
37
+ cause = undefined;
38
+ });
39
+ };
40
+ const keydown = (event) => {
41
+ if (event.key === "Escape")
42
+ note("escape-key", event);
43
+ };
44
+ // Light dismiss closes on `pointerup`. `popovertarget` toggles on
45
+ // `click`, which a key fires too, so a click counts only on the
46
+ // trigger: a key on another popover's trigger is no press outside.
47
+ const pointerup = (event) => {
48
+ const target = event.target;
49
+ if (options.trigger?.contains(target))
50
+ note("trigger-press", event);
51
+ else if (!popup.contains(target))
52
+ note("outside-press", event);
53
+ };
54
+ const click = (event) => {
55
+ if (options.trigger?.contains(event.target))
56
+ note("trigger-press", event);
57
+ };
58
+ const beforetoggle = (event) => {
59
+ if (event.newState !== "closed" || !options.open)
60
+ return;
61
+ options.onDismiss(cause ?? { reason: "close-request", event });
62
+ };
63
+ // `toggle` comes a task after the popover is hidden, when the popup's
64
+ // own write has landed, so a refused close is the only one still open.
65
+ const toggle = () => {
66
+ if (options.open && !popup.matches(":popover-open"))
67
+ popup.showPopover();
68
+ };
69
+ document.addEventListener("keydown", keydown, true);
70
+ document.addEventListener("pointerup", pointerup, true);
71
+ document.addEventListener("click", click, true);
72
+ popup.addEventListener("beforetoggle", beforetoggle);
73
+ popup.addEventListener("toggle", toggle);
74
+ return () => {
75
+ document.removeEventListener("keydown", keydown, true);
76
+ document.removeEventListener("pointerup", pointerup, true);
77
+ document.removeEventListener("click", click, true);
78
+ popup.removeEventListener("beforetoggle", beforetoggle);
79
+ popup.removeEventListener("toggle", toggle);
80
+ };
81
+ });
82
+ }