menhir 0.1.2 → 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 (155) 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/presence/presence.js +57 -0
  31. package/dist/floating/scroll-lock/scrollLock.js +125 -0
  32. package/dist/popover/arrow/PopoverArrow.js +39 -0
  33. package/dist/popover/close/PopoverClose.js +33 -0
  34. package/dist/popover/description/PopoverDescription.js +27 -0
  35. package/dist/popover/index.js +2 -0
  36. package/dist/popover/index.parts.js +8 -0
  37. package/dist/popover/popup/PopoverPopup.js +116 -0
  38. package/dist/popover/popup/PopoverPopupContext.js +10 -0
  39. package/dist/popover/root/PopoverRoot.js +50 -0
  40. package/dist/popover/root/PopoverRootContext.js +10 -0
  41. package/dist/popover/title/PopoverTitle.js +27 -0
  42. package/dist/popover/trigger/PopoverTrigger.js +44 -0
  43. package/dist/source/alert-dialog/index.d.ts +1 -0
  44. package/dist/source/alert-dialog/index.js +1 -0
  45. package/dist/source/alert-dialog/index.parts.d.ts +6 -0
  46. package/dist/source/alert-dialog/index.parts.js +7 -0
  47. package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
  48. package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
  49. package/dist/source/core/createControllableSignal.d.ts +5 -4
  50. package/dist/source/core/createControllableSignal.js +4 -3
  51. package/dist/source/core/slot.d.ts +21 -0
  52. package/dist/source/core/slot.js +28 -0
  53. package/dist/source/dialog/close/DialogClose.d.ts +11 -0
  54. package/dist/source/dialog/close/DialogClose.jsx +25 -0
  55. package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
  56. package/dist/source/dialog/description/DialogDescription.jsx +26 -0
  57. package/dist/source/dialog/index.d.ts +1 -0
  58. package/dist/source/dialog/index.js +1 -0
  59. package/dist/source/dialog/index.parts.d.ts +6 -0
  60. package/dist/source/dialog/index.parts.js +6 -0
  61. package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
  62. package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
  63. package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
  64. package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
  65. package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
  66. package/dist/source/dialog/root/DialogRoot.jsx +39 -0
  67. package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
  68. package/dist/source/dialog/root/DialogRootContext.js +14 -0
  69. package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
  70. package/dist/source/dialog/title/DialogTitle.jsx +26 -0
  71. package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
  72. package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
  73. package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
  74. package/dist/source/floating/dismissal/dialogClose.js +69 -0
  75. package/dist/source/floating/dismissal/escape.d.ts +23 -0
  76. package/dist/source/floating/dismissal/escape.js +47 -0
  77. package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
  78. package/dist/source/floating/dismissal/outsidePress.js +50 -0
  79. package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
  80. package/dist/source/floating/dismissal/popoverClose.js +82 -0
  81. package/dist/source/floating/dismissal/reason.d.ts +30 -0
  82. package/dist/source/floating/dismissal/reason.js +1 -0
  83. package/dist/source/floating/focus/initialFocus.d.ts +24 -0
  84. package/dist/source/floating/focus/initialFocus.js +38 -0
  85. package/dist/source/floating/focus/returnFocus.d.ts +27 -0
  86. package/dist/source/floating/focus/returnFocus.js +81 -0
  87. package/dist/source/floating/focus/tabWrap.d.ts +21 -0
  88. package/dist/source/floating/focus/tabWrap.js +69 -0
  89. package/dist/source/floating/focus/tabbable.d.ts +16 -0
  90. package/dist/source/floating/focus/tabbable.js +69 -0
  91. package/dist/source/floating/focus/target.d.ts +8 -0
  92. package/dist/source/floating/focus/target.js +1 -0
  93. package/dist/source/floating/hover/group.d.ts +39 -0
  94. package/dist/source/floating/hover/group.js +38 -0
  95. package/dist/source/floating/hover/hover.d.ts +35 -0
  96. package/dist/source/floating/hover/hover.js +130 -0
  97. package/dist/source/floating/hover/safeArea.d.ts +23 -0
  98. package/dist/source/floating/hover/safeArea.js +67 -0
  99. package/dist/source/floating/presence/presence.d.ts +24 -0
  100. package/dist/source/floating/presence/presence.js +73 -0
  101. package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
  102. package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
  103. package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
  104. package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
  105. package/dist/source/popover/close/PopoverClose.d.ts +11 -0
  106. package/dist/source/popover/close/PopoverClose.jsx +25 -0
  107. package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
  108. package/dist/source/popover/description/PopoverDescription.jsx +26 -0
  109. package/dist/source/popover/index.d.ts +1 -0
  110. package/dist/source/popover/index.js +1 -0
  111. package/dist/source/popover/index.parts.d.ts +7 -0
  112. package/dist/source/popover/index.parts.js +7 -0
  113. package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
  114. package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
  115. package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
  116. package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
  117. package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
  118. package/dist/source/popover/root/PopoverRoot.jsx +42 -0
  119. package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
  120. package/dist/source/popover/root/PopoverRootContext.js +13 -0
  121. package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
  122. package/dist/source/popover/title/PopoverTitle.jsx +26 -0
  123. package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
  124. package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
  125. package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
  126. package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
  127. package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
  128. package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
  129. package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
  130. package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
  131. package/dist/source/tooltip/index.d.ts +1 -0
  132. package/dist/source/tooltip/index.js +1 -0
  133. package/dist/source/tooltip/index.parts.d.ts +5 -0
  134. package/dist/source/tooltip/index.parts.js +5 -0
  135. package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
  136. package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
  137. package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
  138. package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
  139. package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
  140. package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
  141. package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
  142. package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
  143. package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
  144. package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
  145. package/dist/tooltip/arrow/TooltipArrow.js +39 -0
  146. package/dist/tooltip/group/TooltipGroup.js +26 -0
  147. package/dist/tooltip/group/TooltipGroupContext.js +4 -0
  148. package/dist/tooltip/index.js +2 -0
  149. package/dist/tooltip/index.parts.js +6 -0
  150. package/dist/tooltip/popup/TooltipPopup.js +86 -0
  151. package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
  152. package/dist/tooltip/root/TooltipRoot.js +79 -0
  153. package/dist/tooltip/root/TooltipRootContext.js +10 -0
  154. package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
  155. package/package.json +21 -1
