2017-04-17 17:14:17 +03:00
|
|
|
import React, { Component, cloneElement } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-01-05 04:42:18 +03:00
|
|
|
import { themr } from 'react-css-themr';
|
2017-01-26 20:05:32 +03:00
|
|
|
import { TABLE } from '../identifiers';
|
|
|
|
import InjectCheckbox from '../checkbox/Checkbox';
|
|
|
|
import InjectTableCell from './TableCell';
|
2015-11-14 12:26:50 +03:00
|
|
|
|
2017-01-05 04:42:18 +03:00
|
|
|
const factory = (Checkbox, TableCell) => {
|
|
|
|
class TableHead extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
className: PropTypes.string,
|
|
|
|
displaySelect: PropTypes.bool,
|
|
|
|
multiSelectable: PropTypes.bool,
|
|
|
|
onSelect: PropTypes.func,
|
|
|
|
selectable: PropTypes.bool,
|
|
|
|
selected: PropTypes.bool,
|
|
|
|
theme: PropTypes.shape({
|
2017-01-26 20:05:32 +03:00
|
|
|
checkboxCell: PropTypes.string,
|
|
|
|
}),
|
2017-01-05 04:42:18 +03:00
|
|
|
}
|
2015-11-14 12:26:50 +03:00
|
|
|
|
2017-01-05 04:42:18 +03:00
|
|
|
static defaultProps = {
|
2017-01-26 20:05:32 +03:00
|
|
|
displaySelect: true,
|
2016-05-30 07:59:44 +03:00
|
|
|
}
|
2015-11-14 12:26:50 +03:00
|
|
|
|
2017-01-05 04:42:18 +03:00
|
|
|
handleSelect = (value, event) => {
|
|
|
|
this.props.onSelect(value, event);
|
|
|
|
};
|
2016-05-30 07:59:44 +03:00
|
|
|
|
2017-01-26 20:05:32 +03:00
|
|
|
render() {
|
2017-01-05 04:42:18 +03:00
|
|
|
const {
|
|
|
|
children,
|
|
|
|
displaySelect,
|
|
|
|
multiSelectable,
|
|
|
|
onSelect, // eslint-disable-line
|
|
|
|
selectable,
|
|
|
|
selected,
|
|
|
|
theme,
|
|
|
|
...other
|
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
<tr {...other}>
|
|
|
|
{selectable && <TableCell className={theme.checkboxCell} tagName="th">
|
|
|
|
{displaySelect && <Checkbox
|
|
|
|
checked={selected}
|
|
|
|
disabled={!multiSelectable}
|
|
|
|
onChange={this.handleSelect}
|
|
|
|
/>}
|
|
|
|
</TableCell>}
|
2017-04-02 15:10:01 +03:00
|
|
|
{React.Children.map(children, (child, index) => {
|
|
|
|
if (!child) return null;
|
|
|
|
return cloneElement(child, {
|
|
|
|
column: index,
|
|
|
|
tagName: 'th',
|
|
|
|
});
|
|
|
|
})}
|
2017-01-05 04:42:18 +03:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-11-14 12:26:50 +03:00
|
|
|
|
2016-05-30 07:59:44 +03:00
|
|
|
return TableHead;
|
2015-11-14 12:26:50 +03:00
|
|
|
};
|
|
|
|
|
2017-01-05 04:42:18 +03:00
|
|
|
const TableHead = factory(InjectCheckbox, InjectTableCell);
|
|
|
|
export default themr(TABLE)(TableHead);
|
|
|
|
export { factory as tableHeadFactory };
|
|
|
|
export { TableHead };
|