react-toolbox/components/table/components/head.jsx

51 lines
1.0 KiB
React
Raw Normal View History

2015-11-03 09:23:23 +03:00
import React from 'react';
import Checkbox from '../../checkbox';
import style from './style';
2015-11-03 09:23:23 +03:00
class Head extends React.Component {
2015-11-03 09:23:23 +03:00
static propTypes = {
className: React.PropTypes.string,
model: React.PropTypes.object,
onSelect: React.PropTypes.func,
selected: React.PropTypes.bool
};
2015-11-03 09:23:23 +03:00
static defaultProps = {
className: '',
model: {},
selected: false
};
handleSelectChange = (event) => {
this.props.onSelect(event);
};
renderCellSelectable () {
if (this.props.onSelect) {
return (
<th className={style.selectable}>
<Checkbox onChange={this.handleSelectChange} checked={this.props.selected}/>
</th>
2015-11-04 15:43:32 +03:00
);
}
2015-11-04 15:43:32 +03:00
}
render () {
return (
<thead data-component-table-head className={this.props.className}>
<tr>
{ this.renderCellSelectable() }
{
Object.keys(this.props.model).map((key) => {
2015-11-04 15:43:32 +03:00
return (<th key={key}>{key}</th>);
})
}
</tr>
</thead>
2015-11-04 15:43:32 +03:00
);
}
}
2015-11-03 09:23:23 +03:00
export default Head;