menhir 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -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 +4 -3
- 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 +43 -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/positioning/arrow.js +21 -0
- package/dist/floating/positioning/createPosition.js +122 -0
- package/dist/floating/positioning/flip.js +1 -0
- package/dist/floating/positioning/hide.js +14 -0
- package/dist/floating/positioning/offset.js +1 -0
- package/dist/floating/positioning/shift.js +1 -0
- package/dist/floating/positioning/size.js +39 -0
- package/dist/floating/presence/presence.js +57 -0
- package/dist/floating/scroll-lock/scrollLock.js +125 -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 +5 -4
- package/dist/source/core/createControllableSignal.js +4 -3
- 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 +23 -0
- package/dist/source/floating/dismissal/escape.js +47 -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 +30 -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/positioning/arrow.d.ts +13 -0
- package/dist/source/floating/positioning/arrow.js +20 -0
- package/dist/source/floating/positioning/createPosition.d.ts +53 -0
- package/dist/source/floating/positioning/createPosition.js +138 -0
- package/dist/source/floating/positioning/flip.d.ts +1 -0
- package/dist/source/floating/positioning/flip.js +3 -0
- package/dist/source/floating/positioning/hide.d.ts +8 -0
- package/dist/source/floating/positioning/hide.js +12 -0
- package/dist/source/floating/positioning/offset.d.ts +1 -0
- package/dist/source/floating/positioning/offset.js +3 -0
- package/dist/source/floating/positioning/shift.d.ts +1 -0
- package/dist/source/floating/positioning/shift.js +2 -0
- package/dist/source/floating/positioning/size.d.ts +12 -0
- package/dist/source/floating/positioning/size.js +35 -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/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 +24 -1
|
@@ -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,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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { usePopoverRootContext } from "../root/PopoverRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId, merge, omit, onSettled } from "solid-js";
|
|
6
|
+
// src/popover/description/PopoverDescription.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<p>`);
|
|
8
|
+
/**
|
|
9
|
+
* What the popover is for, which describes the Popup in
|
|
10
|
+
* `aria-describedby`: a `<p>`. Place it inside `Popover.Popup`.
|
|
11
|
+
*/
|
|
12
|
+
function PopoverDescription(props) {
|
|
13
|
+
const root = usePopoverRootContext();
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const id = () => props.id ?? generated;
|
|
16
|
+
onSettled(() => root.registerDescriptionId(id));
|
|
17
|
+
const ownProps = merge(root.attributes, { get id() {
|
|
18
|
+
return id();
|
|
19
|
+
} });
|
|
20
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
21
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
22
|
+
var _el$ = _tmpl$();
|
|
23
|
+
spread(_el$, p, false);
|
|
24
|
+
return _el$;
|
|
25
|
+
})());
|
|
26
|
+
}
|
|
27
|
+
export { PopoverDescription };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PopoverRoot } from "./root/PopoverRoot.js";
|
|
2
|
+
import { PopoverTrigger } from "./trigger/PopoverTrigger.js";
|
|
3
|
+
import { PopoverPopup } from "./popup/PopoverPopup.js";
|
|
4
|
+
import { PopoverArrow } from "./arrow/PopoverArrow.js";
|
|
5
|
+
import { PopoverTitle } from "./title/PopoverTitle.js";
|
|
6
|
+
import { PopoverDescription } from "./description/PopoverDescription.js";
|
|
7
|
+
import { PopoverClose } from "./close/PopoverClose.js";
|
|
8
|
+
export { PopoverArrow as Arrow, PopoverClose as Close, PopoverDescription as Description, PopoverPopup as Popup, PopoverRoot as Root, PopoverTitle as Title, PopoverTrigger as Trigger };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createSlot } from "../../core/slot.js";
|
|
4
|
+
import { createPopoverClose } from "../../floating/dismissal/popoverClose.js";
|
|
5
|
+
import { createInitialFocus } from "../../floating/focus/initialFocus.js";
|
|
6
|
+
import { createReturnFocus } from "../../floating/focus/returnFocus.js";
|
|
7
|
+
import { createPosition } from "../../floating/positioning/createPosition.js";
|
|
8
|
+
import { flip } from "../../floating/positioning/flip.js";
|
|
9
|
+
import { offset } from "../../floating/positioning/offset.js";
|
|
10
|
+
import { shift } from "../../floating/positioning/shift.js";
|
|
11
|
+
import { createPresence } from "../../floating/presence/presence.js";
|
|
12
|
+
import { usePopoverRootContext } from "../root/PopoverRootContext.js";
|
|
13
|
+
import { PopoverPopupContext } from "./PopoverPopupContext.js";
|
|
14
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
15
|
+
import { merge, omit } from "solid-js";
|
|
16
|
+
// src/popover/popup/PopoverPopup.tsx
|
|
17
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
18
|
+
/**
|
|
19
|
+
* The popover itself: a `<div popover="auto" role="dialog">` in the top
|
|
20
|
+
* layer, placed against the Trigger. A press outside, Escape and the
|
|
21
|
+
* Trigger close it; the page stays usable. Named by `Popover.Title` and
|
|
22
|
+
* described by `Popover.Description` when they are rendered inside it.
|
|
23
|
+
* Place it inside `Popover.Root`, right after `Popover.Trigger`, so that
|
|
24
|
+
* Tab moves from the Trigger into it.
|
|
25
|
+
*/
|
|
26
|
+
function PopoverPopup(props) {
|
|
27
|
+
const root = usePopoverRootContext();
|
|
28
|
+
let popup;
|
|
29
|
+
let focusInside = false;
|
|
30
|
+
const [arrow, registerArrow] = createSlot();
|
|
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
|
+
get returnFocus() {
|
|
46
|
+
return props.returnFocus ?? ((focused) => focused ?? (focusInside ? root.trigger : void 0));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
createPresence(options);
|
|
50
|
+
createPopoverClose(options);
|
|
51
|
+
createInitialFocus(options);
|
|
52
|
+
createReturnFocus(options);
|
|
53
|
+
const position = createPosition({
|
|
54
|
+
get anchor() {
|
|
55
|
+
const anchor = props.anchor;
|
|
56
|
+
return (typeof anchor === "function" ? anchor() : anchor) ?? root.trigger;
|
|
57
|
+
},
|
|
58
|
+
get popup() {
|
|
59
|
+
return popup;
|
|
60
|
+
},
|
|
61
|
+
get open() {
|
|
62
|
+
return root.open();
|
|
63
|
+
},
|
|
64
|
+
get side() {
|
|
65
|
+
return props.side;
|
|
66
|
+
},
|
|
67
|
+
get align() {
|
|
68
|
+
return props.align;
|
|
69
|
+
},
|
|
70
|
+
get middleware() {
|
|
71
|
+
const padding = props.collisionPadding ?? 5;
|
|
72
|
+
const middleware = [
|
|
73
|
+
offset({
|
|
74
|
+
mainAxis: props.sideOffset ?? 0,
|
|
75
|
+
alignmentAxis: props.alignOffset ?? 0
|
|
76
|
+
}),
|
|
77
|
+
flip({ padding }),
|
|
78
|
+
shift({ padding })
|
|
79
|
+
];
|
|
80
|
+
const arrowMiddleware = arrow();
|
|
81
|
+
return arrowMiddleware ? [...middleware, arrowMiddleware] : middleware;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const ownProps = merge(root.attributes, {
|
|
85
|
+
id: root.popupId,
|
|
86
|
+
popover: "auto",
|
|
87
|
+
role: "dialog",
|
|
88
|
+
get "aria-labelledby"() {
|
|
89
|
+
return props["aria-labelledby"] ?? root.titleId();
|
|
90
|
+
},
|
|
91
|
+
get "aria-describedby"() {
|
|
92
|
+
return props["aria-describedby"] ?? root.descriptionId();
|
|
93
|
+
},
|
|
94
|
+
onBeforeToggle: (event) => {
|
|
95
|
+
focusInside = event.newState === "closed" && popup.contains(document.activeElement);
|
|
96
|
+
},
|
|
97
|
+
ref: (element) => {
|
|
98
|
+
popup = element;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "side", "align", "sideOffset", "alignOffset", "collisionPadding", "anchor", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby", "id"));
|
|
102
|
+
return createComponent(PopoverPopupContext, {
|
|
103
|
+
value: {
|
|
104
|
+
position,
|
|
105
|
+
registerArrow
|
|
106
|
+
},
|
|
107
|
+
get children() {
|
|
108
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
109
|
+
var _el$ = _tmpl$();
|
|
110
|
+
spread(_el$, p, false);
|
|
111
|
+
return _el$;
|
|
112
|
+
})());
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
export { PopoverPopup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/popover/popup/PopoverPopupContext.ts
|
|
4
|
+
var PopoverPopupContext = createContext(null);
|
|
5
|
+
function usePopoverPopupContext() {
|
|
6
|
+
const context = useContext(PopoverPopupContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Popover.Arrow must be placed within <Popover.Popup>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { PopoverPopupContext, usePopoverPopupContext };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { createIdSlot } from "../../core/slot.js";
|
|
3
|
+
import { PopoverRootContext } from "./PopoverRootContext.js";
|
|
4
|
+
import { createComponent } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId } from "solid-js";
|
|
6
|
+
// src/popover/root/PopoverRoot.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A non-modal popup placed against its trigger: holds whether it is open
|
|
9
|
+
* and shares it with `Popover.Trigger`, `Popover.Popup` and the parts
|
|
10
|
+
* inside it. Renders no element of its own.
|
|
11
|
+
*/
|
|
12
|
+
function PopoverRoot(props) {
|
|
13
|
+
const [open, setOpen] = createControllableSignal({
|
|
14
|
+
get value() {
|
|
15
|
+
return props.open;
|
|
16
|
+
},
|
|
17
|
+
get defaultValue() {
|
|
18
|
+
return props.defaultOpen ?? false;
|
|
19
|
+
},
|
|
20
|
+
onChange: (value, details) => props.onOpenChange?.(value, details)
|
|
21
|
+
});
|
|
22
|
+
const attributes = {
|
|
23
|
+
get "data-open"() {
|
|
24
|
+
return open() ? "" : void 0;
|
|
25
|
+
},
|
|
26
|
+
get "data-closed"() {
|
|
27
|
+
return open() ? void 0 : "";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const [titleId, registerTitleId] = createIdSlot();
|
|
31
|
+
const [descriptionId, registerDescriptionId] = createIdSlot();
|
|
32
|
+
const context = {
|
|
33
|
+
open,
|
|
34
|
+
setOpen,
|
|
35
|
+
popupId: createUniqueId(),
|
|
36
|
+
trigger: void 0,
|
|
37
|
+
titleId,
|
|
38
|
+
registerTitleId,
|
|
39
|
+
descriptionId,
|
|
40
|
+
registerDescriptionId,
|
|
41
|
+
attributes
|
|
42
|
+
};
|
|
43
|
+
return createComponent(PopoverRootContext, {
|
|
44
|
+
value: context,
|
|
45
|
+
get children() {
|
|
46
|
+
return props.children;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export { PopoverRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/popover/root/PopoverRootContext.ts
|
|
4
|
+
var PopoverRootContext = createContext(null);
|
|
5
|
+
function usePopoverRootContext() {
|
|
6
|
+
const context = useContext(PopoverRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Popover parts must be placed within <Popover.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { PopoverRootContext, usePopoverRootContext };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { usePopoverRootContext } from "../root/PopoverRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId, merge, omit, onSettled } from "solid-js";
|
|
6
|
+
// src/popover/title/PopoverTitle.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<h2>`);
|
|
8
|
+
/**
|
|
9
|
+
* The popover's title, which names the Popup in `aria-labelledby`: an
|
|
10
|
+
* `<h2>`. Place it inside `Popover.Popup`.
|
|
11
|
+
*/
|
|
12
|
+
function PopoverTitle(props) {
|
|
13
|
+
const root = usePopoverRootContext();
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const id = () => props.id ?? generated;
|
|
16
|
+
onSettled(() => root.registerTitleId(id));
|
|
17
|
+
const ownProps = merge(root.attributes, { get id() {
|
|
18
|
+
return id();
|
|
19
|
+
} });
|
|
20
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
21
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
22
|
+
var _el$ = _tmpl$();
|
|
23
|
+
spread(_el$, p, false);
|
|
24
|
+
return _el$;
|
|
25
|
+
})());
|
|
26
|
+
}
|
|
27
|
+
export { PopoverTitle };
|
|
@@ -0,0 +1,44 @@
|
|
|
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/trigger/PopoverTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that opens and closes the popover: a `<button type="button"
|
|
11
|
+
* aria-haspopup="dialog">` with `aria-expanded`, naming the Popup in
|
|
12
|
+
* `popovertarget` and `aria-controls`. Place it inside `Popover.Root`,
|
|
13
|
+
* right before `Popover.Popup`.
|
|
14
|
+
*/
|
|
15
|
+
function PopoverTrigger(props) {
|
|
16
|
+
const root = usePopoverRootContext();
|
|
17
|
+
const ownProps = merge(root.attributes, {
|
|
18
|
+
type: "button",
|
|
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
|
+
event.preventDefault();
|
|
27
|
+
root.setOpen(!root.open(), {
|
|
28
|
+
reason: "trigger-press",
|
|
29
|
+
event
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
ref: (element) => {
|
|
33
|
+
root.trigger = element;
|
|
34
|
+
if (isDev) warnUnlessButton(element, "Popover.Trigger");
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
38
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
39
|
+
var _el$ = _tmpl$();
|
|
40
|
+
spread(_el$, p, false);
|
|
41
|
+
return _el$;
|
|
42
|
+
})());
|
|
43
|
+
}
|
|
44
|
+
export { PopoverTrigger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as AlertDialog from "./index.parts.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as AlertDialog from "./index.parts.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DialogRoot as Root } from "../dialog/root/DialogRoot.tsx";
|
|
2
|
+
export { DialogTrigger as Trigger } from "../dialog/trigger/DialogTrigger.tsx";
|
|
3
|
+
export { AlertDialogPopup as Popup } from "./popup/AlertDialogPopup.tsx";
|
|
4
|
+
export { DialogTitle as Title } from "../dialog/title/DialogTitle.tsx";
|
|
5
|
+
export { DialogDescription as Description } from "../dialog/description/DialogDescription.tsx";
|
|
6
|
+
export { DialogClose as Close } from "../dialog/close/DialogClose.tsx";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Dialog's parts, but the Popup (README, "Decisions"; #32).
|
|
2
|
+
export { DialogRoot as Root } from "../dialog/root/DialogRoot.jsx";
|
|
3
|
+
export { DialogTrigger as Trigger } from "../dialog/trigger/DialogTrigger.jsx";
|
|
4
|
+
export { AlertDialogPopup as Popup } from "./popup/AlertDialogPopup.jsx";
|
|
5
|
+
export { DialogTitle as Title } from "../dialog/title/DialogTitle.jsx";
|
|
6
|
+
export { DialogDescription as Description } from "../dialog/description/DialogDescription.jsx";
|
|
7
|
+
export { DialogClose as Close } from "../dialog/close/DialogClose.jsx";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DialogPopupProps } from "../../dialog/popup/renderDialogPopup.tsx";
|
|
2
|
+
export type AlertDialogPopupProps = DialogPopupProps;
|
|
3
|
+
/**
|
|
4
|
+
* The alert dialog itself: a `<dialog role="alertdialog">`, opened with
|
|
5
|
+
* `showModal()`, so it is modal, in the top layer, over an inert page.
|
|
6
|
+
* Named by `AlertDialog.Title` and described by `AlertDialog.Description`,
|
|
7
|
+
* the message, when they are rendered inside it. Escape closes it; a press
|
|
8
|
+
* on the backdrop does not. Place it inside `AlertDialog.Root`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function AlertDialogPopup(props: AlertDialogPopupProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { renderDialogPopup } from "../../dialog/popup/renderDialogPopup.jsx";
|
|
2
|
+
/**
|
|
3
|
+
* The alert dialog itself: a `<dialog role="alertdialog">`, opened with
|
|
4
|
+
* `showModal()`, so it is modal, in the top layer, over an inert page.
|
|
5
|
+
* Named by `AlertDialog.Title` and described by `AlertDialog.Description`,
|
|
6
|
+
* the message, when they are rendered inside it. Escape closes it; a press
|
|
7
|
+
* on the backdrop does not. Place it inside `AlertDialog.Root`.
|
|
8
|
+
*/
|
|
9
|
+
export function AlertDialogPopup(props) {
|
|
10
|
+
return renderDialogPopup(props, undefined, "alertdialog");
|
|
11
|
+
}
|
|
@@ -18,10 +18,11 @@ import type { Accessor } from "solid-js";
|
|
|
18
18
|
* (`onFlush`), so async work that `onChange` starts does not hold it back.
|
|
19
19
|
* Setting the value it already has, counting earlier sets in the same turn,
|
|
20
20
|
* does nothing. Set from event handlers, not from a component body or a
|
|
21
|
-
* memo.
|
|
21
|
+
* memo. A set may pass `details`, such as why a popup closed, which
|
|
22
|
+
* `onChange` receives after the value.
|
|
22
23
|
*/
|
|
23
|
-
export declare function createControllableSignal<T>(options: {
|
|
24
|
+
export declare function createControllableSignal<T, Details = void>(options: {
|
|
24
25
|
readonly value?: T;
|
|
25
26
|
readonly defaultValue: T;
|
|
26
|
-
onChange?: (value: T) => void;
|
|
27
|
-
}): [value: Accessor<T>, setValue: (next: T) => void];
|
|
27
|
+
onChange?: (value: T, details: Details) => void;
|
|
28
|
+
}): [value: Accessor<T>, setValue: (next: T, details: Details) => void];
|
|
@@ -19,7 +19,8 @@ import { createSignal, onFlush, untrack } from "solid-js";
|
|
|
19
19
|
* (`onFlush`), so async work that `onChange` starts does not hold it back.
|
|
20
20
|
* Setting the value it already has, counting earlier sets in the same turn,
|
|
21
21
|
* does nothing. Set from event handlers, not from a component body or a
|
|
22
|
-
* memo.
|
|
22
|
+
* memo. A set may pass `details`, such as why a popup closed, which
|
|
23
|
+
* `onChange` receives after the value.
|
|
23
24
|
*/
|
|
24
25
|
export function createControllableSignal(options) {
|
|
25
26
|
// A writable derived signal that reads the default once, untracked, so a
|
|
@@ -51,7 +52,7 @@ export function createControllableSignal(options) {
|
|
|
51
52
|
// Reads lag writes, so a set is compared with the last value set in this
|
|
52
53
|
// turn, if any, not with what `value` still reads.
|
|
53
54
|
let pending;
|
|
54
|
-
const setValue = (next) => {
|
|
55
|
+
const setValue = (next, details) => {
|
|
55
56
|
if (Object.is(next, pending ? pending[0] : untrack(value)))
|
|
56
57
|
return;
|
|
57
58
|
// The part's own write is an update of its own, after the pending
|
|
@@ -60,7 +61,7 @@ export function createControllableSignal(options) {
|
|
|
60
61
|
// until that work settled.
|
|
61
62
|
if (!untrack(isControlled))
|
|
62
63
|
onFlush(() => setInternal(() => next));
|
|
63
|
-
options.onChange?.(next);
|
|
64
|
+
options.onChange?.(next, details);
|
|
64
65
|
const set = [next];
|
|
65
66
|
pending = set;
|
|
66
67
|
// `onFlush` callbacks run in call order, each flushed before the next,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value that one part registers once mounted, for another part to read,
|
|
3
|
+
* such as the Arrow's middleware, which a popup's Popup uses to place it.
|
|
4
|
+
* Returns the value, `undefined` while none is registered, and `register`,
|
|
5
|
+
* which takes the value as a getter and returns what unregisters it, for
|
|
6
|
+
* the part's disposal. Unregistering removes only the part's own value, so
|
|
7
|
+
* one that another part registered after it stays.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createSlot<T>(): [
|
|
10
|
+
value: () => T | undefined,
|
|
11
|
+
register: (value: () => T) => () => void
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* A slot for the `id` of a part that another part names, such as a popup's
|
|
15
|
+
* Title, which the Popup names in `aria-labelledby`. `false`, a consumer's
|
|
16
|
+
* way to remove the part's `id`, names nothing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createIdSlot(): [
|
|
19
|
+
id: () => string | undefined,
|
|
20
|
+
register: (id: () => string | false) => () => void
|
|
21
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createSignal } from "solid-js";
|
|
2
|
+
/**
|
|
3
|
+
* A value that one part registers once mounted, for another part to read,
|
|
4
|
+
* such as the Arrow's middleware, which a popup's Popup uses to place it.
|
|
5
|
+
* Returns the value, `undefined` while none is registered, and `register`,
|
|
6
|
+
* which takes the value as a getter and returns what unregisters it, for
|
|
7
|
+
* the part's disposal. Unregistering removes only the part's own value, so
|
|
8
|
+
* one that another part registered after it stays.
|
|
9
|
+
*/
|
|
10
|
+
export function createSlot() {
|
|
11
|
+
const [slot, setSlot] = createSignal();
|
|
12
|
+
const value = () => slot()?.();
|
|
13
|
+
const register = (next) => {
|
|
14
|
+
setSlot(() => next);
|
|
15
|
+
return () => setSlot((current) => (current === next ? undefined : current));
|
|
16
|
+
};
|
|
17
|
+
return [value, register];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A slot for the `id` of a part that another part names, such as a popup's
|
|
21
|
+
* Title, which the Popup names in `aria-labelledby`. `false`, a consumer's
|
|
22
|
+
* way to remove the part's `id`, names nothing.
|
|
23
|
+
*/
|
|
24
|
+
export function createIdSlot() {
|
|
25
|
+
const [slot, register] = createSlot();
|
|
26
|
+
const id = () => slot() || undefined;
|
|
27
|
+
return [id, register];
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface DialogCloseProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
render?: RenderProp;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A button that closes the dialog: a `<button type="button">`, such as
|
|
8
|
+
* "Cancel" or a close icon with an `aria-label`. Place it inside
|
|
9
|
+
* `Dialog.Popup`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function DialogClose(props: DialogCloseProps): JSX.Element;
|