Created
February 13, 2016 16:55
-
-
Save masahirompp/abcfa0045c66bb354545 to your computer and use it in GitHub Desktop.
mithril(msx) radio button sample.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ラジオボタンを生成する | |
* @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