@@ -0,0 +1,39 @@
1
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
2
+ /**
3
+ * The popover'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 PopoverStateAttributes = {
8
+ readonly "data-open": "" | undefined;
9
+ readonly "data-closed": "" | undefined;
10
+ };
11
+ /** What the Root shares with its parts. */
12
+ export interface PopoverRootContextValue {
13
+ /** Whether the popover is open. */
14
+ open(): boolean;
15
+ /** Asks to open or close the popover, saying why. */
16
+ setOpen(open: boolean, details: OpenChangeDetails): void;
17
+ /**
18
+ * The Popup's `id`, which the Trigger names in `popovertarget` and
19
+ * `aria-controls` before the Popup is rendered.
20
+ */
21
+ readonly popupId: string;
22
+ /** The Trigger's element, once rendered: the anchor by default. */
23
+ trigger: HTMLElement | undefined;
24
+ /** The `id` of the rendered Title, which the Popup names, if any. */
25
+ titleId(): string | undefined;
26
+ /**
27
+ * Registers the `id` of a mounted Title, as a getter. Returns what
28
+ * unregisters it, for the Title's disposal.
29
+ */
30
+ registerTitleId(id: () => string | false): () => void;
31
+ /** The `id` of the rendered Description, which the Popup names, if any. */
32
+ descriptionId(): string | undefined;
33
+ /** As `registerTitleId`, for the Description. */
34
+ registerDescriptionId(id: () => string | false): () => void;
35
+ /** The `data-*` attributes every part carries. */
36
+ readonly attributes: PopoverStateAttributes;
37
+ }
38
+ export declare const PopoverRootContext: import("solid-js").Context<PopoverRootContextValue | null>;
39
+ export declare function usePopoverRootContext(): PopoverRootContextValue;
@@ -0,0 +1,13 @@
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 PopoverRootContext = createContext(null);
6
+ export function usePopoverRootContext() {
7
+ const context = useContext(PopoverRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] Popover parts must be placed within <Popover.Root>.");
11
+ }
12
+ return context;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface PopoverTitleProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The popover's title, which names the Popup in `aria-labelledby`: an
8
+ * `<h2>`. Place it inside `Popover.Popup`.
9
+ */
10
+ export declare function PopoverTitle(props: PopoverTitleProps): 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
+ * The popover's title, which names the Popup in `aria-labelledby`: an
7
+ * `<h2>`. Place it inside `Popover.Popup`.
8
+ */
9
+ export function PopoverTitle(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 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,12 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface PopoverTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that opens and closes the popover: a `<button type="button"
8
+ * aria-haspopup="dialog">` with `aria-expanded`, naming the Popup in
9
+ * `popovertarget` and `aria-controls`. Place it inside `Popover.Root`,
10
+ * right before `Popover.Popup`.
11
+ */
12
+ export declare function PopoverTrigger(props: PopoverTriggerProps): JSX.Element;
@@ -0,0 +1,40 @@
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
+ * The button that opens and closes the popover: a `<button type="button"
9
+ * aria-haspopup="dialog">` with `aria-expanded`, naming the Popup in
10
+ * `popovertarget` and `aria-controls`. Place it inside `Popover.Root`,
11
+ * right before `Popover.Popup`.
12
+ */
13
+ export function PopoverTrigger(props) {
14
+ const root = usePopoverRootContext();
15
+ const ownProps = merge(root.attributes, {
16
+ type: "button",
17
+ // So that the browser counts a press on the Trigger as one on the
18
+ // popover, which light dismiss leaves open (README, "Decisions").
19
+ popovertarget: root.popupId,
20
+ "aria-haspopup": "dialog",
21
+ get "aria-expanded"() {
22
+ return root.open() ? "true" : "false";
23
+ },
24
+ "aria-controls": root.popupId,
25
+ onClick: (event) => {
26
+ // The state shows and hides the popover, in the flush that places
27
+ // it: the browser's own toggle would show it a task before.
28
+ event.preventDefault();
29
+ root.setOpen(!root.open(), { reason: "trigger-press", event });
30
+ },
31
+ ref: (element) => {
32
+ root.trigger = element;
33
+ // Production builds drop the check with `isDev`.
34
+ if (isDev)
35
+ warnUnlessButton(element, "Popover.Trigger");
36
+ },
37
+ });
38
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
39
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
40
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface TooltipArrowProps 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 `Tooltip.Popup`.
10
+ */
11
+ export declare function TooltipArrow(props: TooltipArrowProps): 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 { useTooltipPopupContext } from "../popup/TooltipPopupContext.js";
6
+ import { useTooltipRootContext } from "../root/TooltipRootContext.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 `Tooltip.Popup`.
11
+ */
12
+ export function TooltipArrow(props) {
13
+ const root = useTooltipRootContext();
14
+ const popup = useTooltipPopupContext();
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,20 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ export interface TooltipGroupProps {
3
+ /**
4
+ * How long the pointer rests on a Trigger before its tooltip opens, in
5
+ * milliseconds, for the Roots inside that set no `delay`. Default 600.
6
+ */
7
+ delay?: number;
8
+ /**
9
+ * How long after the last tooltip of the group closed the next still
10
+ * opens at once, in milliseconds. Default 400.
11
+ */
12
+ timeout?: number;
13
+ children?: JSX.Element;
14
+ }
15
+ /**
16
+ * A delay group, such as the tooltips of a toolbar: once one tooltip inside
17
+ * is open, hovering another Trigger opens its tooltip at once and closes
18
+ * the first. Renders no element of its own.
19
+ */
20
+ export declare function TooltipGroup(props: TooltipGroupProps): JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { createHoverGroup } from "../../floating/hover/group.js";
2
+ import { TooltipGroupContext } from "./TooltipGroupContext.js";
3
+ /**
4
+ * A delay group, such as the tooltips of a toolbar: once one tooltip inside
5
+ * is open, hovering another Trigger opens its tooltip at once and closes
6
+ * the first. Renders no element of its own.
7
+ */
8
+ export function TooltipGroup(props) {
9
+ const group = createHoverGroup({
10
+ get delay() {
11
+ return props.delay;
12
+ },
13
+ get timeout() {
14
+ return props.timeout;
15
+ },
16
+ });
17
+ return (<TooltipGroupContext value={group}>{props.children}</TooltipGroupContext>);
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { HoverGroup } from "../../floating/hover/group.ts";
2
+ export declare const TooltipGroupContext: import("solid-js").Context<HoverGroup | null>;
@@ -0,0 +1,5 @@
1
+ import { createContext } from "solid-js";
2
+ // Its own file, holding no code of `hover/group`: a Root reads it whether or
3
+ // not a Group is rendered, and only an app that renders one bundles the
4
+ // group (README, "Decisions"). `null` outside a Group.
5
+ export const TooltipGroupContext = createContext(null);
@@ -0,0 +1 @@
1
+ export * as Tooltip from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Tooltip from "./index.parts.js";
@@ -0,0 +1,5 @@
1
+ export { TooltipRoot as Root } from "./root/TooltipRoot.tsx";
2
+ export { TooltipTrigger as Trigger } from "./trigger/TooltipTrigger.tsx";
3
+ export { TooltipPopup as Popup } from "./popup/TooltipPopup.tsx";
4
+ export { TooltipArrow as Arrow } from "./arrow/TooltipArrow.tsx";
5
+ export { TooltipGroup as Group } from "./group/TooltipGroup.tsx";
@@ -0,0 +1,5 @@
1
+ export { TooltipRoot as Root } from "./root/TooltipRoot.jsx";
2
+ export { TooltipTrigger as Trigger } from "./trigger/TooltipTrigger.jsx";
3
+ export { TooltipPopup as Popup } from "./popup/TooltipPopup.jsx";
4
+ export { TooltipArrow as Arrow } from "./arrow/TooltipArrow.jsx";
5
+ export { TooltipGroup as Group } from "./group/TooltipGroup.jsx";
@@ -0,0 +1,31 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ import type { Align, Side, VirtualElement } from "../../floating/positioning/createPosition.ts";
4
+ /** What the Popup is placed against: an element, or a virtual one. */
5
+ export type TooltipAnchor = Element | VirtualElement;
6
+ export interface TooltipPopupProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "id"> {
7
+ /** The side of the anchor it is placed against. Default `"top"`. */
8
+ side?: Side;
9
+ /** Where along that side, following the writing direction. Default `"center"`. */
10
+ align?: Align;
11
+ /** The gap from the anchor, in pixels. Default 0. */
12
+ sideOffset?: number;
13
+ /** The shift along the anchor's side, in pixels. Default 0. */
14
+ alignOffset?: number;
15
+ /** The space kept from the viewport's edges, in pixels. Default 5. */
16
+ collisionPadding?: number;
17
+ /**
18
+ * What it is placed against instead of the Trigger: an element, a virtual
19
+ * element such as a point, or a function returning one, such as
20
+ * `() => field` for an element reached through a ref.
21
+ */
22
+ anchor?: TooltipAnchor | (() => TooltipAnchor | undefined);
23
+ render?: RenderProp;
24
+ }
25
+ /**
26
+ * The tooltip itself: a `<div popover="manual" role="tooltip">` in the top
27
+ * layer, placed against the Trigger, which it describes. It never takes
28
+ * focus: put only text in it, and content a user must reach in a Popover.
29
+ * Place it inside `Tooltip.Root`, after `Tooltip.Trigger`.
30
+ */
31
+ export declare function TooltipPopup(props: TooltipPopupProps): JSX.Element;
@@ -0,0 +1,77 @@
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 { createPosition } from "../../floating/positioning/createPosition.js";
6
+ import { flip } from "../../floating/positioning/flip.js";
7
+ import { offset } from "../../floating/positioning/offset.js";
8
+ import { shift } from "../../floating/positioning/shift.js";
9
+ import { createPresence } from "../../floating/presence/presence.js";
10
+ import { useTooltipRootContext } from "../root/TooltipRootContext.js";
11
+ import { TooltipPopupContext } from "./TooltipPopupContext.js";
12
+ /**
13
+ * The tooltip itself: a `<div popover="manual" role="tooltip">` in the top
14
+ * layer, placed against the Trigger, which it describes. It never takes
15
+ * focus: put only text in it, and content a user must reach in a Popover.
16
+ * Place it inside `Tooltip.Root`, after `Tooltip.Trigger`.
17
+ */
18
+ export function TooltipPopup(props) {
19
+ const root = useTooltipRootContext();
20
+ const [arrow, registerArrow] = createSlot();
21
+ // Presence first: the popover is shown before it is placed.
22
+ createPresence({
23
+ get popup() {
24
+ return root.popup;
25
+ },
26
+ get open() {
27
+ return root.open();
28
+ },
29
+ });
30
+ const position = createPosition({
31
+ get anchor() {
32
+ const anchor = props.anchor;
33
+ return (typeof anchor === "function" ? anchor() : anchor) ?? root.trigger;
34
+ },
35
+ get popup() {
36
+ return root.popup;
37
+ },
38
+ get open() {
39
+ return root.open();
40
+ },
41
+ get side() {
42
+ return props.side ?? "top";
43
+ },
44
+ get align() {
45
+ return props.align;
46
+ },
47
+ get middleware() {
48
+ const padding = props.collisionPadding ?? 5;
49
+ const middleware = [
50
+ offset({
51
+ mainAxis: props.sideOffset ?? 0,
52
+ alignmentAxis: props.alignOffset ?? 0,
53
+ }),
54
+ flip({ padding }),
55
+ shift({ padding }),
56
+ ];
57
+ // Only an app that renders an Arrow bundles its middleware.
58
+ const arrowMiddleware = arrow();
59
+ return arrowMiddleware ? [...middleware, arrowMiddleware] : middleware;
60
+ },
61
+ });
62
+ const ownProps = merge(root.attributes, {
63
+ id: root.popupId,
64
+ popover: "manual",
65
+ role: "tooltip",
66
+ ref: (element) => {
67
+ root.popup = element;
68
+ },
69
+ });
70
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "side", "align", "sideOffset", "alignOffset", "collisionPadding", "anchor",
71
+ // Kept out, as typed: a stray one would break `aria-describedby`.
72
+ "id"));
73
+ const context = { position, registerArrow };
74
+ return (<TooltipPopupContext value={context}>
75
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
76
+ </TooltipPopupContext>);
77
+ }
@@ -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 TooltipPopupContextValue {
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 TooltipPopupContext: import("solid-js").Context<TooltipPopupContextValue | null>;
14
+ export declare function useTooltipPopupContext(): TooltipPopupContextValue;
@@ -0,0 +1,11 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ export const TooltipPopupContext = createContext(null);
4
+ export function useTooltipPopupContext() {
5
+ const context = useContext(TooltipPopupContext);
6
+ // Production builds drop the check, and its message, with `isDev`.
7
+ if (isDev && !context) {
8
+ throw new Error("[menhir] Tooltip.Arrow must be placed within <Tooltip.Popup>.");
9
+ }
10
+ return context;
11
+ }
@@ -0,0 +1,31 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
3
+ export interface TooltipRootProps {
4
+ /** Whether the tooltip is open, when controlled. */
5
+ open?: boolean;
6
+ /** Whether the tooltip 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
+ * tooltip. When controlled, the tooltip changes only if `open` does.
11
+ */
12
+ onOpenChange?: (open: boolean, details: OpenChangeDetails) => void;
13
+ /**
14
+ * How long the pointer rests on the Trigger before the tooltip opens, in
15
+ * milliseconds. Default 600, or the Group's.
16
+ */
17
+ delay?: number;
18
+ /**
19
+ * How long after the pointer has left the Trigger and the Popup the
20
+ * tooltip closes, in milliseconds. Default 0.
21
+ */
22
+ closeDelay?: number;
23
+ children?: JSX.Element;
24
+ }
25
+ /**
26
+ * A short description of its Trigger, shown on hover and on keyboard
27
+ * focus: holds whether it is open and shares it with `Tooltip.Trigger` and
28
+ * `Tooltip.Popup`. Renders no element of its own. Inside a `Tooltip.Group`,
29
+ * it joins the group's delays.
30
+ */
31
+ export declare function TooltipRoot(props: TooltipRootProps): JSX.Element;
@@ -0,0 +1,80 @@
1
+ import { createUniqueId, useContext } from "solid-js";
2
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { createEscape } from "../../floating/dismissal/escape.js";
4
+ import { createHover } from "../../floating/hover/hover.js";
5
+ import { TooltipGroupContext } from "../group/TooltipGroupContext.js";
6
+ import { TooltipRootContext } from "./TooltipRootContext.js";
7
+ /**
8
+ * A short description of its Trigger, shown on hover and on keyboard
9
+ * focus: holds whether it is open and shares it with `Tooltip.Trigger` and
10
+ * `Tooltip.Popup`. Renders no element of its own. Inside a `Tooltip.Group`,
11
+ * it joins the group's delays.
12
+ */
13
+ export function TooltipRoot(props) {
14
+ const [open, setOpen] = createControllableSignal({
15
+ get value() {
16
+ return props.open;
17
+ },
18
+ get defaultValue() {
19
+ return props.defaultOpen ?? false;
20
+ },
21
+ onChange: (value, details) => props.onOpenChange?.(value, details),
22
+ });
23
+ const attributes = {
24
+ get "data-open"() {
25
+ return open() ? "" : undefined;
26
+ },
27
+ get "data-closed"() {
28
+ return open() ? undefined : "";
29
+ },
30
+ };
31
+ const context = {
32
+ open,
33
+ setOpen,
34
+ popupId: createUniqueId(),
35
+ trigger: undefined,
36
+ popup: undefined,
37
+ pressed: false,
38
+ attributes,
39
+ };
40
+ const group = useContext(TooltipGroupContext) ?? undefined;
41
+ createHover({
42
+ get trigger() {
43
+ return context.trigger;
44
+ },
45
+ get popup() {
46
+ return context.popup;
47
+ },
48
+ get open() {
49
+ return open();
50
+ },
51
+ get delay() {
52
+ return props.delay;
53
+ },
54
+ get closeDelay() {
55
+ return props.closeDelay;
56
+ },
57
+ // Read when the pointer enters and when the delay ends. A disabled
58
+ // button cannot take focus, so its tooltip would be the pointer's
59
+ // alone; a press before the delay ended cancels the opening (README,
60
+ // "Decisions").
61
+ get disabled() {
62
+ return (context.pressed ||
63
+ context.trigger?.disabled);
64
+ },
65
+ group,
66
+ // Hovered or focused keeps it open: the pointer leaving does not close
67
+ // a tooltip whose Trigger has keyboard focus (README, "Decisions").
68
+ onOpenChange: (value, details) => {
69
+ if (value || !context.trigger?.matches(":focus-visible"))
70
+ setOpen(value, details);
71
+ },
72
+ });
73
+ createEscape({
74
+ get open() {
75
+ return open();
76
+ },
77
+ onDismiss: (details) => setOpen(false, details),
78
+ });
79
+ return (<TooltipRootContext value={context}>{props.children}</TooltipRootContext>);
80
+ }
@@ -0,0 +1,35 @@
1
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
2
+ /**
3
+ * The tooltip'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 TooltipStateAttributes = {
8
+ readonly "data-open": "" | undefined;
9
+ readonly "data-closed": "" | undefined;
10
+ };
11
+ /** What the Root shares with its parts. */
12
+ export interface TooltipRootContextValue {
13
+ /** Whether the tooltip is open. */
14
+ open(): boolean;
15
+ /** Asks to open or close the tooltip, saying why. */
16
+ setOpen(open: boolean, details: OpenChangeDetails): void;
17
+ /**
18
+ * The Popup's `id`, which the Trigger names in `aria-describedby` before
19
+ * the Popup is rendered.
20
+ */
21
+ readonly popupId: string;
22
+ /** The Trigger's element, once rendered: the anchor by default. */
23
+ trigger: HTMLElement | undefined;
24
+ /** The Popup's element, once rendered. */
25
+ popup: HTMLElement | undefined;
26
+ /**
27
+ * Whether the Trigger was pressed since the pointer last entered it: hover
28
+ * opens nothing until the pointer leaves and comes back.
29
+ */
30
+ pressed: boolean;
31
+ /** The `data-*` attributes every part carries. */
32
+ readonly attributes: TooltipStateAttributes;
33
+ }
34
+ export declare const TooltipRootContext: import("solid-js").Context<TooltipRootContextValue | null>;
35
+ export declare function useTooltipRootContext(): TooltipRootContextValue;
@@ -0,0 +1,13 @@
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 TooltipRootContext = createContext(null);
6
+ export function useTooltipRootContext() {
7
+ const context = useContext(TooltipRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] Tooltip parts must be placed within <Tooltip.Root>.");
11
+ }
12
+ return context;
13
+ }
@@ -0,0 +1,12 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface TooltipTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The element the tooltip describes: a `<button type="button">` whose
8
+ * `aria-describedby` names the Popup. Hovering it opens the tooltip after
9
+ * the Root's `delay`, keyboard focus opens it at once, and a press closes
10
+ * it. Place it inside `Tooltip.Root`, before `Tooltip.Popup`.
11
+ */
12
+ export declare function TooltipTrigger(props: TooltipTriggerProps): JSX.Element;
@@ -0,0 +1,52 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useTooltipRootContext } from "../root/TooltipRootContext.js";
5
+ /**
6
+ * The element the tooltip describes: a `<button type="button">` whose
7
+ * `aria-describedby` names the Popup. Hovering it opens the tooltip after
8
+ * the Root's `delay`, keyboard focus opens it at once, and a press closes
9
+ * it. Place it inside `Tooltip.Root`, before `Tooltip.Popup`.
10
+ */
11
+ export function TooltipTrigger(props) {
12
+ const root = useTooltipRootContext();
13
+ const ownProps = merge(root.attributes, {
14
+ type: "button",
15
+ // Always, since the closed Popup stays in the document and still gives
16
+ // its text (README, "Decisions"). The consumer's wins, kept out of the
17
+ // merge, where a wrapper's `undefined` would remove it; `false` removes
18
+ // it.
19
+ get "aria-describedby"() {
20
+ return props["aria-describedby"] ?? root.popupId;
21
+ },
22
+ // Keyboard focus only: a press that focuses the Trigger does not open
23
+ // it (README, "Decisions").
24
+ onFocus: (event) => {
25
+ if (root.trigger.matches(":focus-visible"))
26
+ root.setOpen(true, { reason: "trigger-focus", event });
27
+ },
28
+ // Hovered or focused keeps it open: blur does not close a tooltip whose
29
+ // Trigger or Popup the pointer is on.
30
+ onBlur: (event) => {
31
+ if (!root.trigger.matches(":hover") && !root.popup?.matches(":hover"))
32
+ root.setOpen(false, { reason: "trigger-focus", event });
33
+ },
34
+ // The press does what the button does, which the tooltip would cover.
35
+ // Hover opens nothing more until the pointer comes onto it again: a
36
+ // key's press, with the pointer elsewhere, holds nothing back.
37
+ onClick: (event) => {
38
+ root.pressed = true;
39
+ root.setOpen(false, { reason: "trigger-press", event });
40
+ },
41
+ // Added as the element is created, so it runs before hover's own
42
+ // listener, which reads `pressed` through `disabled`.
43
+ onPointerEnter: () => {
44
+ root.pressed = false;
45
+ },
46
+ ref: (element) => {
47
+ root.trigger = element;
48
+ },
49
+ });
50
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "aria-describedby"));
51
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
52
+ }