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) 829 B
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../core.node.cjs"),r=require("../util/server-theme.util.cjs");const o=e.createContext(null);function n({children:n,theme:s}){const[c,d]=e.useState(s);if(!s)throw new Error("`theme` prop must be defined");const u={theme:c,setTheme:e=>{"function"==typeof e&&(e=e(c)),document.cookie=`theme=${e.mode}; path=/;`,d(e)}};return e.useInsertionEffect(()=>{const e=r.buildThemeVariablesCss(c);if(!e)return;const t=document.createElement("style");return t.setAttribute("data-meonode-theme-vars",""),t.textContent=e,document.head.appendChild(t),()=>{t.remove()}},[c]),t.Node(o.Provider,{value:u,children:n}).render()}n.__meonodeAcceptsServerCss=!0,n.__meonodeProvidesServerTheme=!0,exports.ThemeContext=o,exports.default=n;