UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

52 lines (51 loc) 1.18 kB
import { jsx as o, Fragment as k } from "react/jsx-runtime"; import { S as G } from "../../index-B_6_jmOO.js"; import { useState as R, useCallback as T } from "react"; import { cn as r } from "../../utils/index.js"; import { Radio as b } from "../Radio/Radio.js"; import { radioGroupVariants as j } from "./RadioGroup.variants.js"; import { useTheme as F } from "../../contexts/theme.hook.js"; const E = ({ asChild: e, className: s, defaultChecked: c, name: i, options: p, theme: d, wrapperClassName: f, direction: a, onValueChange: m }) => { const n = e ? G : "div", { theme: S } = F(), [h, l] = R( () => c ), x = T( (t) => { l(t), m == null || m(t); }, [m] ); return /* @__PURE__ */ o( n, { className: r( j({ className: f, direction: a }) ), children: /* @__PURE__ */ o(k, { children: p.map(({ value: t, ...N }) => /* @__PURE__ */ o( b, { value: t, theme: d ?? S, name: i, className: r(s), checked: h === t, onChange: () => x(t), ...N }, t )) }) } ); }; export { E as RadioGroup };