UNPKG

welcome-ui

Version:

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

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