@clubmed/trident-ui
Version:
Shared ClubMed React UI components
50 lines (49 loc) • 1.26 kB
JavaScript
import { jsx as I } from "react/jsx-runtime";
import { useId as N, Children as v, isValidElement as g, cloneElement as h } from "react";
import { useValue as k } from "../../../hooks/useValue.js";
import { c as E } from "../../../chunks/index.js";
function q(m) {
const i = N(), {
id: r = i,
name: n = r,
children: u,
value: c,
defaultValue: p,
onChange: d,
disabled: f,
readOnly: V,
tabIndex: b = 0,
...s
} = m, { value: a, setValue: o } = k({
name: n,
initialValue: c,
formatter(e) {
return e !== void 0 ? [].concat(e) : e;
},
defaultValue: p || [],
onChange: d
});
return /* @__PURE__ */ I("div", { ...s, className: s.className, role: "listbox", children: v.map(u, (e, l) => {
if (g(e)) {
const t = e.props.value;
return h(e, {
...e.props,
name: n,
id: `${r}-${l}`,
disabled: f,
readOnly: V,
tabIndex: b + l + 1,
className: E(e.props.className || "mt-8 first:mt-0"),
checked: a.includes(t),
onChange($, x) {
o(x === null ? a.filter((C) => C !== t) : a.concat(t));
}
});
}
return e;
}) });
}
export {
q as Checkboxes
};
//# sourceMappingURL=Checkboxes.js.map