diff --git a/components/Table/index.tsx b/components/Table/index.tsx index cacfe0ef1..e8e80b9fc 100644 --- a/components/Table/index.tsx +++ b/components/Table/index.tsx @@ -1,15 +1,43 @@ import React from 'react'; interface Props extends JSX.IntrinsicAttributes { + align?: ('left' | 'center' | 'right')[]; children: [React.ReactElement]; + rows?: [[any]]; } +const TableContent = ({ rows, align = [] }: Omit) => { + const [head, ...body] = rows; + + return ( + <> + + + {head.map((cell, index) => ( + {cell} + ))} + + + + {body.map(row => ( + + {row.map((cell, index) => ( + {cell} + ))} + + ))} + + + ); +}; + const Table = (props: Props) => { - const { children } = props; + const { children, ...rest } = props; + return (
- {children}
+ {rest.rows ? : children}
); diff --git a/docs/mdx-components.mdx b/docs/mdx-components.mdx new file mode 100644 index 000000000..26b759bbc --- /dev/null +++ b/docs/mdx-components.mdx @@ -0,0 +1,23 @@ +## Tables + +If you have some tabular data, it may be easier to write it with mdx: + +```jsx MDX +export const table = [ + ['Left', 'Center', 'Right'], + ['L0', '**bold**', '$1600'], + ['L1', '`code`', '$12'], + ['L2', '_italic_', '$1'], +]; + +; +``` + +export const table = [ + ['Left', 'Center', 'Right'], + ['L0', '**bold**', '$1600'], + ['L1', '`code`', '$12'], + ['L2', '_italic_', '$1'], +]; + +
diff --git a/docs/tables.md b/docs/tables.md index b34d7d73b..b19f77361 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -1,8 +1,9 @@ --- -title: "Tables" +title: 'Tables' category: 5fdf7610134322007389a6ed hidden: false --- + ## Syntax | Left | Center | Right | @@ -20,7 +21,7 @@ hidden: false This example also shows off custom theming! | Left | Center | Right | -|:-----|:--------:|------:| +| :--- | :------: | ----: | | L0 | **bold** | $1600 | | L1 | `code` | $12 | | L2 | _italic_ | $1 | @@ -35,25 +36,32 @@ Tables have been simplified to mirror a more standard implementation. We've also --table-head: #5b1c9f; --table-head-text: white; --table-stripe: #f0eaf7; - --table-edges: rgba(34, 5, 64, .5); + --table-edges: rgba(34, 5, 64, 0.5); --table-row: white; } ``` + ```scss CSS Selectors /* Table */ -.markdown-body .rdmd-table table {} +.markdown-body .rdmd-table table { +} /* Rows */ -.markdown-body .rdmd-table tr {} -.markdown-body .rdmd-table thead tr {} /* header row's background */ -.markdown-body .rdmd-table tr:nth-child(2n) {} /* striped rows' background */ +.markdown-body .rdmd-table tr { +} +.markdown-body .rdmd-table thead tr { +} /* header row's background */ +.markdown-body .rdmd-table tr:nth-child(2n) { +} /* striped rows' background */ /* Cells */ -.markdown-body .rdmd-table th {} -.markdown-body .rdmd-table td {} +.markdown-body .rdmd-table th { +} +.markdown-body .rdmd-table td { +} ```