dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
34 lines (33 loc) • 915 B
JavaScript
import { j as d } from "../jsx-runtime-DS1N_tNq.js";
import { useState as l, useEffect as T } from "react";
import { T as t } from "../ThemeMode-CqURAYDL.js";
import { T as h } from "../ThemeProviderContext-DGw2_Ad5.js";
function x({
children: c,
defaultTheme: a = t.SYSTEM,
storageKey: s = "theme",
...i
}) {
const [o, m] = l(
() => localStorage.getItem(s) || a
);
T(() => {
const e = window.document.documentElement;
if (e.classList.remove(t.LIGHT, t.DARK), o === t.SYSTEM) {
const r = window.matchMedia("(prefers-color-scheme: dark)").matches ? t.DARK : t.LIGHT;
e.classList.add(r), m(r);
return;
}
e.style.colorScheme = o, e.classList.add(o);
}, [o]);
const n = {
theme: o,
setTheme: (e) => {
localStorage.setItem(s, e), m(e);
}
};
return /* @__PURE__ */ d.jsx(h, { ...i, value: n, children: c });
}
export {
x as ThemeProvider
};