Skip to content

Commit

Permalink
feat: 🎸 improve <ListTable> and add reference to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Feb 5, 2019
1 parent 66fad9b commit d95444d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const MyComponent = mock();
- [`<OutsideClick>`](./docs/en/OutsideClick.md)
- [`<Ripple>`](./docs/en/Ripple.md) and [`withRipple()`](./docs/en/Ripple.md#withripple) &mdash; [**example**](https://codesandbox.io/s/983q7jr80o)
- [`<Img>`](./docs/en/Img.md)
- [`<ListTable>`](./docs/en/ListTable.md)
- [`<WidthQuery>`](./docs/en/WidthQuery.md), [`<View>`](./docs/en/View.md), [`<WindowWidthQuery>`](./docs/en/WindowWidthQuery.md), and [`<InlineWidthQuery>`](./docs/en/InlineWidthQuery.md)
- [`<Audio>`](./docs/en/Audio.md) and [`<Video>`](./docs/en/Video.md)
- [`<Speak>`](./docs/en/Speak.md), [`<Vibrate>`](./docs/en/Vibrate.md), [`<Alert>`](./docs/en/Alert.md)
Expand Down
27 changes: 27 additions & 0 deletions docs/en/ListTable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# `<ListTable>`

Wraps `children` into a table with specified column number.

## Usage

Below renders 2x3 table.

```jsx
import {ListTable} from 'libreact/lib/ListTable';

<ListTable cols={2}>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</ListTable>
```


## Props

- `cols` &mdash; optional, number or columns table should have, defaults to `3`.
- `renderRow` &mdash; optional, function that receives an array of `<td>` cells as React
elements and should return a `<tr>` React element, defaults to `cells => h('tr', null, ...cells)`.
1 change: 1 addition & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- [`<OutsideClick>`](./OutsideClick.md)
- [`<Ripple>`](./Ripple.md) and [`withRipple()`](./Ripple.md#withripple) &mdash; [**example**](https://codesandbox.io/s/983q7jr80o)
- [`<Img>`](./Img.md)
- [`<ListTable>`](./ListTable.md)
- [`<WidthQuery>`](./WidthQuery.md), [`<View>`](./View.md), [`<WindowWidthQuery>`](./WindowWidthQuery.md), and [`<InlineWidthQuery>`](./InlineWidthQuery.md)
- [`<Audio>`](./Audio.md) and [`<Video>`](./Video.md)
- [`<Speak>`](./Speak.md), [`<Vibrate>`](./Vibrate.md), [`<Alert>`](./Alert.md), `<Prompt>`, `<Confirm>`
Expand Down
1 change: 1 addition & 0 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* [OutsideClick](OutsideClick.md)
* [Ripple](Ripple.md)
* [Img](Img.md)
* [ListTable](ListTable.md)
* [Group](Group.md)
* [InfiniteScroll](InfiniteScroll.md)
* [WidthQuery](WidthQuery.md)
Expand Down
2 changes: 1 addition & 1 deletion src/ListTable/__story__/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ListTable} from '..';
import ShowDocs from '../../ShowDocs'

storiesOf('UI/ListTable', module)
// .add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/ListTable.md')}))
.add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/ListTable.md')}))
.add('Default', () =>
<ListTable>
<div>1</div>
Expand Down
6 changes: 3 additions & 3 deletions src/ListTable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const h = React.createElement;

const defaultRenderRow = cells => h('tr', null, ...cells);

export interface Props {
export interface Props extends React.AllHTMLAttributes<any> {
cols?: number;
renderRow?: (cells: React.ReactElement<any>[]) => React.ReactElement<any>;
}

export const ListTable: React.SFC<Props> = ({cols, renderRow, children}) => {
export const ListTable: React.SFC<Props> = ({cols, renderRow, children, ...rest}) => {
const list = React.Children.toArray(children);
const rows: React.ReactElement<any>[] = [];
const length = list.length;
Expand All @@ -25,7 +25,7 @@ export const ListTable: React.SFC<Props> = ({cols, renderRow, children}) => {
rows.push(renderRow(cells));
}

return h('table', null, h('tbody', null,
return h('table', rest, h('tbody', null,
...rows,
));
};
Expand Down

1 comment on commit d95444d

@streamich
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build version: 2.11.0-list-table.162 🤞 list-table on Travis 🎉

Please sign in to comment.