import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Table, Pagination } from 'src'
import ConfigItem from './config-item'
import Headers from './headers'
import Rows from './rows'
import styled from 'styled-components'
const DataTableStyled = styled.div`
position: relative;
.tableHeader{
padding: 0;
}
.tableFooter{
height: 80px;
display: flex;
align-items: center;
position: relative;
}
.pageCount{
position: absolute;
right: 0;
> span{
color:#000;
font-size: 14px;
}
}
`
class DataTable extends Component {
state = {
columns: []
}
componentDidMount () {
this.normalizeData(this.props)
}
componentWillReceiveProps (props) {
this.normalizeData(props)
}
normalizeData = ({ columns }) => {
this.setState({
columns: columns.map(item => new ConfigItem(item))
})
}
render () {
const {
paintBorderRow,
data = [],
isLoading,
onClickPage,
onClickNextPage,
onClickPreviousPage,
page,
totalCount,
countPages,
renderEmpty
} = this.props
const { columns } = this.state
return (
<DataTableStyled>
<Table>
<Headers columns={columns} />
<Rows
list={data}
columns={columns}
paintBorderRow={paintBorderRow}
/>
</Table>
<div className="tableFooter">
<Pagination
onClickPage={onClickPage}
onClickNextPage={onClickNextPage}
onClickPreviousPage={onClickPreviousPage}
total={countPages}
activePage={page}
/>
<div className="pageCount">
<span>Total de registros: {totalCount}</span>
</div>
</div>
{/* <If test={data.length === 0 && !isLoading && renderEmpty}>{renderEmpty}</If> */}
</DataTableStyled>
)
}
}
DataTable.propTypes = {
blankslate: PropTypes.node,
paintBorderRow: PropTypes.object,
columns: PropTypes.array,
isLoading: PropTypes.bool,
onClickPage: PropTypes.func,
onClickNextPage: PropTypes.func,
onClickPreviousPage: PropTypes.func,
page: PropTypes.number,
totalCount: PropTypes.number,
countPages: PropTypes.number,
renderEmpty: PropTypes.node
}
export { DataTable }
|