@lablup/ui-common 0.2.0-alpha.15 → 0.2.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -5
- package/dist/astryx/Markdown/parser.d.ts +1 -0
- package/dist/astryx/Markdown/parser.js +1 -0
- package/dist/astryx/Markdown/plugins.d.ts +1 -0
- package/dist/astryx/Markdown/plugins.js +1 -0
- package/dist/astryx/Markdown/remark.d.ts +1 -0
- package/dist/astryx/Markdown/remark.js +1 -0
- package/dist/astryx/Timer.d.ts +1 -0
- package/dist/astryx/Timer.js +1 -0
- package/dist/astryx/lab.d.ts +2 -2
- package/dist/astryx/lab.js +2 -2
- package/dist/components/Modal/modalStack.d.ts +2 -0
- package/dist/components/Modal/modalStack.js +29 -26
- package/dist/components/Modal/modalStack.js.map +1 -1
- package/dist/components/PagedSelector/PanelSearchInput.d.ts +1 -1
- package/dist/components/PagedSelector/PanelSearchInput.js +1 -1
- package/dist/components/PagedSelector/PanelSearchInput.js.map +1 -1
- package/dist/forks/ComplexSelector/ComplexSelector.js.map +1 -1
- package/dist/forks/ComplexSelector/ComplexSelector.styles.d.ts +4 -0
- package/dist/forks/ComplexSelector/ComplexSelector.styles.js +5 -1
- package/dist/forks/ComplexSelector/ComplexSelector.styles.js.map +1 -1
- package/dist/forks/Drawer/Drawer.d.ts +25 -14
- package/dist/forks/Drawer/Drawer.js +79 -79
- package/dist/forks/Drawer/Drawer.js.map +1 -1
- package/dist/forks/Drawer/Drawer.styles.d.ts +16 -9
- package/dist/forks/Drawer/Drawer.styles.js +26 -16
- package/dist/forks/Drawer/Drawer.styles.js.map +1 -1
- package/dist/forks/Drawer/useDrawerDialogPresence.d.ts +7 -6
- package/dist/forks/Drawer/useDrawerDialogPresence.js +30 -21
- package/dist/forks/Drawer/useDrawerDialogPresence.js.map +1 -1
- package/dist/forks/Tour/Tour.js.map +1 -1
- package/dist/forks/Tour/TourContext.js.map +1 -1
- package/dist/forks/Tour/TourStep.js.map +1 -1
- package/dist/forks/Tour/TourStep.styles.js.map +1 -1
- package/dist/forks/Tour/useTour.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/instance.js +2 -2
- package/dist/locales/af-ZA.generated.d.ts +8 -0
- package/dist/locales/af-ZA.generated.js +381 -0
- package/dist/locales/af-ZA.json +530 -1
- package/dist/locales/ar-SA.generated.d.ts +8 -0
- package/dist/locales/ar-SA.generated.js +381 -0
- package/dist/locales/ar-SA.json +490 -1
- package/dist/locales/ca-ES.generated.d.ts +8 -0
- package/dist/locales/ca-ES.generated.js +381 -0
- package/dist/locales/ca-ES.json +514 -1
- package/dist/locales/cs-CZ.generated.d.ts +8 -0
- package/dist/locales/cs-CZ.generated.js +381 -0
- package/dist/locales/cs-CZ.json +498 -1
- package/dist/locales/da-DK.generated.d.ts +8 -0
- package/dist/locales/da-DK.generated.js +381 -0
- package/dist/locales/da-DK.json +522 -1
- package/dist/locales/de-DE.generated.d.ts +8 -0
- package/dist/locales/de-DE.generated.js +381 -0
- package/dist/locales/de-DE.json +522 -1
- package/dist/locales/el-GR.generated.d.ts +8 -0
- package/dist/locales/el-GR.generated.js +381 -0
- package/dist/locales/el-GR.json +498 -1
- package/dist/locales/en.generated.d.ts +8 -0
- package/dist/locales/en.generated.js +385 -0
- package/dist/locales/en.json +16 -0
- package/dist/locales/es-ES.generated.d.ts +8 -0
- package/dist/locales/es-ES.generated.js +381 -0
- package/dist/locales/es-ES.json +510 -1
- package/dist/locales/fi-FI.generated.d.ts +8 -0
- package/dist/locales/fi-FI.generated.js +381 -0
- package/dist/locales/fi-FI.json +498 -1
- package/dist/locales/fr-FR.generated.d.ts +8 -0
- package/dist/locales/fr-FR.generated.js +381 -0
- package/dist/locales/fr-FR.json +534 -1
- package/dist/locales/he-IL.generated.d.ts +8 -0
- package/dist/locales/he-IL.generated.js +381 -0
- package/dist/locales/he-IL.json +498 -1
- package/dist/locales/hu-HU.generated.d.ts +8 -0
- package/dist/locales/hu-HU.generated.js +381 -0
- package/dist/locales/hu-HU.json +498 -1
- package/dist/locales/it-IT.generated.d.ts +8 -0
- package/dist/locales/it-IT.generated.js +381 -0
- package/dist/locales/it-IT.json +510 -1
- package/dist/locales/ja-JP.generated.d.ts +8 -0
- package/dist/locales/ja-JP.generated.js +381 -0
- package/dist/locales/ja-JP.json +492 -3
- package/dist/locales/ko-KR.generated.d.ts +8 -0
- package/dist/locales/ko-KR.generated.js +381 -0
- package/dist/locales/ko-KR.json +500 -3
- package/dist/locales/nl-NL.generated.d.ts +8 -0
- package/dist/locales/nl-NL.generated.js +381 -0
- package/dist/locales/nl-NL.json +534 -1
- package/dist/locales/no-NO.generated.d.ts +8 -0
- package/dist/locales/no-NO.generated.js +381 -0
- package/dist/locales/no-NO.json +510 -1
- package/dist/locales/pl-PL.generated.d.ts +8 -0
- package/dist/locales/pl-PL.generated.js +381 -0
- package/dist/locales/pl-PL.json +506 -1
- package/dist/locales/pseudo.generated.d.ts +8 -0
- package/dist/locales/pseudo.generated.js +385 -0
- package/dist/locales/pseudo.json +12 -0
- package/dist/locales/pt-BR.generated.d.ts +8 -0
- package/dist/locales/pt-BR.generated.js +381 -0
- package/dist/locales/pt-BR.json +506 -1
- package/dist/locales/pt-PT.generated.d.ts +8 -0
- package/dist/locales/pt-PT.generated.js +381 -0
- package/dist/locales/pt-PT.json +506 -1
- package/dist/locales/ro-RO.generated.d.ts +8 -0
- package/dist/locales/ro-RO.generated.js +381 -0
- package/dist/locales/ro-RO.json +506 -1
- package/dist/locales/ru-RU.generated.d.ts +8 -0
- package/dist/locales/ru-RU.generated.js +381 -0
- package/dist/locales/ru-RU.json +498 -1
- package/dist/locales/sr-SP.generated.d.ts +8 -0
- package/dist/locales/sr-SP.generated.js +381 -0
- package/dist/locales/sr-SP.json +498 -1
- package/dist/locales/sv-SE.generated.d.ts +8 -0
- package/dist/locales/sv-SE.generated.js +381 -0
- package/dist/locales/sv-SE.json +502 -1
- package/dist/locales/tr-TR.generated.d.ts +8 -0
- package/dist/locales/tr-TR.generated.js +381 -0
- package/dist/locales/tr-TR.json +498 -1
- package/dist/locales/uk-UA.generated.d.ts +8 -0
- package/dist/locales/uk-UA.generated.js +381 -0
- package/dist/locales/uk-UA.json +498 -1
- package/dist/locales/vi-VN.generated.d.ts +8 -0
- package/dist/locales/vi-VN.generated.js +381 -0
- package/dist/locales/vi-VN.json +502 -1
- package/dist/locales/zh-CN.generated.d.ts +8 -0
- package/dist/locales/zh-CN.generated.js +381 -0
- package/dist/locales/zh-CN.json +503 -14
- package/dist/locales/zh-TW.generated.d.ts +8 -0
- package/dist/locales/zh-TW.generated.js +381 -0
- package/dist/locales/zh-TW.json +503 -14
- package/dist/theme/lablup/built/lablup.d.ts +2 -2
- package/dist/theme/lablup/built/lablup.js +2 -2
- package/dist/theme/lablup/built/lablup.variants.d.ts +2 -2
- package/dist/theme/lablup/built/theme.css +6 -2
- package/package.json +26 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { BaseProps } from '@astryxdesign/core';
|
|
3
|
+
import { DialogPurpose } from '@astryxdesign/core/Dialog';
|
|
3
4
|
export interface DrawerProps extends BaseProps<HTMLDialogElement> {
|
|
4
5
|
/** Ref forwarded to the root <dialog> element */
|
|
5
6
|
ref?: React.Ref<HTMLDialogElement>;
|
|
@@ -8,10 +9,11 @@ export interface DrawerProps extends BaseProps<HTMLDialogElement> {
|
|
|
8
9
|
*/
|
|
9
10
|
isOpen: boolean;
|
|
10
11
|
/**
|
|
11
|
-
* Called when the drawer requests an open-state change. Escape
|
|
12
|
-
* click
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Called when the drawer requests an open-state change. Escape and a scrim
|
|
13
|
+
* click call it with `false` as `purpose` allows; a `DrawerHeader` close
|
|
14
|
+
* button calls it when you pass the same callback to the header. The caller
|
|
15
|
+
* owns the open state. When sibling drawers are open, Escape only closes the
|
|
16
|
+
* top (last-opened) drawer.
|
|
15
17
|
*/
|
|
16
18
|
onOpenChange: (isOpen: boolean) => void;
|
|
17
19
|
/**
|
|
@@ -46,19 +48,22 @@ export interface DrawerProps extends BaseProps<HTMLDialogElement> {
|
|
|
46
48
|
* Whether to render a modal scrim behind the drawer.
|
|
47
49
|
* - `true` (default) — `showModal()`: top layer, focus trap, body scroll
|
|
48
50
|
* lock, click-outside-to-close.
|
|
49
|
-
* - `false` — `
|
|
50
|
-
* interactive. Escape still closes
|
|
51
|
-
* the top-most layer).
|
|
51
|
+
* - `false` — `showPopover()`: non-modal top-layer overlay; the page behind
|
|
52
|
+
* stays interactive. Escape still closes through the shared layer stack.
|
|
52
53
|
* @default true
|
|
53
54
|
*/
|
|
54
55
|
hasScrim?: boolean;
|
|
55
56
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
57
|
+
* Configures how the drawer enables dismissals, matching Dialog.
|
|
58
|
+
* - required: Disables Escape and scrim click (for mandatory flows); a
|
|
59
|
+
* modal required drawer is exposed as an `alertdialog`
|
|
60
|
+
* - form: Prevents scrim click, allows the Escape key
|
|
61
|
+
* - info: Allows Escape and scrim click
|
|
62
|
+
*
|
|
63
|
+
* A non-modal drawer has no scrim, so `form` and `info` behave the same.
|
|
64
|
+
* @default 'info'
|
|
60
65
|
*/
|
|
61
|
-
|
|
66
|
+
purpose?: DialogPurpose;
|
|
62
67
|
/**
|
|
63
68
|
* Drawer content. Rendered inside a full-height scrollable area.
|
|
64
69
|
* Focus the element with `data-autofocus` on open, if present.
|
|
@@ -81,18 +86,24 @@ export interface DrawerProps extends BaseProps<HTMLDialogElement> {
|
|
|
81
86
|
* closes the top-most open drawer; focus returns to the element that
|
|
82
87
|
* opened it.
|
|
83
88
|
*
|
|
89
|
+
* Dismissal matches Dialog: `purpose` decides whether Escape and a scrim click
|
|
90
|
+
* close the drawer, and `DrawerHeader` renders a close button when given
|
|
91
|
+
* `onOpenChange`.
|
|
92
|
+
*
|
|
84
93
|
* @example
|
|
85
94
|
* ```
|
|
86
95
|
* const [selected, setSelected] = useState(null);
|
|
96
|
+
* const handleOpenChange = isOpen => !isOpen && setSelected(null);
|
|
87
97
|
* <Drawer
|
|
88
98
|
* isOpen={selected != null}
|
|
89
|
-
* onOpenChange={
|
|
99
|
+
* onOpenChange={handleOpenChange}
|
|
90
100
|
* label={`Details: ${selected?.name}`}>
|
|
101
|
+
* <DrawerHeader title={selected?.name} onOpenChange={handleOpenChange} />
|
|
91
102
|
* <HostDetails host={selected} />
|
|
92
103
|
* </Drawer>
|
|
93
104
|
* ```
|
|
94
105
|
*/
|
|
95
|
-
export declare function Drawer({ isOpen, onOpenChange, side, width, isFullWidthOnMobile, label, hasScrim,
|
|
106
|
+
export declare function Drawer({ isOpen, onOpenChange, side, width, isFullWidthOnMobile, label, hasScrim, purpose, children, xstyle, className, style, onClick: onClickProp, onKeyDown: onKeyDownProp, ref, ...props }: DrawerProps): import("react").JSX.Element;
|
|
96
107
|
export declare namespace Drawer {
|
|
97
108
|
var displayName: string;
|
|
98
109
|
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { ModalPortalContext as e } from "../../components/Modal/modalStack.js";
|
|
3
|
-
import { compiledStyles as
|
|
4
|
-
import { dynamicStyles as
|
|
5
|
-
import { useDrawerDialogPresence as
|
|
6
|
-
import { useCallback as
|
|
2
|
+
import { ModalPortalContext as e, modalZIndexBase as t } from "../../components/Modal/modalStack.js";
|
|
3
|
+
import { compiledStyles as n } from "../compiled.js";
|
|
4
|
+
import { dynamicStyles as r, styles as i } from "./Drawer.styles.js";
|
|
5
|
+
import { useDrawerDialogPresence as a } from "./useDrawerDialogPresence.js";
|
|
6
|
+
import { useCallback as o, useEffect as s, useId as ee, useRef as c, useState as l } from "react";
|
|
7
7
|
import { overlayPaddingReset as te } from "@astryxdesign/core/Layout";
|
|
8
|
-
import { useScrollLock as
|
|
9
|
-
import { LayerDepthProvider as
|
|
10
|
-
import { composeEventHandlers as
|
|
11
|
-
import { jsx as
|
|
12
|
-
import
|
|
13
|
-
import { IconButton as v } from "@astryxdesign/core/IconButton";
|
|
14
|
-
import * as y from "@stylexjs/stylex";
|
|
8
|
+
import { useFocusTrap as u, useMergedRefs as d, useScrollLock as f } from "@astryxdesign/core/hooks";
|
|
9
|
+
import { LayerDepthProvider as p, useLayerDismissal as m } from "@astryxdesign/core/Layer";
|
|
10
|
+
import { composeEventHandlers as ne, mergeProps as h, themeProps as g } from "@astryxdesign/core/utils";
|
|
11
|
+
import { jsx as _ } from "react/jsx-runtime";
|
|
12
|
+
import * as v from "@stylexjs/stylex";
|
|
15
13
|
//#region src/forks/Drawer/Drawer.tsx
|
|
16
|
-
var b =
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
close: t
|
|
21
|
-
}), S += 1, b + S - 1;
|
|
14
|
+
var y = 56, re = "100dvw", b = n(i), ie = r, ae = 1e3, x = /* @__PURE__ */ new Map();
|
|
15
|
+
function oe(e) {
|
|
16
|
+
let n = Math.max(999, ...x.values()), r = Math.min(n + 1, t() - 1);
|
|
17
|
+
return x.set(e, r), r;
|
|
22
18
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
t !== -1 && x.splice(t, 1), x.length === 0 && (S = 0);
|
|
19
|
+
function S(e) {
|
|
20
|
+
x.delete(e);
|
|
26
21
|
}
|
|
27
|
-
var
|
|
28
|
-
function
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, [n]);
|
|
33
|
-
let [U, W] = c(b), [G, K] = c(t);
|
|
34
|
-
t && !G && K(!0), i({
|
|
35
|
-
dialogRef: B,
|
|
22
|
+
var C = "x1iyjqo2 x2lwn1j xh8yej3 x1odjw0f x6ikm8r xish69e xx69xxh x1a148e8 x1a2a7pz";
|
|
23
|
+
function w({ isOpen: t, onOpenChange: n, side: r = "end", width: i = 400, isFullWidthOnMobile: x = !1, label: w, hasScrim: T = !0, purpose: E = "info", children: D, xstyle: O, className: k, style: A, onClick: j, onKeyDown: M, ref: N, ...P }) {
|
|
24
|
+
let F = c(null), { containerRef: I } = u({ isActive: t && T }), L = d(N, F, I), R = E !== "required", z = E === "info", [B, V] = l(t);
|
|
25
|
+
t && !B && V(!0), a({
|
|
26
|
+
dialogRef: F,
|
|
36
27
|
isOpen: t,
|
|
37
|
-
isModal:
|
|
38
|
-
setIsRendered:
|
|
28
|
+
isModal: T,
|
|
29
|
+
setIsRendered: V
|
|
39
30
|
});
|
|
40
|
-
let [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}, [t,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return W
|
|
47
|
-
}, [
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, [n
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
31
|
+
let [H, U] = l(null);
|
|
32
|
+
s(() => {
|
|
33
|
+
U(t && T ? F.current : null);
|
|
34
|
+
}, [t, T]);
|
|
35
|
+
let W = ee(), [G, K] = l(ae);
|
|
36
|
+
s(() => {
|
|
37
|
+
if (!(!B || T)) return K(oe(W)), () => S(W);
|
|
38
|
+
}, [
|
|
39
|
+
B,
|
|
40
|
+
T,
|
|
41
|
+
W
|
|
42
|
+
]);
|
|
43
|
+
let q = o(() => {
|
|
44
|
+
n(!1);
|
|
45
|
+
}, [n]), { shouldDismissOnCloseRequest: J } = m({
|
|
46
|
+
isActive: B,
|
|
47
|
+
escapeBehavior: R ? "close" : "block",
|
|
48
|
+
onDismiss: q,
|
|
49
|
+
getContainer: () => F.current
|
|
50
|
+
});
|
|
51
|
+
f(t && T);
|
|
52
|
+
let se = o((e) => {
|
|
53
|
+
e.preventDefault(), J() && R && q();
|
|
54
|
+
}, [
|
|
55
|
+
R,
|
|
56
|
+
q,
|
|
57
|
+
J
|
|
58
|
+
]), ce = o((e) => {
|
|
59
|
+
e.target === e.currentTarget && T && z && n(!1);
|
|
60
|
+
}, [
|
|
61
|
+
z,
|
|
62
|
+
T,
|
|
63
|
+
n
|
|
64
|
+
]), Y = typeof i == "number" ? `${i}px` : i, le = x ? re : `min(${Y}, calc(100dvw - ${y}px))`, X = c(r);
|
|
65
|
+
t && (X.current = r);
|
|
66
|
+
let Z = t ? r : X.current, ue = Z === "start" ? b.start : b.end, Q = Z === "start" ? b.startOpen : b.endOpen, { open: de, ...$ } = P;
|
|
67
|
+
return /* @__PURE__ */ _("dialog", {
|
|
68
|
+
ref: L,
|
|
69
|
+
...h(g("drawer", { side: Z }), v.props(b.dialog, te.reset, ue, ie.inlineSize(Y, le), B && b.rendered, t && Q, T && b.scrim, T && t && b.scrimOpen, O), k, T ? A : {
|
|
70
|
+
zIndex: G,
|
|
71
|
+
...A
|
|
72
|
+
}),
|
|
62
73
|
...$,
|
|
63
|
-
"aria-label":
|
|
64
|
-
"aria-modal": $["aria-modal"] ?? (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
"aria-label": w,
|
|
75
|
+
"aria-modal": $["aria-modal"] ?? (T ? "true" : void 0),
|
|
76
|
+
...E === "required" && T ? { role: "alertdialog" } : void 0,
|
|
77
|
+
onClick: ne(j, ce),
|
|
78
|
+
onKeyDown: M,
|
|
79
|
+
onCancel: se,
|
|
80
|
+
children: /* @__PURE__ */ _(p, { children: /* @__PURE__ */ _("div", {
|
|
69
81
|
tabIndex: -1,
|
|
70
|
-
className:
|
|
71
|
-
children: /* @__PURE__ */
|
|
72
|
-
value:
|
|
73
|
-
children:
|
|
74
|
-
}) })
|
|
75
|
-
}), M && /* @__PURE__ */ h("div", {
|
|
76
|
-
className: k,
|
|
77
|
-
children: /* @__PURE__ */ h(v, {
|
|
78
|
-
icon: /* @__PURE__ */ h(_, {
|
|
79
|
-
icon: "close",
|
|
80
|
-
size: "sm",
|
|
81
|
-
color: "inherit"
|
|
82
|
-
}),
|
|
83
|
-
label: "Close",
|
|
84
|
-
variant: "ghost",
|
|
85
|
-
onClick: () => n(!1)
|
|
82
|
+
className: C,
|
|
83
|
+
children: /* @__PURE__ */ _(e, {
|
|
84
|
+
value: H,
|
|
85
|
+
children: D
|
|
86
86
|
})
|
|
87
|
-
})
|
|
87
|
+
}) })
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
w.displayName = "Drawer";
|
|
91
91
|
//#endregion
|
|
92
|
-
export {
|
|
92
|
+
export { w as Drawer };
|
|
93
93
|
|
|
94
94
|
//# sourceMappingURL=Drawer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.js","names":[],"sources":["../../../src/forks/Drawer/Drawer.tsx"],"sourcesContent":["// Copyright (c) Meta Platforms, Inc. and affiliates.\n// Modifications copyright (c) Lablup Inc.\n//\n// Forked from @astryxdesign/lab 0.6.2-canary.c9fb1ad, src/Drawer/Drawer.tsx\n// (MIT; see NOTICE). Provenance and the drift guard: src/forks/provenance.json.\n\n\"use client\";\n\n/**\n * Drawer, ui-common's copy of Astryx lab's, with three changes (not upstream):\n *\n * - **Escape goes through core's layer-dismissal stack.** Lab's drawer runs\n * its own element-level Escape handler, which claims the press before the\n * stack's document listener sees it, so an Escape in a popover, selector or\n * modal opened inside the drawer closed the drawer too (or, for a portalled\n * modal, neither). The drawer now registers with `useLayerDismissal` the way\n * core's `Dialog` does and wraps its content in `LayerDepthProvider`: one\n * press closes exactly the top-most layer, nested drawers close top-first,\n * an IME Escape closes nothing, and the native `cancel` answers only while\n * this drawer is on top. A non-modal drawer therefore closes on Escape\n * wherever focus is, as core's non-modal popovers do, not only while focus\n * is inside it.\n * - **`aria-modal` passes through.** A scrimless drawer is non-modal, but a\n * consumer that restores modality by hand (its own mask and focus trap) can\n * now say so; the default is unchanged.\n * - **ui-common's `Modal` opens above it.** A scrimmed drawer is a modal\n * `<dialog>`, which makes everything outside it inert, so a `Modal`\n * portalled to the body sat behind the drawer, unreachable. The drawer\n * provides its dialog through `ModalPortalContext` while it is open and\n * modal, and a `Modal` inside renders there, in the top layer\n * (modalStack.ts). Core's `Dialog` needs none of this: it is top layer\n * itself, and ui-common's `Modal` is not.\n *\n * Everything else is upstream's. Its style namespaces are Astryx's compiled\n * output (src/forks/compiled.ts). The LIFO drawer registry is module-level,\n * so this copy stacks with other drawers from this copy only; lab's own\n * `Drawer` is not exported by ui-common. Escape no longer consults it: it\n * only assigns non-modal z-indexes.\n *\n * Delete this fork, and its exports.exclude.json entry, once lab ships the\n * first two and `Modal` no longer needs the third\n * (CONTRIBUTING, \"Forks of Astryx components\").\n */\n\n/*\n * Upstream's file notes, kept:\n *\n * Overlay panel for inspectors and detail views — the \"click a table row,\n * see its details\" pattern. Slides in from the inline start or end edge and\n * floats above the page content: unlike a docked panel it never reflows the\n * layout underneath, it overlays it (with or without a scrim).\n *\n * Inline axis only (start/end). Block-axis sheets are BottomSheet's job;\n * a drawer is always a full-height side panel.\n *\n * Sizing is viewport-aware: `width` is the desktop budget, and below\n * the mobile breakpoint it preserves a 56px reveal of the page behind, capped\n * by the requested width (or fills the viewport with `isFullWidthOnMobile`).\n *\n * Uses the native `<dialog>` element (same precedent as Dialog/MobileNav):\n * - `showModal()` when `hasScrim` (default) — top-layer rendering, focus\n * trapping, `::backdrop`, no z-index management.\n * - `show()` when `hasScrim={false}` — non-modal overlay; the page behind\n * stays interactive (e.g. master-detail inspectors).\n *\n * Entry animation uses `@starting-style`; exit slides out before\n * `dialog.close()` releases the top layer and restores focus to the element\n * that opened the drawer. React owns `display` for both legs rather than a\n * discrete `display` transition, so the panel stops painting in the same\n * commit as `close()`.\n *\n * Sibling drawers coordinate through a module-level LIFO registry: Escape\n * closes only the top (last-opened) drawer, and non-modal drawers stack\n * last-opened-on-top via registry-assigned z-indexes.\n */\n\nimport { useCallback, useEffect, useId, useRef, useState, type ReactNode } from \"react\";\nimport * as stylex from \"@stylexjs/stylex\";\nimport type { StyleXStyles } from \"@stylexjs/stylex\";\nimport type { BaseProps } from \"@astryxdesign/core\";\nimport { Icon } from \"@astryxdesign/core/Icon\";\nimport { IconButton } from \"@astryxdesign/core/IconButton\";\nimport { LayerDepthProvider, useLayerDismissal } from \"@astryxdesign/core/Layer\";\nimport { useScrollLock } from \"@astryxdesign/core/hooks\";\nimport {\n composeEventHandlers,\n mergeProps,\n mergeRefs,\n themeProps,\n} from \"@astryxdesign/core/utils\";\nimport { overlayPaddingReset } from \"@astryxdesign/core/Layout\";\n\nimport { compiledStyles } from \"../compiled\";\nimport * as compiled from \"./Drawer.styles\";\nimport { ModalPortalContext } from \"../../components/Modal/modalStack\";\nimport { useDrawerDialogPresence } from \"./useDrawerDialogPresence\";\n\n// =============================================================================\n// LIFO stacking registry (internal)\n// =============================================================================\n\n// Module-level registry of currently open drawers, in open order (last entry\n// is the top of the stack). SSR-safe: only mutated inside effects.\n// ui-common: Escape no longer consults it (core's layer stack orders that);\n// non-modal (show()) drawers get incrementing z-indexes so the\n// last-opened one paints on top; modal drawers rely on the native top\n// layer's chronological stacking instead.\ntype DrawerRegistryEntry = { id: string; close: () => void };\n\n// Without the top layer (hasScrim={false} uses show(), not showModal())\n// the panel needs explicit stacking. No z-index token exists in the theme;\n// 1000 matches the app-level drawer convention.\nconst NON_MODAL_BASE_Z = 1000;\n\nconst openDrawerStack: DrawerRegistryEntry[] = [];\nlet registrationCounter = 0;\n\nfunction registerDrawer(id: string, close: () => void): number {\n openDrawerStack.push({ id, close });\n registrationCounter += 1;\n return NON_MODAL_BASE_Z + registrationCounter - 1;\n}\n\nfunction unregisterDrawer(id: string): void {\n const index = openDrawerStack.findIndex((entry) => entry.id === id);\n if (index !== -1) {\n openDrawerStack.splice(index, 1);\n }\n if (openDrawerStack.length === 0) {\n registrationCounter = 0;\n }\n}\n\n// =============================================================================\n// Styles\n// =============================================================================\n\n// Material's established mobile drawer pattern leaves a 56dp reveal. Using\n// the same value in CSS pixels gives the overlay a stable visual relationship\n// to the page behind while the requested width remains an upper bound.\nconst MOBILE_PAGE_REVEAL = 56;\nconst MOBILE_WIDTH_FULL = \"100dvw\";\n\n// @astryxdesign/lab dist/Drawer/Drawer.js `styles` and `dynamicStyles`.\nconst styles = compiledStyles(compiled.styles);\nconst dynamicStyles = compiled.dynamicStyles as {\n inlineSize: (desktopWidth: string, mobileWidth: string) => StyleXStyles;\n stackZ: (z: number) => StyleXStyles;\n};\n\n// Upstream's `content` and `controls` styles, which its compiler folded into\n// these class lists (dist/Drawer/Drawer.js).\nconst CONTENT_CLASS_NAME =\n \"x1iyjqo2 x2lwn1j xh8yej3 x1odjw0f x6ikm8r xish69e xx69xxh x1a148e8 x1a2a7pz\";\nconst CONTROLS_CLASS_NAME = \"x10l6tqk xctzyg x72tfeb x78zum5 xzye2dw x1vjfegm\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport interface DrawerProps extends BaseProps<HTMLDialogElement> {\n /** Ref forwarded to the root <dialog> element */\n ref?: React.Ref<HTMLDialogElement>;\n\n /**\n * Whether the drawer is open. Fully controlled — pair with `onOpenChange`.\n */\n isOpen: boolean;\n\n /**\n * Called when the drawer requests an open-state change. Escape, scrim\n * click, and the built-in close button call it with `false`. The caller owns\n * the open state. When sibling drawers are open, Escape only closes the top\n * (last-opened) drawer.\n */\n onOpenChange: (isOpen: boolean) => void;\n\n /**\n * Which edge the drawer slides from.\n * - `'end'` — inline-end edge (right in LTR) — the inspector convention\n * - `'start'` — inline-start edge (left in LTR)\n * @default 'end'\n */\n side?: \"start\" | \"end\";\n\n /**\n * Desktop width budget. A number is pixels; a string is any CSS length\n * (`'50%'`, `'32rem'`). Below the mobile breakpoint (640px), this\n * remains the maximum while the drawer preserves a 56px reveal of the page\n * behind — see `isFullWidthOnMobile`.\n * @default 400\n */\n width?: number | string;\n\n /**\n * Whether the drawer covers the full viewport width on mobile\n * (below 640px) instead of preserving the default 56px reveal of the page\n * behind. The reveal makes the drawer read as an overlay rather than a\n * navigation.\n * @default false\n */\n isFullWidthOnMobile?: boolean;\n\n /**\n * Accessible label for the drawer (required — the drawer has no\n * built-in heading to derive a name from).\n */\n label: string;\n\n /**\n * Whether to render a modal scrim behind the drawer.\n * - `true` (default) — `showModal()`: top layer, focus trap, body scroll\n * lock, click-outside-to-close.\n * - `false` — `show()`: non-modal overlay; the page behind stays\n * interactive. Escape still closes it (ui-common: wherever focus is, as\n * the top-most layer).\n * @default true\n */\n hasScrim?: boolean;\n\n /**\n * Whether to render the built-in close button in the top-trailing\n * corner. Enabled by default for both modal and non-modal drawers so every\n * overlay has an obvious dismissal affordance.\n * @default true\n */\n hasCloseButton?: boolean;\n\n /**\n * Drawer content. Rendered inside a full-height scrollable area.\n * Focus the element with `data-autofocus` on open, if present.\n */\n children: ReactNode;\n\n /**\n * Test ID for the root element.\n */\n \"data-testid\"?: string;\n}\n\n// =============================================================================\n// Component\n// =============================================================================\n\n/**\n * An overlay panel for inspectors and detail views.\n *\n * Slides in from the logical start or end edge and floats above the page\n * using the native `<dialog>` element: modal with a scrim by default, or a\n * non-modal overlay with `hasScrim={false}` that leaves the page behind\n * interactive. `width` is the desktop budget; below 640px the panel preserves\n * a 56px page reveal without exceeding that budget (or fills the viewport\n * with `isFullWidthOnMobile`). Escape\n * closes the top-most open drawer; focus returns to the element that\n * opened it.\n *\n * @example\n * ```\n * const [selected, setSelected] = useState(null);\n * <Drawer\n * isOpen={selected != null}\n * onOpenChange={isOpen => !isOpen && setSelected(null)}\n * label={`Details: ${selected?.name}`}>\n * <HostDetails host={selected} />\n * </Drawer>\n * ```\n */\nexport function Drawer({\n isOpen,\n onOpenChange,\n side = \"end\",\n width = 400,\n isFullWidthOnMobile = false,\n label,\n hasScrim = true,\n hasCloseButton = true,\n children,\n xstyle,\n className,\n style,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n ref,\n ...props\n}: DrawerProps) {\n const dialogRef = useRef<HTMLDialogElement>(null);\n // Registry identity + latest onOpenChange (stable across re-renders so the\n // registration effect doesn't churn on every onOpenChange identity change).\n const drawerId = useId();\n const onOpenChangeRef = useRef(onOpenChange);\n useEffect(() => {\n onOpenChangeRef.current = onOpenChange;\n }, [onOpenChange]);\n // z-index assigned by the registry on open (non-modal stacking only).\n const [stackZ, setStackZ] = useState(NON_MODAL_BASE_Z);\n // Whether the panel paints: true while open and for the whole slide-out.\n const [isRendered, setIsRendered] = useState(isOpen);\n\n // Adjusted during render, not in an effect: the panel has to be rendered in\n // the same commit that targets the open transform, or @starting-style has\n // nothing to animate from.\n if (isOpen && !isRendered) {\n setIsRendered(true);\n }\n\n useDrawerDialogPresence({\n dialogRef,\n isOpen,\n isModal: hasScrim,\n setIsRendered,\n });\n\n // ui-common: the dialog a Modal inside renders into, set only once\n // showModal() has run (the effect above), so the Modal's popover enters the\n // top layer after the dialog and paints above it.\n const [modalHost, setModalHost] = useState<HTMLDialogElement | null>(null);\n useEffect(() => {\n setModalHost(isOpen && hasScrim ? dialogRef.current : null);\n }, [isOpen, hasScrim]);\n\n // LIFO registry membership: register on open, unregister on close or\n // unmount. The returned z-index stacks non-modal siblings in open order.\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const z = registerDrawer(drawerId, () => onOpenChangeRef.current(false));\n setStackZ(z);\n return () => unregisterDrawer(drawerId);\n }, [isOpen, drawerId]);\n\n // Lock body scroll while a modal drawer is open (iOS Safari workaround).\n useScrollLock(isOpen && hasScrim);\n\n // ui-common: Escape goes through core's shared layer-dismissal stack, as in\n // core's Dialog. The stack owns the one Escape listener and hands each press\n // to the top-most layer, so a popover or modal opened inside this drawer\n // closes first, and nested drawers peel off top-first.\n const { shouldDismissOnCloseRequest } = useLayerDismissal({\n isActive: isOpen,\n escapeBehavior: \"close\",\n onDismiss: () => onOpenChangeRef.current(false),\n });\n\n // Native cancel event (a close request the stack never saw a press for) —\n // prevent the browser from closing the dialog directly, then answer it by\n // the stack's rules: only the top-most layer, never mid-composition.\n const handleCancel = useCallback(\n (event: React.SyntheticEvent<HTMLDialogElement>) => {\n event.preventDefault();\n if (shouldDismissOnCloseRequest()) {\n onOpenChange(false);\n }\n },\n [onOpenChange, shouldDismissOnCloseRequest],\n );\n\n // Clicks on the ::backdrop target the <dialog> element itself; clicks on\n // drawer content always target a child (the content area fills the panel).\n const handleClick = useCallback(\n (event: React.MouseEvent<HTMLDialogElement>) => {\n if (event.target === event.currentTarget && hasScrim) {\n onOpenChange(false);\n }\n },\n [hasScrim, onOpenChange],\n );\n\n const widthValue = typeof width === \"number\" ? `${width}px` : width;\n const mobileWidth = isFullWidthOnMobile\n ? MOBILE_WIDTH_FULL\n : `min(${widthValue}, calc(100dvw - ${MOBILE_PAGE_REVEAL}px))`;\n\n // The side the panel is ANCHORED to, which is the side it must slide back\n // out to. Latched at open, because a consumer commonly derives `side` from\n // the same state that drives `isOpen` (`side={selected?.side ?? 'end'}`):\n // that state clears on close, so the live prop flips mid-exit and the panel\n // teleports to the other edge and slides out the wrong way. Children stay\n // mounted for the exit for the same reason; so does the anchor.\n const exitSideRef = useRef(side);\n if (isOpen) {\n exitSideRef.current = side;\n }\n const anchoredSide = isOpen ? side : exitSideRef.current;\n\n const sideStyle = anchoredSide === \"start\" ? styles.start : styles.end;\n const sideOpenStyle = anchoredSide === \"start\" ? styles.startOpen : styles.endOpen;\n\n // Filter out native `open` to prevent InvalidStateError when passed\n const { open: _open, ...safeProps } = props as Record<string, unknown>;\n\n return (\n <dialog\n ref={mergeRefs(ref, dialogRef)}\n {...mergeProps(\n themeProps(\"drawer\", { side: anchoredSide }),\n stylex.props(\n styles.dialog,\n overlayPaddingReset.reset,\n sideStyle,\n dynamicStyles.inlineSize(widthValue, mobileWidth),\n isRendered && styles.rendered,\n isOpen && sideOpenStyle,\n hasScrim ? styles.scrim : dynamicStyles.stackZ(stackZ),\n hasScrim && isOpen && styles.scrimOpen,\n xstyle,\n ),\n className,\n style,\n )}\n {...safeProps}\n aria-label={label}\n // ui-common: scrimless by itself is non-modal, but a consumer that\n // restores the modality by hand (a portal supplying its own mask and\n // focus trap) must be able to say so.\n aria-modal={\n (safeProps[\"aria-modal\"] as React.AriaAttributes[\"aria-modal\"]) ??\n (hasScrim ? \"true\" : undefined)\n }\n onClick={composeEventHandlers(onClickProp, handleClick)}\n onKeyDown={onKeyDownProp}\n onCancel={handleCancel}\n >\n {/* Scrollable content area — tabIndex so the dialog's focusing steps\n land on the panel body rather than the first button inside. */}\n <div tabIndex={-1} className={CONTENT_CLASS_NAME}>\n <LayerDepthProvider>\n <ModalPortalContext value={modalHost}>{children}</ModalPortalContext>\n </LayerDepthProvider>\n </div>\n {hasCloseButton && (\n <div className={CONTROLS_CLASS_NAME}>\n <IconButton\n icon={<Icon icon=\"close\" size=\"sm\" color=\"inherit\" />}\n label=\"Close\"\n variant=\"ghost\"\n onClick={() => onOpenChange(false)}\n />\n </div>\n )}\n </dialog>\n );\n}\n\nDrawer.displayName = \"Drawer\";\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"Drawer.js","names":[],"sources":["../../../src/forks/Drawer/Drawer.tsx"],"sourcesContent":["// Copyright (c) Meta Platforms, Inc. and affiliates.\n// Modifications copyright (c) Lablup Inc.\n//\n// Forked from @astryxdesign/lab 0.6.5-canary.8701623, src/Drawer/Drawer.tsx\n// (MIT; see NOTICE). Provenance and the drift guard: src/forks/provenance.json.\n\n\"use client\";\n\n/**\n * Drawer, ui-common's copy of Astryx lab's, with three changes (not upstream):\n *\n * - **A scrimless drawer stays out of the top layer.** lab 0.6.5 opens it as\n * a manual popover; this copy keeps the `show()` + z-index it had before\n * (base 1000, later drawers above), because ui-common's `Modal` and\n * notification stack are z-index surfaces: a top-layer drawer painted over\n * a confirm or a notification opened while it was up, and the modal stack\n * then inerted the drawer it could not cover.\n * - **`aria-modal` passes through.** A scrimless drawer is non-modal, but a\n * consumer that restores modality by hand (its own mask and focus trap) can\n * now say so; the default is unchanged.\n * - **ui-common's `Modal` opens above a scrimmed drawer.** That drawer is a\n * modal `<dialog>`, top layer and inerting everything outside it, so a\n * `Modal` portalled to the body sat behind it, unreachable. The drawer\n * provides its dialog through `ModalPortalContext` while it is open and\n * modal, and a `Modal` inside renders there and enters the top layer\n * after it (modalStack.ts).\n *\n * Escape routing is upstream's since lab 0.6.5: the drawer registers with\n * core's layer-dismissal stack, so a popover, selector or modal opened inside\n * it closes first and nested drawers close top-first. Everything else is\n * upstream's too. Its style namespaces are Astryx's compiled output\n * (src/forks/compiled.ts).\n *\n * Delete this fork, and its exports.exclude.json entry, once ui-common's\n * `Modal` and notification stack are top layer themselves and lab passes\n * `aria-modal` through (CONTRIBUTING, \"Forks of Astryx components\").\n */\n\n/*\n * Upstream's file notes, kept:\n *\n * Overlay panel for inspectors and detail views — the \"click a table row,\n * see its details\" pattern. Slides in from the inline start or end edge and\n * floats above the page content: unlike a docked panel it never reflows the\n * layout underneath, it overlays it (with or without a scrim).\n *\n * Inline axis only (start/end). Block-axis sheets are BottomSheet's job;\n * a drawer is always a full-height side panel.\n *\n * Sizing is viewport-aware: `width` is the desktop budget, and below\n * the mobile breakpoint it preserves a 56px reveal of the page behind, capped\n * by the requested width (or fills the viewport with `isFullWidthOnMobile`).\n *\n * Uses the native `<dialog>` element (same precedent as Dialog/MobileNav):\n * - `showModal()` when `hasScrim` (default) — top-layer rendering, focus\n * trapping, `::backdrop`, no z-index management.\n * - `showPopover()` when `hasScrim={false}` — non-modal top-layer overlay;\n * the page behind stays interactive (e.g. master-detail inspectors).\n * (ui-common: `show()` and a z-index instead; see the header above.)\n *\n * Entry animation uses `@starting-style`; exit slides out before the active\n * modal-dialog or manual-popover host releases the top layer and focus returns\n * to the element that opened the drawer. React owns `display` for both legs\n * rather than a discrete `display` transition, so the panel stops painting in\n * the same commit as the host closes — see the `rendered` style for why.\n *\n * Sibling drawers use the shared layer dismissal stack for topmost-only Escape\n * handling and the browser top layer's chronological paint order.\n *\n * Dismissal follows Dialog: `purpose` decides whether Escape and a scrim click\n * request close, and Drawer renders no close button of its own. Compose\n * `DrawerHeader` with `onOpenChange` for a visible close action, as with\n * `DialogHeader`.\n *\n */\n\nimport { useCallback, useEffect, useId, useRef, useState, type ReactNode } from \"react\";\nimport * as stylex from \"@stylexjs/stylex\";\nimport type { StyleXStyles } from \"@stylexjs/stylex\";\nimport type { BaseProps } from \"@astryxdesign/core\";\nimport type { DialogPurpose } from \"@astryxdesign/core/Dialog\";\nimport { useFocusTrap, useMergedRefs, useScrollLock } from \"@astryxdesign/core/hooks\";\nimport { LayerDepthProvider, useLayerDismissal } from \"@astryxdesign/core/Layer\";\nimport { composeEventHandlers, mergeProps, themeProps } from \"@astryxdesign/core/utils\";\nimport { overlayPaddingReset } from \"@astryxdesign/core/Layout\";\n\nimport { compiledStyles } from \"../compiled\";\nimport * as compiled from \"./Drawer.styles\";\nimport { ModalPortalContext, modalZIndexBase } from \"../../components/Modal/modalStack\";\nimport { useDrawerDialogPresence } from \"./useDrawerDialogPresence\";\n\n// =============================================================================\n// Styles\n// =============================================================================\n\n// Material's established mobile drawer pattern leaves a 56dp reveal. Using\n// the same value in CSS pixels gives the overlay a stable visual relationship\n// to the page behind while the requested width remains an upper bound.\nconst MOBILE_PAGE_REVEAL = 56;\nconst MOBILE_WIDTH_FULL = \"100dvw\";\n\n// @astryxdesign/lab dist/Drawer/Drawer.js `styles` and `dynamicStyles`.\nconst styles = compiledStyles(compiled.styles);\nconst dynamicStyles = compiled.dynamicStyles as {\n inlineSize: (desktopWidth: string, mobileWidth: string) => StyleXStyles;\n};\n\n// ui-common: stacking for scrimless drawers, which open with `show()` and so\n// need a z-index; modal drawers rely on the top layer's chronological order.\n// Module-level; only mutated inside effects (SSR-safe). 1000 is the app-level\n// drawer convention lab used before 0.6.5. A new drawer goes one above the\n// highest OPEN one, so the value is bounded by how many are open at once, and\n// it stays below the modal band so a Modal always paints over a drawer.\nconst NON_MODAL_BASE_Z = 1000;\nconst openNonModalDrawers = new Map<string, number>();\n\nfunction registerNonModalDrawer(id: string): number {\n const highest = Math.max(NON_MODAL_BASE_Z - 1, ...openNonModalDrawers.values());\n const z = Math.min(highest + 1, modalZIndexBase() - 1);\n openNonModalDrawers.set(id, z);\n return z;\n}\n\nfunction unregisterNonModalDrawer(id: string): void {\n openNonModalDrawers.delete(id);\n}\n\n// Upstream's `content` style, which its compiler folded into this class list\n// (dist/Drawer/Drawer.js).\nconst CONTENT_CLASS_NAME =\n \"x1iyjqo2 x2lwn1j xh8yej3 x1odjw0f x6ikm8r xish69e xx69xxh x1a148e8 x1a2a7pz\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport interface DrawerProps extends BaseProps<HTMLDialogElement> {\n /** Ref forwarded to the root <dialog> element */\n ref?: React.Ref<HTMLDialogElement>;\n\n /**\n * Whether the drawer is open. Fully controlled — pair with `onOpenChange`.\n */\n isOpen: boolean;\n\n /**\n * Called when the drawer requests an open-state change. Escape and a scrim\n * click call it with `false` as `purpose` allows; a `DrawerHeader` close\n * button calls it when you pass the same callback to the header. The caller\n * owns the open state. When sibling drawers are open, Escape only closes the\n * top (last-opened) drawer.\n */\n onOpenChange: (isOpen: boolean) => void;\n\n /**\n * Which edge the drawer slides from.\n * - `'end'` — inline-end edge (right in LTR) — the inspector convention\n * - `'start'` — inline-start edge (left in LTR)\n * @default 'end'\n */\n side?: \"start\" | \"end\";\n\n /**\n * Desktop width budget. A number is pixels; a string is any CSS length\n * (`'50%'`, `'32rem'`). Below the mobile breakpoint (640px), this\n * remains the maximum while the drawer preserves a 56px reveal of the page\n * behind — see `isFullWidthOnMobile`.\n * @default 400\n */\n width?: number | string;\n\n /**\n * Whether the drawer covers the full viewport width on mobile\n * (below 640px) instead of preserving the default 56px reveal of the page\n * behind. The reveal makes the drawer read as an overlay rather than a\n * navigation.\n * @default false\n */\n isFullWidthOnMobile?: boolean;\n\n /**\n * Accessible label for the drawer (required — the drawer has no\n * built-in heading to derive a name from).\n */\n label: string;\n\n /**\n * Whether to render a modal scrim behind the drawer.\n * - `true` (default) — `showModal()`: top layer, focus trap, body scroll\n * lock, click-outside-to-close.\n * - `false` — `showPopover()`: non-modal top-layer overlay; the page behind\n * stays interactive. Escape still closes through the shared layer stack.\n * @default true\n */\n hasScrim?: boolean;\n\n /**\n * Configures how the drawer enables dismissals, matching Dialog.\n * - required: Disables Escape and scrim click (for mandatory flows); a\n * modal required drawer is exposed as an `alertdialog`\n * - form: Prevents scrim click, allows the Escape key\n * - info: Allows Escape and scrim click\n *\n * A non-modal drawer has no scrim, so `form` and `info` behave the same.\n * @default 'info'\n */\n purpose?: DialogPurpose;\n\n /**\n * Drawer content. Rendered inside a full-height scrollable area.\n * Focus the element with `data-autofocus` on open, if present.\n */\n children: ReactNode;\n\n /**\n * Test ID for the root element.\n */\n \"data-testid\"?: string;\n}\n\n// =============================================================================\n// Component\n// =============================================================================\n\n/**\n * An overlay panel for inspectors and detail views.\n *\n * Slides in from the logical start or end edge and floats above the page\n * using the native `<dialog>` element: modal with a scrim by default, or a\n * non-modal overlay with `hasScrim={false}` that leaves the page behind\n * interactive. `width` is the desktop budget; below 640px the panel preserves\n * a 56px page reveal without exceeding that budget (or fills the viewport\n * with `isFullWidthOnMobile`). Escape\n * closes the top-most open drawer; focus returns to the element that\n * opened it.\n *\n * Dismissal matches Dialog: `purpose` decides whether Escape and a scrim click\n * close the drawer, and `DrawerHeader` renders a close button when given\n * `onOpenChange`.\n *\n * @example\n * ```\n * const [selected, setSelected] = useState(null);\n * const handleOpenChange = isOpen => !isOpen && setSelected(null);\n * <Drawer\n * isOpen={selected != null}\n * onOpenChange={handleOpenChange}\n * label={`Details: ${selected?.name}`}>\n * <DrawerHeader title={selected?.name} onOpenChange={handleOpenChange} />\n * <HostDetails host={selected} />\n * </Drawer>\n * ```\n */\nexport function Drawer({\n isOpen,\n onOpenChange,\n side = \"end\",\n width = 400,\n isFullWidthOnMobile = false,\n label,\n hasScrim = true,\n purpose = \"info\",\n children,\n xstyle,\n className,\n style,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n ref,\n ...props\n}: DrawerProps) {\n const dialogRef = useRef<HTMLDialogElement>(null);\n const { containerRef: focusTrapRef } = useFocusTrap<HTMLDialogElement>({\n isActive: isOpen && hasScrim,\n });\n const mergedDialogRef = useMergedRefs(ref, dialogRef, focusTrapRef);\n // Derive dismissal behavior from purpose, as Dialog does.\n const allowEscape = purpose !== \"required\";\n const allowScrimClick = purpose === \"info\";\n // Whether the panel paints: true while open and for the whole slide-out.\n const [isRendered, setIsRendered] = useState(isOpen);\n\n // Adjusted during render, not in an effect: the panel has to be rendered in\n // the same commit that targets the open transform, or @starting-style has\n // nothing to animate from.\n if (isOpen && !isRendered) {\n setIsRendered(true);\n }\n\n useDrawerDialogPresence({\n dialogRef,\n isOpen,\n isModal: hasScrim,\n setIsRendered,\n });\n\n // ui-common: the dialog a Modal inside renders into, set only once\n // showModal() has run (the effect above), so the Modal's popover enters the\n // top layer after the dialog and paints above it. A scrimless drawer is not\n // top layer (`show()`), so a body-portalled Modal already stacks above it.\n const [modalHost, setModalHost] = useState<HTMLDialogElement | null>(null);\n useEffect(() => {\n setModalHost(isOpen && hasScrim ? dialogRef.current : null);\n }, [isOpen, hasScrim]);\n\n // ui-common: a scrimless drawer's z-index, last opened on top.\n const drawerId = useId();\n const [stackZ, setStackZ] = useState(NON_MODAL_BASE_Z);\n // Held while the panel paints, slide-out included, so a drawer opened during\n // another's exit goes above it rather than taking the same value.\n useEffect(() => {\n if (!isRendered || hasScrim) return;\n setStackZ(registerNonModalDrawer(drawerId));\n return () => unregisterNonModalDrawer(drawerId);\n }, [isRendered, hasScrim, drawerId]);\n\n const handleDismiss = useCallback(() => {\n onOpenChange(false);\n }, [onOpenChange]);\n\n // The shared stack owns Escape delivery across every overlay family. The\n // provider below gives layers opened from Drawer content a greater logical\n // depth even when they render elsewhere in the DOM or browser top layer.\n const { shouldDismissOnCloseRequest } = useLayerDismissal({\n // The native host stays present through the slide-out. Keep this entry on\n // the stack until the same commit that hides the host, so a second Escape\n // cannot fall through to a lower layer during the exit animation.\n isActive: isRendered,\n // A `required` drawer consumes Escape without closing, so the press cannot\n // fall through and dismiss a layer behind it either.\n escapeBehavior: allowEscape ? \"close\" : \"block\",\n onDismiss: handleDismiss,\n getContainer: () => dialogRef.current,\n });\n\n // Lock body scroll while a modal drawer is open (iOS Safari workaround).\n useScrollLock(isOpen && hasScrim);\n\n // A modal dialog's native cancel event is a platform close request (for\n // example Android Back). Keep controlled state authoritative and apply the\n // same top-most/IME rules as the shared Escape listener.\n const handleCancel = useCallback(\n (event: React.SyntheticEvent<HTMLDialogElement>) => {\n event.preventDefault();\n if (shouldDismissOnCloseRequest() && allowEscape) {\n handleDismiss();\n }\n },\n [allowEscape, handleDismiss, shouldDismissOnCloseRequest],\n );\n\n // Clicks on the ::backdrop target the <dialog> element itself; clicks on\n // drawer content always target a child (the content area fills the panel).\n const handleClick = useCallback(\n (event: React.MouseEvent<HTMLDialogElement>) => {\n if (event.target === event.currentTarget && hasScrim && allowScrimClick) {\n onOpenChange(false);\n }\n },\n [allowScrimClick, hasScrim, onOpenChange],\n );\n\n const widthValue = typeof width === \"number\" ? `${width}px` : width;\n const mobileWidth = isFullWidthOnMobile\n ? MOBILE_WIDTH_FULL\n : `min(${widthValue}, calc(100dvw - ${MOBILE_PAGE_REVEAL}px))`;\n\n // The side the panel is ANCHORED to, which is the side it must slide back\n // out to. Latched at open, because a consumer commonly derives `side` from\n // the same state that drives `isOpen` (`side={selected?.side ?? 'end'}`):\n // that state clears on close, so the live prop flips mid-exit and the panel\n // teleports to the other edge and slides out the wrong way. Children stay\n // mounted for the exit for the same reason; so does the anchor.\n const exitSideRef = useRef(side);\n if (isOpen) {\n exitSideRef.current = side;\n }\n const anchoredSide = isOpen ? side : exitSideRef.current;\n\n const sideStyle = anchoredSide === \"start\" ? styles.start : styles.end;\n const sideOpenStyle = anchoredSide === \"start\" ? styles.startOpen : styles.endOpen;\n\n // Filter out native `open` to prevent InvalidStateError when passed\n const { open: _open, ...safeProps } = props as Record<string, unknown>;\n\n return (\n <dialog\n ref={mergedDialogRef}\n {...mergeProps(\n themeProps(\"drawer\", { side: anchoredSide }),\n stylex.props(\n styles.dialog,\n overlayPaddingReset.reset,\n sideStyle,\n dynamicStyles.inlineSize(widthValue, mobileWidth),\n isRendered && styles.rendered,\n isOpen && sideOpenStyle,\n hasScrim && styles.scrim,\n hasScrim && isOpen && styles.scrimOpen,\n xstyle,\n ),\n className,\n // ui-common: the consumer's style may still override the stack.\n hasScrim ? style : { zIndex: stackZ, ...style },\n )}\n {...safeProps}\n aria-label={label}\n // ui-common: scrimless by itself is non-modal, but a consumer that\n // restores the modality by hand (a portal supplying its own mask and\n // focus trap) must be able to say so.\n aria-modal={\n (safeProps[\"aria-modal\"] as React.AriaAttributes[\"aria-modal\"]) ??\n (hasScrim ? \"true\" : undefined)\n }\n {...(purpose === \"required\" && hasScrim ? { role: \"alertdialog\" } : undefined)}\n onClick={composeEventHandlers(onClickProp, handleClick)}\n onKeyDown={onKeyDownProp}\n onCancel={handleCancel}\n >\n <LayerDepthProvider>\n {/* Scrollable content area — tabIndex so the dialog's focusing steps\n land on the panel body rather than the first button inside. */}\n <div tabIndex={-1} className={CONTENT_CLASS_NAME}>\n <ModalPortalContext value={modalHost}>{children}</ModalPortalContext>\n </div>\n </LayerDepthProvider>\n </dialog>\n );\n}\n\nDrawer.displayName = \"Drawer\";\n"],"mappings":"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"}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
export declare const styles: {
|
|
2
2
|
dialog: {
|
|
3
|
+
kMv6JI: string;
|
|
4
|
+
kGuDYH: string;
|
|
5
|
+
k63SB2: string;
|
|
6
|
+
kLWn49: string;
|
|
7
|
+
kKX8nH: string;
|
|
8
|
+
k9WMMc: string;
|
|
9
|
+
kJI5tL: string;
|
|
10
|
+
kTHuQy: string;
|
|
11
|
+
kP9fke: string;
|
|
12
|
+
kb6lSQ: string;
|
|
13
|
+
k4JVr9: string;
|
|
14
|
+
kKMj4B: string;
|
|
15
|
+
khDVqt: string;
|
|
16
|
+
kTgw9: string;
|
|
17
|
+
kHjlTd: string;
|
|
18
|
+
kE4Cay: string;
|
|
3
19
|
kVAEAm: string;
|
|
4
20
|
kogj98: string;
|
|
5
21
|
kmVPX3: string;
|
|
@@ -87,13 +103,4 @@ export declare const dynamicStyles: {
|
|
|
87
103
|
kzqmXN?: undefined;
|
|
88
104
|
$$css?: undefined;
|
|
89
105
|
})[];
|
|
90
|
-
stackZ: (z: any) => ({
|
|
91
|
-
kY2c9j: any;
|
|
92
|
-
$$css: boolean;
|
|
93
|
-
"--x-zIndex"?: undefined;
|
|
94
|
-
} | {
|
|
95
|
-
"--x-zIndex": any;
|
|
96
|
-
kY2c9j?: undefined;
|
|
97
|
-
$$css?: undefined;
|
|
98
|
-
})[];
|
|
99
106
|
};
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
//#region src/forks/Drawer/Drawer.styles.ts
|
|
2
2
|
var e = {
|
|
3
3
|
dialog: {
|
|
4
|
+
kMv6JI: "x9ynric",
|
|
5
|
+
kGuDYH: "xjm74w1",
|
|
6
|
+
k63SB2: "xxovm9e",
|
|
7
|
+
kLWn49: "xw6l6zx",
|
|
8
|
+
kKX8nH: "x1j61x8r",
|
|
9
|
+
k9WMMc: "x1yc453h",
|
|
10
|
+
kJI5tL: "x7ssn7h",
|
|
11
|
+
kTHuQy: "xzugeeo",
|
|
12
|
+
kP9fke: "x6mezaz",
|
|
13
|
+
kb6lSQ: "x1i21sxh",
|
|
14
|
+
k4JVr9: "xp3md9m",
|
|
15
|
+
kKMj4B: "x19pm5ym",
|
|
16
|
+
khDVqt: "xeaf4i8",
|
|
17
|
+
kTgw9: "x1lldw8n",
|
|
18
|
+
kHjlTd: "x1h4wwuj",
|
|
19
|
+
kE4Cay: "xxydokm",
|
|
4
20
|
kVAEAm: "xixxii4",
|
|
5
21
|
kogj98: "x1ghz6dp",
|
|
6
22
|
kmVPX3: "x1717udv",
|
|
@@ -71,23 +87,17 @@ var e = {
|
|
|
71
87
|
}, t = {
|
|
72
88
|
ks0D6T: "xlbgzzq",
|
|
73
89
|
$$css: !0
|
|
74
|
-
}, n = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
kzqmXN: (e == null ? e : "x11ymkkh ") + (n == null ? n : "xci7e5a"),
|
|
79
|
-
$$css: !0
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"--x-1xmrurk": ((e) => typeof e == "number" ? e + "px" : e ?? void 0)(e),
|
|
83
|
-
"--x-fqzwsx": ((e) => typeof e == "number" ? e + "px" : e ?? void 0)(n)
|
|
84
|
-
}
|
|
85
|
-
],
|
|
86
|
-
stackZ: (e) => [{
|
|
87
|
-
kY2c9j: e == null ? e : "xr3buco",
|
|
90
|
+
}, n = { inlineSize: (e, n) => [
|
|
91
|
+
t,
|
|
92
|
+
{
|
|
93
|
+
kzqmXN: (e == null ? e : "x11ymkkh ") + (n == null ? n : "xci7e5a"),
|
|
88
94
|
$$css: !0
|
|
89
|
-
},
|
|
90
|
-
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"--x-1xmrurk": ((e) => typeof e == "number" ? e + "px" : e ?? void 0)(e),
|
|
98
|
+
"--x-fqzwsx": ((e) => typeof e == "number" ? e + "px" : e ?? void 0)(n)
|
|
99
|
+
}
|
|
100
|
+
] };
|
|
91
101
|
//#endregion
|
|
92
102
|
export { t as _temp, n as dynamicStyles, e as styles };
|
|
93
103
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.styles.js","names":[],"sources":["../../../src/forks/Drawer/Drawer.styles.ts"],"sourcesContent":["/* eslint-disable */\n// @ts-nocheck\n// @generated by scripts/sync-forks.mjs. Do not edit.\n//\n// Compiled StyleX from @astryxdesign/lab 0.6.
|
|
1
|
+
{"version":3,"file":"Drawer.styles.js","names":[],"sources":["../../../src/forks/Drawer/Drawer.styles.ts"],"sourcesContent":["/* eslint-disable */\n// @ts-nocheck\n// @generated by scripts/sync-forks.mjs. Do not edit.\n//\n// Compiled StyleX from @astryxdesign/lab 0.6.5-canary.8701623, reused by the\n// Drawer fork so it renders with upstream's own class names\n// (src/forks/compiled.ts). Copyright (c) Meta Platforms, Inc. and\n// affiliates; MIT, see NOTICE.\n\n// dist/Drawer/Drawer.js\nexport const styles = {\n dialog: {\n kMv6JI: \"x9ynric\",\n kGuDYH: \"xjm74w1\",\n k63SB2: \"xxovm9e\",\n kLWn49: \"xw6l6zx\",\n kKX8nH: \"x1j61x8r\",\n k9WMMc: \"x1yc453h\",\n kJI5tL: \"x7ssn7h\",\n kTHuQy: \"xzugeeo\",\n kP9fke: \"x6mezaz\",\n kb6lSQ: \"x1i21sxh\",\n k4JVr9: \"xp3md9m\",\n kKMj4B: \"x19pm5ym\",\n khDVqt: \"xeaf4i8\",\n kTgw9: \"x1lldw8n\",\n kHjlTd: \"x1h4wwuj\",\n kE4Cay: \"xxydokm\",\n kVAEAm: \"xixxii4\",\n kogj98: \"x1ghz6dp\",\n kmVPX3: \"x1717udv\",\n kaIpWk: \"x2u8bby\",\n ks0D6T: \"x1x1rfll\",\n kskxy: \"x7ab17h\",\n kB7OPa: \"x9f619\",\n kXwgrk: \"xdt5ytf\",\n kWkggS: \"x10xzikg\",\n kGVxlE: \"x1kcpxr7\",\n kVQacm: \"xb3r6kr\",\n kZeWKH: \"xish69e\",\n kI3sdo: \"x1a2a7pz\",\n k87sOh: \"x13vifvy\",\n krVfgx: \"x1ey2m1c\",\n kZKoxP: \"xtdtrs8\",\n k1xSpc: \"x1s85apg\",\n k1ekBW: \"x11xpdln\",\n kIyJzY: \"x80gvsz\",\n kAMwcw: \"xlr8y92\",\n k6CgDc: \"xzg1mie\",\n $$css: true,\n },\n rendered: {\n k1xSpc: \"x78zum5\",\n $$css: true,\n },\n end: {\n kt4wiu: \"xtijo5x\",\n kLqNvP: \"xhi6v0a\",\n k2ei4v: \"xgbv0en\",\n kVhnKS: \"x1t7ytsu\",\n kGJrpR: \"x1j92z86\",\n k3aq6I: \"xumwmo6 x1df3fe5\",\n $$css: true,\n },\n endOpen: {\n k3aq6I: \"xbryuvx x1yqmsfc x1lymnkk\",\n $$css: true,\n },\n start: {\n kLqNvP: \"x1o0tod\",\n kt4wiu: \"x1woyocn\",\n ke9TFa: \"xw8tdv1\",\n k8ry5P: \"x18b5jzi\",\n kBCPoo: \"x1gejf6u\",\n k3aq6I: \"x5i6ehr xttggg\",\n $$css: true,\n },\n startOpen: {\n k3aq6I: \"xbryuvx x6mt36l x14gflnl\",\n $$css: true,\n },\n scrim: {\n kGyWv1: \"xnixb3f\",\n kba3nw: \"x1abwkk1\",\n k5sjJv: \"xph5o2a\",\n kND0Po: \"x167zut7\",\n k9an0g: \"xft5bk6\",\n kb4ib: \"x15h3t91\",\n kA5Tbj: \"x1viac0w\",\n $$css: true,\n },\n scrimOpen: {\n k5sjJv: \"xb3n6bw xxiuuzi\",\n $$css: true,\n },\n};\nexport const _temp = {\n ks0D6T: \"xlbgzzq\",\n $$css: true,\n};\nexport const dynamicStyles = {\n inlineSize: (desktopWidth, mobileWidth) => [\n _temp,\n {\n kzqmXN:\n (desktopWidth != null ? \"x11ymkkh \" : desktopWidth) +\n (mobileWidth != null ? \"xci7e5a\" : mobileWidth),\n $$css: true,\n },\n {\n \"--x-1xmrurk\": ((val) =>\n typeof val === \"number\" ? val + \"px\" : val != null ? val : undefined)(\n desktopWidth,\n ),\n \"--x-fqzwsx\": ((val) =>\n typeof val === \"number\" ? val + \"px\" : val != null ? val : undefined)(\n mobileWidth,\n ),\n },\n ],\n};\n"],"mappings":";AAUA,IAAa,IAAS;CACpB,QAAQ;EACN,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,UAAU;EACR,QAAQ;EACR,OAAO;CACT;CACA,KAAK;EACH,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,SAAS;EACP,QAAQ;EACR,OAAO;CACT;CACA,OAAO;EACL,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,WAAW;EACT,QAAQ;EACR,OAAO;CACT;CACA,OAAO;EACL,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,OAAO;CACT;CACA,WAAW;EACT,QAAQ;EACR,OAAO;CACT;AACF,GACa,IAAQ;CACnB,QAAQ;CACR,OAAO;AACT,GACa,IAAgB,EAC3B,aAAa,GAAc,MAAgB;CACzC;CACA;EACE,SACG,KAAgB,OAAqB,IAAd,gBACvB,KAAe,OAAmB,IAAZ;EACzB,OAAO;CACT;CACA;EACE,iBAAiB,MACf,OAAO,KAAQ,WAAW,IAAM,OAAO,KAAoB,KAAA,EAAA,CAC3D,CACF;EACA,gBAAgB,MACd,OAAO,KAAQ,WAAW,IAAM,OAAO,KAAoB,KAAA,EAAA,CAC3D,CACF;CACF;AACF,EACF"}
|
|
@@ -8,12 +8,13 @@ type UseDrawerDialogPresenceOptions = {
|
|
|
8
8
|
/**
|
|
9
9
|
* Coordinates the native dialog and React-rendered presence for Drawer.
|
|
10
10
|
*
|
|
11
|
-
* Opening captures the trigger, opens the
|
|
12
|
-
* component's `data-autofocus` contract. Closing waits for the
|
|
13
|
-
* transform transition (with a computed-duration backstop), then
|
|
14
|
-
* native
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* Opening captures the trigger, opens the dialog (`showModal()` or `show()`),
|
|
12
|
+
* and honours the component's `data-autofocus` contract. Closing waits for the
|
|
13
|
+
* actual transform transition (with a computed-duration backstop), then calls
|
|
14
|
+
* `close()` (which fires the native `close` event) and synchronously hides the
|
|
15
|
+
* panel before the browser can paint it outside the top layer, then restores
|
|
16
|
+
* focus to the captured trigger. Unmount cleanup closes a dialog left open by
|
|
17
|
+
* React Activity or a removed subtree.
|
|
17
18
|
*/
|
|
18
19
|
export declare function useDrawerDialogPresence({ dialogRef, isOpen, isModal, setIsRendered, }: UseDrawerDialogPresenceOptions): void;
|
|
19
20
|
export {};
|
|
@@ -3,60 +3,69 @@ import { useEffect as e, useRef as t } from "react";
|
|
|
3
3
|
import { flushSync as n } from "react-dom";
|
|
4
4
|
//#region src/forks/Drawer/useDrawerDialogPresence.ts
|
|
5
5
|
var r = 50, i = 250;
|
|
6
|
-
function a(
|
|
7
|
-
|
|
6
|
+
function a(e) {
|
|
7
|
+
return e.open;
|
|
8
|
+
}
|
|
9
|
+
function o(e, t) {
|
|
10
|
+
t ? e.showModal() : e.show();
|
|
11
|
+
}
|
|
12
|
+
function s(e) {
|
|
13
|
+
e.open && e.close();
|
|
14
|
+
}
|
|
15
|
+
function c({ dialogRef: r, isOpen: i, isModal: c, setIsRendered: u }) {
|
|
16
|
+
let d = t(null);
|
|
8
17
|
e(() => {
|
|
9
18
|
let e = r.current;
|
|
10
19
|
if (e) {
|
|
11
20
|
if (i) {
|
|
12
|
-
e
|
|
21
|
+
a(e) || (d.current = document.activeElement, o(e, c), e.querySelector("[data-autofocus]")?.focus());
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
15
|
-
if (e
|
|
16
|
-
e
|
|
17
|
-
|
|
18
|
-
}),
|
|
24
|
+
if (a(e)) return l(e, () => {
|
|
25
|
+
s(e), n(() => {
|
|
26
|
+
u(!1);
|
|
27
|
+
}), d.current?.focus(), d.current = null;
|
|
19
28
|
});
|
|
20
29
|
}
|
|
21
30
|
}, [
|
|
22
31
|
r,
|
|
23
|
-
|
|
32
|
+
c,
|
|
24
33
|
i,
|
|
25
|
-
|
|
34
|
+
u
|
|
26
35
|
]), e(() => {
|
|
27
36
|
let e = r.current;
|
|
28
37
|
return () => {
|
|
29
|
-
e
|
|
38
|
+
e && a(e) && s(e);
|
|
30
39
|
};
|
|
31
40
|
}, [r]);
|
|
32
41
|
}
|
|
33
|
-
function
|
|
42
|
+
function l(e, t) {
|
|
34
43
|
let n = !1, a = null, o = () => {
|
|
35
|
-
n || (n = !0, a != null && clearTimeout(a), e.removeEventListener("transitionend",
|
|
36
|
-
},
|
|
44
|
+
n || (n = !0, a != null && clearTimeout(a), e.removeEventListener("transitionend", s), e.removeEventListener("transitioncancel", s), t());
|
|
45
|
+
}, s = (t) => {
|
|
37
46
|
t.target === e && t.propertyName === "transform" && o();
|
|
38
47
|
};
|
|
39
|
-
e.addEventListener("transitionend",
|
|
40
|
-
let
|
|
41
|
-
return a = setTimeout(o, (
|
|
42
|
-
n = !0, a != null && clearTimeout(a), e.removeEventListener("transitionend",
|
|
48
|
+
e.addEventListener("transitionend", s), e.addEventListener("transitioncancel", s);
|
|
49
|
+
let c = u(e);
|
|
50
|
+
return a = setTimeout(o, (c ?? i) + r), () => {
|
|
51
|
+
n = !0, a != null && clearTimeout(a), e.removeEventListener("transitionend", s), e.removeEventListener("transitioncancel", s);
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
|
-
function
|
|
46
|
-
let t = window.getComputedStyle(e), n = t.transitionProperty.split(",").map((e) => e.trim()), r =
|
|
54
|
+
function u(e) {
|
|
55
|
+
let t = window.getComputedStyle(e), n = t.transitionProperty.split(",").map((e) => e.trim()), r = d(t.transitionDuration), i = d(t.transitionDelay);
|
|
47
56
|
return n.length === 0 || r.length === 0 || i.length === 0 || r.includes(null) || i.includes(null) ? null : n.reduce((e, t, n) => {
|
|
48
57
|
if (t !== "transform" && t !== "all") return e;
|
|
49
58
|
let a = r[n % r.length], o = i[n % i.length];
|
|
50
59
|
return Math.max(e, (a ?? 0) + (o ?? 0));
|
|
51
60
|
}, 0);
|
|
52
61
|
}
|
|
53
|
-
function
|
|
62
|
+
function d(e) {
|
|
54
63
|
return e.split(",").map((e) => {
|
|
55
64
|
let t = e.trim(), n = Number.parseFloat(t);
|
|
56
65
|
return Number.isFinite(n) ? t.endsWith("ms") ? n : t.endsWith("s") ? n * 1e3 : null : null;
|
|
57
66
|
});
|
|
58
67
|
}
|
|
59
68
|
//#endregion
|
|
60
|
-
export {
|
|
69
|
+
export { c as useDrawerDialogPresence };
|
|
61
70
|
|
|
62
71
|
//# sourceMappingURL=useDrawerDialogPresence.js.map
|