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