2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-01-27 23:41:11 +08:00
|
|
|
import Icon from '../icon/component';
|
|
|
|
import styles from './styles';
|
2017-09-29 23:35:05 +08:00
|
|
|
import cx from 'classnames';
|
2017-01-27 23:41:11 +08:00
|
|
|
|
|
|
|
export default class Checkbox extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
this.onChange = props.onChange;
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange() {
|
|
|
|
this.onChange();
|
2017-01-27 23:41:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-29 23:35:05 +08:00
|
|
|
const { ariaLabel, ariaLabelledBy, ariaDesc, ariaDescribedBy } = this.props;
|
2017-04-25 10:08:18 +08:00
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
return (
|
2017-09-29 23:35:05 +08:00
|
|
|
<div className={styles.container}>
|
2017-01-27 23:41:11 +08:00
|
|
|
<input
|
2017-06-03 03:25:02 +08:00
|
|
|
type="checkbox"
|
2017-01-27 23:41:11 +08:00
|
|
|
onChange={this.handleChange}
|
2017-09-29 23:35:05 +08:00
|
|
|
checked={this.props.checked}
|
2017-04-25 10:08:18 +08:00
|
|
|
className={styles.input}
|
|
|
|
aria-labelledby={ariaLabelledBy}
|
2017-05-04 04:51:17 +08:00
|
|
|
aria-describedby={ariaDescribedBy}
|
2017-06-03 03:25:02 +08:00
|
|
|
/>
|
2017-09-29 23:35:05 +08:00
|
|
|
<div onClick={this.handleChange}>
|
|
|
|
{ this.props.checked ?
|
2017-06-03 03:25:02 +08:00
|
|
|
<Icon iconName="check" className={cx(styles.icon, styles.checked)} /> :
|
|
|
|
<Icon iconName="circle" className={styles.icon} />
|
2017-02-16 02:49:40 +08:00
|
|
|
}
|
2017-01-27 23:41:11 +08:00
|
|
|
</div>
|
2017-04-25 10:08:18 +08:00
|
|
|
<div id={ariaLabelledBy} hidden>{ariaLabel}</div>
|
|
|
|
<div id={ariaDescribedBy} hidden>{ariaDesc}</div>
|
2017-01-27 23:41:11 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|