import React from 'react'; import TableHead from './head'; import TableRow from './row'; import style from './style'; class Table extends React.Component { static propTypes = { className: React.PropTypes.string, heading: React.PropTypes.bool, model: React.PropTypes.object, onChange: React.PropTypes.func, onSelect: React.PropTypes.func, selected: React.PropTypes.array, source: React.PropTypes.array }; static defaultProps = { className: '', heading: true, selected: [], source: [] }; handleFullSelect = () => { if (this.props.onSelect) { const {source, selected} = this.props; const newSelected = source.length === selected.length ? [] : source.map((i, idx) => idx); this.props.onSelect(newSelected); } }; handleRowSelect = (index) => { if (this.props.onSelect) { const position = this.props.selected.indexOf(index); const newSelected = [...this.props.selected]; if (position !== -1) newSelected.splice(position, 1); else newSelected.push(index); this.props.onSelect(newSelected); } }; handleRowChange = (index, key, value) => { if (this.props.onChange) { this.props.onChange(index, key, value); } }; renderHead () { if (this.props.heading) { const {model, selected, source} = this.props; const isSelected = selected.length === source.length; return ; } } renderBody () { const rows = this.props.source.map((data, idx) => { return ( ); }); return {rows}; } render () { let className = style.root; if (this.props.className) className += ` ${this.props.className}`; return ( { this.renderHead() } { this.renderBody() }
); } } export default Table;