@wisdomgarden/torque 0.2.4 → 0.3.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/dist/components/button/button.types.d.ts +1 -1
- package/dist/components/button/styles/button-variables.module.css.js +1 -1
- package/dist/components/modal/index.d.ts +12 -1
- package/dist/components/modal/index.js +22 -2
- package/dist/components/modal/modal-context.d.ts +22 -0
- package/dist/components/modal/modal-context.js +15 -0
- package/dist/components/modal/modal-events.d.ts +24 -0
- package/dist/components/modal/modal-events.js +24 -0
- package/dist/components/modal/modal-manager.d.ts +11 -0
- package/dist/components/modal/modal-manager.js +139 -0
- package/dist/components/modal/modal-root.d.ts +13 -0
- package/dist/components/modal/modal-root.js +159 -0
- package/dist/components/modal/modal.d.ts +33 -7
- package/dist/components/modal/modal.js +38 -193
- package/dist/components/modal/modal.module.css.js +18 -16
- package/dist/components/modal/modal.types.d.ts +59 -3
- package/dist/components/modal/subs/modal-body.d.ts +6 -0
- package/dist/components/modal/subs/modal-body.js +24 -0
- package/dist/components/modal/subs/modal-close-button.d.ts +7 -0
- package/dist/components/modal/subs/modal-close-button.js +38 -0
- package/dist/components/modal/subs/modal-content.d.ts +9 -0
- package/dist/components/modal/subs/modal-content.js +60 -0
- package/dist/components/modal/subs/modal-header.d.ts +6 -0
- package/dist/components/modal/subs/modal-header.js +24 -0
- package/dist/components/modal/subs/modal-overlay.d.ts +6 -0
- package/dist/components/modal/subs/modal-overlay.js +25 -0
- package/dist/components/modal/subs/modal-title.d.ts +8 -0
- package/dist/components/modal/subs/modal-title.js +28 -0
- package/dist/index.css +1 -1
- package/dist/index.js +204 -184
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IconName } from '@wisdomgarden/torque-icons';
|
|
2
2
|
import React, { ButtonHTMLAttributes } from 'react';
|
|
3
3
|
import { ButtonSize, RefProps } from '../../common/components.types';
|
|
4
|
-
export type ButtonColor = 'brand' | 'regular' | 'air' | 'secondary' | 'dangerous';
|
|
4
|
+
export type ButtonColor = 'brand' | 'regular' | 'air' | 'secondary' | 'orange' | 'dangerous';
|
|
5
5
|
/**
|
|
6
6
|
* 按钮组件的属性定义
|
|
7
7
|
*/
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export { Modal } from './modal';
|
|
2
|
-
export
|
|
2
|
+
export { ModalRoot } from './modal-root';
|
|
3
|
+
export { ModalOverlay } from './subs/modal-overlay';
|
|
4
|
+
export { ModalContent } from './subs/modal-content';
|
|
5
|
+
export { ModalHeader } from './subs/modal-header';
|
|
6
|
+
export { ModalTitle } from './subs/modal-title';
|
|
7
|
+
export { ModalBody } from './subs/modal-body';
|
|
8
|
+
export { ModalCloseButton } from './subs/modal-close-button';
|
|
9
|
+
export { useModalContext } from './modal-context';
|
|
10
|
+
export type { ModalContextValue } from './modal-context';
|
|
11
|
+
export { modals } from './modal-events';
|
|
12
|
+
export { ModalManager } from './modal-manager';
|
|
13
|
+
export type { ConfirmModalEventProps, ModalClassNames, ModalCloseButtonProps, ModalConfirmButtonProps, ModalConfirmLabels, ModalEventPayload, ModalEventProps, ModalOverlayProps, ModalProps, ModalRootProps, ModalSizePreset, ModalSpacingPreset, ModalStyles, ModalStylesName, } from './modal.types';
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Modal as
|
|
2
|
+
import { Modal as e } from "./modal.js";
|
|
3
|
+
import { ModalRoot as a } from "./modal-root.js";
|
|
4
|
+
import { ModalOverlay as d } from "./subs/modal-overlay.js";
|
|
5
|
+
import { ModalContent as x } from "./subs/modal-content.js";
|
|
6
|
+
import { ModalHeader as p } from "./subs/modal-header.js";
|
|
7
|
+
import { ModalTitle as n } from "./subs/modal-title.js";
|
|
8
|
+
import { ModalBody as u } from "./subs/modal-body.js";
|
|
9
|
+
import { ModalCloseButton as i } from "./subs/modal-close-button.js";
|
|
10
|
+
import { useModalContext as B } from "./modal-context.js";
|
|
11
|
+
import { modals as g } from "./modal-events.js";
|
|
12
|
+
import { ModalManager as H } from "./modal-manager.js";
|
|
3
13
|
export {
|
|
4
|
-
|
|
14
|
+
e as Modal,
|
|
15
|
+
u as ModalBody,
|
|
16
|
+
i as ModalCloseButton,
|
|
17
|
+
x as ModalContent,
|
|
18
|
+
p as ModalHeader,
|
|
19
|
+
H as ModalManager,
|
|
20
|
+
d as ModalOverlay,
|
|
21
|
+
a as ModalRoot,
|
|
22
|
+
n as ModalTitle,
|
|
23
|
+
g as modals,
|
|
24
|
+
B as useModalContext
|
|
5
25
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ModalClassNames, ModalStyles } from './modal.types';
|
|
3
|
+
export interface ModalContextValue {
|
|
4
|
+
opened: boolean;
|
|
5
|
+
close: () => void;
|
|
6
|
+
animState: 'open' | 'closing';
|
|
7
|
+
/** 面板节点:层级模块贴 ref、焦点查询都靠它,由 `Modal.Content` 挂上 */
|
|
8
|
+
contentRef: React.RefObject<HTMLDivElement | null>;
|
|
9
|
+
layerRef: React.Ref<HTMLDivElement>;
|
|
10
|
+
titleId: string;
|
|
11
|
+
/** `Modal.Title` 挂载后回填,Content 据此决定 aria-labelledby */
|
|
12
|
+
titleMounted: boolean;
|
|
13
|
+
setTitleMounted: (mounted: boolean) => void;
|
|
14
|
+
classNames?: ModalClassNames;
|
|
15
|
+
styles?: ModalStyles;
|
|
16
|
+
onContentTransitionEnd: (event: React.TransitionEvent<HTMLDivElement>) => void;
|
|
17
|
+
}
|
|
18
|
+
declare const ModalContext: React.Context<ModalContextValue | null>;
|
|
19
|
+
export declare const useModalContext: () => ModalContextValue;
|
|
20
|
+
/** 槽位内联样式:context 里的 `styles[槽位]` 打底,子组件自己的 `style` 覆盖 */
|
|
21
|
+
export declare const slotStyle: (fromContext?: React.CSSProperties, own?: React.CSSProperties) => React.CSSProperties | undefined;
|
|
22
|
+
export { ModalContext };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useContext as e, createContext as n } from "react";
|
|
3
|
+
const r = n(null), s = () => {
|
|
4
|
+
const t = e(r);
|
|
5
|
+
if (!t)
|
|
6
|
+
throw new Error(
|
|
7
|
+
"[@wisdomgarden/torque] <Modal.Overlay /> 等子组件必须写在 <Modal.Root> 里面"
|
|
8
|
+
);
|
|
9
|
+
return t;
|
|
10
|
+
}, a = (t, o) => t || o ? { ...t, ...o } : void 0;
|
|
11
|
+
export {
|
|
12
|
+
r as ModalContext,
|
|
13
|
+
a as slotStyle,
|
|
14
|
+
s as useModalContext
|
|
15
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ConfirmModalEventProps, ModalEventPayload, ModalEventProps } from './modal.types';
|
|
2
|
+
type ModalEventHandlers = {
|
|
3
|
+
open: (payload: ModalEventPayload) => void;
|
|
4
|
+
close: (id?: string) => void;
|
|
5
|
+
closeAll: () => void;
|
|
6
|
+
};
|
|
7
|
+
declare const useModalEvents: (events: ModalEventHandlers) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 对话框操作的指令。需要 `<ModalManager />` 挂在应用根部。
|
|
10
|
+
*
|
|
11
|
+
* 与 `drawers` 的两点差别:`open` 返回 id,`close` 按 id 关(不传 id 才关最上层)——
|
|
12
|
+
* 因为命令式打开的对话框常常要在自己的内容里关掉自己。
|
|
13
|
+
*/
|
|
14
|
+
export declare const modals: {
|
|
15
|
+
/** 打开一个对话框,返回它的 id */
|
|
16
|
+
open: (props: ModalEventProps) => string;
|
|
17
|
+
/** 打开一个带确认 / 取消页脚的对话框,返回它的 id */
|
|
18
|
+
openConfirmModal: (props: ConfirmModalEventProps) => string;
|
|
19
|
+
/** 关闭指定 id 的对话框;不传 id 关最上层 */
|
|
20
|
+
close: (id?: string) => void;
|
|
21
|
+
/** 关闭全部对话框 */
|
|
22
|
+
closeAll: () => void;
|
|
23
|
+
};
|
|
24
|
+
export { useModalEvents };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createUseExternalEvents as l } from "@mantine/core";
|
|
3
|
+
const [r, n] = l("modal-manager");
|
|
4
|
+
let s = 0;
|
|
5
|
+
const t = () => `torque-modal-${s += 1}`, a = {
|
|
6
|
+
/** 打开一个对话框,返回它的 id */
|
|
7
|
+
open: (e) => {
|
|
8
|
+
const o = t();
|
|
9
|
+
return n("open")({ id: o, kind: "content", props: e }), o;
|
|
10
|
+
},
|
|
11
|
+
/** 打开一个带确认 / 取消页脚的对话框,返回它的 id */
|
|
12
|
+
openConfirmModal: (e) => {
|
|
13
|
+
const o = t();
|
|
14
|
+
return n("open")({ id: o, kind: "confirm", props: e }), o;
|
|
15
|
+
},
|
|
16
|
+
/** 关闭指定 id 的对话框;不传 id 关最上层 */
|
|
17
|
+
close: (e) => n("close")(e),
|
|
18
|
+
/** 关闭全部对话框 */
|
|
19
|
+
closeAll: () => n("closeAll")()
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
a as modals,
|
|
23
|
+
r as useModalEvents
|
|
24
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 用于指令式打开对话框的全局组件,挂在应用根部(与 `DrawerManager` 并列)。
|
|
4
|
+
*
|
|
5
|
+
* 与 Mantine 的 `ModalsProvider` 不同:这里每个实例各自渲染一个 `Modal`,
|
|
6
|
+
* 多个对话框是真正叠起来的——层级由 `overlay-layer` 按打开顺序算,Escape 只关最上层。
|
|
7
|
+
*/
|
|
8
|
+
export declare const ModalManager: {
|
|
9
|
+
(): React.JSX.Element;
|
|
10
|
+
displayName: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as d, Fragment as v, jsxs as E } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as m, useState as M, useCallback as p, Suspense as I, useEffect as F, useImperativeHandle as S } from "react";
|
|
4
|
+
import { flushSync as C } from "react-dom";
|
|
5
|
+
import "../../provider/ui-context.js";
|
|
6
|
+
import { useLocale as j } from "../../provider/hooks.js";
|
|
7
|
+
import { Button as g } from "../button/button.js";
|
|
8
|
+
import { Modal as k } from "./modal.js";
|
|
9
|
+
import { useModalEvents as y } from "./modal-events.js";
|
|
10
|
+
import N from "./modal.module.css.js";
|
|
11
|
+
const T = ({
|
|
12
|
+
labels: n,
|
|
13
|
+
confirmProps: t,
|
|
14
|
+
cancelProps: a,
|
|
15
|
+
onConfirm: s,
|
|
16
|
+
onCancel: c
|
|
17
|
+
}) => {
|
|
18
|
+
const l = j(), { color: o, ...r } = a ?? {}, { color: e, ...u } = t ?? {};
|
|
19
|
+
return /* @__PURE__ */ E("div", { className: N.confirmFooter, children: [
|
|
20
|
+
n?.cancel !== "" && /* @__PURE__ */ d(
|
|
21
|
+
g,
|
|
22
|
+
{
|
|
23
|
+
variant: "stroke",
|
|
24
|
+
color: o === "red" ? "dangerous" : o ?? "regular",
|
|
25
|
+
...r,
|
|
26
|
+
onClick: (i) => {
|
|
27
|
+
a?.onClick?.(i), c();
|
|
28
|
+
},
|
|
29
|
+
children: a?.children ?? n?.cancel ?? l.cancel
|
|
30
|
+
}
|
|
31
|
+
),
|
|
32
|
+
/* @__PURE__ */ d(
|
|
33
|
+
g,
|
|
34
|
+
{
|
|
35
|
+
color: e === "red" ? "dangerous" : e,
|
|
36
|
+
...u,
|
|
37
|
+
onClick: (i) => {
|
|
38
|
+
t?.onClick?.(i), s();
|
|
39
|
+
},
|
|
40
|
+
children: t?.children ?? n?.confirm ?? l.confirm
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
] });
|
|
44
|
+
}, b = ({
|
|
45
|
+
item: n,
|
|
46
|
+
removeInstance: t,
|
|
47
|
+
ref: a
|
|
48
|
+
}) => {
|
|
49
|
+
const [s, c] = M(!1), l = m(!1);
|
|
50
|
+
F(() => {
|
|
51
|
+
l.current || c(!0);
|
|
52
|
+
}, []);
|
|
53
|
+
const o = p(() => {
|
|
54
|
+
l.current || (l.current = !0, c(!1), n.props.onClose?.());
|
|
55
|
+
}, [n]);
|
|
56
|
+
S(a, () => ({ close: o }), [o]);
|
|
57
|
+
const r = p(() => {
|
|
58
|
+
n.props.onExitTransitionEnd?.(), t(n.id);
|
|
59
|
+
}, [n, t]), e = {
|
|
60
|
+
opened: s,
|
|
61
|
+
onClose: o,
|
|
62
|
+
onExitTransitionEnd: r
|
|
63
|
+
};
|
|
64
|
+
if (n.kind === "confirm") {
|
|
65
|
+
const {
|
|
66
|
+
labels: u,
|
|
67
|
+
confirmProps: i,
|
|
68
|
+
cancelProps: f,
|
|
69
|
+
onConfirm: R,
|
|
70
|
+
onCancel: x,
|
|
71
|
+
...h
|
|
72
|
+
} = n.props;
|
|
73
|
+
return /* @__PURE__ */ E(k, { ...h, ...e, children: [
|
|
74
|
+
h.children,
|
|
75
|
+
/* @__PURE__ */ d(
|
|
76
|
+
T,
|
|
77
|
+
{
|
|
78
|
+
labels: u,
|
|
79
|
+
confirmProps: i,
|
|
80
|
+
cancelProps: f,
|
|
81
|
+
onConfirm: () => {
|
|
82
|
+
C(o), R?.();
|
|
83
|
+
},
|
|
84
|
+
onCancel: () => {
|
|
85
|
+
C(o), x?.();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
] });
|
|
90
|
+
}
|
|
91
|
+
return /* @__PURE__ */ d(k, { ...n.props, ...e });
|
|
92
|
+
}, w = () => {
|
|
93
|
+
const n = m([]), [t, a] = M([]), s = m(/* @__PURE__ */ new Map()), c = p((r) => {
|
|
94
|
+
n.current = r, a(r);
|
|
95
|
+
}, []), l = p(
|
|
96
|
+
(r) => {
|
|
97
|
+
s.current.delete(r), c(n.current.filter((e) => e.id !== r));
|
|
98
|
+
},
|
|
99
|
+
[c]
|
|
100
|
+
), o = p(
|
|
101
|
+
(r) => {
|
|
102
|
+
const e = r ?? n.current[n.current.length - 1]?.id;
|
|
103
|
+
if (!e) return;
|
|
104
|
+
const u = s.current.get(e);
|
|
105
|
+
if (u) {
|
|
106
|
+
u.close();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const i = n.current.find((f) => f.id === e);
|
|
110
|
+
i && (c(n.current.filter((f) => f.id !== e)), i.props.onClose?.());
|
|
111
|
+
},
|
|
112
|
+
[c]
|
|
113
|
+
);
|
|
114
|
+
return y({
|
|
115
|
+
open: (r) => c([...n.current, r]),
|
|
116
|
+
close: o,
|
|
117
|
+
closeAll: () => {
|
|
118
|
+
[...n.current].forEach((r) => o(r.id));
|
|
119
|
+
}
|
|
120
|
+
}), /* @__PURE__ */ d(v, { children: t.map((r) => (
|
|
121
|
+
// 弹窗内容由调用方传入,用到的 i18n ns 无法枚举,也就无法预热。本组件挂在 root
|
|
122
|
+
// layout 且是 children 的兄弟节点,没有边界时未加载的 ns 会在 render 期挂起并冒泡
|
|
123
|
+
// 到路由段骨架,整页变 loading。每个实例各自成边界,互不影响。
|
|
124
|
+
/* @__PURE__ */ d(I, { fallback: null, children: /* @__PURE__ */ d(
|
|
125
|
+
b,
|
|
126
|
+
{
|
|
127
|
+
item: r,
|
|
128
|
+
removeInstance: l,
|
|
129
|
+
ref: (e) => {
|
|
130
|
+
e ? s.current.set(r.id, e) : s.current.delete(r.id);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
) }, r.id)
|
|
134
|
+
)) });
|
|
135
|
+
};
|
|
136
|
+
w.displayName = "ModalManager";
|
|
137
|
+
export {
|
|
138
|
+
w as ModalManager
|
|
139
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ModalRootProps } from './modal.types';
|
|
3
|
+
/**
|
|
4
|
+
* 对话框的机制层:层级、Escape、点遮罩、滚动锁、进出场动画、焦点管理都在这里,
|
|
5
|
+
* 结构由子组件(`Modal.Overlay` / `Modal.Content` / …)拼。
|
|
6
|
+
*
|
|
7
|
+
* 层级、Escape、点遮罩都交给层级模块 `overlay-layer`:层级按打开顺序计算,
|
|
8
|
+
* Escape 只关最上层,写在 Popover 里面还是外面结果一样。
|
|
9
|
+
*/
|
|
10
|
+
export declare const ModalRoot: {
|
|
11
|
+
({ opened, onClose, children, centered, fullScreen, size, padding, radius, yOffset, xOffset, zIndex, closeOnClickOutside, closeOnEscape, keepMounted, overlayProps, onExitTransitionEnd, transitionProps, classNames, styles: slotStyles, className, style, }: ModalRootProps): React.JSX.Element | null;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
3
|
+
import { RemoveScroll as X } from "@mantine/core";
|
|
4
|
+
import { useIsomorphicEffect as Y } from "@mantine/hooks";
|
|
5
|
+
import { clsx as Z } from "clsx";
|
|
6
|
+
import { useId as H, useRef as n, useState as J, useEffect as u, useCallback as S } from "react";
|
|
7
|
+
import { Portal as Q } from "../_inner/portal/portal.js";
|
|
8
|
+
import { OverlayParentProvider as V } from "../overlay-layer/overlay-parent-context.js";
|
|
9
|
+
import { useOverlayLayerInternal as W } from "../overlay-layer/use-overlay-layer.js";
|
|
10
|
+
import { useAnimatedMount as tt, getFocusableElements as rt } from "../popover/hooks.js";
|
|
11
|
+
import { ModalContext as et } from "./modal-context.js";
|
|
12
|
+
import ot from "./modal.module.css.js";
|
|
13
|
+
const M = 200, nt = M + 100, st = {
|
|
14
|
+
xs: "320px",
|
|
15
|
+
sm: "380px",
|
|
16
|
+
md: "440px",
|
|
17
|
+
lg: "620px",
|
|
18
|
+
xl: "780px"
|
|
19
|
+
}, at = {
|
|
20
|
+
xs: "var(--t-space-mini)",
|
|
21
|
+
sm: "var(--t-space-xs)",
|
|
22
|
+
md: "var(--t-space-lg)",
|
|
23
|
+
lg: "var(--t-space-xl)",
|
|
24
|
+
xl: "var(--t-space-xxl)"
|
|
25
|
+
}, ct = {
|
|
26
|
+
xs: "2px",
|
|
27
|
+
sm: "var(--t-radius-xs)",
|
|
28
|
+
md: "var(--t-radius-sm)",
|
|
29
|
+
lg: "var(--t-radius-lg)",
|
|
30
|
+
xl: "var(--t-radius-lg)"
|
|
31
|
+
}, it = /^\d+(\.\d+)?$/, p = (t) => typeof t == "number" || it.test(t) ? `${t}px` : t, v = (t, e) => typeof e == "string" && e in t ? t[e] : p(e), lt = ({
|
|
32
|
+
opened: t,
|
|
33
|
+
onClose: e,
|
|
34
|
+
children: O,
|
|
35
|
+
centered: w = !0,
|
|
36
|
+
fullScreen: C = !1,
|
|
37
|
+
size: y = "md",
|
|
38
|
+
padding: N = "xl",
|
|
39
|
+
radius: b = "lg",
|
|
40
|
+
yOffset: L = "5dvh",
|
|
41
|
+
xOffset: P = "5vw",
|
|
42
|
+
zIndex: D,
|
|
43
|
+
closeOnClickOutside: F = !1,
|
|
44
|
+
closeOnEscape: U = !0,
|
|
45
|
+
keepMounted: _ = !1,
|
|
46
|
+
overlayProps: E,
|
|
47
|
+
onExitTransitionEnd: g,
|
|
48
|
+
transitionProps: I,
|
|
49
|
+
classNames: R,
|
|
50
|
+
styles: h,
|
|
51
|
+
className: $,
|
|
52
|
+
style: k
|
|
53
|
+
}) => {
|
|
54
|
+
const z = H(), d = n(null), [j, q] = J(!1), { mounted: m, animState: s, handleTransitionEnd: T } = tt(
|
|
55
|
+
t,
|
|
56
|
+
_
|
|
57
|
+
), f = W({
|
|
58
|
+
opened: t,
|
|
59
|
+
zIndex: D,
|
|
60
|
+
close: () => e(),
|
|
61
|
+
closeOnEscape: U,
|
|
62
|
+
closeOnClickOutside: F,
|
|
63
|
+
name: "modal"
|
|
64
|
+
}), a = n(!1), x = n(t), A = n({
|
|
65
|
+
handleTransitionEnd: T,
|
|
66
|
+
onExitTransitionEnd: g,
|
|
67
|
+
onExited: I?.onExited
|
|
68
|
+
});
|
|
69
|
+
u(() => {
|
|
70
|
+
A.current = {
|
|
71
|
+
handleTransitionEnd: T,
|
|
72
|
+
onExitTransitionEnd: g,
|
|
73
|
+
onExited: I?.onExited
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const c = S(() => {
|
|
77
|
+
if (!a.current) return;
|
|
78
|
+
a.current = !1;
|
|
79
|
+
const r = A.current;
|
|
80
|
+
r.onExitTransitionEnd?.(), r.onExited?.(), r.handleTransitionEnd();
|
|
81
|
+
}, []);
|
|
82
|
+
u(() => {
|
|
83
|
+
if (t) {
|
|
84
|
+
x.current = !0, a.current = !1;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!x.current) return;
|
|
88
|
+
x.current = !1, a.current = !0;
|
|
89
|
+
const r = window.setTimeout(c, nt);
|
|
90
|
+
return () => window.clearTimeout(r);
|
|
91
|
+
}, [t, c]);
|
|
92
|
+
const B = S(
|
|
93
|
+
(r) => {
|
|
94
|
+
r.target === r.currentTarget && s === "closing" && c();
|
|
95
|
+
},
|
|
96
|
+
[s, c]
|
|
97
|
+
), i = n(null);
|
|
98
|
+
if (Y(() => {
|
|
99
|
+
t && !i.current && (i.current = document.activeElement);
|
|
100
|
+
}, [t]), u(() => {
|
|
101
|
+
if (!t || !m) return;
|
|
102
|
+
const r = d.current;
|
|
103
|
+
if (!r || r.contains(document.activeElement)) return;
|
|
104
|
+
(r.querySelector("[data-autofocus]") ?? rt([r])[0] ?? r).focus();
|
|
105
|
+
}, [t, m]), u(() => {
|
|
106
|
+
if (t) return;
|
|
107
|
+
const r = i.current;
|
|
108
|
+
if (i.current = null, !r?.isConnected) return;
|
|
109
|
+
const l = document.activeElement;
|
|
110
|
+
(!l || l === document.body || d.current?.contains(l)) && r.focus();
|
|
111
|
+
}, [t]), !m) return null;
|
|
112
|
+
const G = E?.backgroundOpacity ?? E?.opacity ?? 0.6, K = {
|
|
113
|
+
...k,
|
|
114
|
+
...h?.root,
|
|
115
|
+
zIndex: f.zIndex,
|
|
116
|
+
"--modal-size": y === "auto" ? "auto" : v(st, y),
|
|
117
|
+
"--modal-padding": v(at, N),
|
|
118
|
+
"--modal-radius": v(ct, b),
|
|
119
|
+
"--modal-y-offset": p(L),
|
|
120
|
+
"--modal-x-offset": p(P),
|
|
121
|
+
"--modal-overlay-opacity": G,
|
|
122
|
+
"--modal-duration": `${M}ms`
|
|
123
|
+
};
|
|
124
|
+
return /* @__PURE__ */ o(Q, { children: /* @__PURE__ */ o(X, { enabled: t, children: /* @__PURE__ */ o(
|
|
125
|
+
et.Provider,
|
|
126
|
+
{
|
|
127
|
+
value: {
|
|
128
|
+
opened: t,
|
|
129
|
+
close: e,
|
|
130
|
+
animState: s,
|
|
131
|
+
contentRef: d,
|
|
132
|
+
layerRef: f.ref,
|
|
133
|
+
titleId: z,
|
|
134
|
+
titleMounted: j,
|
|
135
|
+
setTitleMounted: q,
|
|
136
|
+
classNames: R,
|
|
137
|
+
styles: h,
|
|
138
|
+
onContentTransitionEnd: B
|
|
139
|
+
},
|
|
140
|
+
children: /* @__PURE__ */ o(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
className: Z(ot.root, R?.root, $),
|
|
144
|
+
style: K,
|
|
145
|
+
"data-state": s,
|
|
146
|
+
"data-centered": w || void 0,
|
|
147
|
+
"data-fullscreen": C || void 0,
|
|
148
|
+
"aria-hidden": t ? void 0 : !0,
|
|
149
|
+
inert: t ? void 0 : !0,
|
|
150
|
+
children: /* @__PURE__ */ o(V, { id: f.id, children: O })
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
) }) });
|
|
155
|
+
};
|
|
156
|
+
lt.displayName = "Modal.Root";
|
|
157
|
+
export {
|
|
158
|
+
lt as ModalRoot
|
|
159
|
+
};
|
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ModalProps } from './modal.types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export declare const Modal: {
|
|
4
|
+
({ title, children, withCloseButton, closeButtonProps, onClick, "aria-label": ariaLabel, ...rootProps }: ModalProps): React.JSX.Element;
|
|
5
|
+
displayName: string;
|
|
6
|
+
} & {
|
|
7
|
+
Root: {
|
|
8
|
+
({ opened, onClose, children, centered, fullScreen, size, padding, radius, yOffset, xOffset, zIndex, closeOnClickOutside, closeOnEscape, keepMounted, overlayProps, onExitTransitionEnd, transitionProps, classNames, styles: slotStyles, className, style, }: import("./modal.types").ModalRootProps): React.JSX.Element | null;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
Overlay: {
|
|
12
|
+
({ className, style, ...rest }: React.ComponentProps<"div">): React.JSX.Element;
|
|
13
|
+
displayName: string;
|
|
14
|
+
};
|
|
15
|
+
Content: {
|
|
16
|
+
({ "aria-label": ariaLabel, className, style, children, ref, ...rest }: React.ComponentProps<"div">): React.JSX.Element;
|
|
17
|
+
displayName: string;
|
|
18
|
+
};
|
|
19
|
+
Header: {
|
|
20
|
+
({ className, style, ...rest }: React.ComponentProps<"div">): React.JSX.Element;
|
|
21
|
+
displayName: string;
|
|
22
|
+
};
|
|
23
|
+
Title: {
|
|
24
|
+
({ className, style, children, ...rest }: React.ComponentProps<"div">): React.JSX.Element;
|
|
25
|
+
displayName: string;
|
|
26
|
+
};
|
|
27
|
+
Body: {
|
|
28
|
+
({ className, style, ...rest }: React.ComponentProps<"div">): React.JSX.Element;
|
|
29
|
+
displayName: string;
|
|
30
|
+
};
|
|
31
|
+
CloseButton: {
|
|
32
|
+
({ className, style, onClick, "aria-label": ariaLabel, ...rest }: import("./modal.types").ModalCloseButtonProps): React.JSX.Element;
|
|
33
|
+
displayName: string;
|
|
34
|
+
};
|
|
35
|
+
};
|