-
-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathCheckbox.jsx
More file actions
37 lines (29 loc) · 836 Bytes
/
Checkbox.jsx
File metadata and controls
37 lines (29 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cls from "classnames";
import { Component } from "preact";
import PropTypes from "prop-types";
import * as styles from "./Checkbox.css";
export default class Checkbox extends Component {
static propTypes = {
className: PropTypes.string,
checked: PropTypes.bool,
onChange: PropTypes.func.isRequired,
children: PropTypes.node,
};
render() {
const { checked, className, children } = this.props;
return (
<label className={cls(styles.label, className)}>
<input
className={styles.checkbox}
type="checkbox"
checked={checked}
onChange={this.handleChange}
/>
{children && <span className={styles.itemText}>{children}</span>}
</label>
);
}
handleChange = () => {
this.props.onChange(!this.props.checked);
};
}