Created
April 26, 2017 10:31
-
-
Save albertorestifo/56e6cc687cbf584cdf8abea89cae6e28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
function Cell({ children }) { | |
return <td>{children}</td>; | |
} | |
function Row({ children }) { | |
return ( | |
<tr> | |
{React.Children.map(children, (el) => { | |
if (el.type === Cell) return el; | |
return <td>{el}</td>; | |
})} | |
</tr> | |
); | |
} | |
function Grid({ children }) { | |
return ( | |
<table> | |
<tbody> | |
{React.Children.map(children, (el) => { | |
if (!el) return; | |
if (el.type === Row) return el; | |
if (el.type === Cell) { | |
return <tr>{el}</tr>; | |
} | |
return ( | |
<tr> | |
<td>{el}</td> | |
</tr> | |
); | |
})} | |
</tbody> | |
</table> | |
); | |
} | |
Grid.Row = Row; | |
Grid.Cell = Cell; | |
export default Grid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment