function radioGroup(labels, options = {}) {
let { names = [...labels] } = options;
let {
value = names[0],
draw = null,
size = 30,
style = "",
buttonStyle = "",
columns = 1000
} = options;
let buttons = [...labels].map((t, i) =>
checkButton(t, {
size,
draw,
style: buttonStyle,
value: value == names[i],
name: names[i]
})
);
let group = htl.html`<div style=${style}>`;
group.style.width = "fit-content";
let table = htl.html`<table>`;
table.style.width = "fit-content";
table.style.margin = 0;
const styleValue = () => {
buttons.forEach((b, i) => b.setValue(names[i] == group.value));
};
group.append(table);
const n = buttons.length;
let row = null;
buttons.forEach((b, i) => {
if (i % columns == 0) {
row = htl.html`<tr>`;
table.append(row);
}
row.append(htl.html`${b}`);
});
group.setValue = (v) => {
group.value = value = v;
styleValue();
};
buttons.forEach((b, i) => {
b.oninput = () => {
group.setValue(names[i]);
group.dispatchEvent(new CustomEvent("input"));
};
});
group.value = value;
return group;
}