UNPKG

dgz-ui-shared

Version:

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

2 lines (1 loc) 878 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../jsx-runtime-DUiatUiq.cjs"),m=require("react"),t=require("../ThemeMode-BO6tit_Z.cjs"),l=require("../ThemeProviderContext-3ysAf7lU.cjs");function u({children:c,defaultTheme:d=t.ThemeMode.SYSTEM,storageKey:r="theme",...n}){const[o,i]=m.useState(()=>localStorage.getItem(r)||d);m.useEffect(()=>{const e=window.document.documentElement;if(e.classList.remove(t.ThemeMode.LIGHT,t.ThemeMode.DARK),e.style.colorScheme=o,o===t.ThemeMode.SYSTEM){const s=window.matchMedia("(prefers-color-scheme: dark)").matches?t.ThemeMode.DARK:t.ThemeMode.LIGHT;e.classList.add(s),e.style.colorScheme=s;return}e.classList.add(o)},[o]);const h={theme:o,setTheme:e=>{localStorage.setItem(r,e),i(e)}};return T.jsxRuntimeExports.jsx(l.ThemeProviderContext,{...n,value:h,children:c})}exports.ThemeProvider=u;