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,73 @@
1
+ import { createEffect } from "solid-js";
2
+ /**
3
+ * Shows a popup when `open` turns true, and hides it once its exit
4
+ * animations have ended after `open` turns false:
5
+ *
6
+ * ```ts
7
+ * createPresence({
8
+ * get popup() { return dialog; },
9
+ * get open() { return open(); },
10
+ * });
11
+ * ```
12
+ *
13
+ * A `<dialog>` is shown with `showModal()` and hidden with `close()`; any
14
+ * other element is a popover, shown with `showPopover()` and hidden with
15
+ * `hidePopover()`. On closing it waits for the animations and transitions
16
+ * running in the popup, its descendants and its `::backdrop`, the ones its
17
+ * `data-closed` starts, and hides it at once if none is running; infinite
18
+ * and paused ones do not count. Meanwhile the popup is `inert`, unless it is
19
+ * a popover that holds focus, which only returns focus to its trigger from
20
+ * inside. Opening again cancels the exit. Nothing runs on the server.
21
+ */
22
+ export function createPresence(options) {
23
+ // Ends the exit under way, if any, and puts the popup's `inert` back. A
24
+ // wait whose exit has ended does nothing.
25
+ let stopLeaving;
26
+ createEffect(() => options.open, (open) => {
27
+ const popup = options.popup;
28
+ if (!popup)
29
+ return;
30
+ const dialog = popup instanceof HTMLDialogElement ? popup : undefined;
31
+ stopLeaving?.();
32
+ if (open) {
33
+ // Still shown if it was leaving.
34
+ if (dialog) {
35
+ if (!dialog.open)
36
+ dialog.showModal();
37
+ }
38
+ else if (!popup.matches(":popover-open"))
39
+ popup.showPopover();
40
+ return;
41
+ }
42
+ if (!popup.matches("[open], :popover-open"))
43
+ return;
44
+ const inert = popup.inert;
45
+ if (dialog || !popup.contains(document.activeElement))
46
+ popup.inert = true;
47
+ const stop = (stopLeaving = () => {
48
+ stopLeaving = undefined;
49
+ popup.inert = inert;
50
+ });
51
+ // Asks again once they have settled, for one that started meanwhile.
52
+ // A cancelled animation settles too, as do those of a popup the
53
+ // browser hid or that left the document.
54
+ const wait = () => {
55
+ if (stopLeaving !== stop)
56
+ return;
57
+ const running = popup
58
+ .getAnimations({ subtree: true })
59
+ .filter((animation) => animation.playState === "running" &&
60
+ animation.effect?.getComputedTiming().endTime !== Infinity);
61
+ if (running.length) {
62
+ void Promise.allSettled(running.map((animation) => animation.finished)).then(wait);
63
+ return;
64
+ }
65
+ stop();
66
+ if (dialog)
67
+ dialog.close();
68
+ else if (popup.matches(":popover-open"))
69
+ popup.hidePopover();
70
+ };
71
+ wait();
72
+ });
73
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Keeps the page from scrolling while a modal popup is open: `overflow:
3
+ * hidden` on `<html>`, as `showModal()` leaves the page scrolling.
4
+ *
5
+ * ```ts
6
+ * createScrollLock({
7
+ * get popup() { return dialog; },
8
+ * get open() { return open(); },
9
+ * });
10
+ * ```
11
+ *
12
+ * Counted, so nested popups unlock the page when the last one closes. A
13
+ * page with a scrollbar gets its width as padding on `<html>`, so nothing
14
+ * moves, and as `--hidden-scrollbar-width` for `position: fixed` elements;
15
+ * a page with `scrollbar-gutter: stable` gets neither. Unlocking puts back
16
+ * the page's own inline styles. The page unlocks once the popup has
17
+ * closed, not when its state turns false: after the flush that closed it,
18
+ * or on its `close` or `toggle` event if it is still shown then, as while
19
+ * an exit animation runs. A popup disposed while open unlocks it at once.
20
+ * While open, the popup gets `overscroll-behavior: contain` and, if it
21
+ * does not scroll itself, `touch-action: pinch-zoom`, without which iOS
22
+ * Safari scrolls the page from a drag on it or on its backdrop.
23
+ */
24
+ export declare function createScrollLock(options: {
25
+ readonly popup: HTMLElement | undefined;
26
+ readonly open: boolean;
27
+ }): void;
@@ -0,0 +1,151 @@
1
+ import { createEffect, onCleanup } from "solid-js";
2
+ // The popups holding a lock, and what puts the page's own styles back once
3
+ // none does. Written only from effects, which do not run on the server.
4
+ let locks = 0;
5
+ let restoreStyles;
6
+ /**
7
+ * Keeps the page from scrolling while a modal popup is open: `overflow:
8
+ * hidden` on `<html>`, as `showModal()` leaves the page scrolling.
9
+ *
10
+ * ```ts
11
+ * createScrollLock({
12
+ * get popup() { return dialog; },
13
+ * get open() { return open(); },
14
+ * });
15
+ * ```
16
+ *
17
+ * Counted, so nested popups unlock the page when the last one closes. A
18
+ * page with a scrollbar gets its width as padding on `<html>`, so nothing
19
+ * moves, and as `--hidden-scrollbar-width` for `position: fixed` elements;
20
+ * a page with `scrollbar-gutter: stable` gets neither. Unlocking puts back
21
+ * the page's own inline styles. The page unlocks once the popup has
22
+ * closed, not when its state turns false: after the flush that closed it,
23
+ * or on its `close` or `toggle` event if it is still shown then, as while
24
+ * an exit animation runs. A popup disposed while open unlocks it at once.
25
+ * While open, the popup gets `overscroll-behavior: contain` and, if it
26
+ * does not scroll itself, `touch-action: pinch-zoom`, without which iOS
27
+ * Safari scrolls the page from a drag on it or on its backdrop.
28
+ */
29
+ export function createScrollLock(options) {
30
+ // What ends this popup's lock while it holds one, and what ends the wait
31
+ // for it to close, while it is still shown after its state turned false.
32
+ let held;
33
+ let stopWaiting;
34
+ const release = () => {
35
+ stopWaiting?.();
36
+ held?.();
37
+ held = undefined;
38
+ };
39
+ // Disposal releases at once, before the check queued below runs.
40
+ onCleanup(release);
41
+ createEffect(() => options.open, (open) => {
42
+ const popup = options.popup;
43
+ if (!open || !popup)
44
+ return;
45
+ // Opened again before the last closing finished: it keeps its lock.
46
+ stopWaiting?.();
47
+ if (!held) {
48
+ lock();
49
+ const unlockTouch = lockTouch(popup);
50
+ held = () => {
51
+ unlockTouch();
52
+ unlock();
53
+ };
54
+ }
55
+ return () => {
56
+ // After the popup's own close in this flush, whichever effect runs
57
+ // first. A microtask, not `onFlush`, which is for event handlers:
58
+ // this runs inside the flush.
59
+ queueMicrotask(() => {
60
+ if (!held || stopWaiting)
61
+ return;
62
+ if (!popup.matches("[open], :popover-open"))
63
+ return release();
64
+ const closed = (event) => {
65
+ if (event.newState !== "open")
66
+ release();
67
+ };
68
+ stopWaiting = () => {
69
+ stopWaiting = undefined;
70
+ popup.removeEventListener("close", closed);
71
+ popup.removeEventListener("toggle", closed);
72
+ };
73
+ popup.addEventListener("close", closed);
74
+ popup.addEventListener("toggle", closed);
75
+ });
76
+ };
77
+ });
78
+ }
79
+ function lock() {
80
+ if (locks++)
81
+ return;
82
+ const html = document.documentElement;
83
+ const style = html.style;
84
+ const lockStyles = {
85
+ "overflow-x": "hidden",
86
+ "overflow-y": "hidden",
87
+ };
88
+ // The page's scrollbar, which `overflow: hidden` takes away. A stable
89
+ // gutter stays, so nothing moves.
90
+ const scrollbarWidth = innerWidth - html.clientWidth;
91
+ const computed = getComputedStyle(html);
92
+ if (scrollbarWidth > 0 &&
93
+ !computed.getPropertyValue("scrollbar-gutter").startsWith("stable")) {
94
+ lockStyles["padding-right"] =
95
+ `${parseFloat(computed.paddingRight) + scrollbarWidth}px`;
96
+ lockStyles["--hidden-scrollbar-width"] = `${scrollbarWidth}px`;
97
+ }
98
+ restoreStyles = saveStyles(style, Object.keys(lockStyles));
99
+ for (const name in lockStyles)
100
+ style.setProperty(name, lockStyles[name]);
101
+ }
102
+ function unlock() {
103
+ if (!--locks)
104
+ restoreStyles();
105
+ }
106
+ /**
107
+ * What keeps iOS Safari from scrolling the page through the popup, whatever
108
+ * the page's `overflow`: `overscroll-behavior: contain`, so a popup that
109
+ * scrolls stops at its end, and `touch-action: pinch-zoom` on a popup that
110
+ * does not scroll itself, so that a drag on it, or on its backdrop, which
111
+ * hits the popup, pans nothing. Checked again as the popup or its content
112
+ * changes size. A popup that scrolls keeps its own `touch-action`, since
113
+ * Chromium would no longer scroll it by touch.
114
+ */
115
+ function lockTouch(popup) {
116
+ const style = popup.style;
117
+ const restoreContain = saveStyles(style, ["overscroll-behavior"]);
118
+ const restoreTouch = saveStyles(style, ["touch-action"]);
119
+ style.setProperty("overscroll-behavior", "contain");
120
+ const observer = new ResizeObserver(() => {
121
+ for (const child of popup.children)
122
+ observer.observe(child);
123
+ if (popup.scrollHeight > popup.clientHeight ||
124
+ popup.scrollWidth > popup.clientWidth)
125
+ restoreTouch();
126
+ else
127
+ style.setProperty("touch-action", "pinch-zoom");
128
+ });
129
+ observer.observe(popup);
130
+ return () => {
131
+ observer.disconnect();
132
+ restoreTouch();
133
+ restoreContain();
134
+ };
135
+ }
136
+ /** Saves the inline values of `names`, and returns what puts them back. */
137
+ function saveStyles(style, names) {
138
+ const saved = names.map((name) => [
139
+ name,
140
+ style.getPropertyValue(name),
141
+ style.getPropertyPriority(name),
142
+ ]);
143
+ return () => {
144
+ for (const [name, value, priority] of saved) {
145
+ if (value)
146
+ style.setProperty(name, value, priority);
147
+ else
148
+ style.removeProperty(name);
149
+ }
150
+ };
151
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface PopoverArrowProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * An arrow that points at the anchor's center: an `aria-hidden` `<div>`
8
+ * whose `left` or `top` the Popup writes. Position it absolutely on the
9
+ * Popup's edge by its `data-side`. Place it inside `Popover.Popup`.
10
+ */
11
+ export declare function PopoverArrow(props: PopoverArrowProps): JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { merge, omit, onSettled } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { arrow } from "../../floating/positioning/arrow.js";
5
+ import { usePopoverPopupContext } from "../popup/PopoverPopupContext.js";
6
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
7
+ /**
8
+ * An arrow that points at the anchor's center: an `aria-hidden` `<div>`
9
+ * whose `left` or `top` the Popup writes. Position it absolutely on the
10
+ * Popup's edge by its `data-side`. Place it inside `Popover.Popup`.
11
+ */
12
+ export function PopoverArrow(props) {
13
+ const root = usePopoverRootContext();
14
+ const popup = usePopoverPopupContext();
15
+ let element;
16
+ // Handed over once mounted, when the element is there to measure.
17
+ onSettled(() => popup.registerArrow(() => arrow({ element: element })));
18
+ const ownProps = merge(root.attributes, {
19
+ "aria-hidden": "true",
20
+ get "data-side"() {
21
+ return popup.position()?.side;
22
+ },
23
+ get "data-align"() {
24
+ return popup.position()?.align;
25
+ },
26
+ ref: (el) => {
27
+ element = el;
28
+ },
29
+ });
30
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
31
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
32
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface PopoverCloseProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * A button that closes the popover: a `<button type="button">`, such as
8
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
9
+ * `Popover.Popup`.
10
+ */
11
+ export declare function PopoverClose(props: PopoverCloseProps): JSX.Element;
@@ -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 { usePopoverRootContext } from "../root/PopoverRootContext.js";
7
+ /**
8
+ * A button that closes the popover: a `<button type="button">`, such as
9
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
10
+ * `Popover.Popup`.
11
+ */
12
+ export function PopoverClose(props) {
13
+ const root = usePopoverRootContext();
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, "Popover.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 PopoverDescriptionProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * What the popover is for, which describes the Popup in
8
+ * `aria-describedby`: a `<p>`. Place it inside `Popover.Popup`.
9
+ */
10
+ export declare function PopoverDescription(props: PopoverDescriptionProps): 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 { usePopoverRootContext } from "../root/PopoverRootContext.js";
5
+ /**
6
+ * What the popover is for, which describes the Popup in
7
+ * `aria-describedby`: a `<p>`. Place it inside `Popover.Popup`.
8
+ */
9
+ export function PopoverDescription(props) {
10
+ const root = usePopoverRootContext();
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 Popover from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Popover from "./index.parts.js";
@@ -0,0 +1,7 @@
1
+ export { PopoverRoot as Root } from "./root/PopoverRoot.tsx";
2
+ export { PopoverTrigger as Trigger } from "./trigger/PopoverTrigger.tsx";
3
+ export { PopoverPopup as Popup } from "./popup/PopoverPopup.tsx";
4
+ export { PopoverArrow as Arrow } from "./arrow/PopoverArrow.tsx";
5
+ export { PopoverTitle as Title } from "./title/PopoverTitle.tsx";
6
+ export { PopoverDescription as Description } from "./description/PopoverDescription.tsx";
7
+ export { PopoverClose as Close } from "./close/PopoverClose.tsx";
@@ -0,0 +1,7 @@
1
+ export { PopoverRoot as Root } from "./root/PopoverRoot.jsx";
2
+ export { PopoverTrigger as Trigger } from "./trigger/PopoverTrigger.jsx";
3
+ export { PopoverPopup as Popup } from "./popup/PopoverPopup.jsx";
4
+ export { PopoverArrow as Arrow } from "./arrow/PopoverArrow.jsx";
5
+ export { PopoverTitle as Title } from "./title/PopoverTitle.jsx";
6
+ export { PopoverDescription as Description } from "./description/PopoverDescription.jsx";
7
+ export { PopoverClose as Close } from "./close/PopoverClose.jsx";
@@ -0,0 +1,47 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ import type { FocusTarget } from "../../floating/focus/target.ts";
4
+ import type { Align, Side, VirtualElement } from "../../floating/positioning/createPosition.ts";
5
+ /** What the Popup is placed against: an element, or a virtual one. */
6
+ export type PopoverAnchor = Element | VirtualElement;
7
+ export interface PopoverPopupProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "id"> {
8
+ /** The side of the anchor it is placed against. Default `"bottom"`. */
9
+ side?: Side;
10
+ /** Where along that side, following the writing direction. Default `"center"`. */
11
+ align?: Align;
12
+ /** The gap from the anchor, in pixels. Default 0. */
13
+ sideOffset?: number;
14
+ /** The shift along the anchor's side, in pixels. Default 0. */
15
+ alignOffset?: number;
16
+ /** The space kept from the viewport's edges, in pixels. Default 5. */
17
+ collisionPadding?: number;
18
+ /**
19
+ * What it is placed against instead of the Trigger: an element, a virtual
20
+ * element such as a point, or a function returning one, such as
21
+ * `() => field` for an element reached through a ref.
22
+ */
23
+ anchor?: PopoverAnchor | (() => PopoverAnchor | undefined);
24
+ /**
25
+ * Where focus goes once the popover has opened, instead of the browser's
26
+ * choice: the element with `autofocus`, else the Trigger, where it was.
27
+ * An element, or a function called on each opening with the element the
28
+ * browser focused inside, or `null`, such as `() => input`.
29
+ */
30
+ initialFocus?: FocusTarget;
31
+ /**
32
+ * Where focus goes once the popover has closed, instead of the Trigger,
33
+ * where it returns when it was inside. An element, or a function called
34
+ * with the element the browser focused, or `null` when it found none.
35
+ */
36
+ returnFocus?: FocusTarget;
37
+ render?: RenderProp;
38
+ }
39
+ /**
40
+ * The popover itself: a `<div popover="auto" role="dialog">` in the top
41
+ * layer, placed against the Trigger. A press outside, Escape and the
42
+ * Trigger close it; the page stays usable. Named by `Popover.Title` and
43
+ * described by `Popover.Description` when they are rendered inside it.
44
+ * Place it inside `Popover.Root`, right after `Popover.Trigger`, so that
45
+ * Tab moves from the Trigger into it.
46
+ */
47
+ export declare function PopoverPopup(props: PopoverPopupProps): JSX.Element;
@@ -0,0 +1,120 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { createSlot } from "../../core/slot.js";
5
+ import { createPopoverClose } from "../../floating/dismissal/popoverClose.js";
6
+ import { createInitialFocus } from "../../floating/focus/initialFocus.js";
7
+ import { createReturnFocus } from "../../floating/focus/returnFocus.js";
8
+ import { createPosition } from "../../floating/positioning/createPosition.js";
9
+ import { flip } from "../../floating/positioning/flip.js";
10
+ import { offset } from "../../floating/positioning/offset.js";
11
+ import { shift } from "../../floating/positioning/shift.js";
12
+ import { createPresence } from "../../floating/presence/presence.js";
13
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
14
+ import { PopoverPopupContext } from "./PopoverPopupContext.js";
15
+ /**
16
+ * The popover itself: a `<div popover="auto" role="dialog">` in the top
17
+ * layer, placed against the Trigger. A press outside, Escape and the
18
+ * Trigger close it; the page stays usable. Named by `Popover.Title` and
19
+ * described by `Popover.Description` when they are rendered inside it.
20
+ * Place it inside `Popover.Root`, right after `Popover.Trigger`, so that
21
+ * Tab moves from the Trigger into it.
22
+ */
23
+ export function PopoverPopup(props) {
24
+ const root = usePopoverRootContext();
25
+ let popup;
26
+ // Whether focus was inside as the popover closed, read on `beforetoggle`,
27
+ // before the browser moves it.
28
+ let focusInside = false;
29
+ const [arrow, registerArrow] = createSlot();
30
+ // What every module of the `floating` layer takes, as getters.
31
+ const options = {
32
+ get popup() {
33
+ return popup;
34
+ },
35
+ get trigger() {
36
+ return root.trigger;
37
+ },
38
+ get open() {
39
+ return root.open();
40
+ },
41
+ onDismiss: (details) => root.setOpen(false, details),
42
+ get initialFocus() {
43
+ return props.initialFocus;
44
+ },
45
+ // The browser returns focus to the Trigger only for the first popover
46
+ // of a stack (HTML standard), so a nested one left focus on the
47
+ // `<body>`. A focus that left the popover before it closed stays.
48
+ get returnFocus() {
49
+ return (props.returnFocus ??
50
+ ((focused) => focused ??
51
+ (focusInside ? root.trigger : undefined)));
52
+ },
53
+ };
54
+ // Presence first: the popover is shown before it is placed.
55
+ createPresence(options);
56
+ createPopoverClose(options);
57
+ createInitialFocus(options);
58
+ createReturnFocus(options);
59
+ const position = createPosition({
60
+ get anchor() {
61
+ const anchor = props.anchor;
62
+ return (typeof anchor === "function" ? anchor() : anchor) ?? root.trigger;
63
+ },
64
+ get popup() {
65
+ return popup;
66
+ },
67
+ get open() {
68
+ return root.open();
69
+ },
70
+ get side() {
71
+ return props.side;
72
+ },
73
+ get align() {
74
+ return props.align;
75
+ },
76
+ get middleware() {
77
+ const padding = props.collisionPadding ?? 5;
78
+ const middleware = [
79
+ offset({
80
+ mainAxis: props.sideOffset ?? 0,
81
+ alignmentAxis: props.alignOffset ?? 0,
82
+ }),
83
+ flip({ padding }),
84
+ shift({ padding }),
85
+ ];
86
+ // Only an app that renders an Arrow bundles its middleware.
87
+ const arrowMiddleware = arrow();
88
+ return arrowMiddleware ? [...middleware, arrowMiddleware] : middleware;
89
+ },
90
+ });
91
+ const ownProps = merge(root.attributes, {
92
+ id: root.popupId,
93
+ popover: "auto",
94
+ role: "dialog",
95
+ // The consumer's, else the Title's and Description's ids. Kept out of
96
+ // the merge, where a wrapper's `aria-labelledby={undefined}` would
97
+ // remove the Title's ("`undefined` is a value", PLAN.md section 8);
98
+ // `false` removes it.
99
+ get "aria-labelledby"() {
100
+ return props["aria-labelledby"] ?? root.titleId();
101
+ },
102
+ get "aria-describedby"() {
103
+ return props["aria-describedby"] ?? root.descriptionId();
104
+ },
105
+ onBeforeToggle: (event) => {
106
+ focusInside =
107
+ event.newState === "closed" && popup.contains(document.activeElement);
108
+ },
109
+ ref: (element) => {
110
+ popup = element;
111
+ },
112
+ });
113
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "side", "align", "sideOffset", "alignOffset", "collisionPadding", "anchor", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby",
114
+ // Kept out, as typed: a stray one would break `popovertarget`.
115
+ "id"));
116
+ const context = { position, registerArrow };
117
+ return (<PopoverPopupContext value={context}>
118
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
119
+ </PopoverPopupContext>);
120
+ }
@@ -0,0 +1,14 @@
1
+ import type { Accessor } from "solid-js";
2
+ import type { Position, PositionMiddleware } from "../../floating/positioning/createPosition.ts";
3
+ /** What the Popup shares with the Arrow. */
4
+ export interface PopoverPopupContextValue {
5
+ /** The placement last written, with its resolved side and alignment. */
6
+ position: Accessor<Position | undefined>;
7
+ /**
8
+ * Registers the middleware of a mounted Arrow, as a getter, for the Popup
9
+ * to place it. Returns what unregisters it, for the Arrow's disposal.
10
+ */
11
+ registerArrow(middleware: () => PositionMiddleware): () => void;
12
+ }
13
+ export declare const PopoverPopupContext: import("solid-js").Context<PopoverPopupContextValue | null>;
14
+ export declare function usePopoverPopupContext(): PopoverPopupContextValue;
@@ -0,0 +1,11 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ export const PopoverPopupContext = createContext(null);
4
+ export function usePopoverPopupContext() {
5
+ const context = useContext(PopoverPopupContext);
6
+ // Production builds drop the check, and its message, with `isDev`.
7
+ if (isDev && !context) {
8
+ throw new Error("[menhir] Popover.Arrow must be placed within <Popover.Popup>.");
9
+ }
10
+ return context;
11
+ }
@@ -0,0 +1,20 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
3
+ export interface PopoverRootProps {
4
+ /** Whether the popover is open, when controlled. */
5
+ open?: boolean;
6
+ /** Whether the popover 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
+ * popover. When controlled, the popover changes only if `open` does.
11
+ */
12
+ onOpenChange?: (open: boolean, details: OpenChangeDetails) => void;
13
+ children?: JSX.Element;
14
+ }
15
+ /**
16
+ * A non-modal popup placed against its trigger: holds whether it is open
17
+ * and shares it with `Popover.Trigger`, `Popover.Popup` and the parts
18
+ * inside it. Renders no element of its own.
19
+ */
20
+ export declare function PopoverRoot(props: PopoverRootProps): JSX.Element;
@@ -0,0 +1,42 @@
1
+ import { createUniqueId } from "solid-js";
2
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { createIdSlot } from "../../core/slot.js";
4
+ import { PopoverRootContext } from "./PopoverRootContext.js";
5
+ /**
6
+ * A non-modal popup placed against its trigger: holds whether it is open
7
+ * and shares it with `Popover.Trigger`, `Popover.Popup` and the parts
8
+ * inside it. Renders no element of its own.
9
+ */
10
+ export function PopoverRoot(props) {
11
+ const [open, setOpen] = createControllableSignal({
12
+ get value() {
13
+ return props.open;
14
+ },
15
+ get defaultValue() {
16
+ return props.defaultOpen ?? false;
17
+ },
18
+ onChange: (value, details) => props.onOpenChange?.(value, details),
19
+ });
20
+ const attributes = {
21
+ get "data-open"() {
22
+ return open() ? "" : undefined;
23
+ },
24
+ get "data-closed"() {
25
+ return open() ? undefined : "";
26
+ },
27
+ };
28
+ const [titleId, registerTitleId] = createIdSlot();
29
+ const [descriptionId, registerDescriptionId] = createIdSlot();
30
+ const context = {
31
+ open,
32
+ setOpen,
33
+ popupId: createUniqueId(),
34
+ trigger: undefined,
35
+ titleId,
36
+ registerTitleId,
37
+ descriptionId,
38
+ registerDescriptionId,
39
+ attributes,
40
+ };
41
+ return (<PopoverRootContext value={context}>{props.children}</PopoverRootContext>);
42
+ }