adding table head to new table

This commit is contained in:
Alex Windett 2017-01-20 11:51:49 +00:00
parent 5dd5bc9498
commit fb579ac378
3 changed files with 43 additions and 12 deletions

View File

@ -42,6 +42,11 @@ const data = [{
status: 'Active', status: 'Active',
role: 'Owner', role: 'Owner',
key: 1 key: 1
}, {
name: 'Alex',
status: 'Inactive',
role: 'Read Only',
key: 2
}]; }];
storiesOf('Table New', module) storiesOf('Table New', module)

View File

@ -2,16 +2,16 @@
// const composers = require('../../shared/composers'); // const composers = require('../../shared/composers');
const React = require('react'); const React = require('react');
// const Styled = require('styled-components'); const Styled = require('styled-components');
// const { // const {
// remcalc // remcalc
// } = fns; // } = fns;
// const { const {
// default: styled, default: styled,
// css // css
// } = Styled; } = Styled;
// const { // const {
// clearfix // clearfix
@ -36,17 +36,39 @@ const React = require('react');
// } // }
// `; // `;
const TableHeader = (columns) => { const StyledTableHeadItem = styled.td`
${props => `width: ${props.width}`}
`;
const TableHeader = ({
columns
}) => {
const fallBackWidth = `${100 / parseInt(columns.length)}%`;
const titles = columns.map( (column, i) => {
columns.map( (column, i) => {
return ( return (
<td key={i}>{column.title}</td> <StyledTableHeadItem
key={i}
width={column.width || fallBackWidth}
>
{column.title}
</StyledTableHeadItem>
); );
}); });
return ( return (
<thead /> <thead>
<tr>
{titles}
</tr>
</thead>
); );
}; };
TableHeader.propTypes = {
columns: React.PropTypes.object
};
module.exports = TableHeader; module.exports = TableHeader;

View File

@ -20,19 +20,23 @@ const StyledTitle = styled.h3`
text-align: center text-align: center
`; `;
const StyledTable = styled.table`
width: 100%;
`;
const TableContent = ({ const TableContent = ({
columns, columns,
data, data,
hasHeader = false, hasHeader = columns.length >= 1,
hasBody = data.length >= 1, hasBody = data.length >= 1,
width = '100%' width = '100%'
}) => { }) => {
return ( return (
<table> <StyledTable>
{hasHeader ? <TableHeader columns={columns} /> : null} {hasHeader ? <TableHeader columns={columns} /> : null}
{hasBody ? <TableBody columns={columns} data={data} /> : null} {hasBody ? <TableBody columns={columns} data={data} /> : null}
</table> </StyledTable>
); );
}; };