UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

74 lines (73 loc) 2.15 kB
import * as s from "react"; import { j as l } from "./jsx-runtime-C5mzlN2N.js"; function b(e, c) { const o = s.createContext(c), x = (r) => { const { children: t, ...n } = r, u = s.useMemo(() => n, Object.values(n)); return /* @__PURE__ */ l.jsx(o.Provider, { value: u, children: t }); }; x.displayName = e + "Provider"; function i(r) { const t = s.useContext(o); if (t) return t; if (c !== void 0) return c; throw new Error(`\`${r}\` must be used within \`${e}\``); } return [x, i]; } function j(e, c = []) { let o = []; function x(r, t) { const n = s.createContext(t), u = o.length; o = [...o, t]; const d = (f) => { var h; const { scope: a, children: v, ...m } = f, p = ((h = a == null ? void 0 : a[e]) == null ? void 0 : h[u]) || n, S = s.useMemo(() => m, Object.values(m)); return /* @__PURE__ */ l.jsx(p.Provider, { value: S, children: v }); }; d.displayName = r + "Provider"; function C(f, a) { var p; const v = ((p = a == null ? void 0 : a[e]) == null ? void 0 : p[u]) || n, m = s.useContext(v); if (m) return m; if (t !== void 0) return t; throw new Error(`\`${f}\` must be used within \`${r}\``); } return [d, C]; } const i = () => { const r = o.map((t) => s.createContext(t)); return function(n) { const u = (n == null ? void 0 : n[e]) || r; return s.useMemo( () => ({ [`__scope${e}`]: { ...n, [e]: u } }), [n, u] ); }; }; return i.scopeName = e, [x, P(i, ...c)]; } function P(...e) { const c = e[0]; if (e.length === 1) return c; const o = () => { const x = e.map((i) => ({ useScope: i(), scopeName: i.scopeName })); return function(r) { const t = x.reduce((n, { useScope: u, scopeName: d }) => { const f = u(r)[`__scope${d}`]; return { ...n, ...f }; }, {}); return s.useMemo(() => ({ [`__scope${c.scopeName}`]: t }), [t]); }; }; return o.scopeName = c.scopeName, o; } var w = globalThis != null && globalThis.document ? s.useLayoutEffect : () => { }; export { b as a, j as c, w as u };