@nobertdev/react-confirm-dialog 1.1.1 → 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 +33 -6
- package/dist/index.mjs +37 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -397,15 +397,42 @@ var DEFAULT_STATE = {
|
|
|
397
397
|
variant: "default",
|
|
398
398
|
icon: void 0
|
|
399
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
|
+
}
|
|
400
411
|
function usePrefersDark() {
|
|
401
|
-
const [dark, setDark] = (0, import_react3.useState)(
|
|
402
|
-
(
|
|
403
|
-
|
|
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
|
+
});
|
|
404
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
|
+
});
|
|
405
427
|
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
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
|
+
};
|
|
409
436
|
}, []);
|
|
410
437
|
return dark;
|
|
411
438
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -19,11 +19,11 @@ 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
28
|
var VARIANT_STYLES = {
|
|
29
29
|
default: {
|
|
@@ -373,15 +373,42 @@ var DEFAULT_STATE = {
|
|
|
373
373
|
variant: "default",
|
|
374
374
|
icon: void 0
|
|
375
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
|
+
}
|
|
376
387
|
function usePrefersDark() {
|
|
377
|
-
const [dark, setDark] =
|
|
378
|
-
(
|
|
379
|
-
|
|
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
|
+
});
|
|
380
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
|
+
});
|
|
381
403
|
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
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
|
+
};
|
|
385
412
|
}, []);
|
|
386
413
|
return dark;
|
|
387
414
|
}
|
|
@@ -392,8 +419,8 @@ 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);
|
|
398
425
|
const isDark = usePrefersDark();
|
|
399
426
|
const close = useCallback((result) => {
|
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",
|