bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/checkbox/component.jsx

76 lines
1.9 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
2017-01-27 23:41:11 +08:00
import Icon from '../icon/component';
2018-01-08 14:17:18 +08:00
import { styles } from './styles';
const propTypes = {
disabled: PropTypes.bool,
checked: PropTypes.bool,
onChange: PropTypes.func.isRequired,
className: PropTypes.string,
ariaLabelledBy: PropTypes.string,
ariaLabel: PropTypes.string,
ariaDescribedBy: PropTypes.string,
ariaDesc: PropTypes.string,
};
const defaultProps = {
disabled: false,
checked: false,
className: null,
ariaLabelledBy: null,
ariaLabel: null,
ariaDescribedBy: null,
ariaDesc: null,
};
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() {
if (this.props.disabled) return;
2017-02-16 02:49:40 +08:00
this.onChange();
2017-01-27 23:41:11 +08:00
}
render() {
const {
ariaLabel, ariaLabelledBy, ariaDesc, ariaDescribedBy,
className, checked, disabled,
} = this.props;
2017-04-25 10:08:18 +08:00
2017-01-27 23:41:11 +08:00
return (
<div className={cx({
[styles.disabled]: !!disabled,
2018-12-06 01:42:31 +08:00
}, className)}
>
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}
checked={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}
disabled={disabled}
2017-06-03 03:25:02 +08:00
/>
<div role="presentation" onClick={this.handleChange}>
2018-12-06 01:42:31 +08:00
{ checked
? <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>
);
}
}
Checkbox.propTypes = propTypes;
Checkbox.defaultProps = defaultProps;