menhir 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/README.md +9 -2
- package/dist/alert-dialog/index.js +2 -0
- package/dist/alert-dialog/index.parts.js +7 -0
- package/dist/alert-dialog/popup/AlertDialogPopup.js +13 -0
- package/dist/core/createControllableSignal.js +15 -5
- package/dist/core/listValue.js +2 -7
- package/dist/core/slot.js +30 -0
- package/dist/dialog/close/DialogClose.js +33 -0
- package/dist/dialog/description/DialogDescription.js +27 -0
- package/dist/dialog/index.js +2 -0
- package/dist/dialog/index.parts.js +7 -0
- package/dist/dialog/popup/DialogPopup.js +13 -0
- package/dist/dialog/popup/renderDialogPopup.js +71 -0
- package/dist/dialog/root/DialogRoot.js +46 -0
- package/dist/dialog/root/DialogRootContext.js +10 -0
- package/dist/dialog/title/DialogTitle.js +27 -0
- package/dist/dialog/trigger/DialogTrigger.js +33 -0
- package/dist/floating/dismissal/dialogClose.js +67 -0
- package/dist/floating/dismissal/escape.js +44 -0
- package/dist/floating/dismissal/outsidePress.js +52 -0
- package/dist/floating/dismissal/popoverClose.js +74 -0
- package/dist/floating/dismissal/reason.js +0 -0
- package/dist/floating/focus/initialFocus.js +33 -0
- package/dist/floating/focus/returnFocus.js +65 -0
- package/dist/floating/focus/tabWrap.js +55 -0
- package/dist/floating/focus/tabbable.js +50 -0
- package/dist/floating/focus/target.js +0 -0
- package/dist/floating/hover/group.js +36 -0
- package/dist/floating/hover/hover.js +105 -0
- package/dist/floating/hover/safeArea.js +64 -0
- package/dist/floating/list-navigation/activeDescendant.js +29 -0
- package/dist/floating/list-navigation/listNavigation.js +108 -0
- package/dist/floating/list-navigation/roving.js +27 -0
- package/dist/floating/presence/presence.js +57 -0
- package/dist/floating/scroll-lock/scrollLock.js +125 -0
- package/dist/floating/typeahead/match.js +24 -0
- package/dist/floating/typeahead/typeahead.js +56 -0
- package/dist/navigation-menu/index.js +2 -0
- package/dist/navigation-menu/index.parts.js +6 -0
- package/dist/navigation-menu/item/NavigationMenuItem.js +83 -0
- package/dist/navigation-menu/item/NavigationMenuItemContext.js +10 -0
- package/dist/navigation-menu/link/NavigationMenuLink.js +26 -0
- package/dist/navigation-menu/panel/NavigationMenuPanel.js +31 -0
- package/dist/navigation-menu/root/NavigationMenuRoot.js +100 -0
- package/dist/navigation-menu/root/NavigationMenuRootContext.js +10 -0
- package/dist/navigation-menu/trigger/NavigationMenuTrigger.js +36 -0
- package/dist/popover/arrow/PopoverArrow.js +39 -0
- package/dist/popover/close/PopoverClose.js +33 -0
- package/dist/popover/description/PopoverDescription.js +27 -0
- package/dist/popover/index.js +2 -0
- package/dist/popover/index.parts.js +8 -0
- package/dist/popover/popup/PopoverPopup.js +116 -0
- package/dist/popover/popup/PopoverPopupContext.js +10 -0
- package/dist/popover/root/PopoverRoot.js +50 -0
- package/dist/popover/root/PopoverRootContext.js +10 -0
- package/dist/popover/title/PopoverTitle.js +27 -0
- package/dist/popover/trigger/PopoverTrigger.js +44 -0
- package/dist/source/alert-dialog/index.d.ts +1 -0
- package/dist/source/alert-dialog/index.js +1 -0
- package/dist/source/alert-dialog/index.parts.d.ts +6 -0
- package/dist/source/alert-dialog/index.parts.js +7 -0
- package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
- package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
- package/dist/source/core/createControllableSignal.d.ts +13 -4
- package/dist/source/core/createControllableSignal.js +11 -5
- package/dist/source/core/listValue.js +4 -10
- package/dist/source/core/slot.d.ts +21 -0
- package/dist/source/core/slot.js +28 -0
- package/dist/source/dialog/close/DialogClose.d.ts +11 -0
- package/dist/source/dialog/close/DialogClose.jsx +25 -0
- package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
- package/dist/source/dialog/description/DialogDescription.jsx +26 -0
- package/dist/source/dialog/index.d.ts +1 -0
- package/dist/source/dialog/index.js +1 -0
- package/dist/source/dialog/index.parts.d.ts +6 -0
- package/dist/source/dialog/index.parts.js +6 -0
- package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
- package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
- package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
- package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
- package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
- package/dist/source/dialog/root/DialogRoot.jsx +39 -0
- package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
- package/dist/source/dialog/root/DialogRootContext.js +14 -0
- package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
- package/dist/source/dialog/title/DialogTitle.jsx +26 -0
- package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
- package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
- package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
- package/dist/source/floating/dismissal/dialogClose.js +69 -0
- package/dist/source/floating/dismissal/escape.d.ts +24 -0
- package/dist/source/floating/dismissal/escape.js +48 -0
- package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
- package/dist/source/floating/dismissal/outsidePress.js +50 -0
- package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
- package/dist/source/floating/dismissal/popoverClose.js +82 -0
- package/dist/source/floating/dismissal/reason.d.ts +34 -0
- package/dist/source/floating/dismissal/reason.js +1 -0
- package/dist/source/floating/focus/initialFocus.d.ts +24 -0
- package/dist/source/floating/focus/initialFocus.js +38 -0
- package/dist/source/floating/focus/returnFocus.d.ts +27 -0
- package/dist/source/floating/focus/returnFocus.js +81 -0
- package/dist/source/floating/focus/tabWrap.d.ts +21 -0
- package/dist/source/floating/focus/tabWrap.js +69 -0
- package/dist/source/floating/focus/tabbable.d.ts +16 -0
- package/dist/source/floating/focus/tabbable.js +69 -0
- package/dist/source/floating/focus/target.d.ts +8 -0
- package/dist/source/floating/focus/target.js +1 -0
- package/dist/source/floating/hover/group.d.ts +39 -0
- package/dist/source/floating/hover/group.js +38 -0
- package/dist/source/floating/hover/hover.d.ts +35 -0
- package/dist/source/floating/hover/hover.js +130 -0
- package/dist/source/floating/hover/safeArea.d.ts +23 -0
- package/dist/source/floating/hover/safeArea.js +67 -0
- package/dist/source/floating/list-navigation/activeDescendant.d.ts +30 -0
- package/dist/source/floating/list-navigation/activeDescendant.js +24 -0
- package/dist/source/floating/list-navigation/listNavigation.d.ts +68 -0
- package/dist/source/floating/list-navigation/listNavigation.js +148 -0
- package/dist/source/floating/list-navigation/roving.d.ts +23 -0
- package/dist/source/floating/list-navigation/roving.js +25 -0
- package/dist/source/floating/presence/presence.d.ts +24 -0
- package/dist/source/floating/presence/presence.js +73 -0
- package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
- package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
- package/dist/source/floating/typeahead/match.d.ts +14 -0
- package/dist/source/floating/typeahead/match.js +32 -0
- package/dist/source/floating/typeahead/typeahead.d.ts +41 -0
- package/dist/source/floating/typeahead/typeahead.js +81 -0
- package/dist/source/navigation-menu/index.d.ts +1 -0
- package/dist/source/navigation-menu/index.js +1 -0
- package/dist/source/navigation-menu/index.parts.d.ts +5 -0
- package/dist/source/navigation-menu/index.parts.js +5 -0
- package/dist/source/navigation-menu/item/NavigationMenuItem.d.ts +16 -0
- package/dist/source/navigation-menu/item/NavigationMenuItem.jsx +85 -0
- package/dist/source/navigation-menu/item/NavigationMenuItemContext.d.ts +27 -0
- package/dist/source/navigation-menu/item/NavigationMenuItemContext.js +12 -0
- package/dist/source/navigation-menu/link/NavigationMenuLink.d.ts +12 -0
- package/dist/source/navigation-menu/link/NavigationMenuLink.jsx +18 -0
- package/dist/source/navigation-menu/panel/NavigationMenuPanel.d.ts +11 -0
- package/dist/source/navigation-menu/panel/NavigationMenuPanel.jsx +26 -0
- package/dist/source/navigation-menu/root/NavigationMenuRoot.d.ts +37 -0
- package/dist/source/navigation-menu/root/NavigationMenuRoot.jsx +103 -0
- package/dist/source/navigation-menu/root/NavigationMenuRootContext.d.ts +33 -0
- package/dist/source/navigation-menu/root/NavigationMenuRootContext.js +13 -0
- package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.d.ts +12 -0
- package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.jsx +32 -0
- package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
- package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
- package/dist/source/popover/close/PopoverClose.d.ts +11 -0
- package/dist/source/popover/close/PopoverClose.jsx +25 -0
- package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
- package/dist/source/popover/description/PopoverDescription.jsx +26 -0
- package/dist/source/popover/index.d.ts +1 -0
- package/dist/source/popover/index.js +1 -0
- package/dist/source/popover/index.parts.d.ts +7 -0
- package/dist/source/popover/index.parts.js +7 -0
- package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
- package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
- package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
- package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
- package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
- package/dist/source/popover/root/PopoverRoot.jsx +42 -0
- package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
- package/dist/source/popover/root/PopoverRootContext.js +13 -0
- package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
- package/dist/source/popover/title/PopoverTitle.jsx +26 -0
- package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
- package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
- package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
- package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
- package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
- package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
- package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
- package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
- package/dist/source/tooltip/index.d.ts +1 -0
- package/dist/source/tooltip/index.js +1 -0
- package/dist/source/tooltip/index.parts.d.ts +5 -0
- package/dist/source/tooltip/index.parts.js +5 -0
- package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
- package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
- package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
- package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
- package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
- package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
- package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
- package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
- package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
- package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
- package/dist/tooltip/arrow/TooltipArrow.js +39 -0
- package/dist/tooltip/group/TooltipGroup.js +26 -0
- package/dist/tooltip/group/TooltipGroupContext.js +4 -0
- package/dist/tooltip/index.js +2 -0
- package/dist/tooltip/index.parts.js +6 -0
- package/dist/tooltip/popup/TooltipPopup.js +86 -0
- package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
- package/dist/tooltip/root/TooltipRoot.js +79 -0
- package/dist/tooltip/root/TooltipRootContext.js +10 -0
- package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
- package/package.json +28 -2
- package/skills/menhir-styling/SKILL.md +35 -0
- package/skills/menhir-styling/looks/shadcn/LICENSE +24 -0
- package/skills/menhir-styling/looks/shadcn/LOOK.md +106 -0
- package/skills/menhir-styling/looks/shadcn/dialog.md +63 -0
- package/skills/menhir-styling/looks/shadcn/popover.md +39 -0
- package/skills/menhir-styling/looks/shadcn/switch.md +26 -0
- package/skills/menhir-styling/looks/shadcn/tabs.md +62 -0
- package/skills/menhir-styling/looks/shadcn/tokens.css +80 -0
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|