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