UNPKG

dgz-ui-shared

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library

33 lines (32 loc) 939 B
import { jsx as n } from "react/jsx-runtime"; import { useState as d, useEffect as l } from "react"; import { T as t } from "../chunks/ThemeMode-CqURAYDL.es.js"; import { T } from "../chunks/ThemeProviderContext-CDiIvEe7.es.js"; function v({ children: c, defaultTheme: a = t.SYSTEM, storageKey: m = "theme", ...i }) { const [o, s] = d( () => localStorage.getItem(m) || a ); return l(() => { 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), s(r); return; } e.style.colorScheme = o, e.classList.add(o); }, [o]), /* @__PURE__ */ n(T, { ...i, value: { theme: o, setTheme: (e) => { localStorage.setItem(m, e), s(e); } }, children: c }); } export { v as ThemeProvider }; //# sourceMappingURL=index.es.js.map