frejya / js /ui /forms.js
wuosyn's picture
Sync from wuosyn/frejya via hub-sync
d160eca verified
Raw History Blame Contribute Delete
1.15 kB
// Small form pieces shared by the sheets.
import { h } from './dom.js';
export const field = (label, control, hint) => h('label', { class: 'field' }, h('span', { class: 'field__label' }, label), control, hint && h('span', { class: 'field__hint' }, hint));
export function switchRow(label, hint, checked, onChange) {
const input = h('input', { type: 'checkbox', checked, onchange: () => onChange(input.checked) });
return h('label', { class: 'switch' }, input, h('span', { class: 'switch__track' }), h('span', { class: 'switch__text' }, label, hint && h('small', {}, hint)));
}
export function choice(name, options, current, onChange, row = false) {
return h('div', { class: `choice${row ? ' choice--row' : ''}`, role: 'radiogroup' }, options.map((o) => {
const input = h('input', { type: 'radio', name, value: o.value, checked: o.value === current, onchange: () => onChange(o.value) });
return h('label', { class: 'choice__item' }, input, h('span', { class: 'choice__card' },
h('span', { class: 'choice__top' }, o.title, o.tag && h('small', {}, o.tag)),
o.blurb && h('span', { class: 'choice__blurb' }, o.blurb)));
}));
}