Skip to content

Instantly share code, notes, and snippets.

@faust45
Created October 22, 2014 16:31
Show Gist options
  • Select an option

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

Select an option

Save faust45/b00eb93c5cb682b86c16 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) {
console.log("on hange happen");
if(onChange) {
onChange(e);
}
});
},
render: function() {
var selected = this.props.selected;
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} />{label}
</label>
)
});
return (
<div className="btn-group" data-toggle="buttons" onChange={this.handleChange}>
{buttons}
</div>
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment