forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableHead.js
More file actions
45 lines (40 loc) · 1.05 KB
/
TableHead.js
File metadata and controls
45 lines (40 loc) · 1.05 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
import React from 'react';
import Checkbox from '../checkbox';
import style from './style';
const TableHead = ({model, onSelect, selectable, multiSelectable, selected}) => {
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={style.selectable}>
<Checkbox onChange={onSelect} checked={selected}/>
</th>
);
} else if (selectable) {
selectCell = (
<th key='select' className={style.selectable}></th>
);
}
return (
<thead>
<tr>{[selectCell, ...contentCells]}</tr>
</thead>
);
};
TableHead.propTypes = {
className: React.PropTypes.string,
model: React.PropTypes.object,
onSelect: React.PropTypes.func,
selectable: React.PropTypes.bool,
multiSelectable: React.PropTypes.bool,
selected: React.PropTypes.bool
};
TableHead.defaultProps = {
className: '',
model: {},
selected: false
};
export default TableHead;