quirk-ui 0.1.54 → 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),e=require("react"),m=e.createContext(void 0);function h({children:t}){const[o,u]=e.useState("light"),[n,a]=e.useState(!1);e.useEffect(()=>{const i=document.documentElement.getAttribute("data-theme")==="dark"?"dark":"light";u(i),a(!0)},[]);const r=e.useCallback(s=>{u(s),localStorage.setItem("theme-mode",s),document.documentElement.setAttribute("data-theme",s)},[]),c=e.useCallback(()=>{r(o==="light"?"dark":"light")},[o,r]),d=e.useMemo(()=>({mode:o,mounted:n,toggleTheme:c,setTheme:r}),[o,n,c,r]);return l.jsx(m.Provider,{value:d,children:t})}function g(){const t=e.useContext(m);if(!t)throw new Error("useTheme must be used within AppThemeProvider");return t}exports.AppThemeProvider=h;exports.useTheme=g;
|
|
@@ -1,41 +1,30 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const m = document.documentElement.getAttribute(
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as f, useContext as g, useState as u, useEffect as p, useCallback as c, useMemo as T } from "react";
|
|
3
|
+
const d = f(void 0);
|
|
4
|
+
function k({ children: e }) {
|
|
5
|
+
const [t, m] = u("light"), [n, a] = u(!1);
|
|
6
|
+
p(() => {
|
|
7
|
+
const h = document.documentElement.getAttribute(
|
|
9
8
|
"data-theme"
|
|
10
9
|
) === "dark" ? "dark" : "light";
|
|
11
|
-
|
|
12
|
-
const n = {
|
|
13
|
-
light: h.background,
|
|
14
|
-
dark: d.background
|
|
15
|
-
}, a = document.querySelector('meta[name="theme-color"]');
|
|
16
|
-
a && a.setAttribute("content", n[m]);
|
|
10
|
+
m(h), a(!0);
|
|
17
11
|
}, []);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}, []), u = l(() => {
|
|
26
|
-
r(o === "light" ? "dark" : "light");
|
|
27
|
-
}, [o, r]), k = v(
|
|
28
|
-
() => ({ mode: o, mounted: s, toggleTheme: u, setTheme: r }),
|
|
29
|
-
[o, s, u, r]
|
|
12
|
+
const o = c((r) => {
|
|
13
|
+
m(r), localStorage.setItem("theme-mode", r), document.documentElement.setAttribute("data-theme", r);
|
|
14
|
+
}, []), s = c(() => {
|
|
15
|
+
o(t === "light" ? "dark" : "light");
|
|
16
|
+
}, [t, o]), i = T(
|
|
17
|
+
() => ({ mode: t, mounted: n, toggleTheme: s, setTheme: o }),
|
|
18
|
+
[t, n, s, o]
|
|
30
19
|
);
|
|
31
|
-
return /* @__PURE__ */
|
|
20
|
+
return /* @__PURE__ */ l(d.Provider, { value: i, children: e });
|
|
32
21
|
}
|
|
33
22
|
function x() {
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
return
|
|
23
|
+
const e = g(d);
|
|
24
|
+
if (!e) throw new Error("useTheme must be used within AppThemeProvider");
|
|
25
|
+
return e;
|
|
37
26
|
}
|
|
38
27
|
export {
|
|
39
|
-
|
|
28
|
+
k as AppThemeProvider,
|
|
40
29
|
x as useTheme
|
|
41
30
|
};
|