fui-fancyui
Version:
FancyUI Libary
27 lines (26 loc) • 950 B
JavaScript
"use client";
import { jsx as p } from "react/jsx-runtime";
import { useState as d, useEffect as i } from "react";
import { ThemeProvider as T } from "styled-components";
import m from "../themeStore/themeStore.js";
import a from "../generateObjectToCssVariables/generateObjectToCssVariables.js";
import y from "../applyThemeToDomStyleSheet/applyThemeToDomStyleSheet.js";
function j(f) {
const { children: c, theme: r, applyCssVars: o = !0, styleSheetId: n = "fui-theme" } = f, [s, h] = d(!1), t = m((e) => e.theme), l = m((e) => e.isDarkTheme), u = m((e) => e.setTheme);
return i(() => {
r && u(r), h(!0);
}, []), i(() => {
if (!o && !s) return;
const e = a(t);
y(e);
}, [r, t, o, s]), i(() => {
if (!o) return;
const e = document.getElementById(n);
e && (e.innerHTML = `:root {
${a(t)}
}`);
}, [t, l, o, n]), /* @__PURE__ */ p(T, { theme: s ? t : r ?? t, children: c });
}
export {
j as default
};