@tabnews/ui
Version:
TabNews UI
40 lines (39 loc) • 1.32 kB
JavaScript
"use client";
import { jsxs as l, jsx as r } from "react/jsx-runtime";
import { useTheme as i } from "@primer/react";
import { useState as s, useEffect as m, useLayoutEffect as a } from "react";
import { COLOR_MODE_COOKIE as f } from "../constants/public.js";
import { ThemeProvider as h } from "../ThemeProvider/ThemeProvider.js";
const y = () => setTimeout(() => document.documentElement.removeAttribute("data-no-flash")), p = typeof document > "u" ? m : a;
function T({ children: e, defaultColorMode: d, noFlash: n = !0, ...u }) {
const [o, c] = s(d === "dark" ? "dark" : "light");
return p(() => {
const t = localStorage.getItem("colorMode") || o;
n && y(), t != o && (document.documentElement.setAttribute("data-color-mode", t), c(t));
}, []), /* @__PURE__ */ l(h, { colorMode: o, ...u, children: [
n && /* @__PURE__ */ r(M, {}),
/* @__PURE__ */ r(C, {}),
e
] });
}
function M() {
return /* @__PURE__ */ r(
"style",
{
dangerouslySetInnerHTML: {
__html: "html[data-no-flash='true'] { visibility: hidden; }"
}
}
);
}
function C() {
const { resolvedColorMode: e } = i();
m(() => {
document.cookie = `${f}=${e}; max-age=31536000; path=/`;
}, [e]);
}
export {
T as AutoThemeProvider,
C as ColorModeCookieSync,
M as NoFlashGlobalStyle
};