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
package/LICENSE
CHANGED
|
@@ -19,3 +19,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The shadcn look of the styling skill, skills/menhir-styling/looks/shadcn/,
|
|
26
|
+
reproduces class strings and token values from shadcn/ui, under the licence in
|
|
27
|
+
that folder's LICENSE file.
|
package/README.md
CHANGED
|
@@ -45,17 +45,24 @@ Nothing is styled. Every part exposes its state as data attributes, such as `dat
|
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
## Styling with a coding agent
|
|
49
|
+
|
|
50
|
+
The package ships a skill for coding agents, [`skills/menhir-styling`](skills/menhir-styling/SKILL.md), that styles Menhir components in one consistent look, such as the shadcn look in Tailwind CSS. Point your agent at it with a line in your project's `AGENTS.md`, "To style Menhir components, follow `node_modules/menhir/skills/menhir-styling/SKILL.md`", or copy the folder into your agent's skills folder. What to ask for, and how a look of your own works: [Styling](https://menhir-ui.com/docs/styling).
|
|
51
|
+
|
|
52
|
+
## Docs
|
|
53
|
+
|
|
48
54
|
For everything else, go to the docs:
|
|
49
55
|
|
|
50
56
|
- [Getting started](https://menhir-ui.com/docs/getting-started)
|
|
57
|
+
- [Styling](https://menhir-ui.com/docs/styling)
|
|
51
58
|
- [Components](https://menhir-ui.com/docs/components)
|
|
52
59
|
- [Bundle size](https://menhir-ui.com/docs/bundle-size) of every entry point
|
|
53
60
|
|
|
54
61
|
## Status
|
|
55
62
|
|
|
56
|
-
Early 0.x versions: the API may change between minor versions.
|
|
63
|
+
Early 0.x versions: the API may change between minor versions. Menu and the other list popups come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
|
|
57
64
|
|
|
58
|
-
- Components: Accordion, Checkbox, Collapsible, Meter, Progress, Separator, Switch, Tabs, Toggle
|
|
65
|
+
- Components: Accordion, Alert Dialog, Checkbox, Collapsible, Dialog, Meter, Navigation Menu, Popover, Progress, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
|
|
59
66
|
- Utilities: color scheme and theme, each with local-storage and cookie storage.
|
|
60
67
|
|
|
61
68
|
## Licence
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DialogRoot } from "../dialog/root/DialogRoot.js";
|
|
2
|
+
import { DialogTrigger } from "../dialog/trigger/DialogTrigger.js";
|
|
3
|
+
import { AlertDialogPopup } from "./popup/AlertDialogPopup.js";
|
|
4
|
+
import { DialogTitle } from "../dialog/title/DialogTitle.js";
|
|
5
|
+
import { DialogDescription } from "../dialog/description/DialogDescription.js";
|
|
6
|
+
import { DialogClose } from "../dialog/close/DialogClose.js";
|
|
7
|
+
export { DialogClose as Close, DialogDescription as Description, AlertDialogPopup as Popup, DialogRoot as Root, DialogTitle as Title, DialogTrigger as Trigger };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { renderDialogPopup } from "../../dialog/popup/renderDialogPopup.js";
|
|
2
|
+
// src/alert-dialog/popup/AlertDialogPopup.tsx
|
|
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
|
+
function AlertDialogPopup(props) {
|
|
11
|
+
return renderDialogPopup(props, void 0, "alertdialog");
|
|
12
|
+
}
|
|
13
|
+
export { AlertDialogPopup };
|
|
@@ -20,7 +20,12 @@ import { createSignal, onFlush, untrack } from "solid-js";
|
|
|
20
20
|
* (`onFlush`), so async work that `onChange` starts does not hold it back.
|
|
21
21
|
* Setting the value it already has, counting earlier sets in the same turn,
|
|
22
22
|
* does nothing. Set from event handlers, not from a component body or a
|
|
23
|
-
* memo.
|
|
23
|
+
* memo. A set may pass `details`, such as why a popup closed, which
|
|
24
|
+
* `onChange` receives after the value.
|
|
25
|
+
*
|
|
26
|
+
* The third item, `requested`, reads untracked the value set last in this
|
|
27
|
+
* turn, or `value` if nothing was: for a handler that builds on a set made
|
|
28
|
+
* earlier in the same turn, which `value` shows only after the flush.
|
|
24
29
|
*/
|
|
25
30
|
function createControllableSignal(options) {
|
|
26
31
|
const [internal, setInternal] = createSignal(() => untrack(() => options.defaultValue));
|
|
@@ -35,16 +40,21 @@ function createControllableSignal(options) {
|
|
|
35
40
|
};
|
|
36
41
|
const value = () => isControlled() ? options.value : internal();
|
|
37
42
|
let pending;
|
|
38
|
-
const
|
|
39
|
-
|
|
43
|
+
const requested = () => pending ? pending[0] : untrack(value);
|
|
44
|
+
const setValue = (next, details) => {
|
|
45
|
+
if (Object.is(next, requested())) return;
|
|
40
46
|
if (!untrack(isControlled)) onFlush(() => setInternal(() => next));
|
|
41
|
-
options.onChange?.(next);
|
|
47
|
+
options.onChange?.(next, details);
|
|
42
48
|
const set = [next];
|
|
43
49
|
pending = set;
|
|
44
50
|
onFlush(() => {
|
|
45
51
|
if (pending === set) pending = void 0;
|
|
46
52
|
});
|
|
47
53
|
};
|
|
48
|
-
return [
|
|
54
|
+
return [
|
|
55
|
+
value,
|
|
56
|
+
setValue,
|
|
57
|
+
requested
|
|
58
|
+
];
|
|
49
59
|
}
|
|
50
60
|
export { createControllableSignal };
|
package/dist/core/listValue.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createControllableSignal } from "./createControllableSignal.js";
|
|
2
|
-
import { onFlush } from "solid-js";
|
|
3
2
|
// src/core/listValue.ts
|
|
4
3
|
/**
|
|
5
4
|
* A part's value that lists items and that the consumer may control, as an
|
|
@@ -21,7 +20,7 @@ import { onFlush } from "solid-js";
|
|
|
21
20
|
* Sets in one turn build on each other, before the flush.
|
|
22
21
|
*/
|
|
23
22
|
function createListValue(options) {
|
|
24
|
-
const [value, setValue] = createControllableSignal({
|
|
23
|
+
const [value, setValue, requested] = createControllableSignal({
|
|
25
24
|
get value() {
|
|
26
25
|
return options.value;
|
|
27
26
|
},
|
|
@@ -30,18 +29,14 @@ function createListValue(options) {
|
|
|
30
29
|
},
|
|
31
30
|
onChange: (value) => options.onChange?.(value)
|
|
32
31
|
});
|
|
33
|
-
let pending;
|
|
34
32
|
return {
|
|
35
33
|
has: (item) => value().includes(item),
|
|
36
34
|
set: (item, included) => {
|
|
37
|
-
const current = pending ?? value();
|
|
38
35
|
let next = included ? [item] : [];
|
|
39
36
|
if (options.multiple) {
|
|
40
|
-
next =
|
|
37
|
+
next = requested().filter((other) => other !== item);
|
|
41
38
|
if (included) next.push(item);
|
|
42
39
|
}
|
|
43
|
-
if (!pending) onFlush(() => pending = void 0);
|
|
44
|
-
pending = next;
|
|
45
40
|
setValue(next);
|
|
46
41
|
}
|
|
47
42
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createSignal } from "solid-js";
|
|
2
|
+
// src/core/slot.ts
|
|
3
|
+
/**
|
|
4
|
+
* A value that one part registers once mounted, for another part to read,
|
|
5
|
+
* such as the Arrow's middleware, which a popup's Popup uses to place it.
|
|
6
|
+
* Returns the value, `undefined` while none is registered, and `register`,
|
|
7
|
+
* which takes the value as a getter and returns what unregisters it, for
|
|
8
|
+
* the part's disposal. Unregistering removes only the part's own value, so
|
|
9
|
+
* one that another part registered after it stays.
|
|
10
|
+
*/
|
|
11
|
+
function createSlot() {
|
|
12
|
+
const [slot, setSlot] = createSignal();
|
|
13
|
+
const value = () => slot()?.();
|
|
14
|
+
const register = (next) => {
|
|
15
|
+
setSlot(() => next);
|
|
16
|
+
return () => setSlot((current) => current === next ? void 0 : current);
|
|
17
|
+
};
|
|
18
|
+
return [value, register];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A slot for the `id` of a part that another part names, such as a popup's
|
|
22
|
+
* Title, which the Popup names in `aria-labelledby`. `false`, a consumer's
|
|
23
|
+
* way to remove the part's `id`, names nothing.
|
|
24
|
+
*/
|
|
25
|
+
function createIdSlot() {
|
|
26
|
+
const [slot, register] = createSlot();
|
|
27
|
+
const id = () => slot() || void 0;
|
|
28
|
+
return [id, register];
|
|
29
|
+
}
|
|
30
|
+
export { createIdSlot, createSlot };
|
|
@@ -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 { useDialogRootContext } from "../root/DialogRootContext.js";
|
|
5
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/dialog/close/DialogClose.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* A button that closes the dialog: a `<button type="button">`, such as
|
|
11
|
+
* "Cancel" or a close icon with an `aria-label`. Place it inside
|
|
12
|
+
* `Dialog.Popup`.
|
|
13
|
+
*/
|
|
14
|
+
function DialogClose(props) {
|
|
15
|
+
const root = useDialogRootContext();
|
|
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, "Dialog.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 { DialogClose };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useDialogRootContext } from "../root/DialogRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId, merge, omit, onSettled } from "solid-js";
|
|
6
|
+
// src/dialog/description/DialogDescription.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<p>`);
|
|
8
|
+
/**
|
|
9
|
+
* What the dialog is for, which describes the Popup in
|
|
10
|
+
* `aria-describedby`: a `<p>`. Place it inside `Dialog.Popup`.
|
|
11
|
+
*/
|
|
12
|
+
function DialogDescription(props) {
|
|
13
|
+
const root = useDialogRootContext();
|
|
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 { DialogDescription };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DialogRoot } from "./root/DialogRoot.js";
|
|
2
|
+
import { DialogTrigger } from "./trigger/DialogTrigger.js";
|
|
3
|
+
import { DialogPopup } from "./popup/DialogPopup.js";
|
|
4
|
+
import { DialogTitle } from "./title/DialogTitle.js";
|
|
5
|
+
import { DialogDescription } from "./description/DialogDescription.js";
|
|
6
|
+
import { DialogClose } from "./close/DialogClose.js";
|
|
7
|
+
export { DialogClose as Close, DialogDescription as Description, DialogPopup as Popup, DialogRoot as Root, DialogTitle as Title, DialogTrigger as Trigger };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createOutsidePress } from "../../floating/dismissal/outsidePress.js";
|
|
2
|
+
import { renderDialogPopup } from "./renderDialogPopup.js";
|
|
3
|
+
// src/dialog/popup/DialogPopup.tsx
|
|
4
|
+
/**
|
|
5
|
+
* The dialog itself: a `<dialog>`, opened with `showModal()`, so it is
|
|
6
|
+
* modal, in the top layer, over an inert page. Named by `Dialog.Title` and
|
|
7
|
+
* described by `Dialog.Description` when they are rendered inside it. A
|
|
8
|
+
* press on the backdrop closes it. Place it inside `Dialog.Root`.
|
|
9
|
+
*/
|
|
10
|
+
function DialogPopup(props) {
|
|
11
|
+
return renderDialogPopup(props, createOutsidePress);
|
|
12
|
+
}
|
|
13
|
+
export { DialogPopup };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { createDialogClose } from "../../floating/dismissal/dialogClose.js";
|
|
4
|
+
import { createInitialFocus } from "../../floating/focus/initialFocus.js";
|
|
5
|
+
import { createReturnFocus } from "../../floating/focus/returnFocus.js";
|
|
6
|
+
import { createTabWrap } from "../../floating/focus/tabWrap.js";
|
|
7
|
+
import { createPresence } from "../../floating/presence/presence.js";
|
|
8
|
+
import { createScrollLock } from "../../floating/scroll-lock/scrollLock.js";
|
|
9
|
+
import { useDialogRootContext } from "../root/DialogRootContext.js";
|
|
10
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
11
|
+
import { merge, omit } from "solid-js";
|
|
12
|
+
// src/dialog/popup/renderDialogPopup.tsx
|
|
13
|
+
var _tmpl$ = /* @__PURE__ */ template(`<dialog>`);
|
|
14
|
+
/**
|
|
15
|
+
* What a modal dialog's Popup does, for `Dialog.Popup` and
|
|
16
|
+
* `AlertDialog.Popup` (#32): a `<dialog>` opened with `showModal()`, closed
|
|
17
|
+
* by a close request, with Tab wrapping inside, the focus props, the page's
|
|
18
|
+
* scroll locked, and named by its Title and Description. `outsidePress`
|
|
19
|
+
* adds Dialog's press on the backdrop, so that Alert Dialog does not bundle
|
|
20
|
+
* it; `role` is Alert Dialog's `alertdialog`. Two arguments, not an
|
|
21
|
+
* options object, which measured 14 B more in `menhir/dialog`.
|
|
22
|
+
*/
|
|
23
|
+
function renderDialogPopup(props, outsidePress, role) {
|
|
24
|
+
const root = useDialogRootContext();
|
|
25
|
+
let dialog;
|
|
26
|
+
const options = {
|
|
27
|
+
get dialog() {
|
|
28
|
+
return dialog;
|
|
29
|
+
},
|
|
30
|
+
get popup() {
|
|
31
|
+
return dialog;
|
|
32
|
+
},
|
|
33
|
+
get open() {
|
|
34
|
+
return root.open();
|
|
35
|
+
},
|
|
36
|
+
onDismiss: (details) => root.setOpen(false, details),
|
|
37
|
+
get initialFocus() {
|
|
38
|
+
return props.initialFocus;
|
|
39
|
+
},
|
|
40
|
+
get returnFocus() {
|
|
41
|
+
return props.returnFocus;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
createPresence(options);
|
|
45
|
+
createDialogClose(options);
|
|
46
|
+
outsidePress?.(options);
|
|
47
|
+
createScrollLock(options);
|
|
48
|
+
createTabWrap(options);
|
|
49
|
+
createInitialFocus(options);
|
|
50
|
+
createReturnFocus(options);
|
|
51
|
+
const ownProps = merge(root.attributes, {
|
|
52
|
+
role,
|
|
53
|
+
get "aria-labelledby"() {
|
|
54
|
+
return props["aria-labelledby"] ?? root.titleId();
|
|
55
|
+
},
|
|
56
|
+
get "aria-describedby"() {
|
|
57
|
+
return props["aria-describedby"] ?? root.descriptionId();
|
|
58
|
+
},
|
|
59
|
+
ref: (element) => {
|
|
60
|
+
if (isDev && !(element instanceof HTMLDialogElement)) console.warn(`[menhir] ${role ? "AlertDialog" : "Dialog"}.Popup's render function rendered a <${element.tagName.toLowerCase()}>. Render a <dialog>, which the Popup opens with showModal().`);
|
|
61
|
+
dialog = element;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby"));
|
|
65
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
66
|
+
var _el$ = _tmpl$();
|
|
67
|
+
spread(_el$, p, false);
|
|
68
|
+
return _el$;
|
|
69
|
+
})());
|
|
70
|
+
}
|
|
71
|
+
export { renderDialogPopup };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { createIdSlot } from "../../core/slot.js";
|
|
3
|
+
import { DialogRootContext } from "./DialogRootContext.js";
|
|
4
|
+
import { createComponent } from "@solidjs/web";
|
|
5
|
+
// src/dialog/root/DialogRoot.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A modal dialog: holds whether it is open and shares it with
|
|
8
|
+
* `Dialog.Trigger`, `Dialog.Popup` and the parts inside it. Renders no
|
|
9
|
+
* element of its own.
|
|
10
|
+
*/
|
|
11
|
+
function DialogRoot(props) {
|
|
12
|
+
const [open, setOpen] = createControllableSignal({
|
|
13
|
+
get value() {
|
|
14
|
+
return props.open;
|
|
15
|
+
},
|
|
16
|
+
get defaultValue() {
|
|
17
|
+
return props.defaultOpen ?? false;
|
|
18
|
+
},
|
|
19
|
+
onChange: (value, details) => props.onOpenChange?.(value, details)
|
|
20
|
+
});
|
|
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 [titleId, registerTitleId] = createIdSlot();
|
|
30
|
+
const [descriptionId, registerDescriptionId] = createIdSlot();
|
|
31
|
+
return createComponent(DialogRootContext, {
|
|
32
|
+
value: {
|
|
33
|
+
open,
|
|
34
|
+
setOpen,
|
|
35
|
+
titleId,
|
|
36
|
+
registerTitleId,
|
|
37
|
+
descriptionId,
|
|
38
|
+
registerDescriptionId,
|
|
39
|
+
attributes
|
|
40
|
+
},
|
|
41
|
+
get children() {
|
|
42
|
+
return props.children;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export { DialogRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/dialog/root/DialogRootContext.ts
|
|
4
|
+
var DialogRootContext = createContext(null);
|
|
5
|
+
function useDialogRootContext() {
|
|
6
|
+
const context = useContext(DialogRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Dialog parts must be placed within <Dialog.Root>, and Alert Dialog parts within <AlertDialog.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { DialogRootContext, useDialogRootContext };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useDialogRootContext } from "../root/DialogRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { createUniqueId, merge, omit, onSettled } from "solid-js";
|
|
6
|
+
// src/dialog/title/DialogTitle.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<h2>`);
|
|
8
|
+
/**
|
|
9
|
+
* The dialog's title, which names the Popup in `aria-labelledby`: an
|
|
10
|
+
* `<h2>`. Place it inside `Dialog.Popup`.
|
|
11
|
+
*/
|
|
12
|
+
function DialogTitle(props) {
|
|
13
|
+
const root = useDialogRootContext();
|
|
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 { DialogTitle };
|
|
@@ -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 { useDialogRootContext } from "../root/DialogRootContext.js";
|
|
5
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/dialog/trigger/DialogTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that opens the dialog: a `<button type="button"
|
|
11
|
+
* aria-haspopup="dialog">`. Place it inside `Dialog.Root`.
|
|
12
|
+
*/
|
|
13
|
+
function DialogTrigger(props) {
|
|
14
|
+
const root = useDialogRootContext();
|
|
15
|
+
const ownProps = merge(root.attributes, {
|
|
16
|
+
type: "button",
|
|
17
|
+
"aria-haspopup": "dialog",
|
|
18
|
+
onClick: (event) => root.setOpen(true, {
|
|
19
|
+
reason: "trigger-press",
|
|
20
|
+
event
|
|
21
|
+
}),
|
|
22
|
+
ref: (element) => {
|
|
23
|
+
if (isDev) warnUnlessButton(element, "Dialog.Trigger");
|
|
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 { DialogTrigger };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createEffect, onFlush } from "solid-js";
|
|
2
|
+
// src/floating/dismissal/dialogClose.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reports a modal `<dialog>` that the browser closes, while `open`: Escape
|
|
5
|
+
* and other close requests (`cancel`), and a `<form method="dialog">`
|
|
6
|
+
* (`close`). The popup closes through its own state:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* createDialogClose({
|
|
10
|
+
* get dialog() { return dialog; },
|
|
11
|
+
* get open() { return open(); },
|
|
12
|
+
* onDismiss: (details) => setOpen(false, details),
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* `cancel` is always prevented, so the state decides. The browser closes
|
|
17
|
+
* the dialog anyway when `cancel` cannot be prevented, such as on a second
|
|
18
|
+
* Escape: that close is reported once, and if the state still says open
|
|
19
|
+
* once it has settled, the dialog is opened again with `showModal()`. A
|
|
20
|
+
* close the popup made itself, after its state turned false, is not
|
|
21
|
+
* reported.
|
|
22
|
+
*/
|
|
23
|
+
function createDialogClose(options) {
|
|
24
|
+
createEffect(() => options.open, (open) => {
|
|
25
|
+
const dialog = options.dialog;
|
|
26
|
+
if (!open || !dialog) return;
|
|
27
|
+
let escapeKey;
|
|
28
|
+
const keydown = (event) => {
|
|
29
|
+
if (event.key !== "Escape") return;
|
|
30
|
+
escapeKey = event;
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
if (escapeKey === event) escapeKey = void 0;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
let reported = false;
|
|
36
|
+
const cancel = (event) => {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
reported = !event.cancelable;
|
|
39
|
+
options.onDismiss(escapeKey ? {
|
|
40
|
+
reason: "escape-key",
|
|
41
|
+
event: escapeKey
|
|
42
|
+
} : {
|
|
43
|
+
reason: "close-request",
|
|
44
|
+
event
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const close = (event) => {
|
|
48
|
+
if (!reported) options.onDismiss({
|
|
49
|
+
reason: "close-request",
|
|
50
|
+
event
|
|
51
|
+
});
|
|
52
|
+
reported = false;
|
|
53
|
+
onFlush(() => {
|
|
54
|
+
if (options.open && !dialog.open) dialog.showModal();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
document.addEventListener("keydown", keydown, true);
|
|
58
|
+
dialog.addEventListener("cancel", cancel);
|
|
59
|
+
dialog.addEventListener("close", close);
|
|
60
|
+
return () => {
|
|
61
|
+
document.removeEventListener("keydown", keydown, true);
|
|
62
|
+
dialog.removeEventListener("cancel", cancel);
|
|
63
|
+
dialog.removeEventListener("close", close);
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export { createDialogClose };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
// src/floating/dismissal/escape.ts
|
|
3
|
+
/**
|
|
4
|
+
* Escape for a popup the browser does not close on Escape, a `manual`
|
|
5
|
+
* popover such as Tooltip's, or for content in the page's flow, such as
|
|
6
|
+
* Navigation Menu's Panels. While `open`, an Escape key calls `onDismiss`
|
|
7
|
+
* with the reason `escape-key`:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createEscape({
|
|
11
|
+
* get open() { return open(); },
|
|
12
|
+
* onDismiss: (details) => setOpen(false, details),
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Only the popup opened last closes, one per key. The key is marked
|
|
17
|
+
* handled (`preventDefault()`), so the browser does not also close a dialog
|
|
18
|
+
* or popover below, and carries on to the page's own listeners. A key
|
|
19
|
+
* already handled, or one pressed while an input method is composing, does
|
|
20
|
+
* nothing.
|
|
21
|
+
*/
|
|
22
|
+
function createEscape(options) {
|
|
23
|
+
createEffect(() => options.open, (open) => {
|
|
24
|
+
if (!open) return;
|
|
25
|
+
const claim = (event) => {
|
|
26
|
+
event.menhirEscapeClaim = claim;
|
|
27
|
+
};
|
|
28
|
+
const close = (event) => {
|
|
29
|
+
if (event.key !== "Escape" || event.isComposing || event.defaultPrevented || event.menhirEscapeClaim !== claim) return;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
options.onDismiss({
|
|
32
|
+
reason: "escape-key",
|
|
33
|
+
event
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
document.addEventListener("keydown", claim, true);
|
|
37
|
+
document.addEventListener("keydown", close);
|
|
38
|
+
return () => {
|
|
39
|
+
document.removeEventListener("keydown", claim, true);
|
|
40
|
+
document.removeEventListener("keydown", close);
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export { createEscape };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
// src/floating/dismissal/outsidePress.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reports a press on a modal `<dialog>`'s backdrop, while `open`, with the
|
|
5
|
+
* reason `outside-press`. The popup closes through its own state:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* createOutsidePress({
|
|
9
|
+
* get dialog() { return dialog; },
|
|
10
|
+
* get open() { return open(); },
|
|
11
|
+
* onDismiss: (details) => setOpen(false, details),
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* A press on the backdrop targets the `<dialog>` itself, as one on its
|
|
16
|
+
* padding or its own scrollbar does, so the backdrop is where the target is
|
|
17
|
+
* the dialog and the point is outside its border box. It closes on release,
|
|
18
|
+
* as the browser's light dismiss does: on the `click` of a primary-button
|
|
19
|
+
* press that also started on the backdrop. So a press dragged out of the
|
|
20
|
+
* dialog, a secondary button (no `click`) and a touch that scrolls
|
|
21
|
+
* (`pointercancel`, no `click`) do not close it.
|
|
22
|
+
*/
|
|
23
|
+
function createOutsidePress(options) {
|
|
24
|
+
createEffect(() => options.open, (open) => {
|
|
25
|
+
const dialog = options.dialog;
|
|
26
|
+
if (!open || !dialog) return;
|
|
27
|
+
const onBackdrop = (event) => {
|
|
28
|
+
if (event.target !== dialog) return false;
|
|
29
|
+
const { left, top, right, bottom } = dialog.getBoundingClientRect();
|
|
30
|
+
const { clientX: x, clientY: y } = event;
|
|
31
|
+
return x < left || x > right || y < top || y > bottom;
|
|
32
|
+
};
|
|
33
|
+
let pressed = false;
|
|
34
|
+
const pointerdown = (event) => {
|
|
35
|
+
pressed = event.button === 0 && onBackdrop(event);
|
|
36
|
+
};
|
|
37
|
+
const click = (event) => {
|
|
38
|
+
if (pressed && onBackdrop(event)) options.onDismiss({
|
|
39
|
+
reason: "outside-press",
|
|
40
|
+
event
|
|
41
|
+
});
|
|
42
|
+
pressed = false;
|
|
43
|
+
};
|
|
44
|
+
dialog.addEventListener("pointerdown", pointerdown);
|
|
45
|
+
dialog.addEventListener("click", click);
|
|
46
|
+
return () => {
|
|
47
|
+
dialog.removeEventListener("pointerdown", pointerdown);
|
|
48
|
+
dialog.removeEventListener("click", click);
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export { createOutsidePress };
|