@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) • 778 B
JavaScript
"use client";
import{createContext as e,useState as t,useInsertionEffect as r}from"react";import{Node as o}from"../core.node.js";import{buildThemeVariablesCss as n}from"../util/server-theme.util.js";const m=e(null);function d({children:e,theme:d}){const[c,s]=t(d);if(!d)throw new Error("`theme` prop must be defined");const i={theme:c,setTheme:e=>{"function"==typeof e&&(e=e(c)),document.cookie=`theme=${e.mode}; path=/;`,s(e)}};return r(()=>{const e=n(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]),o(m.Provider,{value:i,children:e}).render()}d.__meonodeAcceptsServerCss=!0,d.__meonodeProvidesServerTheme=!0;export{m as ThemeContext,d as default};