@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.cjs
CHANGED
|
@@ -2842,31 +2842,36 @@ var import_react14 = require("react");
|
|
|
2842
2842
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2843
2843
|
var ThemeContext = (0, import_react14.createContext)(null);
|
|
2844
2844
|
var ThemeProviderWrapper = ({ children }) => {
|
|
2845
|
-
const
|
|
2846
|
-
const [theme, setTheme] = (0, import_react14.useState)(storedTheme != null ? storedTheme : "light");
|
|
2847
|
-
const docEl = document.documentElement;
|
|
2845
|
+
const [theme, setTheme] = (0, import_react14.useState)("light");
|
|
2848
2846
|
const switchToLight = () => {
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2847
|
+
if (typeof window !== "undefined") {
|
|
2848
|
+
document.documentElement.classList.add("light");
|
|
2849
|
+
document.documentElement.classList.remove("dark");
|
|
2850
|
+
setTheme("light");
|
|
2851
|
+
localStorage.setItem("theme", "light");
|
|
2852
|
+
}
|
|
2853
2853
|
};
|
|
2854
2854
|
const switchToDark = () => {
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2855
|
+
if (typeof window !== "undefined") {
|
|
2856
|
+
document.documentElement.classList.remove("light");
|
|
2857
|
+
document.documentElement.classList.add("dark");
|
|
2858
|
+
setTheme("dark");
|
|
2859
|
+
localStorage.setItem("theme", "dark");
|
|
2860
|
+
}
|
|
2859
2861
|
};
|
|
2860
2862
|
(0, import_react14.useEffect)(() => {
|
|
2861
|
-
if (
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2863
|
+
if (typeof window !== "undefined") {
|
|
2864
|
+
const storedTheme = localStorage.getItem("theme");
|
|
2865
|
+
if (storedTheme) {
|
|
2866
|
+
if (theme === "light") switchToLight();
|
|
2867
|
+
else switchToDark();
|
|
2868
|
+
} else {
|
|
2869
|
+
if (window.matchMedia("(prefers-color-scheme: dark)").matches)
|
|
2870
|
+
switchToDark();
|
|
2871
|
+
else switchToLight();
|
|
2872
|
+
}
|
|
2868
2873
|
}
|
|
2869
|
-
}, [theme
|
|
2874
|
+
}, [theme]);
|
|
2870
2875
|
const switchTheme = () => {
|
|
2871
2876
|
if (theme === "light") switchToDark();
|
|
2872
2877
|
else switchToLight();
|