function radio(config = {}) {
let {
value: formValue,
title,
description,
submit,
options,
disabled
} = Array.isArray(config) ? { options: config } : config;
options = options.map(o =>
typeof o === "string" ? { value: o, label: o } : o
);
const form = input({
type: "radio",
title,
description,
submit,
getValue: input => {
if (input.checked) return input.value;
const checked = Array.prototype.find.call(input, radio => radio.checked);
return checked ? checked.value : undefined;
},
form: html`
<form>
${options.map(({ value, label }, i) => {
const input = html`<input type=radio name=input ${
value === formValue ? "checked" : ""
} style="vertical-align: top; ${
i === 0 ? `margin-left: 1px;` : ``
}" />`;
input.setAttribute("value", value);
if (disabled) input.setAttribute("value", disabled);
const tag = html`
<label style="display: inline-block; margin: 5px 10px 3px 0; font-size: 0.85em;">
${input}
${label}
</label>`;
return tag;
})}
</form>
`
});
form.output.remove();
return form;
}