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,57 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
// src/floating/presence/presence.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shows a popup when `open` turns true, and hides it once its exit
|
|
5
|
+
* animations have ended after `open` turns false:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* createPresence({
|
|
9
|
+
* get popup() { return dialog; },
|
|
10
|
+
* get open() { return open(); },
|
|
11
|
+
* });
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* A `<dialog>` is shown with `showModal()` and hidden with `close()`; any
|
|
15
|
+
* other element is a popover, shown with `showPopover()` and hidden with
|
|
16
|
+
* `hidePopover()`. On closing it waits for the animations and transitions
|
|
17
|
+
* running in the popup, its descendants and its `::backdrop`, the ones its
|
|
18
|
+
* `data-closed` starts, and hides it at once if none is running; infinite
|
|
19
|
+
* and paused ones do not count. Meanwhile the popup is `inert`, unless it is
|
|
20
|
+
* a popover that holds focus, which only returns focus to its trigger from
|
|
21
|
+
* inside. Opening again cancels the exit. Nothing runs on the server.
|
|
22
|
+
*/
|
|
23
|
+
function createPresence(options) {
|
|
24
|
+
let stopLeaving;
|
|
25
|
+
createEffect(() => options.open, (open) => {
|
|
26
|
+
const popup = options.popup;
|
|
27
|
+
if (!popup) return;
|
|
28
|
+
const dialog = popup instanceof HTMLDialogElement ? popup : void 0;
|
|
29
|
+
stopLeaving?.();
|
|
30
|
+
if (open) {
|
|
31
|
+
if (dialog) {
|
|
32
|
+
if (!dialog.open) dialog.showModal();
|
|
33
|
+
} else if (!popup.matches(":popover-open")) popup.showPopover();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!popup.matches("[open], :popover-open")) return;
|
|
37
|
+
const inert = popup.inert;
|
|
38
|
+
if (dialog || !popup.contains(document.activeElement)) popup.inert = true;
|
|
39
|
+
const stop = stopLeaving = () => {
|
|
40
|
+
stopLeaving = void 0;
|
|
41
|
+
popup.inert = inert;
|
|
42
|
+
};
|
|
43
|
+
const wait = () => {
|
|
44
|
+
if (stopLeaving !== stop) return;
|
|
45
|
+
const running = popup.getAnimations({ subtree: true }).filter((animation) => animation.playState === "running" && animation.effect?.getComputedTiming().endTime !== Infinity);
|
|
46
|
+
if (running.length) {
|
|
47
|
+
Promise.allSettled(running.map((animation) => animation.finished)).then(wait);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
stop();
|
|
51
|
+
if (dialog) dialog.close();
|
|
52
|
+
else if (popup.matches(":popover-open")) popup.hidePopover();
|
|
53
|
+
};
|
|
54
|
+
wait();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export { createPresence };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
2
|
+
// src/floating/scroll-lock/scrollLock.ts
|
|
3
|
+
var locks = 0;
|
|
4
|
+
var restoreStyles;
|
|
5
|
+
/**
|
|
6
|
+
* Keeps the page from scrolling while a modal popup is open: `overflow:
|
|
7
|
+
* hidden` on `<html>`, as `showModal()` leaves the page scrolling.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createScrollLock({
|
|
11
|
+
* get popup() { return dialog; },
|
|
12
|
+
* get open() { return open(); },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Counted, so nested popups unlock the page when the last one closes. A
|
|
17
|
+
* page with a scrollbar gets its width as padding on `<html>`, so nothing
|
|
18
|
+
* moves, and as `--hidden-scrollbar-width` for `position: fixed` elements;
|
|
19
|
+
* a page with `scrollbar-gutter: stable` gets neither. Unlocking puts back
|
|
20
|
+
* the page's own inline styles. The page unlocks once the popup has
|
|
21
|
+
* closed, not when its state turns false: after the flush that closed it,
|
|
22
|
+
* or on its `close` or `toggle` event if it is still shown then, as while
|
|
23
|
+
* an exit animation runs. A popup disposed while open unlocks it at once.
|
|
24
|
+
* While open, the popup gets `overscroll-behavior: contain` and, if it
|
|
25
|
+
* does not scroll itself, `touch-action: pinch-zoom`, without which iOS
|
|
26
|
+
* Safari scrolls the page from a drag on it or on its backdrop.
|
|
27
|
+
*/
|
|
28
|
+
function createScrollLock(options) {
|
|
29
|
+
let held;
|
|
30
|
+
let stopWaiting;
|
|
31
|
+
const release = () => {
|
|
32
|
+
stopWaiting?.();
|
|
33
|
+
held?.();
|
|
34
|
+
held = void 0;
|
|
35
|
+
};
|
|
36
|
+
onCleanup(release);
|
|
37
|
+
createEffect(() => options.open, (open) => {
|
|
38
|
+
const popup = options.popup;
|
|
39
|
+
if (!open || !popup) return;
|
|
40
|
+
stopWaiting?.();
|
|
41
|
+
if (!held) {
|
|
42
|
+
lock();
|
|
43
|
+
const unlockTouch = lockTouch(popup);
|
|
44
|
+
held = () => {
|
|
45
|
+
unlockTouch();
|
|
46
|
+
unlock();
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return () => {
|
|
50
|
+
queueMicrotask(() => {
|
|
51
|
+
if (!held || stopWaiting) return;
|
|
52
|
+
if (!popup.matches("[open], :popover-open")) return release();
|
|
53
|
+
const closed = (event) => {
|
|
54
|
+
if (event.newState !== "open") release();
|
|
55
|
+
};
|
|
56
|
+
stopWaiting = () => {
|
|
57
|
+
stopWaiting = void 0;
|
|
58
|
+
popup.removeEventListener("close", closed);
|
|
59
|
+
popup.removeEventListener("toggle", closed);
|
|
60
|
+
};
|
|
61
|
+
popup.addEventListener("close", closed);
|
|
62
|
+
popup.addEventListener("toggle", closed);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function lock() {
|
|
68
|
+
if (locks++) return;
|
|
69
|
+
const html = document.documentElement;
|
|
70
|
+
const style = html.style;
|
|
71
|
+
const lockStyles = {
|
|
72
|
+
"overflow-x": "hidden",
|
|
73
|
+
"overflow-y": "hidden"
|
|
74
|
+
};
|
|
75
|
+
const scrollbarWidth = innerWidth - html.clientWidth;
|
|
76
|
+
const computed = getComputedStyle(html);
|
|
77
|
+
if (scrollbarWidth > 0 && !computed.getPropertyValue("scrollbar-gutter").startsWith("stable")) {
|
|
78
|
+
lockStyles["padding-right"] = `${parseFloat(computed.paddingRight) + scrollbarWidth}px`;
|
|
79
|
+
lockStyles["--hidden-scrollbar-width"] = `${scrollbarWidth}px`;
|
|
80
|
+
}
|
|
81
|
+
restoreStyles = saveStyles(style, Object.keys(lockStyles));
|
|
82
|
+
for (const name in lockStyles) style.setProperty(name, lockStyles[name]);
|
|
83
|
+
}
|
|
84
|
+
function unlock() {
|
|
85
|
+
if (!--locks) restoreStyles();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* What keeps iOS Safari from scrolling the page through the popup, whatever
|
|
89
|
+
* the page's `overflow`: `overscroll-behavior: contain`, so a popup that
|
|
90
|
+
* scrolls stops at its end, and `touch-action: pinch-zoom` on a popup that
|
|
91
|
+
* does not scroll itself, so that a drag on it, or on its backdrop, which
|
|
92
|
+
* hits the popup, pans nothing. Checked again as the popup or its content
|
|
93
|
+
* changes size. A popup that scrolls keeps its own `touch-action`, since
|
|
94
|
+
* Chromium would no longer scroll it by touch.
|
|
95
|
+
*/
|
|
96
|
+
function lockTouch(popup) {
|
|
97
|
+
const style = popup.style;
|
|
98
|
+
const restoreContain = saveStyles(style, ["overscroll-behavior"]);
|
|
99
|
+
const restoreTouch = saveStyles(style, ["touch-action"]);
|
|
100
|
+
style.setProperty("overscroll-behavior", "contain");
|
|
101
|
+
const observer = new ResizeObserver(() => {
|
|
102
|
+
for (const child of popup.children) observer.observe(child);
|
|
103
|
+
if (popup.scrollHeight > popup.clientHeight || popup.scrollWidth > popup.clientWidth) restoreTouch();
|
|
104
|
+
else style.setProperty("touch-action", "pinch-zoom");
|
|
105
|
+
});
|
|
106
|
+
observer.observe(popup);
|
|
107
|
+
return () => {
|
|
108
|
+
observer.disconnect();
|
|
109
|
+
restoreTouch();
|
|
110
|
+
restoreContain();
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Saves the inline values of `names`, and returns what puts them back. */
|
|
114
|
+
function saveStyles(style, names) {
|
|
115
|
+
const saved = names.map((name) => [
|
|
116
|
+
name,
|
|
117
|
+
style.getPropertyValue(name),
|
|
118
|
+
style.getPropertyPriority(name)
|
|
119
|
+
]);
|
|
120
|
+
return () => {
|
|
121
|
+
for (const [name, value, priority] of saved) if (value) style.setProperty(name, value, priority);
|
|
122
|
+
else style.removeProperty(name);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export { createScrollLock };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/floating/typeahead/match.ts
|
|
2
|
+
var collator;
|
|
3
|
+
/**
|
|
4
|
+
* The item that `typed` moves to, from `active`, or `undefined`:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const item = findMatch(list.items(), list.active(), "ba");
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
function findMatch(items, active, typed) {
|
|
11
|
+
const characters = [...typed];
|
|
12
|
+
const cycles = characters.every((character) => character === characters[0]);
|
|
13
|
+
const search = cycles ? characters[0] : typed;
|
|
14
|
+
const count = items.length;
|
|
15
|
+
const index = items.indexOf(active);
|
|
16
|
+
const start = index < 0 ? 0 : index + (cycles ? 1 : 0);
|
|
17
|
+
for (let offset = 0; offset < count; offset++) {
|
|
18
|
+
const item = items[(start + offset) % count];
|
|
19
|
+
const text = (item.text ?? item.element.textContent ?? "").trimStart();
|
|
20
|
+
collator ??= new Intl.Collator(void 0, { sensitivity: "base" });
|
|
21
|
+
if (!collator.compare(text.slice(0, search.length), search)) return item;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export { findMatch };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { findMatch } from "./match.js";
|
|
2
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
3
|
+
// src/floating/typeahead/typeahead.ts
|
|
4
|
+
var resetDelay = 1e3;
|
|
5
|
+
/**
|
|
6
|
+
* Typing characters moves to the item whose text starts with them
|
|
7
|
+
* (`findMatch`). Characters typed less than a second apart make one string;
|
|
8
|
+
* Space joins a string being typed. The component hands over list
|
|
9
|
+
* navigation's items, active item and move, and calls the handler from its
|
|
10
|
+
* items' key events, before its own Space activation:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const typeahead = createTypeahead<Entry>({
|
|
14
|
+
* get open() { return open(); },
|
|
15
|
+
* get items() { return list.items(); },
|
|
16
|
+
* get active() { return list.active(); },
|
|
17
|
+
* move: (item) => list.move(item),
|
|
18
|
+
* });
|
|
19
|
+
* // In the item part:
|
|
20
|
+
* onKeyDown: (event) => {
|
|
21
|
+
* if (typeahead.onKeyDown(event) || list.onKeyDown(event)) return;
|
|
22
|
+
* if (event.key === " " || event.key === "Enter") activate(event);
|
|
23
|
+
* },
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* The handler cancels each key it uses. Closing the popup (`open` turning
|
|
27
|
+
* false) and disposal clear the string and its timer; opening does not, so
|
|
28
|
+
* a closed Select's trigger may open on the first key and the string goes
|
|
29
|
+
* on. Nothing runs at import time, nor, until a key, on the server.
|
|
30
|
+
*/
|
|
31
|
+
function createTypeahead(options) {
|
|
32
|
+
let typed = "";
|
|
33
|
+
let timer;
|
|
34
|
+
const reset = () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
typed = "";
|
|
37
|
+
};
|
|
38
|
+
createEffect(() => options.open, (open) => {
|
|
39
|
+
if (open === false) reset();
|
|
40
|
+
});
|
|
41
|
+
onCleanup(reset);
|
|
42
|
+
return { onKeyDown: (event) => {
|
|
43
|
+
const { key, target } = event;
|
|
44
|
+
const items = options.items;
|
|
45
|
+
if (target !== event.currentTarget && !items.some((item) => item.element === target) || event.isComposing || event.ctrlKey || event.altKey || event.metaKey || !/^.$/u.test(key) || key === " " && !typed) return false;
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
typed += key;
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
timer = setTimeout(reset, resetDelay);
|
|
50
|
+
const active = options.active;
|
|
51
|
+
const match = findMatch(items, active, typed);
|
|
52
|
+
if (match && match !== active) options.move(match);
|
|
53
|
+
return true;
|
|
54
|
+
} };
|
|
55
|
+
}
|
|
56
|
+
export { createTypeahead };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NavigationMenuRoot } from "./root/NavigationMenuRoot.js";
|
|
2
|
+
import { NavigationMenuItem } from "./item/NavigationMenuItem.js";
|
|
3
|
+
import { NavigationMenuTrigger } from "./trigger/NavigationMenuTrigger.js";
|
|
4
|
+
import { NavigationMenuPanel } from "./panel/NavigationMenuPanel.js";
|
|
5
|
+
import { NavigationMenuLink } from "./link/NavigationMenuLink.js";
|
|
6
|
+
export { NavigationMenuItem as Item, NavigationMenuLink as Link, NavigationMenuPanel as Panel, NavigationMenuRoot as Root, NavigationMenuTrigger as Trigger };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createEscape } from "../../floating/dismissal/escape.js";
|
|
4
|
+
import { createHover } from "../../floating/hover/hover.js";
|
|
5
|
+
import { useNavigationMenuRootContext } from "../root/NavigationMenuRootContext.js";
|
|
6
|
+
import { NavigationMenuItemContext } from "./NavigationMenuItemContext.js";
|
|
7
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
8
|
+
import { createUniqueId, merge, omit } from "solid-js";
|
|
9
|
+
// src/navigation-menu/item/NavigationMenuItem.tsx
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template(`<li>`);
|
|
11
|
+
/**
|
|
12
|
+
* One entry of the bar: an `<li>` around a `NavigationMenu.Trigger` and its
|
|
13
|
+
* `NavigationMenu.Panel`. Place it inside `NavigationMenu.Root`, in the
|
|
14
|
+
* `<ul>` of the bar.
|
|
15
|
+
*/
|
|
16
|
+
function NavigationMenuItem(props) {
|
|
17
|
+
const root = useNavigationMenuRootContext("Item");
|
|
18
|
+
const panelId = createUniqueId();
|
|
19
|
+
const value = () => props.value ?? panelId;
|
|
20
|
+
const open = () => root.value() === value();
|
|
21
|
+
const attributes = {
|
|
22
|
+
get "data-open"() {
|
|
23
|
+
return open() ? "" : void 0;
|
|
24
|
+
},
|
|
25
|
+
get "data-closed"() {
|
|
26
|
+
return open() ? void 0 : "";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const context = {
|
|
30
|
+
open,
|
|
31
|
+
toggle: (event) => root.toggle(value(), event),
|
|
32
|
+
panelId,
|
|
33
|
+
trigger: void 0,
|
|
34
|
+
panel: void 0,
|
|
35
|
+
attributes
|
|
36
|
+
};
|
|
37
|
+
let element;
|
|
38
|
+
createHover({
|
|
39
|
+
get trigger() {
|
|
40
|
+
return context.trigger;
|
|
41
|
+
},
|
|
42
|
+
get popup() {
|
|
43
|
+
return context.panel;
|
|
44
|
+
},
|
|
45
|
+
get open() {
|
|
46
|
+
return open();
|
|
47
|
+
},
|
|
48
|
+
get delay() {
|
|
49
|
+
return root.hoverDelay();
|
|
50
|
+
},
|
|
51
|
+
get closeDelay() {
|
|
52
|
+
return root.closeDelay();
|
|
53
|
+
},
|
|
54
|
+
onOpenChange: (next, details) => {
|
|
55
|
+
if (next) root.hoverOpen(value(), details);
|
|
56
|
+
else if (!context.panel?.contains(document.activeElement)) root.hoverClose(value(), details);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
createEscape({
|
|
60
|
+
get open() {
|
|
61
|
+
return open();
|
|
62
|
+
},
|
|
63
|
+
onDismiss: (details) => {
|
|
64
|
+
if (element?.contains(document.activeElement)) context.trigger?.focus();
|
|
65
|
+
root.close(details);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const ownProps = merge(attributes, { ref: (el) => {
|
|
69
|
+
element = el;
|
|
70
|
+
} });
|
|
71
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value"));
|
|
72
|
+
return createComponent(NavigationMenuItemContext, {
|
|
73
|
+
value: context,
|
|
74
|
+
get children() {
|
|
75
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
76
|
+
var _el$ = _tmpl$();
|
|
77
|
+
spread(_el$, p, false);
|
|
78
|
+
return _el$;
|
|
79
|
+
})());
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export { NavigationMenuItem };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/navigation-menu/item/NavigationMenuItemContext.ts
|
|
4
|
+
var NavigationMenuItemContext = createContext(null);
|
|
5
|
+
function useNavigationMenuItemContext() {
|
|
6
|
+
const context = useContext(NavigationMenuItemContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] NavigationMenu.Trigger and NavigationMenu.Panel must be placed within <NavigationMenu.Item>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { NavigationMenuItemContext, useNavigationMenuItemContext };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useNavigationMenuRootContext } from "../root/NavigationMenuRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/navigation-menu/link/NavigationMenuLink.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<a>`);
|
|
8
|
+
/**
|
|
9
|
+
* A link of the navigation: an `<a>` that closes the open Panel when it is
|
|
10
|
+
* activated, by pointer or by Enter, so a router's page change leaves no
|
|
11
|
+
* menu open. Pass `href`, and `aria-current="page"` on the current page's
|
|
12
|
+
* link. Place it anywhere inside `NavigationMenu.Root`.
|
|
13
|
+
*/
|
|
14
|
+
function NavigationMenuLink(props) {
|
|
15
|
+
const root = useNavigationMenuRootContext("Link");
|
|
16
|
+
const elementProps = mergeElementProps({ onClick: (event) => root.close({
|
|
17
|
+
reason: "link-press",
|
|
18
|
+
event
|
|
19
|
+
}) }, omit(props, "render"));
|
|
20
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
21
|
+
var _el$ = _tmpl$();
|
|
22
|
+
spread(_el$, p, false);
|
|
23
|
+
return _el$;
|
|
24
|
+
})());
|
|
25
|
+
}
|
|
26
|
+
export { NavigationMenuLink };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useNavigationMenuItemContext } from "../item/NavigationMenuItemContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { merge, omit } from "solid-js";
|
|
6
|
+
// src/navigation-menu/panel/NavigationMenuPanel.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The links its Item's Trigger shows and hides: a `<div>` in the page's
|
|
10
|
+
* flow, `hidden` while closed, which your CSS places under the Item. Place
|
|
11
|
+
* it inside `NavigationMenu.Item`, after `NavigationMenu.Trigger`.
|
|
12
|
+
*/
|
|
13
|
+
function NavigationMenuPanel(props) {
|
|
14
|
+
const item = useNavigationMenuItemContext();
|
|
15
|
+
const ownProps = merge(item.attributes, {
|
|
16
|
+
id: item.panelId,
|
|
17
|
+
get hidden() {
|
|
18
|
+
return !item.open();
|
|
19
|
+
},
|
|
20
|
+
ref: (element) => {
|
|
21
|
+
item.panel = element;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
25
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
26
|
+
var _el$ = _tmpl$();
|
|
27
|
+
spread(_el$, p, false);
|
|
28
|
+
return _el$;
|
|
29
|
+
})());
|
|
30
|
+
}
|
|
31
|
+
export { NavigationMenuPanel };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { NavigationMenuRootContext } from "./NavigationMenuRootContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { createEffect, omit } from "solid-js";
|
|
7
|
+
// src/navigation-menu/root/NavigationMenuRoot.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<nav>`);
|
|
9
|
+
/**
|
|
10
|
+
* A site's navigation: a `<nav>` that holds which `NavigationMenu.Item` is
|
|
11
|
+
* open, one at a time. Focus moving out of it, and a press outside it,
|
|
12
|
+
* close the open Item.
|
|
13
|
+
*/
|
|
14
|
+
function NavigationMenuRoot(props) {
|
|
15
|
+
const [value, setValue, requested] = createControllableSignal({
|
|
16
|
+
get value() {
|
|
17
|
+
return props.value;
|
|
18
|
+
},
|
|
19
|
+
get defaultValue() {
|
|
20
|
+
return props.defaultValue ?? null;
|
|
21
|
+
},
|
|
22
|
+
onChange: (next, details) => props.onValueChange?.(next, details)
|
|
23
|
+
});
|
|
24
|
+
let pressedItem = null;
|
|
25
|
+
let closedAt = -Infinity;
|
|
26
|
+
const set = (next, details) => {
|
|
27
|
+
if (next === null && requested() !== null) closedAt = Date.now();
|
|
28
|
+
pressedItem = null;
|
|
29
|
+
setValue(next, details);
|
|
30
|
+
};
|
|
31
|
+
const close = (details) => set(null, details);
|
|
32
|
+
let nav;
|
|
33
|
+
const inside = (target) => !!target && !!nav?.contains(target);
|
|
34
|
+
let pressOutside = false;
|
|
35
|
+
createEffect(() => value() !== null, (open) => {
|
|
36
|
+
if (!open) return;
|
|
37
|
+
const down = (event) => {
|
|
38
|
+
pressOutside = event.button === 0 && !inside(event.target);
|
|
39
|
+
};
|
|
40
|
+
const cancel = () => {
|
|
41
|
+
pressOutside = false;
|
|
42
|
+
};
|
|
43
|
+
const click = (event) => {
|
|
44
|
+
if (pressOutside && !inside(event.target)) close({
|
|
45
|
+
reason: "outside-press",
|
|
46
|
+
event
|
|
47
|
+
});
|
|
48
|
+
pressOutside = false;
|
|
49
|
+
};
|
|
50
|
+
document.addEventListener("pointerdown", down, true);
|
|
51
|
+
document.addEventListener("pointercancel", cancel, true);
|
|
52
|
+
document.addEventListener("click", click, true);
|
|
53
|
+
return () => {
|
|
54
|
+
cancel();
|
|
55
|
+
document.removeEventListener("pointerdown", down, true);
|
|
56
|
+
document.removeEventListener("pointercancel", cancel, true);
|
|
57
|
+
document.removeEventListener("click", click, true);
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
const context = {
|
|
61
|
+
value,
|
|
62
|
+
toggle: (item, event) => {
|
|
63
|
+
const next = requested() === item ? null : item;
|
|
64
|
+
set(next, {
|
|
65
|
+
reason: "trigger-press",
|
|
66
|
+
event
|
|
67
|
+
});
|
|
68
|
+
pressedItem = next;
|
|
69
|
+
},
|
|
70
|
+
hoverOpen: set,
|
|
71
|
+
hoverClose: (item, details) => {
|
|
72
|
+
if (requested() === item && pressedItem !== item) close(details);
|
|
73
|
+
},
|
|
74
|
+
close,
|
|
75
|
+
hoverDelay: () => requested() !== null || Date.now() - closedAt < (props.timeout ?? 400) ? 0 : props.delay ?? 300,
|
|
76
|
+
closeDelay: () => props.closeDelay ?? 200
|
|
77
|
+
};
|
|
78
|
+
const elementProps = mergeElementProps({
|
|
79
|
+
onFocusOut: (event) => {
|
|
80
|
+
if (event.relatedTarget && !inside(event.relatedTarget) && !pressOutside) close({
|
|
81
|
+
reason: "focus-out",
|
|
82
|
+
event
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
ref: (element) => {
|
|
86
|
+
nav = element;
|
|
87
|
+
}
|
|
88
|
+
}, omit(props, "render", "value", "defaultValue", "onValueChange", "delay", "closeDelay", "timeout"));
|
|
89
|
+
return createComponent(NavigationMenuRootContext, {
|
|
90
|
+
value: context,
|
|
91
|
+
get children() {
|
|
92
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
93
|
+
var _el$ = _tmpl$();
|
|
94
|
+
spread(_el$, p, false);
|
|
95
|
+
return _el$;
|
|
96
|
+
})());
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
export { NavigationMenuRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/navigation-menu/root/NavigationMenuRootContext.ts
|
|
4
|
+
var NavigationMenuRootContext = createContext(null);
|
|
5
|
+
function useNavigationMenuRootContext(part) {
|
|
6
|
+
const context = useContext(NavigationMenuRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error(`[menhir] NavigationMenu.${part} must be placed within <NavigationMenu.Root>.`);
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { NavigationMenuRootContext, useNavigationMenuRootContext };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { useNavigationMenuItemContext } from "../item/NavigationMenuItemContext.js";
|
|
5
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/navigation-menu/trigger/NavigationMenuTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that shows and hides its Item's Panel: a
|
|
11
|
+
* `<button type="button" aria-expanded>`. A press toggles the Panel, and
|
|
12
|
+
* the pointer resting on it opens it. Place it inside
|
|
13
|
+
* `NavigationMenu.Item`, before `NavigationMenu.Panel`.
|
|
14
|
+
*/
|
|
15
|
+
function NavigationMenuTrigger(props) {
|
|
16
|
+
const item = useNavigationMenuItemContext();
|
|
17
|
+
const ownProps = merge(item.attributes, {
|
|
18
|
+
type: "button",
|
|
19
|
+
get "aria-expanded"() {
|
|
20
|
+
return item.open() ? "true" : "false";
|
|
21
|
+
},
|
|
22
|
+
"aria-controls": item.panelId,
|
|
23
|
+
onClick: (event) => item.toggle(event),
|
|
24
|
+
ref: (element) => {
|
|
25
|
+
item.trigger = element;
|
|
26
|
+
if (isDev) warnUnlessButton(element, "NavigationMenu.Trigger");
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
30
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
31
|
+
var _el$ = _tmpl$();
|
|
32
|
+
spread(_el$, p, false);
|
|
33
|
+
return _el$;
|
|
34
|
+
})());
|
|
35
|
+
}
|
|
36
|
+
export { NavigationMenuTrigger };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { arrow } from "../../floating/positioning/arrow.js";
|
|
4
|
+
import { usePopoverPopupContext } from "../popup/PopoverPopupContext.js";
|
|
5
|
+
import { usePopoverRootContext } from "../root/PopoverRootContext.js";
|
|
6
|
+
import { spread, template } from "@solidjs/web";
|
|
7
|
+
import { merge, omit, onSettled } from "solid-js";
|
|
8
|
+
// src/popover/arrow/PopoverArrow.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
10
|
+
/**
|
|
11
|
+
* An arrow that points at the anchor's center: an `aria-hidden` `<div>`
|
|
12
|
+
* whose `left` or `top` the Popup writes. Position it absolutely on the
|
|
13
|
+
* Popup's edge by its `data-side`. Place it inside `Popover.Popup`.
|
|
14
|
+
*/
|
|
15
|
+
function PopoverArrow(props) {
|
|
16
|
+
const root = usePopoverRootContext();
|
|
17
|
+
const popup = usePopoverPopupContext();
|
|
18
|
+
let element;
|
|
19
|
+
onSettled(() => popup.registerArrow(() => arrow({ element })));
|
|
20
|
+
const ownProps = merge(root.attributes, {
|
|
21
|
+
"aria-hidden": "true",
|
|
22
|
+
get "data-side"() {
|
|
23
|
+
return popup.position()?.side;
|
|
24
|
+
},
|
|
25
|
+
get "data-align"() {
|
|
26
|
+
return popup.position()?.align;
|
|
27
|
+
},
|
|
28
|
+
ref: (el) => {
|
|
29
|
+
element = el;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
33
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
34
|
+
var _el$ = _tmpl$();
|
|
35
|
+
spread(_el$, p, false);
|
|
36
|
+
return _el$;
|
|
37
|
+
})());
|
|
38
|
+
}
|
|
39
|
+
export { PopoverArrow };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { usePopoverRootContext } from "../root/PopoverRootContext.js";
|
|
5
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/popover/close/PopoverClose.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* A button that closes the popover: a `<button type="button">`, such as
|
|
11
|
+
* "Cancel" or a close icon with an `aria-label`. Place it inside
|
|
12
|
+
* `Popover.Popup`.
|
|
13
|
+
*/
|
|
14
|
+
function PopoverClose(props) {
|
|
15
|
+
const root = usePopoverRootContext();
|
|
16
|
+
const ownProps = merge(root.attributes, {
|
|
17
|
+
type: "button",
|
|
18
|
+
onClick: (event) => root.setOpen(false, {
|
|
19
|
+
reason: "close-press",
|
|
20
|
+
event
|
|
21
|
+
}),
|
|
22
|
+
ref: (element) => {
|
|
23
|
+
if (isDev) warnUnlessButton(element, "Popover.Close");
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
27
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
28
|
+
var _el$ = _tmpl$();
|
|
29
|
+
spread(_el$, p, false);
|
|
30
|
+
return _el$;
|
|
31
|
+
})());
|
|
32
|
+
}
|
|
33
|
+
export { PopoverClose };
|