UNPKG

@meonode/ui

Version:

A structured approach to component composition, direct CSS-first prop styling, built-in theming, smart prop handling (including raw property pass-through), and dynamic children.

3 lines (2 loc) 717 B
"use client"; "use strict";var e=require("react"),t=require("../components/theme-provider.client.cjs");exports.useTheme=()=>{const s=e.useContext(t.ThemeContext);if(!s)throw new Error("useTheme must be used within a ThemeProvider");const{theme:m}=s;return e.useEffect(()=>{const e=globalThis.localStorage;if(e&&"function"==typeof e.getItem&&"function"==typeof e.setItem){const t=e.getItem("theme");t&&t===m.mode||e.setItem("theme",m.mode)}const t=document.documentElement;"dark"===m.mode?(t.setAttribute("data-theme","dark"),t.classList.add("dark-theme"),t.classList.remove("light-theme")):(t.setAttribute("data-theme","light"),t.classList.add("light-theme"),t.classList.remove("dark-theme"))},[m.mode,m.system]),s};