2016-05-02 14:50:50 +05:30
|
|
|
import React, { PropTypes } from 'react';
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import styles from './form.scss';
|
2016-05-02 14:50:50 +05:30
|
|
|
import FormInputComponent from './FormInputComponent';
|
2016-05-02 12:45:42 +05:30
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
export default class Checkbox extends FormInputComponent {
|
2016-05-02 12:45:42 +05:30
|
|
|
static displayName = 'Checkbox';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
color: PropTypes.oneOf(['green', 'blue', 'red']),
|
|
|
|
skin: PropTypes.oneOf(['dark', 'light']),
|
|
|
|
label: PropTypes.oneOfType([
|
|
|
|
PropTypes.shape({
|
|
|
|
id: PropTypes.string
|
|
|
|
}),
|
|
|
|
PropTypes.string
|
|
|
|
]).isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let { label, color = 'green', skin = 'dark' } = this.props;
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
label = this.formatMessage(label);
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames(styles[`${color}CheckboxRow`], styles[`${skin}CheckboxRow`])}>
|
|
|
|
<label className={styles.checkboxContainer}>
|
|
|
|
<input ref={this.setEl} className={styles.checkboxInput} type="checkbox" {...this.props} />
|
|
|
|
<div className={styles.checkbox} />
|
|
|
|
{label}
|
|
|
|
</label>
|
2016-05-02 14:50:50 +05:30
|
|
|
{this.renderError()}
|
2016-05-02 12:45:42 +05:30
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.el.checked ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
this.el.focus();
|
|
|
|
}
|
|
|
|
}
|