2015-10-11 20:07:09 +03:00
|
|
|
import React from 'react';
|
2015-11-28 21:54:45 +03:00
|
|
|
import ClassNames from 'classnames';
|
2015-12-07 03:40:59 +03:00
|
|
|
import Radio from './Radio';
|
2015-10-06 20:40:47 +03:00
|
|
|
import style from './style';
|
|
|
|
|
2015-10-22 02:31:17 +03:00
|
|
|
class RadioButton extends React.Component {
|
2015-10-20 08:40:51 +03:00
|
|
|
static propTypes = {
|
2015-10-06 20:40:47 +03:00
|
|
|
checked: React.PropTypes.bool,
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
disabled: React.PropTypes.bool,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
onBlur: React.PropTypes.func,
|
|
|
|
onChange: React.PropTypes.func,
|
|
|
|
onFocus: React.PropTypes.func,
|
|
|
|
value: React.PropTypes.any
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-10-06 20:40:47 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
|
|
|
checked: false,
|
|
|
|
className: '',
|
|
|
|
disabled: false
|
|
|
|
};
|
2015-10-06 20:40:47 +03:00
|
|
|
|
2015-11-07 05:36:51 +03:00
|
|
|
handleClick = (event) => {
|
2015-12-07 03:40:59 +03:00
|
|
|
const {checked, disabled, onChange} = this.props;
|
|
|
|
if (event.pageX !== 0 && event.pageY !== 0) this.blur();
|
|
|
|
if (!disabled && !checked && onChange) onChange(event, this);
|
2015-11-07 05:36:51 +03:00
|
|
|
};
|
|
|
|
|
2015-11-22 23:41:28 +03:00
|
|
|
blur () {
|
|
|
|
this.refs.input.blur();
|
|
|
|
}
|
|
|
|
|
|
|
|
focus () {
|
|
|
|
this.refs.input.focus();
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:40:47 +03:00
|
|
|
render () {
|
2015-12-07 03:40:59 +03:00
|
|
|
const className = ClassNames(style[this.props.disabled ? 'disabled' : 'field'], this.props.className);
|
|
|
|
const { onChange, ...others } = this.props;
|
2015-10-06 20:40:47 +03:00
|
|
|
|
|
|
|
return (
|
2016-02-08 21:43:14 +03:00
|
|
|
<label data-react-toolbox='radio-button' className={className}>
|
2015-10-06 20:40:47 +03:00
|
|
|
<input
|
2015-12-07 03:40:59 +03:00
|
|
|
{...others}
|
2015-10-06 20:40:47 +03:00
|
|
|
className={style.input}
|
2015-12-07 03:40:59 +03:00
|
|
|
onClick={this.handleClick}
|
2015-12-07 04:14:10 +03:00
|
|
|
readOnly
|
2015-12-07 03:40:59 +03:00
|
|
|
ref='input'
|
2015-11-07 05:36:51 +03:00
|
|
|
type='radio'
|
2015-10-06 20:40:47 +03:00
|
|
|
/>
|
2015-12-07 03:40:59 +03:00
|
|
|
<Radio checked={this.props.checked} disabled={this.props.disabled}/>
|
2015-11-22 23:41:28 +03:00
|
|
|
{this.props.label ? <span className={style.text}>{this.props.label}</span> : null}
|
2015-10-06 20:40:47 +03:00
|
|
|
</label>
|
|
|
|
);
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-10-21 13:25:07 +03:00
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
|
|
|
|
export default RadioButton;
|