@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 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 storedTheme = localStorage.getItem("theme");
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
- docEl.classList.add("light");
2850
- docEl.classList.remove("dark");
2851
- setTheme("light");
2852
- localStorage.setItem("theme", "light");
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
- docEl.classList.remove("light");
2856
- docEl.classList.add("dark");
2857
- setTheme("dark");
2858
- localStorage.setItem("theme", "dark");
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 (storedTheme) {
2862
- if (theme === "light") switchToLight();
2863
- else switchToDark();
2864
- } else {
2865
- if (window.matchMedia("(prefers-color-scheme: dark)").matches)
2866
- switchToDark();
2867
- else switchToLight();
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, localStorage.getItem("theme"), docEl]);
2874
+ }, [theme]);
2870
2875
  const switchTheme = () => {
2871
2876
  if (theme === "light") switchToDark();
2872
2877
  else switchToLight();