Created
December 7, 2016 05:05
-
-
Save thebigredgeek/87c1d6bcdb7e32cac2a4b99746cf67eb to your computer and use it in GitHub Desktop.
broken radio
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
import React, { PropTypes } from 'react'; | |
import classNames from 'classnames'; | |
import { autobind } from 'core-decorators'; | |
import withStyles from 'isomorph-style-loader/lib/withStyles'; | |
import PureComponent from '../../components/common/pure'; | |
import style from './radio.css'; | |
@withStyles(style) | |
export default class Radio extends PureComponent { | |
static propTypes = { | |
onChange: PropTypes.func.isRequired, | |
checked: PropTypes.bool.isRequired, | |
text: PropTypes.string.isRequired, | |
value: PropTypes.any.isRequired, | |
name: PropTypes.string.isRequired, | |
className: PropTypes.string | |
}; | |
static defaultProps = { | |
onChange: d => D, | |
checked: false, | |
text: '', | |
value: '', | |
className: '' | |
}; | |
constructor (props, context) { | |
super(props, context); | |
} | |
@autobind | |
_onChange (e) { | |
e.preventDefault(); | |
const value = this.props.value; | |
const checked = !this.props.checked; | |
this.props.onChange({ | |
value, | |
checked | |
}); | |
} | |
render () { | |
console.log(this.props.value, this.props.checked); | |
return ( | |
<label className={classNames('radio-inline', style.radio, this.props.className)}> | |
<input | |
type='radio' | |
name={this.props.name} | |
value={this.props.value} | |
checked={this.props.checked} | |
onChange={this._onChange} | |
/> | |
<span>{this.props.text}</span> | |
</label> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment