2015-10-11 20:07:09 +03:00
|
|
|
import React from 'react';
|
2016-05-22 23:18:41 +03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { themr } from 'react-css-themr';
|
2015-12-07 03:40:59 +03:00
|
|
|
import Radio from './Radio';
|
2015-10-06 20:40:47 +03:00
|
|
|
|
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,
|
2016-05-22 23:18:41 +03:00
|
|
|
theme: React.PropTypes.shape({
|
|
|
|
disabled: React.PropTypes.string.isRequired,
|
|
|
|
field: React.PropTypes.string.isRequired,
|
|
|
|
input: React.PropTypes.string.isRequired,
|
|
|
|
text: React.PropTypes.string.isRequired
|
|
|
|
}),
|
2015-10-06 20:40:47 +03:00
|
|
|
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 () {
|
2016-05-22 23:18:41 +03:00
|
|
|
const { className, checked, disabled, label, theme, onChange, ...others } = this.props; // eslint-disable-line
|
|
|
|
const _className = classnames(theme[this.props.disabled ? 'disabled' : 'field'], className);
|
2015-10-06 20:40:47 +03:00
|
|
|
return (
|
2016-05-22 23:18:41 +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}
|
2016-05-22 23:18:41 +03:00
|
|
|
className={theme.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
|
|
|
/>
|
2016-05-22 23:18:41 +03:00
|
|
|
<Radio checked={checked} disabled={disabled}/>
|
|
|
|
{label ? <span className={theme.text}>{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
|
|
|
|
2016-05-22 23:18:41 +03:00
|
|
|
export default themr('ToolboxRadio')(RadioButton);
|