menhir 0.1.1 → 0.1.3

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 (176) hide show
  1. package/README.md +2 -2
  2. package/dist/alert-dialog/index.js +2 -0
  3. package/dist/alert-dialog/index.parts.js +7 -0
  4. package/dist/alert-dialog/popup/AlertDialogPopup.js +13 -0
  5. package/dist/core/createControllableSignal.js +4 -3
  6. package/dist/core/slot.js +30 -0
  7. package/dist/dialog/close/DialogClose.js +33 -0
  8. package/dist/dialog/description/DialogDescription.js +27 -0
  9. package/dist/dialog/index.js +2 -0
  10. package/dist/dialog/index.parts.js +7 -0
  11. package/dist/dialog/popup/DialogPopup.js +13 -0
  12. package/dist/dialog/popup/renderDialogPopup.js +71 -0
  13. package/dist/dialog/root/DialogRoot.js +46 -0
  14. package/dist/dialog/root/DialogRootContext.js +10 -0
  15. package/dist/dialog/title/DialogTitle.js +27 -0
  16. package/dist/dialog/trigger/DialogTrigger.js +33 -0
  17. package/dist/floating/dismissal/dialogClose.js +67 -0
  18. package/dist/floating/dismissal/escape.js +43 -0
  19. package/dist/floating/dismissal/outsidePress.js +52 -0
  20. package/dist/floating/dismissal/popoverClose.js +74 -0
  21. package/dist/floating/dismissal/reason.js +0 -0
  22. package/dist/floating/focus/initialFocus.js +33 -0
  23. package/dist/floating/focus/returnFocus.js +65 -0
  24. package/dist/floating/focus/tabWrap.js +55 -0
  25. package/dist/floating/focus/tabbable.js +50 -0
  26. package/dist/floating/focus/target.js +0 -0
  27. package/dist/floating/hover/group.js +36 -0
  28. package/dist/floating/hover/hover.js +105 -0
  29. package/dist/floating/hover/safeArea.js +64 -0
  30. package/dist/floating/positioning/arrow.js +21 -0
  31. package/dist/floating/positioning/createPosition.js +122 -0
  32. package/dist/floating/positioning/flip.js +1 -0
  33. package/dist/floating/positioning/hide.js +14 -0
  34. package/dist/floating/positioning/offset.js +1 -0
  35. package/dist/floating/positioning/shift.js +1 -0
  36. package/dist/floating/positioning/size.js +39 -0
  37. package/dist/floating/presence/presence.js +57 -0
  38. package/dist/floating/scroll-lock/scrollLock.js +125 -0
  39. package/dist/popover/arrow/PopoverArrow.js +39 -0
  40. package/dist/popover/close/PopoverClose.js +33 -0
  41. package/dist/popover/description/PopoverDescription.js +27 -0
  42. package/dist/popover/index.js +2 -0
  43. package/dist/popover/index.parts.js +8 -0
  44. package/dist/popover/popup/PopoverPopup.js +116 -0
  45. package/dist/popover/popup/PopoverPopupContext.js +10 -0
  46. package/dist/popover/root/PopoverRoot.js +50 -0
  47. package/dist/popover/root/PopoverRootContext.js +10 -0
  48. package/dist/popover/title/PopoverTitle.js +27 -0
  49. package/dist/popover/trigger/PopoverTrigger.js +44 -0
  50. package/dist/source/alert-dialog/index.d.ts +1 -0
  51. package/dist/source/alert-dialog/index.js +1 -0
  52. package/dist/source/alert-dialog/index.parts.d.ts +6 -0
  53. package/dist/source/alert-dialog/index.parts.js +7 -0
  54. package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
  55. package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
  56. package/dist/source/core/createControllableSignal.d.ts +5 -4
  57. package/dist/source/core/createControllableSignal.js +4 -3
  58. package/dist/source/core/slot.d.ts +21 -0
  59. package/dist/source/core/slot.js +28 -0
  60. package/dist/source/dialog/close/DialogClose.d.ts +11 -0
  61. package/dist/source/dialog/close/DialogClose.jsx +25 -0
  62. package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
  63. package/dist/source/dialog/description/DialogDescription.jsx +26 -0
  64. package/dist/source/dialog/index.d.ts +1 -0
  65. package/dist/source/dialog/index.js +1 -0
  66. package/dist/source/dialog/index.parts.d.ts +6 -0
  67. package/dist/source/dialog/index.parts.js +6 -0
  68. package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
  69. package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
  70. package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
  71. package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
  72. package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
  73. package/dist/source/dialog/root/DialogRoot.jsx +39 -0
  74. package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
  75. package/dist/source/dialog/root/DialogRootContext.js +14 -0
  76. package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
  77. package/dist/source/dialog/title/DialogTitle.jsx +26 -0
  78. package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
  79. package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
  80. package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
  81. package/dist/source/floating/dismissal/dialogClose.js +69 -0
  82. package/dist/source/floating/dismissal/escape.d.ts +23 -0
  83. package/dist/source/floating/dismissal/escape.js +47 -0
  84. package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
  85. package/dist/source/floating/dismissal/outsidePress.js +50 -0
  86. package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
  87. package/dist/source/floating/dismissal/popoverClose.js +82 -0
  88. package/dist/source/floating/dismissal/reason.d.ts +30 -0
  89. package/dist/source/floating/dismissal/reason.js +1 -0
  90. package/dist/source/floating/focus/initialFocus.d.ts +24 -0
  91. package/dist/source/floating/focus/initialFocus.js +38 -0
  92. package/dist/source/floating/focus/returnFocus.d.ts +27 -0
  93. package/dist/source/floating/focus/returnFocus.js +81 -0
  94. package/dist/source/floating/focus/tabWrap.d.ts +21 -0
  95. package/dist/source/floating/focus/tabWrap.js +69 -0
  96. package/dist/source/floating/focus/tabbable.d.ts +16 -0
  97. package/dist/source/floating/focus/tabbable.js +69 -0
  98. package/dist/source/floating/focus/target.d.ts +8 -0
  99. package/dist/source/floating/focus/target.js +1 -0
  100. package/dist/source/floating/hover/group.d.ts +39 -0
  101. package/dist/source/floating/hover/group.js +38 -0
  102. package/dist/source/floating/hover/hover.d.ts +35 -0
  103. package/dist/source/floating/hover/hover.js +130 -0
  104. package/dist/source/floating/hover/safeArea.d.ts +23 -0
  105. package/dist/source/floating/hover/safeArea.js +67 -0
  106. package/dist/source/floating/positioning/arrow.d.ts +13 -0
  107. package/dist/source/floating/positioning/arrow.js +20 -0
  108. package/dist/source/floating/positioning/createPosition.d.ts +53 -0
  109. package/dist/source/floating/positioning/createPosition.js +138 -0
  110. package/dist/source/floating/positioning/flip.d.ts +1 -0
  111. package/dist/source/floating/positioning/flip.js +3 -0
  112. package/dist/source/floating/positioning/hide.d.ts +8 -0
  113. package/dist/source/floating/positioning/hide.js +12 -0
  114. package/dist/source/floating/positioning/offset.d.ts +1 -0
  115. package/dist/source/floating/positioning/offset.js +3 -0
  116. package/dist/source/floating/positioning/shift.d.ts +1 -0
  117. package/dist/source/floating/positioning/shift.js +2 -0
  118. package/dist/source/floating/positioning/size.d.ts +12 -0
  119. package/dist/source/floating/positioning/size.js +35 -0
  120. package/dist/source/floating/presence/presence.d.ts +24 -0
  121. package/dist/source/floating/presence/presence.js +73 -0
  122. package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
  123. package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
  124. package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
  125. package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
  126. package/dist/source/popover/close/PopoverClose.d.ts +11 -0
  127. package/dist/source/popover/close/PopoverClose.jsx +25 -0
  128. package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
  129. package/dist/source/popover/description/PopoverDescription.jsx +26 -0
  130. package/dist/source/popover/index.d.ts +1 -0
  131. package/dist/source/popover/index.js +1 -0
  132. package/dist/source/popover/index.parts.d.ts +7 -0
  133. package/dist/source/popover/index.parts.js +7 -0
  134. package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
  135. package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
  136. package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
  137. package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
  138. package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
  139. package/dist/source/popover/root/PopoverRoot.jsx +42 -0
  140. package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
  141. package/dist/source/popover/root/PopoverRootContext.js +13 -0
  142. package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
  143. package/dist/source/popover/title/PopoverTitle.jsx +26 -0
  144. package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
  145. package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
  146. package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
  147. package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
  148. package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
  149. package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
  150. package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
  151. package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
  152. package/dist/source/tooltip/index.d.ts +1 -0
  153. package/dist/source/tooltip/index.js +1 -0
  154. package/dist/source/tooltip/index.parts.d.ts +5 -0
  155. package/dist/source/tooltip/index.parts.js +5 -0
  156. package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
  157. package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
  158. package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
  159. package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
  160. package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
  161. package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
  162. package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
  163. package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
  164. package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
  165. package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
  166. package/dist/tooltip/arrow/TooltipArrow.js +39 -0
  167. package/dist/tooltip/group/TooltipGroup.js +26 -0
  168. package/dist/tooltip/group/TooltipGroupContext.js +4 -0
  169. package/dist/tooltip/index.js +2 -0
  170. package/dist/tooltip/index.parts.js +6 -0
  171. package/dist/tooltip/popup/TooltipPopup.js +86 -0
  172. package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
  173. package/dist/tooltip/root/TooltipRoot.js +79 -0
  174. package/dist/tooltip/root/TooltipRootContext.js +10 -0
  175. package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
  176. package/package.json +24 -1
