forked from react-toolbox/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTableHead.js
More file actions
50 lines (44 loc) · 1.17 KB
/
TableHead.js
File metadata and controls
50 lines (44 loc) · 1.17 KB
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
42
43
44
45
46
47
48
49
50
import React, { PropTypes } from 'react';
const factory = (Checkbox) => {
const TableHead = ({model, onSelect, selectable, multiSelectable, selected, theme}) => {
let selectCell;
const contentCells = Object.keys(model).map((key) => {
const name = model[key].title || key;
return <th key={key}>{name}</th>;
});
if (selectable && multiSelectable) {
selectCell = (
<th key='select' className={theme.selectable}>
<Checkbox onChange={onSelect} checked={selected}/>
</th>
);
} else if (selectable) {
selectCell = (
<th key='select' className={theme.selectable}></th>
);
}
return (
<thead>
<tr>{[selectCell, ...contentCells]}</tr>
</thead>
);
};
TableHead.propTypes = {
className: PropTypes.string,
model: PropTypes.object,
multiSelectable: PropTypes.bool,
onSelect: PropTypes.func,
selectable: PropTypes.bool,
selected: PropTypes.bool,
theme: PropTypes.shape({
selectable: PropTypes.string
})
};
TableHead.defaultProps = {
className: '',
model: {},
selected: false
};
return TableHead;
};
export default factory;