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