Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mithril(msx) radio button sample.
/**
* ラジオボタンを生成する
* @param {[type]} args: {value: string; label: string }[] [description]
* @param {[type]} name: string [description]
* @param {[type]} currentValue: string [description]
* @param {[type]} callback: (value:string)=>void [description]
* @return {[type]} [description]
*/
export function radios(args: { value: string; label: string }[], name: string, currentValue: string, callback: (value: string) => void) {
if (args.length === 0) {
return;
}
return <ul>
{args.map(arg => {
let id = name + '-' + arg.value
return <li>
<label class="c-radio" for={id}>
<input
id={id}
type="radio"
name={name}
onclick={m.withAttr('value', callback) }
checked={currentValue === arg.value}
value={arg.value}
/>
<span>{arg.label}</span>
</label>
</li>
}) }
</ul>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.