@zealakit/overlay-react 0.0.0-stage → 1.0.1
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 +21 -0
- package/README.md +547 -2
- package/dist/animation/index.d.ts +1 -0
- package/dist/animation/index.js +1 -0
- package/dist/animation/presence.d.ts +31 -0
- package/dist/animation/presence.js +104 -0
- package/dist/components/arrow.d.ts +30 -0
- package/dist/components/arrow.js +58 -0
- package/dist/components/context-menu/content.d.ts +37 -0
- package/dist/components/context-menu/content.js +52 -0
- package/dist/components/context-menu/context-menu.d.ts +20 -0
- package/dist/components/context-menu/context-menu.js +78 -0
- package/dist/components/context-menu/context.d.ts +47 -0
- package/dist/components/context-menu/context.js +27 -0
- package/dist/components/context-menu/index.d.ts +7 -0
- package/dist/components/context-menu/index.js +6 -0
- package/dist/components/context-menu/items.d.ts +71 -0
- package/dist/components/context-menu/items.js +207 -0
- package/dist/components/context-menu/menu-navigation.d.ts +3 -0
- package/dist/components/context-menu/menu-navigation.js +42 -0
- package/dist/components/context-menu/menu-surface.d.ts +58 -0
- package/dist/components/context-menu/menu-surface.js +172 -0
- package/dist/components/context-menu/sub.d.ts +45 -0
- package/dist/components/context-menu/sub.js +180 -0
- package/dist/components/context-menu/trigger.d.ts +17 -0
- package/dist/components/context-menu/trigger.js +62 -0
- package/dist/components/context-menu/types.d.ts +9 -0
- package/dist/components/context-menu/types.js +1 -0
- package/dist/components/dialog/content.d.ts +87 -0
- package/dist/components/dialog/content.js +238 -0
- package/dist/components/dialog/context.d.ts +41 -0
- package/dist/components/dialog/context.js +26 -0
- package/dist/components/dialog/dialog.d.ts +27 -0
- package/dist/components/dialog/dialog.js +88 -0
- package/dist/components/dialog/helpers.d.ts +24 -0
- package/dist/components/dialog/helpers.js +59 -0
- package/dist/components/dialog/index.d.ts +5 -0
- package/dist/components/dialog/index.js +5 -0
- package/dist/components/dialog/modal-background.d.ts +7 -0
- package/dist/components/dialog/modal-background.js +21 -0
- package/dist/components/dialog/trigger.d.ts +11 -0
- package/dist/components/dialog/trigger.js +29 -0
- package/dist/components/overlay-context.d.ts +13 -0
- package/dist/components/overlay-context.js +10 -0
- package/dist/components/popover/content.d.ts +131 -0
- package/dist/components/popover/content.js +261 -0
- package/dist/components/popover/context.d.ts +27 -0
- package/dist/components/popover/context.js +18 -0
- package/dist/components/popover/helpers.d.ts +23 -0
- package/dist/components/popover/helpers.js +58 -0
- package/dist/components/popover/index.d.ts +4 -0
- package/dist/components/popover/index.js +4 -0
- package/dist/components/popover/popover.d.ts +39 -0
- package/dist/components/popover/popover.js +98 -0
- package/dist/components/portal.d.ts +14 -0
- package/dist/components/portal.js +19 -0
- package/dist/components/slot.d.ts +12 -0
- package/dist/components/slot.js +60 -0
- package/dist/components/tooltip/content.d.ts +21 -0
- package/dist/components/tooltip/content.js +95 -0
- package/dist/components/tooltip/context.d.ts +22 -0
- package/dist/components/tooltip/context.js +10 -0
- package/dist/components/tooltip/index.d.ts +5 -0
- package/dist/components/tooltip/index.js +5 -0
- package/dist/components/tooltip/provider.d.ts +29 -0
- package/dist/components/tooltip/provider.js +29 -0
- package/dist/components/tooltip/tooltip.d.ts +25 -0
- package/dist/components/tooltip/tooltip.js +268 -0
- package/dist/components/tooltip/trigger.d.ts +11 -0
- package/dist/components/tooltip/trigger.js +67 -0
- package/dist/hooks/use-escape-key.d.ts +12 -0
- package/dist/hooks/use-escape-key.js +30 -0
- package/dist/hooks/use-layer.d.ts +33 -0
- package/dist/hooks/use-layer.js +84 -0
- package/dist/hooks/use-overlay.d.ts +31 -0
- package/dist/hooks/use-overlay.js +69 -0
- package/dist/hooks/use-positioner.d.ts +28 -0
- package/dist/hooks/use-positioner.js +127 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/vendor/core/animation/index.d.ts +2 -0
- package/dist/vendor/core/animation/index.js +2 -0
- package/dist/vendor/core/animation/keyframes.d.ts +56 -0
- package/dist/vendor/core/animation/keyframes.js +155 -0
- package/dist/vendor/core/animation/run-animation.d.ts +27 -0
- package/dist/vendor/core/animation/run-animation.js +175 -0
- package/dist/vendor/core/controller/animator.d.ts +19 -0
- package/dist/vendor/core/controller/animator.js +117 -0
- package/dist/vendor/core/controller/context-menu-behavior.d.ts +15 -0
- package/dist/vendor/core/controller/context-menu-behavior.js +123 -0
- package/dist/vendor/core/controller/host.d.ts +10 -0
- package/dist/vendor/core/controller/host.js +1 -0
- package/dist/vendor/core/controller/index.d.ts +2 -0
- package/dist/vendor/core/controller/index.js +1 -0
- package/dist/vendor/core/controller/overlay-controller.d.ts +9 -0
- package/dist/vendor/core/controller/overlay-controller.js +723 -0
- package/dist/vendor/core/controller/tooltip-behavior.d.ts +9 -0
- package/dist/vendor/core/controller/tooltip-behavior.js +123 -0
- package/dist/vendor/core/controller/types.d.ts +92 -0
- package/dist/vendor/core/controller/types.js +1 -0
- package/dist/vendor/core/events/index.d.ts +3 -0
- package/dist/vendor/core/events/index.js +3 -0
- package/dist/vendor/core/events/keyboard.d.ts +2 -0
- package/dist/vendor/core/events/keyboard.js +4 -0
- package/dist/vendor/core/events/outside.d.ts +8 -0
- package/dist/vendor/core/events/outside.js +33 -0
- package/dist/vendor/core/events/pointer.d.ts +13 -0
- package/dist/vendor/core/events/pointer.js +18 -0
- package/dist/vendor/core/focus/focus.d.ts +73 -0
- package/dist/vendor/core/focus/focus.js +312 -0
- package/dist/vendor/core/focus/index.d.ts +1 -0
- package/dist/vendor/core/focus/index.js +1 -0
- package/dist/vendor/core/index.d.ts +13 -0
- package/dist/vendor/core/index.js +13 -0
- package/dist/vendor/core/layer/create-layer-stack.d.ts +25 -0
- package/dist/vendor/core/layer/create-layer-stack.js +247 -0
- package/dist/vendor/core/layer/create-layer.d.ts +10 -0
- package/dist/vendor/core/layer/create-layer.js +78 -0
- package/dist/vendor/core/layer/index.d.ts +3 -0
- package/dist/vendor/core/layer/index.js +3 -0
- package/dist/vendor/core/layer/manager.d.ts +9 -0
- package/dist/vendor/core/layer/manager.js +157 -0
- package/dist/vendor/core/lifecycle/events.d.ts +8 -0
- package/dist/vendor/core/lifecycle/events.js +21 -0
- package/dist/vendor/core/lifecycle/index.d.ts +1 -0
- package/dist/vendor/core/lifecycle/index.js +1 -0
- package/dist/vendor/core/menu/index.d.ts +1 -0
- package/dist/vendor/core/menu/index.js +1 -0
- package/dist/vendor/core/menu/navigation.d.ts +22 -0
- package/dist/vendor/core/menu/navigation.js +107 -0
- package/dist/vendor/core/modal/background.d.ts +10 -0
- package/dist/vendor/core/modal/background.js +115 -0
- package/dist/vendor/core/modal/index.d.ts +1 -0
- package/dist/vendor/core/modal/index.js +1 -0
- package/dist/vendor/core/portal/index.d.ts +1 -0
- package/dist/vendor/core/portal/index.js +1 -0
- package/dist/vendor/core/portal/portal.d.ts +13 -0
- package/dist/vendor/core/portal/portal.js +25 -0
- package/dist/vendor/core/positioning/arrow.d.ts +34 -0
- package/dist/vendor/core/positioning/arrow.js +142 -0
- package/dist/vendor/core/positioning/compute.d.ts +9 -0
- package/dist/vendor/core/positioning/compute.js +22 -0
- package/dist/vendor/core/positioning/coordinates.d.ts +11 -0
- package/dist/vendor/core/positioning/coordinates.js +45 -0
- package/dist/vendor/core/positioning/create-positioner.d.ts +8 -0
- package/dist/vendor/core/positioning/create-positioner.js +251 -0
- package/dist/vendor/core/positioning/index.d.ts +6 -0
- package/dist/vendor/core/positioning/index.js +6 -0
- package/dist/vendor/core/positioning/placement.d.ts +8 -0
- package/dist/vendor/core/positioning/placement.js +30 -0
- package/dist/vendor/core/positioning/same-result.d.ts +8 -0
- package/dist/vendor/core/positioning/same-result.js +13 -0
- package/dist/vendor/core/positioning/strategy.d.ts +12 -0
- package/dist/vendor/core/positioning/strategy.js +46 -0
- package/dist/vendor/core/scroll-lock/index.d.ts +1 -0
- package/dist/vendor/core/scroll-lock/index.js +1 -0
- package/dist/vendor/core/scroll-lock/scroll-lock.d.ts +12 -0
- package/dist/vendor/core/scroll-lock/scroll-lock.js +68 -0
- package/dist/vendor/core/types/animation.d.ts +81 -0
- package/dist/vendor/core/types/animation.js +93 -0
- package/dist/vendor/core/types/dismissal.d.ts +2 -0
- package/dist/vendor/core/types/dismissal.js +1 -0
- package/dist/vendor/core/types/element.d.ts +20 -0
- package/dist/vendor/core/types/element.js +1 -0
- package/dist/vendor/core/types/geometry.d.ts +22 -0
- package/dist/vendor/core/types/geometry.js +1 -0
- package/dist/vendor/core/types/index.d.ts +9 -0
- package/dist/vendor/core/types/index.js +8 -0
- package/dist/vendor/core/types/layer.d.ts +126 -0
- package/dist/vendor/core/types/layer.js +1 -0
- package/dist/vendor/core/types/lifecycle.d.ts +2 -0
- package/dist/vendor/core/types/lifecycle.js +1 -0
- package/dist/vendor/core/types/positioner.d.ts +74 -0
- package/dist/vendor/core/types/positioner.js +1 -0
- package/dist/vendor/core/types/positioning.d.ts +23 -0
- package/dist/vendor/core/types/positioning.js +1 -0
- package/dist/vendor/core/utils/dom.d.ts +11 -0
- package/dist/vendor/core/utils/dom.js +21 -0
- package/dist/vendor/core/utils/element.d.ts +15 -0
- package/dist/vendor/core/utils/element.js +21 -0
- package/dist/vendor/core/utils/global-state.d.ts +1 -0
- package/dist/vendor/core/utils/global-state.js +24 -0
- package/dist/vendor/core/utils/index.d.ts +2 -0
- package/dist/vendor/core/utils/index.js +2 -0
- package/package.json +74 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { LayerStackHandle } from "../../vendor/core/index.js";
|
|
3
|
+
import { type DialogChangeReason, type DialogDirection } from "./context.js";
|
|
4
|
+
export type DialogProps = {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
/** Controlled visibility. When set, the Dialog does not own the state. */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** Initial visibility in uncontrolled mode. Defaults to false. */
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
onOpenChange?: (open: boolean, reason: DialogChangeReason) => void;
|
|
11
|
+
/** Defaults to true. */
|
|
12
|
+
modal?: boolean;
|
|
13
|
+
/** Lock document scrolling while modal. Defaults to modal. */
|
|
14
|
+
lockScroll?: boolean;
|
|
15
|
+
/** Defaults to true. */
|
|
16
|
+
dismissOnEscape?: boolean;
|
|
17
|
+
/** Defaults to true. */
|
|
18
|
+
dismissOnOutsidePress?: boolean;
|
|
19
|
+
dir?: DialogDirection;
|
|
20
|
+
/** Optional explicit parent layer; otherwise inherited from the enclosing overlay. */
|
|
21
|
+
parentLayer?: LayerStackHandle | null;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Headless Dialog root. Owns controlled/uncontrolled state and the title,
|
|
25
|
+
* description, trigger, and content IDs. It renders no DOM.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Dialog({ children, open: controlledOpen, defaultOpen, onOpenChange, modal, lockScroll, dismissOnEscape, dismissOnOutsidePress, dir, parentLayer, }: DialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useContext, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { OverlayLayerContext } from "../overlay-context.js";
|
|
5
|
+
import { DialogContext, DialogNestingContext, } from "./context.js";
|
|
6
|
+
/**
|
|
7
|
+
* Headless Dialog root. Owns controlled/uncontrolled state and the title,
|
|
8
|
+
* description, trigger, and content IDs. It renders no DOM.
|
|
9
|
+
*/
|
|
10
|
+
export function Dialog({ children, open: controlledOpen, defaultOpen = false, onOpenChange, modal = true, lockScroll, dismissOnEscape = true, dismissOnOutsidePress = true, dir = "ltr", parentLayer, }) {
|
|
11
|
+
const inheritedLayer = useContext(OverlayLayerContext);
|
|
12
|
+
const nesting = useContext(DialogNestingContext);
|
|
13
|
+
const resolvedParentLayer = parentLayer ?? inheritedLayer?.handle ?? null;
|
|
14
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
15
|
+
const isControlled = controlledOpen !== undefined;
|
|
16
|
+
const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
|
|
17
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
18
|
+
const id = useId();
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
onOpenChangeRef.current = onOpenChange;
|
|
21
|
+
}, [onOpenChange]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!nesting) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (isOpen) {
|
|
27
|
+
nesting.reportNestedOpen(true);
|
|
28
|
+
}
|
|
29
|
+
return () => {
|
|
30
|
+
if (isOpen) {
|
|
31
|
+
nesting.reportNestedOpen(false);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}, [isOpen, nesting]);
|
|
35
|
+
const setOpen = useCallback((next, reason) => {
|
|
36
|
+
if (next === isOpen) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!isControlled) {
|
|
40
|
+
setUncontrolledOpen(next);
|
|
41
|
+
}
|
|
42
|
+
onOpenChangeRef.current?.(next, reason);
|
|
43
|
+
}, [isControlled, isOpen]);
|
|
44
|
+
const open = useCallback(() => {
|
|
45
|
+
setOpen(true, "programmatic");
|
|
46
|
+
}, [setOpen]);
|
|
47
|
+
const close = useCallback((reason = "programmatic") => {
|
|
48
|
+
setOpen(false, reason);
|
|
49
|
+
}, [setOpen]);
|
|
50
|
+
const toggle = useCallback((reason = "trigger") => {
|
|
51
|
+
setOpen(!isOpen, reason);
|
|
52
|
+
}, [isOpen, setOpen]);
|
|
53
|
+
const [triggerElement, setTriggerElement] = useState(null);
|
|
54
|
+
const contextValue = useMemo(() => ({
|
|
55
|
+
isOpen,
|
|
56
|
+
open,
|
|
57
|
+
close,
|
|
58
|
+
toggle,
|
|
59
|
+
triggerElement,
|
|
60
|
+
setTriggerElement,
|
|
61
|
+
triggerId: `${id}-trigger`,
|
|
62
|
+
contentId: `${id}-content`,
|
|
63
|
+
titleId: `${id}-title`,
|
|
64
|
+
descriptionId: `${id}-description`,
|
|
65
|
+
direction: dir,
|
|
66
|
+
modal,
|
|
67
|
+
nested: nesting !== null,
|
|
68
|
+
lockScroll: lockScroll ?? modal,
|
|
69
|
+
dismissOnEscape,
|
|
70
|
+
dismissOnOutsidePress,
|
|
71
|
+
parentLayer: resolvedParentLayer,
|
|
72
|
+
}), [
|
|
73
|
+
close,
|
|
74
|
+
dir,
|
|
75
|
+
dismissOnEscape,
|
|
76
|
+
dismissOnOutsidePress,
|
|
77
|
+
id,
|
|
78
|
+
isOpen,
|
|
79
|
+
lockScroll,
|
|
80
|
+
modal,
|
|
81
|
+
nesting,
|
|
82
|
+
open,
|
|
83
|
+
resolvedParentLayer,
|
|
84
|
+
toggle,
|
|
85
|
+
triggerElement,
|
|
86
|
+
]);
|
|
87
|
+
return (_jsx(DialogContext.Provider, { value: contextValue, children: children }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type HTMLAttributes } from "react";
|
|
2
|
+
import type { DialogDataAttributes } from "./content.js";
|
|
3
|
+
export type DialogHeaderProps = HTMLAttributes<HTMLDivElement> & DialogDataAttributes;
|
|
4
|
+
/** Optional layout wrapper only; it carries no accessibility semantics. */
|
|
5
|
+
export declare const DialogHeader: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & DialogDataAttributes & import("react").RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export type DialogTitleProps = HTMLAttributes<HTMLHeadingElement> & DialogDataAttributes;
|
|
7
|
+
/**
|
|
8
|
+
* Provides the Dialog's accessible name. It sets the popup's
|
|
9
|
+
* `aria-labelledby` relationship.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DialogTitle: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLHeadingElement> & DialogDataAttributes & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
12
|
+
export type DialogDescriptionProps = HTMLAttributes<HTMLParagraphElement> & DialogDataAttributes;
|
|
13
|
+
/** Optional accessible description for the Dialog. */
|
|
14
|
+
export declare const DialogDescription: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLParagraphElement> & DialogDataAttributes & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
15
|
+
export type DialogFooterProps = HTMLAttributes<HTMLDivElement> & DialogDataAttributes;
|
|
16
|
+
/** Optional layout wrapper for actions. No close-on-click behavior is applied. */
|
|
17
|
+
export declare const DialogFooter: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & DialogDataAttributes & import("react").RefAttributes<HTMLDivElement>>;
|
|
18
|
+
export type DialogCloseProps = ComponentPropsWithoutRef<"button"> & DialogDataAttributes & {
|
|
19
|
+
asChild?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Optional explicit close control. Dialog never injects one automatically. */
|
|
22
|
+
export declare const DialogClose: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & DialogDataAttributes & {
|
|
23
|
+
asChild?: boolean;
|
|
24
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect, useMemo, } from "react";
|
|
4
|
+
import { useDialogContentContext, useDialogContext } from "./context.js";
|
|
5
|
+
import { Slot, composeRefs } from "../slot.js";
|
|
6
|
+
/** Optional layout wrapper only; it carries no accessibility semantics. */
|
|
7
|
+
export const DialogHeader = forwardRef(function DialogHeader(props, ref) {
|
|
8
|
+
return _jsx("div", { ...props, ref: ref });
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Provides the Dialog's accessible name. It sets the popup's
|
|
12
|
+
* `aria-labelledby` relationship.
|
|
13
|
+
*/
|
|
14
|
+
export const DialogTitle = forwardRef(function DialogTitle({ id, ...rest }, ref) {
|
|
15
|
+
const dialog = useDialogContext("DialogTitle");
|
|
16
|
+
const { setTitleId } = useDialogContentContext("DialogTitle");
|
|
17
|
+
const titleId = id ?? dialog.titleId;
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setTitleId(titleId);
|
|
20
|
+
return () => {
|
|
21
|
+
setTitleId(null);
|
|
22
|
+
};
|
|
23
|
+
}, [setTitleId, titleId]);
|
|
24
|
+
return _jsx("h2", { ...rest, id: titleId, ref: ref });
|
|
25
|
+
});
|
|
26
|
+
/** Optional accessible description for the Dialog. */
|
|
27
|
+
export const DialogDescription = forwardRef(function DialogDescription({ id, ...rest }, ref) {
|
|
28
|
+
const dialog = useDialogContext("DialogDescription");
|
|
29
|
+
const { setDescriptionId } = useDialogContentContext("DialogDescription");
|
|
30
|
+
const descriptionId = id ?? dialog.descriptionId;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setDescriptionId(descriptionId);
|
|
33
|
+
return () => {
|
|
34
|
+
setDescriptionId(null);
|
|
35
|
+
};
|
|
36
|
+
}, [descriptionId, setDescriptionId]);
|
|
37
|
+
return _jsx("p", { ...rest, id: descriptionId, ref: ref });
|
|
38
|
+
});
|
|
39
|
+
/** Optional layout wrapper for actions. No close-on-click behavior is applied. */
|
|
40
|
+
export const DialogFooter = forwardRef(function DialogFooter(props, ref) {
|
|
41
|
+
return _jsx("div", { ...props, ref: ref });
|
|
42
|
+
});
|
|
43
|
+
/** Optional explicit close control. Dialog never injects one automatically. */
|
|
44
|
+
export const DialogClose = forwardRef(function DialogClose({ asChild = false, onClick, type, children, ...rest }, forwardedRef) {
|
|
45
|
+
const dialog = useDialogContext("DialogClose");
|
|
46
|
+
const refs = useMemo(() => composeRefs(forwardedRef), [forwardedRef]);
|
|
47
|
+
const handleClick = (event) => {
|
|
48
|
+
onClick?.(event);
|
|
49
|
+
if (event.defaultPrevented) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
dialog.close("close-button");
|
|
53
|
+
};
|
|
54
|
+
const shared = { ...rest, onClick: handleClick };
|
|
55
|
+
if (asChild) {
|
|
56
|
+
return (_jsx(Slot, { ...shared, ref: refs, children: children }));
|
|
57
|
+
}
|
|
58
|
+
return (_jsx("button", { ...shared, ref: refs, type: type ?? "button", children: children }));
|
|
59
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Dialog, type DialogProps } from "./dialog.js";
|
|
2
|
+
export { DialogTrigger, type DialogTriggerProps } from "./trigger.js";
|
|
3
|
+
export { DialogBackdrop, DialogContent, DialogPopup, DialogPortal, DialogViewport, type DialogBackdropProps, type DialogContentProps, type DialogFocusTarget, type DialogPopupProps, type DialogPortalProps, type DialogViewportProps, } from "./content.js";
|
|
4
|
+
export { DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogTitle, type DialogCloseProps, type DialogDescriptionProps, type DialogFooterProps, type DialogHeaderProps, type DialogTitleProps, } from "./helpers.js";
|
|
5
|
+
export type { DialogChangeReason, DialogDirection, } from "./context.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { Dialog } from "./dialog.js";
|
|
3
|
+
export { DialogTrigger } from "./trigger.js";
|
|
4
|
+
export { DialogBackdrop, DialogContent, DialogPopup, DialogPortal, DialogViewport, } from "./content.js";
|
|
5
|
+
export { DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "./helpers.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mark all body-level background siblings inert while a modal dialog is open.
|
|
3
|
+
* Dialog portal roots (including other open dialogs) are preserved so this does
|
|
4
|
+
* not fight nested dialog lifecycles or sibling overlays rendered inside the
|
|
5
|
+
* dialog portal.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useModalBackground(root: Element | null, enabled: boolean): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { acquireModalBackground } from "../../vendor/core/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Mark all body-level background siblings inert while a modal dialog is open.
|
|
6
|
+
* Dialog portal roots (including other open dialogs) are preserved so this does
|
|
7
|
+
* not fight nested dialog lifecycles or sibling overlays rendered inside the
|
|
8
|
+
* dialog portal.
|
|
9
|
+
*/
|
|
10
|
+
export function useModalBackground(root, enabled) {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!enabled || !root?.isConnected) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const documentRef = root.ownerDocument;
|
|
16
|
+
if (!documentRef?.body) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return acquireModalBackground(documentRef, [root]);
|
|
20
|
+
}, [enabled, root]);
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import type { DialogDataAttributes } from "./content.js";
|
|
3
|
+
export type DialogTriggerProps = ComponentPropsWithoutRef<"button"> & DialogDataAttributes & {
|
|
4
|
+
/** Merge trigger behavior onto the single child element instead of wrapping it. */
|
|
5
|
+
asChild?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/** Button that toggles the Dialog and supplies dialog trigger ARIA. */
|
|
8
|
+
export declare const DialogTrigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & DialogDataAttributes & {
|
|
9
|
+
/** Merge trigger behavior onto the single child element instead of wrapping it. */
|
|
10
|
+
asChild?: boolean;
|
|
11
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useMemo, } from "react";
|
|
4
|
+
import { useDialogContext } from "./context.js";
|
|
5
|
+
import { Slot, composeRefs } from "../slot.js";
|
|
6
|
+
/** Button that toggles the Dialog and supplies dialog trigger ARIA. */
|
|
7
|
+
export const DialogTrigger = forwardRef(function DialogTrigger({ asChild = false, disabled = false, onClick, type, id, children, ...rest }, forwardedRef) {
|
|
8
|
+
const dialog = useDialogContext("DialogTrigger");
|
|
9
|
+
const refs = useMemo(() => composeRefs(forwardedRef, dialog.setTriggerElement), [dialog.setTriggerElement, forwardedRef]);
|
|
10
|
+
const handleClick = (event) => {
|
|
11
|
+
onClick?.(event);
|
|
12
|
+
if (event.defaultPrevented || disabled) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
dialog.toggle("trigger");
|
|
16
|
+
};
|
|
17
|
+
const shared = {
|
|
18
|
+
...rest,
|
|
19
|
+
id: id ?? dialog.triggerId,
|
|
20
|
+
"aria-haspopup": "dialog",
|
|
21
|
+
"aria-expanded": dialog.isOpen,
|
|
22
|
+
"aria-controls": dialog.isOpen ? dialog.contentId : undefined,
|
|
23
|
+
onClick: handleClick,
|
|
24
|
+
};
|
|
25
|
+
if (asChild) {
|
|
26
|
+
return (_jsx(Slot, { ...shared, ...(disabled ? { disabled: true, "aria-disabled": true } : {}), ref: refs, children: children }));
|
|
27
|
+
}
|
|
28
|
+
return (_jsx("button", { ...shared, ref: refs, type: type ?? "button", disabled: disabled, children: children }));
|
|
29
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LayerStackHandle } from "../vendor/core/index.js";
|
|
2
|
+
export type OverlayLayerContextValue = {
|
|
3
|
+
handle: LayerStackHandle | null;
|
|
4
|
+
isTopmost: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** Shared parent-layer context for nested popovers and dialogs. */
|
|
7
|
+
export declare const OverlayLayerContext: import("react").Context<OverlayLayerContextValue | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Portal target supplied by an open modal Dialog popup. Nested Popover and
|
|
10
|
+
* Tooltip portals default into this element so they remain inside the dialog's
|
|
11
|
+
* interaction/focus boundary instead of becoming body-level siblings.
|
|
12
|
+
*/
|
|
13
|
+
export declare const OverlayPortalContainerContext: import("react").Context<Element | null>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
/** Shared parent-layer context for nested popovers and dialogs. */
|
|
4
|
+
export const OverlayLayerContext = createContext(null);
|
|
5
|
+
/**
|
|
6
|
+
* Portal target supplied by an open modal Dialog popup. Nested Popover and
|
|
7
|
+
* Tooltip portals default into this element so they remain inside the dialog's
|
|
8
|
+
* interaction/focus boundary instead of becoming body-level siblings.
|
|
9
|
+
*/
|
|
10
|
+
export const OverlayPortalContainerContext = createContext(null);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { type CSSProperties, type HTMLAttributes, type ReactNode, type RefCallback } from "react";
|
|
2
|
+
import { type AnimationSetting, type Placement, type PositionerBoundary, type PositionerResult, type Strategy } from "../../vendor/core/index.js";
|
|
3
|
+
export type PopoverSide = "top" | "right" | "bottom" | "left";
|
|
4
|
+
export type PopoverAlign = "start" | "center" | "end";
|
|
5
|
+
export type PopoverCollisionAvoidance = {
|
|
6
|
+
/** Flip to the opposite side when there is not enough room. Defaults to true. */
|
|
7
|
+
flip?: boolean;
|
|
8
|
+
/** Shift along the cross axis to stay inside the boundary. Defaults to true. */
|
|
9
|
+
shift?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type PopoverPositionerProps = {
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
/** Explicit positioning reference. Defaults to the trigger element. */
|
|
14
|
+
anchor?: Element | null;
|
|
15
|
+
/** Physical side. Defaults to bottom. */
|
|
16
|
+
side?: PopoverSide;
|
|
17
|
+
/** Alignment within the side. Defaults to center. */
|
|
18
|
+
align?: PopoverAlign;
|
|
19
|
+
/** Main-axis gap. */
|
|
20
|
+
sideOffset?: number;
|
|
21
|
+
/** Cross-axis offset. */
|
|
22
|
+
alignOffset?: number;
|
|
23
|
+
/** Core collision boundary. */
|
|
24
|
+
collisionBoundary?: PositionerBoundary;
|
|
25
|
+
/** Gap from the collision boundary. */
|
|
26
|
+
collisionPadding?: number;
|
|
27
|
+
/** Toggle flip/shift collision avoidance. Both default to true. */
|
|
28
|
+
collisionAvoidance?: PopoverCollisionAvoidance;
|
|
29
|
+
/** CSS positioning method. Defaults to automatic: absolute (scrolls with the page), or fixed for fixed/sticky anchors and viewport points. */
|
|
30
|
+
positionMethod?: Strategy;
|
|
31
|
+
/** Render a default arrow. Disabled by default. */
|
|
32
|
+
arrow?: boolean;
|
|
33
|
+
/** Default arrow edge length in pixels. Defaults to 8. */
|
|
34
|
+
arrowSize?: number;
|
|
35
|
+
/** Default arrow padding from popup edges. Defaults to 0. */
|
|
36
|
+
arrowPadding?: number;
|
|
37
|
+
/** Default arrow class name. */
|
|
38
|
+
arrowClassName?: string;
|
|
39
|
+
/** Default arrow inline style; merged over base geometry. */
|
|
40
|
+
arrowStyle?: CSSProperties;
|
|
41
|
+
};
|
|
42
|
+
export type PopoverPortalProps = {
|
|
43
|
+
children?: ReactNode;
|
|
44
|
+
/** Defaults to document.body. */
|
|
45
|
+
container?: Element | null;
|
|
46
|
+
/** Render in place instead of portaling. */
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type PopoverDataAttributes = {
|
|
50
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
51
|
+
};
|
|
52
|
+
export type PopoverPopupProps = HTMLAttributes<HTMLDivElement> & PopoverDataAttributes & {
|
|
53
|
+
/** Focus the first focusable element when the popup opens. Defaults to false. */
|
|
54
|
+
initialFocus?: boolean;
|
|
55
|
+
/** Contain focus while this layer is topmost. Defaults to false. */
|
|
56
|
+
trapFocus?: boolean;
|
|
57
|
+
/** Restore focus to the trigger when closing from inside. Defaults to true. */
|
|
58
|
+
restoreFocus?: boolean;
|
|
59
|
+
/** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
|
|
60
|
+
animation?: AnimationSetting;
|
|
61
|
+
};
|
|
62
|
+
export type PopoverContentProps = Omit<PopoverPositionerProps, "children"> & PopoverPopupProps & {
|
|
63
|
+
/**
|
|
64
|
+
* `true`/omitted portals to document.body, an Element selects a container,
|
|
65
|
+
* and `false` renders in place.
|
|
66
|
+
*/
|
|
67
|
+
portal?: boolean | Element | null;
|
|
68
|
+
};
|
|
69
|
+
export type PopoverArrowConfig = {
|
|
70
|
+
enabled: boolean;
|
|
71
|
+
shorthand: boolean;
|
|
72
|
+
size: number;
|
|
73
|
+
padding: number;
|
|
74
|
+
className?: string;
|
|
75
|
+
style?: CSSProperties;
|
|
76
|
+
};
|
|
77
|
+
export type PopoverPositionerContextValue = {
|
|
78
|
+
result: PositionerResult | null;
|
|
79
|
+
referenceElement: Element | null;
|
|
80
|
+
floatingElement: HTMLElement | null;
|
|
81
|
+
floatingRef: RefCallback<HTMLElement>;
|
|
82
|
+
placement: Placement;
|
|
83
|
+
arrow: PopoverArrowConfig;
|
|
84
|
+
setArrowElement(element: Element | null): void;
|
|
85
|
+
setArrowPadding(padding: number): void;
|
|
86
|
+
};
|
|
87
|
+
export declare function usePopoverPositionerContext(part: string): PopoverPositionerContextValue;
|
|
88
|
+
/**
|
|
89
|
+
* Portal part for advanced composition. The convenience Content uses it by
|
|
90
|
+
* default. It renders nothing while the Popover is closed.
|
|
91
|
+
*/
|
|
92
|
+
export declare function PopoverPortal({ children, container, disabled, }: PopoverPortalProps): import("react").JSX.Element | null;
|
|
93
|
+
/**
|
|
94
|
+
* Advanced positioning part. Renders no DOM; provides the positioner state to
|
|
95
|
+
* PopoverPopup. Positioning props are consumed here and never reach the popup.
|
|
96
|
+
*/
|
|
97
|
+
export declare function PopoverPositioner({ children, anchor, side, align, sideOffset, alignOffset, collisionBoundary, collisionPadding, collisionAvoidance, positionMethod, arrow, arrowSize, arrowPadding, arrowClassName, arrowStyle, }: PopoverPositionerProps): import("react").JSX.Element;
|
|
98
|
+
/**
|
|
99
|
+
* Advanced popup part. Owns the floating element, layer registration, ARIA
|
|
100
|
+
* title/description wiring, focus policy, and state/data attributes.
|
|
101
|
+
*/
|
|
102
|
+
export declare const PopoverPopup: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & PopoverDataAttributes & {
|
|
103
|
+
/** Focus the first focusable element when the popup opens. Defaults to false. */
|
|
104
|
+
initialFocus?: boolean;
|
|
105
|
+
/** Contain focus while this layer is topmost. Defaults to false. */
|
|
106
|
+
trapFocus?: boolean;
|
|
107
|
+
/** Restore focus to the trigger when closing from inside. Defaults to true. */
|
|
108
|
+
restoreFocus?: boolean;
|
|
109
|
+
/** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
|
|
110
|
+
animation?: AnimationSetting;
|
|
111
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
112
|
+
/**
|
|
113
|
+
* Convenience composition: Portal -> Positioner -> Popup. Positioning props are
|
|
114
|
+
* consumed by the Positioner; native props go to the Popup.
|
|
115
|
+
*/
|
|
116
|
+
export declare const PopoverContent: import("react").ForwardRefExoticComponent<Omit<PopoverPositionerProps, "children"> & HTMLAttributes<HTMLDivElement> & PopoverDataAttributes & {
|
|
117
|
+
/** Focus the first focusable element when the popup opens. Defaults to false. */
|
|
118
|
+
initialFocus?: boolean;
|
|
119
|
+
/** Contain focus while this layer is topmost. Defaults to false. */
|
|
120
|
+
trapFocus?: boolean;
|
|
121
|
+
/** Restore focus to the trigger when closing from inside. Defaults to true. */
|
|
122
|
+
restoreFocus?: boolean;
|
|
123
|
+
/** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
|
|
124
|
+
animation?: AnimationSetting;
|
|
125
|
+
} & {
|
|
126
|
+
/**
|
|
127
|
+
* `true`/omitted portals to document.body, an Element selects a container,
|
|
128
|
+
* and `false` renders in place.
|
|
129
|
+
*/
|
|
130
|
+
portal?: boolean | Element | null;
|
|
131
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|