-
-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathCheckboxListItem.jsx
More file actions
41 lines (33 loc) · 966 Bytes
/
CheckboxListItem.jsx
File metadata and controls
41 lines (33 loc) · 966 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
38
39
40
41
import { Component } from "preact";
import PropTypes from "prop-types";
import Checkbox from "./Checkbox.jsx";
import * as styles from "./CheckboxList.css";
import CheckboxList from "./CheckboxList.jsx";
import { ViewerDataItemType } from "./types.js";
export default class CheckboxListItem extends Component {
static propTypes = {
item: PropTypes.oneOfType([ViewerDataItemType, PropTypes.symbol])
.isRequired,
onChange: PropTypes.func.isRequired,
children: PropTypes.func,
};
render() {
return (
<div className={styles.item}>
<Checkbox {...this.props} onChange={this.handleChange}>
{this.renderLabel()}
</Checkbox>
</div>
);
}
renderLabel() {
const { children, item } = this.props;
if (children) {
return children(item);
}
return item === CheckboxList.ALL_ITEM ? "All" : item.label;
}
handleChange = () => {
this.props.onChange(this.props.item);
};
}