@mshuja288/aksuicore 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +21 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/primitives/Dialog.tsx +28 -3
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type { ReactNode } from "react";
|
|
3
|
+
import type { MouseEvent, ReactNode } from "react";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
4
5
|
import { Button } from "./Button";
|
|
5
6
|
|
|
6
7
|
export function Dialog({
|
|
@@ -16,18 +17,42 @@ export function Dialog({
|
|
|
16
17
|
children: ReactNode;
|
|
17
18
|
wide?: boolean;
|
|
18
19
|
}) {
|
|
20
|
+
const allowBackdropClose = useRef(false);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!open) {
|
|
24
|
+
allowBackdropClose.current = false;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Ignore the opening gesture so View/Update clicks cannot close the dialog immediately.
|
|
29
|
+
allowBackdropClose.current = false;
|
|
30
|
+
const timer = window.setTimeout(() => {
|
|
31
|
+
allowBackdropClose.current = true;
|
|
32
|
+
}, 0);
|
|
33
|
+
|
|
34
|
+
return () => window.clearTimeout(timer);
|
|
35
|
+
}, [open]);
|
|
36
|
+
|
|
19
37
|
if (!open) {
|
|
20
38
|
return null;
|
|
21
39
|
}
|
|
22
40
|
|
|
41
|
+
function onBackdropMouseDown(event: MouseEvent<HTMLDivElement>) {
|
|
42
|
+
if (event.target !== event.currentTarget || !allowBackdropClose.current) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
onClose();
|
|
46
|
+
}
|
|
47
|
+
|
|
23
48
|
return (
|
|
24
|
-
<div className="dialog-backdrop"
|
|
49
|
+
<div className="dialog-backdrop" onMouseDown={onBackdropMouseDown}>
|
|
25
50
|
<div
|
|
26
51
|
className={wide ? "dialog form-dialog" : "dialog"}
|
|
27
52
|
role="dialog"
|
|
28
53
|
aria-modal="true"
|
|
29
54
|
aria-label={title}
|
|
30
|
-
|
|
55
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
31
56
|
>
|
|
32
57
|
<div className="dialog-head">
|
|
33
58
|
<h2>{title}</h2>
|