UNPKG

welcome-ui

Version:

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

90 lines (89 loc) 2.87 kB
"use client"; import { u as $ } from "./2W3RN7C5-bkX-rIa3.js"; import { createContext as w, useState as D, useRef as H, useEffect as O } from "react"; import { e as V, f as W, c as q, b as z, _ as B, N as G, A as I, $ as J, u as P, x as K, d as L, p as Q, a as p, r as X } from "./OE2EFRVA-C3721cM3.js"; import { u as Y } from "./RTNCFSKZ-P4icqVD0.js"; import { jsx as Z } from "react/jsx-runtime"; var ee = w(!1), re = V(), te = re.useContext, _ = "input"; function y(t, a) { a ? t.indeterminate = !0 : t.indeterminate && (t.indeterminate = !1); } function ne(t, a) { return t === "input" && (!a || a === "checkbox"); } function A(t) { return Array.isArray(t) ? t.toString() : t; } var oe = q( function(a) { var f = a, { store: i, name: h, value: n, checked: v, defaultChecked: C } = f, r = B(f, [ "store", "name", "value", "checked", "defaultChecked" ]); const T = te(); i = i || T; const [E, N] = D(C ?? !1), u = Y(i, (e) => { if (v !== void 0) return v; if ((e == null ? void 0 : e.value) === void 0) return E; if (n != null) { if (Array.isArray(e.value)) { const d = A(n); return e.value.includes(d); } return e.value === n; } return Array.isArray(e.value) ? !1 : typeof e.value == "boolean" ? e.value : !1; }), k = H(null), S = G(k, _), o = ne(S, r.type), m = u ? u === "mixed" : void 0, s = u === "mixed" ? !1 : u, R = I(r), [U, j] = J(); O(() => { const e = k.current; e && (y(e, m), !o && (e.checked = s, h !== void 0 && (e.name = h), n !== void 0 && (e.value = `${n}`))); }, [U, m, o, s, h, n]); const x = r.onChange, b = P((e) => { if (R) { e.stopPropagation(), e.preventDefault(); return; } if (y(e.currentTarget, m), o || (e.currentTarget.checked = !e.currentTarget.checked, j()), x == null || x(e), e.defaultPrevented) return; const d = e.currentTarget.checked; N(d), i == null || i.setValue((c) => { if (n == null) return d; const l = A(n); return Array.isArray(c) ? d ? c.includes(l) ? c : [...c, l] : c.filter((M) => M !== l) : c === l ? !1 : l; }); }), g = r.onClick, F = P((e) => { g == null || g(e), !e.defaultPrevented && (o || b(e)); }); return r = K( r, (e) => /* @__PURE__ */ Z(ee.Provider, { value: s, children: e }), [s] ), r = L(p({ role: o ? void 0 : "checkbox", type: o ? "checkbox" : void 0, "aria-checked": u }, r), { ref: Q(k, r.ref), onChange: b, onClick: F }), r = $(p({ clickOnEnter: !o }, r)), X(p({ name: o ? h : void 0, value: o ? n : void 0, checked: s }, r)); } ), de = W(function(a) { const f = oe(a); return z(_, f); }); export { de as C };