@@ -0,0 +1,25 @@
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
+ * A button that closes the dialog: a `<button type="button">`, such as
9
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
10
+ * `Dialog.Popup`.
11
+ */
12
+ export function DialogClose(props) {
13
+ const root = useDialogRootContext();
14
+ const ownProps = merge(root.attributes, {
15
+ type: "button",
16
+ onClick: (event) => root.setOpen(false, { reason: "close-press", event }),
17
+ ref: (element) => {
18
+ // Production builds drop the check with `isDev`.
19
+ if (isDev)
20
+ warnUnlessButton(element, "Dialog.Close");
21
+ },
22
+ });
23
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
24
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
25
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface DialogDescriptionProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * What the dialog is for, which describes the Popup in
8
+ * `aria-describedby`: a `<p>`. Place it inside `Dialog.Popup`.
9
+ */
10
+ export declare function DialogDescription(props: DialogDescriptionProps): 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
+ * What the dialog is for, which describes the Popup in
7
+ * `aria-describedby`: a `<p>`. Place it inside `Dialog.Popup`.
8
+ */
9
+ export function DialogDescription(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 Description that is
17
+ // rendered, and none in the server HTML (README, "Decisions").
18
+ onSettled(() => root.registerDescriptionId(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) => <p {...p}/>);
26
+ }
@@ -0,0 +1 @@
1
+ export * as Dialog from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Dialog from "./index.parts.js";
@@ -0,0 +1,6 @@
1
+ export { DialogRoot as Root } from "./root/DialogRoot.tsx";
2
+ export { DialogTrigger as Trigger } from "./trigger/DialogTrigger.tsx";
3
+ export { DialogPopup as Popup } from "./popup/DialogPopup.tsx";
4
+ export { DialogTitle as Title } from "./title/DialogTitle.tsx";
5
+ export { DialogDescription as Description } from "./description/DialogDescription.tsx";
6
+ export { DialogClose as Close } from "./close/DialogClose.tsx";
@@ -0,0 +1,6 @@
1
+ export { DialogRoot as Root } from "./root/DialogRoot.jsx";
2
+ export { DialogTrigger as Trigger } from "./trigger/DialogTrigger.jsx";
3
+ export { DialogPopup as Popup } from "./popup/DialogPopup.jsx";
4
+ export { DialogTitle as Title } from "./title/DialogTitle.jsx";
5
+ export { DialogDescription as Description } from "./description/DialogDescription.jsx";
6
+ export { DialogClose as Close } from "./close/DialogClose.jsx";
@@ -0,0 +1,9 @@
1
+ import type { DialogPopupProps } from "./renderDialogPopup.tsx";
2
+ export type { DialogPopupProps } from "./renderDialogPopup.tsx";
3
+ /**
4
+ * The dialog itself: a `<dialog>`, opened with `showModal()`, so it is
5
+ * modal, in the top layer, over an inert page. Named by `Dialog.Title` and
6
+ * described by `Dialog.Description` when they are rendered inside it. A
7
+ * press on the backdrop closes it. Place it inside `Dialog.Root`.
8
+ */
9
+ export declare function DialogPopup(props: DialogPopupProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { createOutsidePress } from "../../floating/dismissal/outsidePress.js";
2
+ import { renderDialogPopup } from "./renderDialogPopup.jsx";
3
+ /**
4
+ * The dialog itself: a `<dialog>`, opened with `showModal()`, so it is
5
+ * modal, in the top layer, over an inert page. Named by `Dialog.Title` and
6
+ * described by `Dialog.Description` when they are rendered inside it. A
7
+ * press on the backdrop closes it. Place it inside `Dialog.Root`.
8
+ */
9
+ export function DialogPopup(props) {
10
+ return renderDialogPopup(props, createOutsidePress);
11
+ }
@@ -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,23 @@
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. While `open`, an Escape key calls `onDismiss`
5
+ * with the reason `escape-key`:
6
+ *
7
+ * ```ts
8
+ * createEscape({
9
+ * get open() { return open(); },
10
+ * onDismiss: (details) => setOpen(false, details),
11
+ * });
12
+ * ```
13
+ *
14
+ * Only the popup opened last closes, one per key. The key is marked
15
+ * handled (`preventDefault()`), so the browser does not also close a dialog
16
+ * or popover below, and carries on to the page's own listeners. A key
17
+ * already handled, or one pressed while an input method is composing, does
18
+ * nothing.
19
+ */
20
+ export declare function createEscape(options: {
21
+ readonly open: boolean;
22
+ onDismiss(details: OpenChangeDetails): void;
23
+ }): void;
@@ -0,0 +1,47 @@
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. While `open`, an Escape key calls `onDismiss`
5
+ * with the reason `escape-key`:
6
+ *
7
+ * ```ts
8
+ * createEscape({
9
+ * get open() { return open(); },
10
+ * onDismiss: (details) => setOpen(false, details),
11
+ * });
12
+ * ```
13
+ *
14
+ * Only the popup opened last closes, one per key. The key is marked
15
+ * handled (`preventDefault()`), so the browser does not also close a dialog
16
+ * or popover below, and carries on to the page's own listeners. A key
17
+ * already handled, or one pressed while an input method is composing, does
18
+ * nothing.
19
+ */
20
+ export function createEscape(options) {
21
+ createEffect(() => options.open, (open) => {
22
+ if (!open)
23
+ return;
24
+ // Listeners of one target and phase run in the order they were
25
+ // added, and each popup adds its own when it opens. In the capture
26
+ // phase, the one opened last claims the key last; in the bubble
27
+ // phase, after the page's listeners, only the claim holder closes.
28
+ const claim = (event) => {
29
+ event.menhirEscapeClaim = claim;
30
+ };
31
+ const close = (event) => {
32
+ if (event.key !== "Escape" ||
33
+ event.isComposing ||
34
+ event.defaultPrevented ||
35
+ event.menhirEscapeClaim !== claim)
36
+ return;
37
+ event.preventDefault();
38
+ options.onDismiss({ reason: "escape-key", event });
39
+ };
40
+ document.addEventListener("keydown", claim, true);
41
+ document.addEventListener("keydown", close);
42
+ return () => {
43
+ document.removeEventListener("keydown", claim, true);
44
+ document.removeEventListener("keydown", close);
45
+ };
46
+ });
47
+ }
@@ -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;