Skip to content

Instantly share code, notes, and snippets.

@faust45
Created October 22, 2014 17:09
Show Gist options
  • Select an option

  • Save faust45/d92f423d896b461efd78 to your computer and use it in GitHub Desktop.

Select an option

Save faust45/d92f423d896b461efd78 to your computer and use it in GitHub Desktop.
var SwitchGroup = React.createClass({
componentDidMount: function() {
//var onChange = this.props.onChange;
// var el = this.getDOMNode().querySelectorAll("input[type=radio]");
//
// $(el).on("change", function(e) {
// if(onChange) {
// onChange(e);
// }
// });
},
render: function() {
var selected = this.props.selected;
var name = uuid();
var onChange = function() { console.log("handle change radio") };
var buttons = _.map(this.props.options, function(data) {
var label = data[0], value = data[1];
var classes = cx({
'btn btn-default': true,
'active': (value == selected),
});
return (
<label className={classes}>
<input type="radio" value={value} name={name} onChange={onChange} />{label}
</label>
)
});
return (
<div className="btn-group" data-toggle="buttons">
{buttons}
</div>
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment