@thi.ng/rdom-components
Version:
Collection of unstyled, customizable components for @thi.ng/rdom
32 lines (31 loc) • 634 B
JavaScript
import { div } from "@thi.ng/hiccup-html/blocks";
import {
label,
radio
} from "@thi.ng/hiccup-html/forms";
import { $input } from "@thi.ng/rdom/event";
const staticRadio = (items, sel, opts) => {
opts = {
label: (x, radio2) => label({ for: String(x) }, String(x), radio2),
value: String,
...opts
};
return div(
{ ...opts.attribs },
...items.map($radio(sel, opts))
);
};
const $radio = (sel, opts) => (x) => {
let v = opts.value(x);
return opts.label(
x,
radio({
value: v,
checked: sel.map((x2) => v === x2),
onchange: $input(sel)
})
);
};
export {
staticRadio
};