Skip to content

Instantly share code, notes, and snippets.

@thebigredgeek
Created December 7, 2016 05:05
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 thebigredgeek/87c1d6bcdb7e32cac2a4b99746cf67eb to your computer and use it in GitHub Desktop.
Save thebigredgeek/87c1d6bcdb7e32cac2a4b99746cf67eb to your computer and use it in GitHub Desktop.
broken radio
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