ayongui
Version:
136 lines (135 loc) • 2.82 kB
JavaScript
import { j as o } from "../../../react/jsx-runtime.mjs";
import f, { useState as h, useEffect as b } from "react";
import N from "../button/index.mjs";
import n from "./index.module.less.mjs";
const C = ({
value: s = !1,
className: m,
disabled: e,
children: a,
isGroup: p = !1,
onChange: r = () => {
}
}) => {
const [l, u] = h(s), c = `${n.label} ${m}`, i = (t) => {
r(!l), u(() => !l);
};
return b(() => {
u(s);
}, [s]), p ? /* @__PURE__ */ o.jsxs(
"label",
{
className: `${c} ${n.group} ${e ? n.disabled : ""}`,
children: [
/* @__PURE__ */ o.jsx(
"input",
{
type: "radio",
className: n.customRadio,
value: s,
checked: s,
onChange: r,
disabled: e
}
),
a
]
}
) : /* @__PURE__ */ o.jsxs("label", { className: `${c} ${e ? n.disabled : ""}`, children: [
/* @__PURE__ */ o.jsx(
"input",
{
type: "radio",
value: s,
className: n.customRadio,
checked: l,
onClick: i,
onChange: () => {
},
disabled: e
}
),
a
] });
}, j = ({
size: s,
index: m,
value: e,
isLast: a,
disabled: p = !1,
children: r,
className: l,
isGroup: u = !1,
onChange: c = () => {
}
}) => {
const [i, t] = h(e), d = `${n.label} ${l}`, y = (k) => {
c(!i), t(() => !i);
}, R = () => {
c(e);
}, $ = () => {
if (!m)
return n.buttonFirst;
if (a)
return n.buttonLast;
if (!a)
return n.buttonRight0;
};
return u ? /* @__PURE__ */ o.jsx("label", { className: d, children: /* @__PURE__ */ o.jsxs(
N,
{
disabled: p,
className: $(),
type: e ? "primary" : "default",
value: e,
size: s,
onClick: R,
children: [
" ",
r
]
}
) }) : /* @__PURE__ */ o.jsx("label", { className: d, children: /* @__PURE__ */ o.jsxs(
N,
{
disabled: p,
type: i ? "primary" : "default",
onClick: y,
size: s,
value: e,
children: [
" ",
r
]
}
) });
}, x = ({
size: s,
children: m,
style: e,
disabled: a,
value: p,
onChange: r = () => {
}
}) => {
const [l, u] = h(p), c = f.Children.count(m) - 1, i = (t) => {
r(t), u(t);
};
return /* @__PURE__ */ o.jsx("div", { style: e, children: f.Children.map(m, (t, d) => f.isValidElement(t) ? f.cloneElement(t, {
value: l === t.props.value,
disabled: t.props.disabled || a,
isGroup: !0,
onChange: () => i(t.props.value),
index: d,
size: s,
isLast: c === d
}) : null) });
};
x.displayName = "RadioGroup";
j.displayName = "Button";
C.Group = x;
C.Button = j;
C.displayName = "Radio";
export {
C as default
};