Skip to content

Commit

Permalink
feat(TableBody): add ability to pass data and render prop to table body
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Oct 30, 2018
1 parent e126561 commit a6b8f88
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/atoms/Table/TableBody.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// @flow
import React from 'react';

import { AsyncContent } from '../../molecules/AsyncContent';
import { Grid } from '../Grid';
import { createStyledTag, createTheme } from '../../utils';

type TableBodyProps = {
children?: React$Node,
loading?: boolean,
data?: any[],
};

const name = 'tableBody';
Expand All @@ -27,9 +30,23 @@ const TableBodyTag = createStyledTag(name, (props: *) => ({

function TableBody({
children,
data,
loading,
...rest
}: TableBodyProps) {
return <TableBodyTag { ...rest } tagName={ Grid.Layout }>{ children }</TableBodyTag>;
return (
<TableBodyTag { ...rest } tagName={ Grid.Layout }>
<AsyncContent loading={ loading } stretch>
{
Array.isArray(data) && typeof children === 'function'
?
React.Children.toArray(data.map(children))
:
children
}
</AsyncContent>
</TableBodyTag>
);
}

export { TableBody, theme };

0 comments on commit a6b8f88

Please sign in to comment.