UNPKG

welcome-ui

Version:

Customizable design system with react • styled-components • styled-system and ariakit.

186 lines (185 loc) 5.66 kB
"use client"; import { m as Y, o as Z, t as ee, c as te, s as y, d as A, e as ne, a as oe, b as P, u as R } from "./YV4JVR4I-BLeUul5N.mjs"; import { B as p, A as se, C as ae, G as re, t as T, f as H, _ as F, g as _, c as ie, h as ue, i as le, w as ce, E as S, D as de, d as O, e as me, y as fe } from "./LVA2YJMS-B8X1PCyC.mjs"; import { createContext as I, useRef as ve, useState as pe, useMemo as Se } from "react"; import { r as De } from "./index-Dct42YPA.mjs"; import { j as M } from "./jsx-runtime-Bqq1Hxg9.mjs"; function Ce(n = {}) { const o = Y( n.store, Z(n.disclosure, ["contentElement", "disclosureElement"]) ); ee(n, o); const e = o == null ? void 0 : o.getState(), t = p( n.open, e == null ? void 0 : e.open, n.defaultOpen, !1 ), i = p(n.animated, e == null ? void 0 : e.animated, !1), r = { open: t, animated: i, animating: !!i && t, mounted: t, contentElement: p(e == null ? void 0 : e.contentElement, null), disclosureElement: p(e == null ? void 0 : e.disclosureElement, null) }, s = te(r, o); return y( s, () => A(s, ["animated", "animating"], (a) => { a.animated || s.setState("animating", !1); }) ), y( s, () => ne(s, ["open"], () => { s.getState().animated && s.setState("animating", !0); }) ), y( s, () => A(s, ["open", "animating"], (a) => { s.setState("mounted", a.open || a.animating); }) ), se(ae({}, s), { disclosure: n.disclosure, setOpen: (a) => s.setState("open", a), show: () => s.setState("open", !0), hide: () => s.setState("open", !1), toggle: () => s.setState("open", (a) => !a), stopAnimation: () => s.setState("animating", !1), setContentElement: (a) => s.setState("contentElement", a), setDisclosureElement: (a) => s.setState("disclosureElement", a) }); } function xe(n, o, e) { return re(o, [e.store, e.disclosure]), P(n, e, "open", "setOpen"), P(n, e, "mounted", "setMounted"), P(n, e, "animated"), Object.assign(n, { disclosure: e.disclosure }); } function He(n = {}) { const [o, e] = oe(Ce, n); return xe(o, e, n); } var b = T(), N = b.useProviderContext, ge = b.ContextProvider, Ee = b.ScopedContextProvider, D = T( [ge], [Ee] ), Fe = D.useScopedContext, Ie = D.useProviderContext, Me = D.ContextProvider, ye = D.ScopedContextProvider, Ne = I(void 0), $e = I(void 0), Pe = "div"; function w(n, o) { const e = setTimeout(o, n); return () => clearTimeout(e); } function _e(n) { let o = requestAnimationFrame(() => { o = requestAnimationFrame(n); }); return () => cancelAnimationFrame(o); } function V(...n) { return n.join(", ").split(", ").reduce((o, e) => { const t = e.endsWith("ms") ? 1 : 1e3, i = Number.parseFloat(e || "0s") * t; return i > o ? i : o; }, 0); } function be(n, o, e) { return !e && o !== !1 && (!n || !!o); } var he = ie(function(o) { var e = o, { store: t, alwaysVisible: i } = e, r = F(e, ["store", "alwaysVisible"]); const s = N(); t = t || s, le( t, process.env.NODE_ENV !== "production" && "DisclosureContent must receive a `store` prop or be wrapped in a DisclosureProvider component." ); const a = ve(null), f = ce(r.id), [l, h] = pe(null), c = t.useState("open"), C = t.useState("mounted"), d = t.useState("animated"), m = t.useState("contentElement"), x = R(t.disclosure, "contentElement"); S(() => { a.current && (t == null || t.setContentElement(a.current)); }, [t]), S(() => { let u; return t == null || t.setState("animated", (v) => (u = v, !0)), () => { u !== void 0 && (t == null || t.setState("animated", u)); }; }, [t]), S(() => { if (d) { if (!(m != null && m.isConnected)) { h(null); return; } return _e(() => { h(c ? "enter" : C ? "leave" : null); }); } }, [d, m, c, C]), S(() => { if (!t || !d || !l || !m) return; const u = () => t == null ? void 0 : t.setState("animating", !1), v = () => De.flushSync(u); if (l === "leave" && c || l === "enter" && !c) return; if (typeof d == "number") return w(d, v); const { transitionDuration: k, animationDuration: q, transitionDelay: U, animationDelay: W } = getComputedStyle(m), { transitionDuration: B = "0", animationDuration: G = "0", transitionDelay: L = "0", animationDelay: z = "0" } = x ? getComputedStyle(x) : {}, J = V( U, W, L, z ), K = V( k, q, B, G ), j = J + K; if (!j) { l === "enter" && t.setState("animated", !1), u(); return; } const Q = 1e3 / 60, X = Math.max(j - Q, 0); return w(X, v); }, [t, d, m, x, c, l]), r = de( r, (u) => /* @__PURE__ */ M.jsx(ye, { value: t, children: u }), [t] ); const g = be(C, r.hidden, i), E = r.style, $ = Se(() => g ? O(_({}, E), { display: "none" }) : E, [g, E]); return r = O(_({ id: f, "data-open": c || void 0, "data-enter": l === "enter" || void 0, "data-leave": l === "leave" || void 0, hidden: g }, r), { ref: me(f ? t.setContentElement : null, a, r.ref), style: $ }), fe(r); }), je = H(function(o) { const e = he(o); return ue(Pe, e); }), ke = H(function(o) { var e = o, { unmountOnHide: t } = e, i = F(e, [ "unmountOnHide" ]); const r = N(), s = i.store || r; return R( s, (f) => !t || (f == null ? void 0 : f.mounted) ) === !1 ? null : /* @__PURE__ */ M.jsx(je, _({}, i)); }); export { ye as D, Ie as a, Fe as b, Me as c, ke as d, He as e, he as f, Ce as g, xe as h, be as i, Ne as j, $e as k, N as u };