UNPKG

welcome-ui

Version:

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

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