Skip to content

Instantly share code, notes, and snippets.

@masahirompp
Created February 13, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahirompp/abcfa0045c66bb354545 to your computer and use it in GitHub Desktop.
Save masahirompp/abcfa0045c66bb354545 to your computer and use it in GitHub Desktop.
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