@nobertdev/react-confirm-dialog 1.1.0 → 1.1.2
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/index.js +44 -15
- package/dist/index.mjs +48 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49,18 +49,6 @@ var import_react_dom = require("react-dom");
|
|
|
49
49
|
// src/components/BuildinDialog.tsx
|
|
50
50
|
var import_react = require("react");
|
|
51
51
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
|
-
function usePrefersDark() {
|
|
53
|
-
const [dark, setDark] = (0, import_react.useState)(
|
|
54
|
-
() => typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : false
|
|
55
|
-
);
|
|
56
|
-
(0, import_react.useEffect)(() => {
|
|
57
|
-
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
58
|
-
const handler = (e) => setDark(e.matches);
|
|
59
|
-
mq.addEventListener("change", handler);
|
|
60
|
-
return () => mq.removeEventListener("change", handler);
|
|
61
|
-
}, []);
|
|
62
|
-
return dark;
|
|
63
|
-
}
|
|
64
52
|
var VARIANT_STYLES = {
|
|
65
53
|
default: {
|
|
66
54
|
confirmBg: "#111",
|
|
@@ -195,11 +183,11 @@ function BuiltInDialog({
|
|
|
195
183
|
providerProps,
|
|
196
184
|
onConfirm,
|
|
197
185
|
onCancel,
|
|
198
|
-
isClosing
|
|
186
|
+
isClosing,
|
|
187
|
+
isDark
|
|
199
188
|
}) {
|
|
200
189
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
201
190
|
const confirmRef = (0, import_react.useRef)(null);
|
|
202
|
-
const isDark = usePrefersDark();
|
|
203
191
|
const variant = (_a = state.variant) != null ? _a : "default";
|
|
204
192
|
const v = VARIANT_STYLES[variant];
|
|
205
193
|
(0, import_react.useEffect)(() => {
|
|
@@ -409,6 +397,45 @@ var DEFAULT_STATE = {
|
|
|
409
397
|
variant: "default",
|
|
410
398
|
icon: void 0
|
|
411
399
|
};
|
|
400
|
+
function detectDarkFromDOM() {
|
|
401
|
+
var _a;
|
|
402
|
+
if (typeof document === "undefined") return null;
|
|
403
|
+
const el = document.documentElement;
|
|
404
|
+
if (el.classList.contains("dark")) return true;
|
|
405
|
+
if (el.classList.contains("light")) return false;
|
|
406
|
+
const dataTheme = (_a = el.getAttribute("data-theme")) != null ? _a : el.getAttribute("data-mode");
|
|
407
|
+
if (dataTheme === "dark") return true;
|
|
408
|
+
if (dataTheme === "light") return false;
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
function usePrefersDark() {
|
|
412
|
+
const [dark, setDark] = (0, import_react3.useState)(() => {
|
|
413
|
+
if (typeof window === "undefined") return false;
|
|
414
|
+
const domDark = detectDarkFromDOM();
|
|
415
|
+
if (domDark !== null) return domDark;
|
|
416
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
417
|
+
});
|
|
418
|
+
(0, import_react3.useEffect)(() => {
|
|
419
|
+
const observer = new MutationObserver(() => {
|
|
420
|
+
const domDark = detectDarkFromDOM();
|
|
421
|
+
if (domDark !== null) setDark(domDark);
|
|
422
|
+
});
|
|
423
|
+
observer.observe(document.documentElement, {
|
|
424
|
+
attributes: true,
|
|
425
|
+
attributeFilter: ["class", "data-theme", "data-mode"]
|
|
426
|
+
});
|
|
427
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
428
|
+
const mqHandler = (e) => {
|
|
429
|
+
if (detectDarkFromDOM() === null) setDark(e.matches);
|
|
430
|
+
};
|
|
431
|
+
mq.addEventListener("change", mqHandler);
|
|
432
|
+
return () => {
|
|
433
|
+
observer.disconnect();
|
|
434
|
+
mq.removeEventListener("change", mqHandler);
|
|
435
|
+
};
|
|
436
|
+
}, []);
|
|
437
|
+
return dark;
|
|
438
|
+
}
|
|
412
439
|
function ConfirmDialogProvider({
|
|
413
440
|
children,
|
|
414
441
|
defaultOptions,
|
|
@@ -419,6 +446,7 @@ function ConfirmDialogProvider({
|
|
|
419
446
|
const [state, setState] = (0, import_react3.useState)(DEFAULT_STATE);
|
|
420
447
|
const [isClosing, setIsClosing] = (0, import_react3.useState)(false);
|
|
421
448
|
const resolveRef = (0, import_react3.useRef)(null);
|
|
449
|
+
const isDark = usePrefersDark();
|
|
422
450
|
const close = (0, import_react3.useCallback)((result) => {
|
|
423
451
|
setIsClosing(true);
|
|
424
452
|
setTimeout(() => {
|
|
@@ -457,7 +485,8 @@ function ConfirmDialogProvider({
|
|
|
457
485
|
providerProps: { classNames, styles, defaultOptions },
|
|
458
486
|
onConfirm,
|
|
459
487
|
onCancel,
|
|
460
|
-
isClosing
|
|
488
|
+
isClosing,
|
|
489
|
+
isDark
|
|
461
490
|
}
|
|
462
491
|
);
|
|
463
492
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ConfirmDialogContext.Provider, { value: contextValue, children: [
|
package/dist/index.mjs
CHANGED
|
@@ -19,24 +19,12 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
21
|
// src/components/ConfirmDialogProvider.tsx
|
|
22
|
-
import { useState
|
|
22
|
+
import { useState, useCallback, useRef as useRef2, useMemo, useEffect as useEffect2 } from "react";
|
|
23
23
|
import { createPortal } from "react-dom";
|
|
24
24
|
|
|
25
25
|
// src/components/BuildinDialog.tsx
|
|
26
|
-
import { useEffect, useRef
|
|
26
|
+
import { useEffect, useRef } from "react";
|
|
27
27
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
28
|
-
function usePrefersDark() {
|
|
29
|
-
const [dark, setDark] = useState(
|
|
30
|
-
() => typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : false
|
|
31
|
-
);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
34
|
-
const handler = (e) => setDark(e.matches);
|
|
35
|
-
mq.addEventListener("change", handler);
|
|
36
|
-
return () => mq.removeEventListener("change", handler);
|
|
37
|
-
}, []);
|
|
38
|
-
return dark;
|
|
39
|
-
}
|
|
40
28
|
var VARIANT_STYLES = {
|
|
41
29
|
default: {
|
|
42
30
|
confirmBg: "#111",
|
|
@@ -171,11 +159,11 @@ function BuiltInDialog({
|
|
|
171
159
|
providerProps,
|
|
172
160
|
onConfirm,
|
|
173
161
|
onCancel,
|
|
174
|
-
isClosing
|
|
162
|
+
isClosing,
|
|
163
|
+
isDark
|
|
175
164
|
}) {
|
|
176
165
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
177
166
|
const confirmRef = useRef(null);
|
|
178
|
-
const isDark = usePrefersDark();
|
|
179
167
|
const variant = (_a = state.variant) != null ? _a : "default";
|
|
180
168
|
const v = VARIANT_STYLES[variant];
|
|
181
169
|
useEffect(() => {
|
|
@@ -385,6 +373,45 @@ var DEFAULT_STATE = {
|
|
|
385
373
|
variant: "default",
|
|
386
374
|
icon: void 0
|
|
387
375
|
};
|
|
376
|
+
function detectDarkFromDOM() {
|
|
377
|
+
var _a;
|
|
378
|
+
if (typeof document === "undefined") return null;
|
|
379
|
+
const el = document.documentElement;
|
|
380
|
+
if (el.classList.contains("dark")) return true;
|
|
381
|
+
if (el.classList.contains("light")) return false;
|
|
382
|
+
const dataTheme = (_a = el.getAttribute("data-theme")) != null ? _a : el.getAttribute("data-mode");
|
|
383
|
+
if (dataTheme === "dark") return true;
|
|
384
|
+
if (dataTheme === "light") return false;
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
function usePrefersDark() {
|
|
388
|
+
const [dark, setDark] = useState(() => {
|
|
389
|
+
if (typeof window === "undefined") return false;
|
|
390
|
+
const domDark = detectDarkFromDOM();
|
|
391
|
+
if (domDark !== null) return domDark;
|
|
392
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
393
|
+
});
|
|
394
|
+
useEffect2(() => {
|
|
395
|
+
const observer = new MutationObserver(() => {
|
|
396
|
+
const domDark = detectDarkFromDOM();
|
|
397
|
+
if (domDark !== null) setDark(domDark);
|
|
398
|
+
});
|
|
399
|
+
observer.observe(document.documentElement, {
|
|
400
|
+
attributes: true,
|
|
401
|
+
attributeFilter: ["class", "data-theme", "data-mode"]
|
|
402
|
+
});
|
|
403
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
404
|
+
const mqHandler = (e) => {
|
|
405
|
+
if (detectDarkFromDOM() === null) setDark(e.matches);
|
|
406
|
+
};
|
|
407
|
+
mq.addEventListener("change", mqHandler);
|
|
408
|
+
return () => {
|
|
409
|
+
observer.disconnect();
|
|
410
|
+
mq.removeEventListener("change", mqHandler);
|
|
411
|
+
};
|
|
412
|
+
}, []);
|
|
413
|
+
return dark;
|
|
414
|
+
}
|
|
388
415
|
function ConfirmDialogProvider({
|
|
389
416
|
children,
|
|
390
417
|
defaultOptions,
|
|
@@ -392,9 +419,10 @@ function ConfirmDialogProvider({
|
|
|
392
419
|
styles,
|
|
393
420
|
renderDialog
|
|
394
421
|
}) {
|
|
395
|
-
const [state, setState] =
|
|
396
|
-
const [isClosing, setIsClosing] =
|
|
422
|
+
const [state, setState] = useState(DEFAULT_STATE);
|
|
423
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
397
424
|
const resolveRef = useRef2(null);
|
|
425
|
+
const isDark = usePrefersDark();
|
|
398
426
|
const close = useCallback((result) => {
|
|
399
427
|
setIsClosing(true);
|
|
400
428
|
setTimeout(() => {
|
|
@@ -433,7 +461,8 @@ function ConfirmDialogProvider({
|
|
|
433
461
|
providerProps: { classNames, styles, defaultOptions },
|
|
434
462
|
onConfirm,
|
|
435
463
|
onCancel,
|
|
436
|
-
isClosing
|
|
464
|
+
isClosing,
|
|
465
|
+
isDark
|
|
437
466
|
}
|
|
438
467
|
);
|
|
439
468
|
return /* @__PURE__ */ jsxs2(ConfirmDialogContext.Provider, { value: contextValue, children: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nobertdev/react-confirm-dialog",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A lightweight, fully customizable confirmation dialog hook (useConfirm()) that replaces window.confirm() with beautiful async modals. Zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|