@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,33 @@
|
|
|
1
|
+
import { type DismissReason, type LayerStack, type LayerStackHandle } from "../vendor/core/index.js";
|
|
2
|
+
export type UseLayerOptions = {
|
|
3
|
+
/** Floating element used for outside-interaction detection. */
|
|
4
|
+
element?: Element | null;
|
|
5
|
+
/** Trigger element that should not count as "outside". */
|
|
6
|
+
reference?: Element | null;
|
|
7
|
+
/** Extra elements that belong to the interaction boundary. */
|
|
8
|
+
boundaries?: readonly (Element | null)[];
|
|
9
|
+
parent?: LayerStackHandle | null;
|
|
10
|
+
dismissOnEscape?: boolean;
|
|
11
|
+
dismissOnOutsidePress?: boolean;
|
|
12
|
+
onDismiss?: (reason: DismissReason) => void;
|
|
13
|
+
/** Share a stack explicitly; defaults to a per-document shared stack. */
|
|
14
|
+
stack?: LayerStack;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type UseLayerReturn = {
|
|
18
|
+
id: string | null;
|
|
19
|
+
isTopmost: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Registered handle. Use it as a `parent` for nested layers; the hook owns
|
|
22
|
+
* its lifecycle and disposes it on cleanup.
|
|
23
|
+
*/
|
|
24
|
+
handle: LayerStackHandle | null;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Register a layer in a shared stack.
|
|
28
|
+
*
|
|
29
|
+
* Registration happens in an effect, is repeated when the relevant inputs
|
|
30
|
+
* change, and is disposed on cleanup — so Strict Mode double-invocation does
|
|
31
|
+
* not leave duplicate layers or listeners behind.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useLayer(options?: UseLayerOptions): UseLayerReturn;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { acquireSharedLayerStack, } from "../vendor/core/index.js";
|
|
4
|
+
function resolveDocument(element, reference) {
|
|
5
|
+
const existing = element?.ownerDocument ?? reference?.ownerDocument;
|
|
6
|
+
if (existing) {
|
|
7
|
+
return existing;
|
|
8
|
+
}
|
|
9
|
+
return typeof document !== "undefined" ? document : null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register a layer in a shared stack.
|
|
13
|
+
*
|
|
14
|
+
* Registration happens in an effect, is repeated when the relevant inputs
|
|
15
|
+
* change, and is disposed on cleanup — so Strict Mode double-invocation does
|
|
16
|
+
* not leave duplicate layers or listeners behind.
|
|
17
|
+
*/
|
|
18
|
+
export function useLayer(options = {}) {
|
|
19
|
+
const { element = null, reference = null, boundaries, parent = null, dismissOnEscape = true, dismissOnOutsidePress = true, onDismiss, stack, disabled = false, } = options;
|
|
20
|
+
const onDismissRef = useRef(onDismiss);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onDismissRef.current = onDismiss;
|
|
23
|
+
}, [onDismiss]);
|
|
24
|
+
const [handle, setHandle] = useState(null);
|
|
25
|
+
const [isTopmost, setIsTopmost] = useState(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (disabled) {
|
|
28
|
+
setHandle(null);
|
|
29
|
+
setIsTopmost(false);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Wait for at least one element so registration does not churn while
|
|
33
|
+
// callback refs are attaching on mount.
|
|
34
|
+
if (!element && !reference) {
|
|
35
|
+
setHandle(null);
|
|
36
|
+
setIsTopmost(false);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let activeStack;
|
|
40
|
+
let lease = null;
|
|
41
|
+
if (stack) {
|
|
42
|
+
activeStack = stack;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const documentRef = resolveDocument(element, reference);
|
|
46
|
+
if (!documentRef) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
lease = acquireSharedLayerStack(documentRef);
|
|
50
|
+
activeStack = lease.stack;
|
|
51
|
+
}
|
|
52
|
+
const layerHandle = activeStack.register({
|
|
53
|
+
element,
|
|
54
|
+
reference,
|
|
55
|
+
boundaries,
|
|
56
|
+
parent,
|
|
57
|
+
dismissOnEscape,
|
|
58
|
+
dismissOnOutsidePress,
|
|
59
|
+
onDismiss: (reason) => onDismissRef.current?.(reason),
|
|
60
|
+
});
|
|
61
|
+
setHandle(layerHandle);
|
|
62
|
+
setIsTopmost(layerHandle.isTopmost);
|
|
63
|
+
const unsubscribe = activeStack.subscribe(() => {
|
|
64
|
+
setIsTopmost(layerHandle.isTopmost);
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
unsubscribe();
|
|
68
|
+
layerHandle.dispose();
|
|
69
|
+
lease?.release();
|
|
70
|
+
setHandle(null);
|
|
71
|
+
setIsTopmost(false);
|
|
72
|
+
};
|
|
73
|
+
}, [
|
|
74
|
+
stack,
|
|
75
|
+
disabled,
|
|
76
|
+
element,
|
|
77
|
+
reference,
|
|
78
|
+
boundaries,
|
|
79
|
+
parent,
|
|
80
|
+
dismissOnEscape,
|
|
81
|
+
dismissOnOutsidePress,
|
|
82
|
+
]);
|
|
83
|
+
return { id: handle?.id ?? null, isTopmost, handle };
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CSSProperties, RefCallback } from "react";
|
|
2
|
+
import type { DismissReason, LayerStack, Placement, PositionerOptions, PositionerResult } from "../vendor/core/index.js";
|
|
3
|
+
export type UseOverlayOptions = PositionerOptions & {
|
|
4
|
+
defaultOpen?: boolean;
|
|
5
|
+
dismissOnEscape?: boolean;
|
|
6
|
+
dismissOnOutsidePress?: boolean;
|
|
7
|
+
/** Extra elements that belong to the layer interaction boundary. */
|
|
8
|
+
boundaries?: readonly (Element | null)[];
|
|
9
|
+
onOpenChange?: (open: boolean, reason?: DismissReason) => void;
|
|
10
|
+
/** Share a layer stack explicitly; defaults to a per-document shared stack. */
|
|
11
|
+
stack?: LayerStack;
|
|
12
|
+
};
|
|
13
|
+
export type UseOverlayReturn = {
|
|
14
|
+
isOpen: boolean;
|
|
15
|
+
/** Placement after the latest measurement (or the requested placement). */
|
|
16
|
+
placement: Placement;
|
|
17
|
+
referenceRef: RefCallback<Element>;
|
|
18
|
+
floatingRef: RefCallback<HTMLElement>;
|
|
19
|
+
referenceElement: Element | null;
|
|
20
|
+
floatingElement: HTMLElement | null;
|
|
21
|
+
floatingStyles: CSSProperties;
|
|
22
|
+
open(): void;
|
|
23
|
+
close(reason?: DismissReason): void;
|
|
24
|
+
toggle(): void;
|
|
25
|
+
update(): Promise<PositionerResult | null>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Uncontrolled overlay composition: positioning plus a layer registration
|
|
29
|
+
* while open. DOM work happens in effects, so the hook is SSR-safe.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useOverlay(options?: UseOverlayOptions): UseOverlayReturn;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useLayer } from "./use-layer.js";
|
|
4
|
+
import { usePositioner } from "./use-positioner.js";
|
|
5
|
+
/**
|
|
6
|
+
* Uncontrolled overlay composition: positioning plus a layer registration
|
|
7
|
+
* while open. DOM work happens in effects, so the hook is SSR-safe.
|
|
8
|
+
*/
|
|
9
|
+
export function useOverlay(options = {}) {
|
|
10
|
+
const { defaultOpen = false, dismissOnEscape = true, dismissOnOutsidePress = true, boundaries, onOpenChange, stack, ...positioning } = options;
|
|
11
|
+
const positioner = usePositioner(positioning);
|
|
12
|
+
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
13
|
+
const isOpenRef = useRef(isOpen);
|
|
14
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
onOpenChangeRef.current = onOpenChange;
|
|
17
|
+
}, [onOpenChange]);
|
|
18
|
+
const open = useCallback(() => {
|
|
19
|
+
if (isOpenRef.current) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
isOpenRef.current = true;
|
|
23
|
+
setIsOpen(true);
|
|
24
|
+
onOpenChangeRef.current?.(true);
|
|
25
|
+
}, []);
|
|
26
|
+
const close = useCallback((reason = "imperative") => {
|
|
27
|
+
if (!isOpenRef.current) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
isOpenRef.current = false;
|
|
31
|
+
setIsOpen(false);
|
|
32
|
+
onOpenChangeRef.current?.(false, reason);
|
|
33
|
+
}, []);
|
|
34
|
+
const toggle = useCallback(() => {
|
|
35
|
+
if (isOpenRef.current) {
|
|
36
|
+
close("imperative");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
open();
|
|
40
|
+
}
|
|
41
|
+
}, [close, open]);
|
|
42
|
+
useLayer({
|
|
43
|
+
element: positioner.floatingElement,
|
|
44
|
+
reference: positioner.referenceElement,
|
|
45
|
+
boundaries,
|
|
46
|
+
dismissOnEscape,
|
|
47
|
+
dismissOnOutsidePress,
|
|
48
|
+
stack,
|
|
49
|
+
disabled: !isOpen,
|
|
50
|
+
onDismiss: close,
|
|
51
|
+
});
|
|
52
|
+
const result = positioner.result;
|
|
53
|
+
const floatingStyles = result
|
|
54
|
+
? { position: result.strategy, left: result.x, top: result.y }
|
|
55
|
+
: { position: "fixed", left: 0, top: 0 };
|
|
56
|
+
return {
|
|
57
|
+
isOpen,
|
|
58
|
+
placement: result?.placement ?? positioning.placement ?? "bottom",
|
|
59
|
+
referenceRef: positioner.referenceRef,
|
|
60
|
+
floatingRef: positioner.floatingRef,
|
|
61
|
+
referenceElement: positioner.referenceElement,
|
|
62
|
+
floatingElement: positioner.floatingElement,
|
|
63
|
+
floatingStyles,
|
|
64
|
+
open,
|
|
65
|
+
close,
|
|
66
|
+
toggle,
|
|
67
|
+
update: positioner.update,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RefCallback } from "react";
|
|
2
|
+
import { type PositionerOptions, type PositionerResult, type ReferenceElement } from "../vendor/core/index.js";
|
|
3
|
+
export type UsePositionerOptions = PositionerOptions & {
|
|
4
|
+
/**
|
|
5
|
+
* Explicit reference, including a virtual point anchor. When omitted, the
|
|
6
|
+
* callback `referenceRef` is used.
|
|
7
|
+
*/
|
|
8
|
+
reference?: ReferenceElement | null;
|
|
9
|
+
};
|
|
10
|
+
export type UsePositionerReturn = {
|
|
11
|
+
result: PositionerResult | null;
|
|
12
|
+
update: () => Promise<PositionerResult | null>;
|
|
13
|
+
/** Callback ref for the anchor element. */
|
|
14
|
+
referenceRef: RefCallback<Element>;
|
|
15
|
+
/** Callback ref for the floating element. */
|
|
16
|
+
floatingRef: RefCallback<HTMLElement>;
|
|
17
|
+
referenceElement: Element | null;
|
|
18
|
+
floatingElement: HTMLElement | null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* React positioning session.
|
|
22
|
+
*
|
|
23
|
+
* The hook owns a Core positioner created in an effect (never during render).
|
|
24
|
+
* Because React refs do not re-render when `.current` changes, it returns
|
|
25
|
+
* callback refs that track element mount/unmount in state; the positioner is
|
|
26
|
+
* updated only when the elements actually change.
|
|
27
|
+
*/
|
|
28
|
+
export declare function usePositioner(options?: UsePositionerOptions): UsePositionerReturn;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { flushSync } from "react-dom";
|
|
4
|
+
import { createPositioner, isSamePositionerResult, } from "../vendor/core/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* React positioning session.
|
|
7
|
+
*
|
|
8
|
+
* The hook owns a Core positioner created in an effect (never during render).
|
|
9
|
+
* Because React refs do not re-render when `.current` changes, it returns
|
|
10
|
+
* callback refs that track element mount/unmount in state; the positioner is
|
|
11
|
+
* updated only when the elements actually change.
|
|
12
|
+
*/
|
|
13
|
+
export function usePositioner(options = {}) {
|
|
14
|
+
const { reference: explicitReference, placement, offset, alignOffset, flip, shift, padding, boundary, strategy, autoUpdate, arrow, } = options;
|
|
15
|
+
const initialOptionsRef = useRef(options);
|
|
16
|
+
const positionerRef = useRef(null);
|
|
17
|
+
const referenceElementRef = useRef(null);
|
|
18
|
+
const floatingElementRef = useRef(null);
|
|
19
|
+
const latestResultRef = useRef(null);
|
|
20
|
+
const [result, setResult] = useState(null);
|
|
21
|
+
const [referenceElement, setReferenceElement] = useState(null);
|
|
22
|
+
const [floatingElement, setFloatingElement] = useState(null);
|
|
23
|
+
const skipInitialOptionsEffect = useRef(true);
|
|
24
|
+
const referenceRef = useCallback((element) => {
|
|
25
|
+
referenceElementRef.current = element;
|
|
26
|
+
setReferenceElement(element);
|
|
27
|
+
if (!element) {
|
|
28
|
+
latestResultRef.current = null;
|
|
29
|
+
setResult(null);
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
const floatingRef = useCallback((element) => {
|
|
33
|
+
floatingElementRef.current = element;
|
|
34
|
+
setFloatingElement(element);
|
|
35
|
+
if (!element) {
|
|
36
|
+
latestResultRef.current = null;
|
|
37
|
+
setResult(null);
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const positioner = createPositioner(initialOptionsRef.current);
|
|
42
|
+
positionerRef.current = positioner;
|
|
43
|
+
const unsubscribe = positioner.subscribe((next) => {
|
|
44
|
+
// Ignore late results after the floating element went away.
|
|
45
|
+
if (!floatingElementRef.current) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (isSamePositionerResult(latestResultRef.current, next)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
latestResultRef.current = next;
|
|
52
|
+
flushSync(() => {
|
|
53
|
+
setResult(next);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
return () => {
|
|
57
|
+
unsubscribe();
|
|
58
|
+
positioner.dispose();
|
|
59
|
+
positionerRef.current = null;
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const positioner = positionerRef.current;
|
|
64
|
+
if (!positioner) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const resolvedReference = explicitReference !== undefined ? explicitReference : referenceElement;
|
|
68
|
+
if (!resolvedReference && latestResultRef.current !== null) {
|
|
69
|
+
latestResultRef.current = null;
|
|
70
|
+
setResult(null);
|
|
71
|
+
}
|
|
72
|
+
positioner.setReference(resolvedReference);
|
|
73
|
+
}, [explicitReference, referenceElement]);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const positioner = positionerRef.current;
|
|
76
|
+
if (!positioner) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!floatingElement && latestResultRef.current !== null) {
|
|
80
|
+
latestResultRef.current = null;
|
|
81
|
+
setResult(null);
|
|
82
|
+
}
|
|
83
|
+
positioner.setFloating(floatingElement);
|
|
84
|
+
}, [floatingElement]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const positioner = positionerRef.current;
|
|
87
|
+
if (!positioner) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (skipInitialOptionsEffect.current) {
|
|
91
|
+
skipInitialOptionsEffect.current = false;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
positioner.setOptions({
|
|
95
|
+
placement,
|
|
96
|
+
offset,
|
|
97
|
+
alignOffset,
|
|
98
|
+
flip,
|
|
99
|
+
shift,
|
|
100
|
+
padding,
|
|
101
|
+
boundary,
|
|
102
|
+
strategy,
|
|
103
|
+
autoUpdate,
|
|
104
|
+
arrow,
|
|
105
|
+
});
|
|
106
|
+
}, [
|
|
107
|
+
placement,
|
|
108
|
+
offset,
|
|
109
|
+
alignOffset,
|
|
110
|
+
flip,
|
|
111
|
+
shift,
|
|
112
|
+
padding,
|
|
113
|
+
boundary,
|
|
114
|
+
strategy,
|
|
115
|
+
autoUpdate,
|
|
116
|
+
arrow,
|
|
117
|
+
]);
|
|
118
|
+
const update = useCallback(() => positionerRef.current?.update() ?? Promise.resolve(null), []);
|
|
119
|
+
return {
|
|
120
|
+
result,
|
|
121
|
+
update,
|
|
122
|
+
referenceRef,
|
|
123
|
+
floatingRef,
|
|
124
|
+
referenceElement,
|
|
125
|
+
floatingElement,
|
|
126
|
+
};
|
|
127
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Portal, type PortalProps } from "./components/portal.js";
|
|
2
|
+
export { PopoverArrow, TooltipArrow, type PopoverArrowProps, } from "./components/arrow.js";
|
|
3
|
+
export { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverHeader, PopoverPopup, PopoverPortal, PopoverPositioner, PopoverTitle, PopoverTrigger, type PopoverAlign, type PopoverArrowConfig, type PopoverChangeReason, type PopoverCollisionAvoidance, type PopoverCloseProps, type PopoverContentProps, type PopoverDescriptionProps, type PopoverDirection, type PopoverHeaderProps, type PopoverPopupProps, type PopoverPortalProps, type PopoverPositionerProps, type PopoverProps, type PopoverSide, type PopoverTitleProps, type PopoverTriggerProps, } from "./components/popover/index.js";
|
|
4
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type TooltipChangeReason, type TooltipContentProps, type TooltipDirection, type TooltipProps, type TooltipProviderProps, type TooltipTriggerProps, } from "./components/tooltip/index.js";
|
|
5
|
+
export { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPopup, DialogPortal, DialogTitle, DialogTrigger, DialogViewport, type DialogBackdropProps, type DialogChangeReason, type DialogCloseProps, type DialogContentProps, type DialogDescriptionProps, type DialogDirection, type DialogFocusTarget, type DialogFooterProps, type DialogHeaderProps, type DialogPopupProps, type DialogPortalProps, type DialogProps, type DialogTitleProps, type DialogTriggerProps, type DialogViewportProps, } from "./components/dialog/index.js";
|
|
6
|
+
export { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, type ContextMenuAlign, type ContextMenuChangeReason, type ContextMenuCheckboxItemProps, type ContextMenuCollisionAvoidance, type ContextMenuContentProps, type ContextMenuDirection, type ContextMenuGroupProps, type ContextMenuItemProps, type ContextMenuLabelProps, type ContextMenuProps, type ContextMenuRadioGroupProps, type ContextMenuRadioItemProps, type ContextMenuSelectEvent, type ContextMenuSeparatorProps, type ContextMenuShortcutProps, type ContextMenuSide, type ContextMenuSubContentProps, type ContextMenuSubProps, type ContextMenuSubTriggerProps, type ContextMenuTriggerProps, } from "./components/context-menu/index.js";
|
|
7
|
+
export { useEscapeKey, type UseEscapeKeyOptions, } from "./hooks/use-escape-key.js";
|
|
8
|
+
export { useLayer, type UseLayerOptions, type UseLayerReturn, } from "./hooks/use-layer.js";
|
|
9
|
+
export { useOverlay, type UseOverlayOptions, type UseOverlayReturn, } from "./hooks/use-overlay.js";
|
|
10
|
+
export { usePositioner, type UsePositionerOptions, type UsePositionerReturn, } from "./hooks/use-positioner.js";
|
|
11
|
+
export { createFocusContainment, focusElement, focusFirst, getActiveElement, getFocusableElements, isFocusable, lockBodyScroll, restoreFocus, type FocusContainment, type FocusContainmentOptions, type FocusContainmentTarget, } from "./vendor/core/index.js";
|
|
12
|
+
export type { AnimationConfig, AnimationDirection, AnimationDirectionSetting, AnimationEasing, AnimationSetting, CustomAnimationClasses, DismissReason, LayerStack, LayerStackHandle, Placement, PositionerOptions, PositionerResult, ResolvedAnimationConfig, } from "./vendor/core/index.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { Portal } from "./components/portal.js";
|
|
3
|
+
export { PopoverArrow, TooltipArrow, } from "./components/arrow.js";
|
|
4
|
+
export { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverHeader, PopoverPopup, PopoverPortal, PopoverPositioner, PopoverTitle, PopoverTrigger, } from "./components/popover/index.js";
|
|
5
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "./components/tooltip/index.js";
|
|
6
|
+
export { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPopup, DialogPortal, DialogTitle, DialogTrigger, DialogViewport, } from "./components/dialog/index.js";
|
|
7
|
+
export { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "./components/context-menu/index.js";
|
|
8
|
+
export { useEscapeKey, } from "./hooks/use-escape-key.js";
|
|
9
|
+
export { useLayer, } from "./hooks/use-layer.js";
|
|
10
|
+
export { useOverlay, } from "./hooks/use-overlay.js";
|
|
11
|
+
export { usePositioner, } from "./hooks/use-positioner.js";
|
|
12
|
+
export { createFocusContainment, focusElement, focusFirst, getActiveElement, getFocusableElements, isFocusable, lockBodyScroll, restoreFocus, } from "./vendor/core/index.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { createExpandKeyframes, createFadeKeyframes, getTransformOrigin, resolveExpandPlan, FADE_MOVE_DISTANCE, type AnimationPhase, } from "./keyframes.js";
|
|
2
|
+
export { prefersReducedMotion, runOverlayAnimation, type OverlayAnimationHandle, type RunOverlayAnimationOptions, } from "./run-animation.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AnimationDirection } from "../types/animation.js";
|
|
2
|
+
import type { Align, Side } from "../types/geometry.js";
|
|
3
|
+
export type AnimationPhase = "enter" | "exit";
|
|
4
|
+
/** Distance in pixels the built-in fade travels. */
|
|
5
|
+
export declare const FADE_MOVE_DISTANCE = 4;
|
|
6
|
+
/** Starting offset of the enter animation for a direction. */
|
|
7
|
+
export declare function fadeOffset(direction: AnimationDirection, distance?: number): {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Keyframes for the built-in fade. The exit animation is the exact reverse of
|
|
13
|
+
* the enter animation, so it moves back in the opposite direction.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createFadeKeyframes(phase: AnimationPhase, direction: AnimationDirection, distance?: number): Keyframe[];
|
|
16
|
+
export type ExpandAxis = "x" | "y" | "both";
|
|
17
|
+
/** Where an expanding popup grows from and which axis it scales. */
|
|
18
|
+
export type ExpandPlan = {
|
|
19
|
+
axis: ExpandAxis;
|
|
20
|
+
/** CSS `transform-origin` pointing at the anchor. */
|
|
21
|
+
transformOrigin: string;
|
|
22
|
+
/** Side of the anchor the popup sits on; null without an anchor (Dialog). */
|
|
23
|
+
side: Side | null;
|
|
24
|
+
align: Align | null;
|
|
25
|
+
};
|
|
26
|
+
declare function splitPlacement(placement: string | undefined): {
|
|
27
|
+
side: Side | null;
|
|
28
|
+
align: Align | null;
|
|
29
|
+
};
|
|
30
|
+
/** CSS `transform-origin` on the edge facing the anchor (RTL aware). */
|
|
31
|
+
export declare function getTransformOrigin(side: Side | null, align: Align | null, rtl?: boolean): string;
|
|
32
|
+
/**
|
|
33
|
+
* Decide how an expand animation grows. `direction` is the growth direction:
|
|
34
|
+
* `auto` follows the final placement; an explicit value overrides the side.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveExpandPlan({ placement, direction, rtl, }: {
|
|
37
|
+
placement?: string;
|
|
38
|
+
direction?: AnimationDirection | "auto";
|
|
39
|
+
rtl?: boolean;
|
|
40
|
+
}): ExpandPlan;
|
|
41
|
+
/**
|
|
42
|
+
* How far (px) the reveal extends past the popup on the sides that do not
|
|
43
|
+
* move, so the arrow and box-shadow are not clipped while it grows.
|
|
44
|
+
*/
|
|
45
|
+
export declare const EXPAND_CLIP_OVERFLOW = 32;
|
|
46
|
+
/** Share of the duration the expand fade takes; the growth uses all of it. */
|
|
47
|
+
export declare const EXPAND_FADE_PORTION = 0.3;
|
|
48
|
+
/**
|
|
49
|
+
* Keyframes for expand/collapse: the popup is revealed out of the anchor edge
|
|
50
|
+
* with a `clip-path` while it fades in (opacity 0 to 1), and collapse is the
|
|
51
|
+
* exact reverse. Content is never scaled, so text keeps its proportions.
|
|
52
|
+
* Without an anchor (Dialog) a uniform, slight scale is used. Reduced motion
|
|
53
|
+
* keeps only the fade.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createExpandKeyframes(phase: AnimationPhase, plan: ExpandPlan, reducedMotion?: boolean): Keyframe[];
|
|
56
|
+
export { splitPlacement };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/** Distance in pixels the built-in fade travels. */
|
|
2
|
+
export const FADE_MOVE_DISTANCE = 4;
|
|
3
|
+
/** Starting offset of the enter animation for a direction. */
|
|
4
|
+
export function fadeOffset(direction, distance = FADE_MOVE_DISTANCE) {
|
|
5
|
+
switch (direction) {
|
|
6
|
+
case "down":
|
|
7
|
+
return { x: 0, y: -distance };
|
|
8
|
+
case "left":
|
|
9
|
+
return { x: distance, y: 0 };
|
|
10
|
+
case "right":
|
|
11
|
+
return { x: -distance, y: 0 };
|
|
12
|
+
default:
|
|
13
|
+
return { x: 0, y: distance };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Keyframes for the built-in fade. The exit animation is the exact reverse of
|
|
18
|
+
* the enter animation, so it moves back in the opposite direction.
|
|
19
|
+
*/
|
|
20
|
+
export function createFadeKeyframes(phase, direction, distance = FADE_MOVE_DISTANCE) {
|
|
21
|
+
const offset = fadeOffset(direction, distance);
|
|
22
|
+
const hidden = { opacity: 0, translate: `${offset.x}px ${offset.y}px` };
|
|
23
|
+
const shown = { opacity: 1, translate: "0px 0px" };
|
|
24
|
+
return phase === "enter" ? [hidden, shown] : [shown, hidden];
|
|
25
|
+
}
|
|
26
|
+
const SIDES = ["top", "right", "bottom", "left"];
|
|
27
|
+
function splitPlacement(placement) {
|
|
28
|
+
const [rawSide = "", rawAlign] = (placement ?? "").split("-");
|
|
29
|
+
const side = SIDES.includes(rawSide) ? rawSide : null;
|
|
30
|
+
const align = side === null
|
|
31
|
+
? null
|
|
32
|
+
: rawAlign === "start" || rawAlign === "end"
|
|
33
|
+
? rawAlign
|
|
34
|
+
: "center";
|
|
35
|
+
return { side, align };
|
|
36
|
+
}
|
|
37
|
+
/** The side a growth direction implies: it grows away from the anchor edge. */
|
|
38
|
+
const DIRECTION_SIDE = {
|
|
39
|
+
down: "bottom",
|
|
40
|
+
up: "top",
|
|
41
|
+
right: "right",
|
|
42
|
+
left: "left",
|
|
43
|
+
};
|
|
44
|
+
/** CSS `transform-origin` on the edge facing the anchor (RTL aware). */
|
|
45
|
+
export function getTransformOrigin(side, align, rtl = false) {
|
|
46
|
+
if (side === null) {
|
|
47
|
+
return "center";
|
|
48
|
+
}
|
|
49
|
+
const alignment = align ?? "center";
|
|
50
|
+
if (side === "top" || side === "bottom") {
|
|
51
|
+
const horizontal = alignment === "center"
|
|
52
|
+
? "center"
|
|
53
|
+
: (alignment === "start") !== rtl
|
|
54
|
+
? "left"
|
|
55
|
+
: "right";
|
|
56
|
+
return `${horizontal} ${side === "bottom" ? "top" : "bottom"}`;
|
|
57
|
+
}
|
|
58
|
+
const vertical = alignment === "center"
|
|
59
|
+
? "center"
|
|
60
|
+
: alignment === "start"
|
|
61
|
+
? "top"
|
|
62
|
+
: "bottom";
|
|
63
|
+
return `${side === "right" ? "left" : "right"} ${vertical}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Decide how an expand animation grows. `direction` is the growth direction:
|
|
67
|
+
* `auto` follows the final placement; an explicit value overrides the side.
|
|
68
|
+
*/
|
|
69
|
+
export function resolveExpandPlan({ placement, direction = "auto", rtl = false, }) {
|
|
70
|
+
const parsed = splitPlacement(placement);
|
|
71
|
+
const side = direction !== "auto" ? DIRECTION_SIDE[direction] : parsed.side;
|
|
72
|
+
const align = side === null ? null : (parsed.align ?? "center");
|
|
73
|
+
const axis = side === null ? "both" : side === "top" || side === "bottom" ? "y" : "x";
|
|
74
|
+
return {
|
|
75
|
+
axis,
|
|
76
|
+
side,
|
|
77
|
+
align,
|
|
78
|
+
transformOrigin: getTransformOrigin(side, align, rtl),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* How far (px) the reveal extends past the popup on the sides that do not
|
|
83
|
+
* move, so the arrow and box-shadow are not clipped while it grows.
|
|
84
|
+
*/
|
|
85
|
+
export const EXPAND_CLIP_OVERFLOW = 32;
|
|
86
|
+
/**
|
|
87
|
+
* `clip-path` that reveals nothing but the overflow margin at the anchor edge.
|
|
88
|
+
* The clipped edge is the one opposite the anchor, so the popup grows away
|
|
89
|
+
* from it without scaling its content.
|
|
90
|
+
*/
|
|
91
|
+
function expandClip(side, shown) {
|
|
92
|
+
const open = `${-EXPAND_CLIP_OVERFLOW}px`;
|
|
93
|
+
const closed = shown ? open : "100%";
|
|
94
|
+
// inset(top right bottom left)
|
|
95
|
+
switch (side) {
|
|
96
|
+
case "bottom":
|
|
97
|
+
return `inset(${open} ${open} ${closed} ${open})`;
|
|
98
|
+
case "top":
|
|
99
|
+
return `inset(${closed} ${open} ${open} ${open})`;
|
|
100
|
+
case "right":
|
|
101
|
+
return `inset(${open} ${closed} ${open} ${open})`;
|
|
102
|
+
default:
|
|
103
|
+
return `inset(${open} ${open} ${open} ${closed})`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Share of the duration the expand fade takes; the growth uses all of it. */
|
|
107
|
+
export const EXPAND_FADE_PORTION = 0.3;
|
|
108
|
+
/**
|
|
109
|
+
* Keyframes for expand/collapse: the popup is revealed out of the anchor edge
|
|
110
|
+
* with a `clip-path` while it fades in (opacity 0 to 1), and collapse is the
|
|
111
|
+
* exact reverse. Content is never scaled, so text keeps its proportions.
|
|
112
|
+
* Without an anchor (Dialog) a uniform, slight scale is used. Reduced motion
|
|
113
|
+
* keeps only the fade.
|
|
114
|
+
*/
|
|
115
|
+
export function createExpandKeyframes(phase, plan, reducedMotion = false) {
|
|
116
|
+
let from = {};
|
|
117
|
+
let to = {};
|
|
118
|
+
if (!reducedMotion) {
|
|
119
|
+
if (plan.side !== null && plan.axis !== "both") {
|
|
120
|
+
from = { clipPath: expandClip(plan.side, false) };
|
|
121
|
+
to = { clipPath: expandClip(plan.side, true) };
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
from = { scale: "0.95 0.95" };
|
|
125
|
+
to = { scale: "1 1" };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const hidden = {
|
|
129
|
+
opacity: 0,
|
|
130
|
+
transformOrigin: plan.transformOrigin,
|
|
131
|
+
...from,
|
|
132
|
+
};
|
|
133
|
+
const shown = {
|
|
134
|
+
opacity: 1,
|
|
135
|
+
transformOrigin: plan.transformOrigin,
|
|
136
|
+
...to,
|
|
137
|
+
};
|
|
138
|
+
if (reducedMotion) {
|
|
139
|
+
return phase === "enter" ? [hidden, shown] : [shown, hidden];
|
|
140
|
+
}
|
|
141
|
+
// The fade finishes early so the growth stays visible instead of playing
|
|
142
|
+
// while the popup is still nearly transparent.
|
|
143
|
+
return phase === "enter"
|
|
144
|
+
? [
|
|
145
|
+
{ ...hidden, offset: 0 },
|
|
146
|
+
{ opacity: 1, offset: EXPAND_FADE_PORTION },
|
|
147
|
+
{ ...shown, offset: 1 },
|
|
148
|
+
]
|
|
149
|
+
: [
|
|
150
|
+
{ ...shown, offset: 0 },
|
|
151
|
+
{ opacity: 1, offset: 1 - EXPAND_FADE_PORTION },
|
|
152
|
+
{ ...hidden, offset: 1 },
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
export { splitPlacement };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ResolvedAnimationConfig } from "../types/animation.js";
|
|
2
|
+
import { type AnimationPhase } from "./keyframes.js";
|
|
3
|
+
export type RunOverlayAnimationOptions = {
|
|
4
|
+
phase: AnimationPhase;
|
|
5
|
+
config: ResolvedAnimationConfig;
|
|
6
|
+
/** Final (collision-adjusted) placement; used for the "auto" direction. */
|
|
7
|
+
placement?: string;
|
|
8
|
+
/** Removes movement and keeps only the opacity change. */
|
|
9
|
+
reducedMotion?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type OverlayAnimationHandle = {
|
|
12
|
+
/** Resolves when the animation completes; never resolves once cancelled. */
|
|
13
|
+
finished: Promise<void>;
|
|
14
|
+
cancel(): void;
|
|
15
|
+
};
|
|
16
|
+
/** Lazily read the user's reduced-motion preference (SSR-safe). */
|
|
17
|
+
export declare function prefersReducedMotion(win?: Window | null | undefined): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Run an enter/exit animation on an element: the built-in `fade` or `expand`
|
|
20
|
+
* (Web Animations API), consumer keyframes, or consumer CSS classes.
|
|
21
|
+
* Positioning uses left/top; these use opacity/translate/scale or CSS
|
|
22
|
+
* animation, so they never compete with positioning coordinates.
|
|
23
|
+
*
|
|
24
|
+
* While it runs, `--overlay-transform-origin` points at the anchor so custom
|
|
25
|
+
* CSS can grow from the right edge too.
|
|
26
|
+
*/
|
|
27
|
+
export declare function runOverlayAnimation(element: HTMLElement, { phase, config, placement, reducedMotion, }: RunOverlayAnimationOptions): OverlayAnimationHandle;
|