Skip to content

Commit

Permalink
Merge pull request #100 from 8base/tabl
Browse files Browse the repository at this point in the history
feat(TableBody): add ability to pass data and render prop to table body
  • Loading branch information
vorobeez authored Oct 30, 2018
2 parents 90784bd + a6b8f88 commit 182517f
Show file tree
Hide file tree
Showing 4 changed files with 32 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 };
12 changes: 12 additions & 0 deletions src/molecules/AsyncContent/AsyncContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { Loader } from '../../atoms/Loader';

const AsyncContent = ({ loading, children, ...props }) => {
if (loading) {
return <Loader { ...props } />;
}

return children;
};

export { AsyncContent };
1 change: 1 addition & 0 deletions src/molecules/AsyncContent/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AsyncContent } from './AsyncContent';
1 change: 1 addition & 0 deletions src/molecules/molecules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
export { Rating } from './Rating';
export { ButtonGroup } from './ButtonGroup';
export { Menu } from './Menu';
export { AsyncContent } from './AsyncContent';

0 comments on commit 182517f

Please sign in to comment.