welcome-ui
Version:
Customizable design system with react • styled-components • styled-system and ariakit.
85 lines (84 loc) • 2.34 kB
JavaScript
"use client";
import { C as U, a as A, u as T } from "./P2CTZE2T-1n7Xlf8m.mjs";
import { t as j, v as w, f as D, c as H, h as M, _ as O, w as $, j as q, l as z, x as B, b as v, d as G, e as J, g as p, y as K } from "./LVA2YJMS-B8X1PCyC.mjs";
import { u as L } from "./YV4JVR4I-BLeUul5N.mjs";
import { useRef as Q, useEffect as R } from "react";
var m = j(
[A],
[U]
), V = m.useContext, re = m.useProviderContext, ne = m.ScopedContextProvider, k = "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 = H(function(r) {
var d = r, {
store: t,
name: c,
value: i,
checked: C
} = d, o = O(d, [
"store",
"name",
"value",
"checked"
]);
const x = V();
t = t || x;
const a = $(o.id), l = Q(null), s = L(
t,
(e) => C ?? W(i, e == null ? void 0 : e.value)
);
R(() => {
!a || !s || (t == null ? void 0 : t.getState().activeId) === a || t == null || t.setActiveId(a);
}, [t, s, a]);
const P = o.onChange, S = q(l, k), n = X(S, o.type), I = z(o), [_, b] = B();
R(() => {
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, b()), P == null || P(e), !e.defaultPrevented && (t == null || t.setValue(i)));
}), g = o.onClick, F = v((e) => {
g == null || g(e), !e.defaultPrevented && (n || f(e));
}), h = o.onFocus, y = v((e) => {
if (h == null || h(e), e.defaultPrevented || !n || !t) return;
const { moves: E, activeId: N } = t.getState();
E && (a && N !== a || f(e));
});
return o = G(p({
id: a,
role: n ? void 0 : "radio",
type: n ? "radio" : void 0,
"aria-checked": s
}, o), {
ref: J(l, o.ref),
onChange: f,
onClick: F,
onFocus: y
}), o = T(p({
store: t,
clickOnEnter: !n
}, o)), K(p({
name: n ? c : void 0,
value: n ? i : void 0,
checked: s
}, o));
}), ie = w(
D(function(r) {
const d = Y(r);
return M(k, d);
})
);
export {
ie as R,
ne as a,
re as u
};