welcome-ui
Version:
Customizable design system with react, typescript, tailwindcss and ariakit.
83 lines (82 loc) • 2.26 kB
JavaScript
"use client";
import { C as E, a as U, b as y } from "./SBSPVDDI-CW8jwL0u.js";
import { e as T, v as w, f as $, c as j, b as D, _ as H, w as M, N as O, A as q, $ as z, u as v, d as B, p as G, a as p, r as J } from "./OE2EFRVA-C3721cM3.js";
import { u as K } from "./RTNCFSKZ-P4icqVD0.js";
import { useRef as L, useEffect as k } from "react";
var Q = T(
[U],
[E]
), V = Q.useContext, P = "input";
function W(u, r) {
if (r !== void 0)
return u != null && r != null ? r === u : !!r;
}
function X(u, r) {
return u === "input" && (!r || r === "radio");
}
var Y = j(function(r) {
var d = r, {
store: t,
name: c,
value: i,
checked: m
} = d, o = H(d, [
"store",
"name",
"value",
"checked"
]);
const R = V();
t = t || R;
const a = M(o.id), l = L(null), s = K(
t,
(e) => m ?? W(i, e == null ? void 0 : e.value)
);
k(() => {
!a || !s || (t == null ? void 0 : t.getState().activeId) === a || t == null || t.setActiveId(a);
}, [t, s, a]);
const C = o.onChange, x = O(l, P), n = X(x, o.type), I = q(o), [_, S] = z();
k(() => {
const e = l.current;
e && (n || (s !== void 0 && (e.checked = s), c !== void 0 && (e.name = c), i !== void 0 && (e.value = `${i}`)));
}, [_, n, s, c, i]);
const f = v((e) => {
if (I) {
e.preventDefault(), e.stopPropagation();
return;
}
(t == null ? void 0 : t.getState().value) !== i && (n || (e.currentTarget.checked = !0, S()), C == null || C(e), !e.defaultPrevented && (t == null || t.setValue(i)));
}), g = o.onClick, b = v((e) => {
g == null || g(e), !e.defaultPrevented && (n || f(e));
}), h = o.onFocus, F = v((e) => {
if (h == null || h(e), e.defaultPrevented || !n || !t) return;
const { moves: N, activeId: A } = t.getState();
N && (a && A !== a || f(e));
});
return o = B(p({
id: a,
role: n ? void 0 : "radio",
type: n ? "radio" : void 0,
"aria-checked": s
}, o), {
ref: G(l, o.ref),
onChange: f,
onClick: b,
onFocus: F
}), o = y(p({
store: t,
clickOnEnter: !n
}, o)), J(p({
name: n ? c : void 0,
value: n ? i : void 0,
checked: s
}, o));
}), re = w(
$(function(r) {
const d = Y(r);
return D(P, d);
})
);
export {
re as R
};