@julseb-lib/react 0.1.34 → 0.1.35
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.cjs +24 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2664,31 +2664,37 @@ import { useState as useState10, useEffect as useEffect8, createContext, useCont
|
|
|
2664
2664
|
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2665
2665
|
var ThemeContext = createContext(null);
|
|
2666
2666
|
var ThemeProviderWrapper = ({ children }) => {
|
|
2667
|
-
const
|
|
2668
|
-
const [theme, setTheme] = useState10(storedTheme != null ? storedTheme : "light");
|
|
2667
|
+
const [theme, setTheme] = useState10("light");
|
|
2669
2668
|
const docEl = document.documentElement;
|
|
2670
2669
|
const switchToLight = () => {
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2670
|
+
if (typeof window !== "undefined") {
|
|
2671
|
+
docEl.classList.add("light");
|
|
2672
|
+
docEl.classList.remove("dark");
|
|
2673
|
+
setTheme("light");
|
|
2674
|
+
localStorage.setItem("theme", "light");
|
|
2675
|
+
}
|
|
2675
2676
|
};
|
|
2676
2677
|
const switchToDark = () => {
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2678
|
+
if (typeof window !== "undefined") {
|
|
2679
|
+
docEl.classList.remove("light");
|
|
2680
|
+
docEl.classList.add("dark");
|
|
2681
|
+
setTheme("dark");
|
|
2682
|
+
localStorage.setItem("theme", "dark");
|
|
2683
|
+
}
|
|
2681
2684
|
};
|
|
2682
2685
|
useEffect8(() => {
|
|
2683
|
-
if (
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2686
|
+
if (typeof window !== "undefined") {
|
|
2687
|
+
const storedTheme = localStorage.getItem("theme");
|
|
2688
|
+
if (storedTheme) {
|
|
2689
|
+
if (theme === "light") switchToLight();
|
|
2690
|
+
else switchToDark();
|
|
2691
|
+
} else {
|
|
2692
|
+
if (window.matchMedia("(prefers-color-scheme: dark)").matches)
|
|
2693
|
+
switchToDark();
|
|
2694
|
+
else switchToLight();
|
|
2695
|
+
}
|
|
2690
2696
|
}
|
|
2691
|
-
}, [theme,
|
|
2697
|
+
}, [theme, docEl]);
|
|
2692
2698
|
const switchTheme = () => {
|
|
2693
2699
|
if (theme === "light") switchToDark();
|
|
2694
2700
|
else switchToLight();
|