UNPKG

welcome-ui

Version:

Customizable design system with react, typescript, tailwindcss and ariakit.

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