diff --git a/frontend/packages/core/src/Table/stories/table.stories.tsx b/frontend/packages/core/src/Table/stories/table.stories.tsx new file mode 100644 index 0000000000..e2bed395b5 --- /dev/null +++ b/frontend/packages/core/src/Table/stories/table.stories.tsx @@ -0,0 +1,31 @@ +import * as React from "react"; +import type { Meta } from "@storybook/react"; + +import type { TableProps } from "../table"; +import { Table, TableRow } from "../table"; + +export default { + title: "Core/Table/Table", + component: Table, +} as Meta; + +const Template = (props: TableProps) => ( +
+ + {[...Array(10)].map((_, index: number) => ( + // eslint-disable-next-line react/no-array-index-key + +
Value 1
+
Value 2
+
+ ))} +
+
+); + +export const Primary = Template.bind({}); + +export const StickHeader = Template.bind({}); +StickHeader.args = { + stickyHeader: true, +}; diff --git a/frontend/packages/core/src/Table/table.tsx b/frontend/packages/core/src/Table/table.tsx index af3a66cc68..6f2281b54a 100644 --- a/frontend/packages/core/src/Table/table.tsx +++ b/frontend/packages/core/src/Table/table.tsx @@ -1,48 +1,50 @@ -import React from "react"; -import type { TableProps as MuiTableProps, TableRowProps } from "@material-ui/core"; +import * as React from "react"; +import styled from "@emotion/styled"; +import type { TableProps as MuiTableProps } from "@material-ui/core"; import { Paper, Table as MuiTable, TableBody, - TableCell, + TableCell as MuiTableCell, TableContainer, TableHead, - TableRow, + TableRow as MuiTableRow, } from "@material-ui/core"; -import styled from "styled-components"; -const TablePaper = styled(Paper)` - max-height: 400px; -`; +const TablePaper = styled(Paper)({ + border: "1px solid #E7E7EA", +}); -interface TableProps extends MuiTableProps { +export const TableCell = styled(MuiTableCell)({ + fontSize: "14px", + padding: "12px 16px", + color: "#0D1030", +}); + +const HeaderTableCell = styled(TableCell)({ + backgroundColor: "rgba(248, 248, 249, 1)", + fontWeight: 600, +}); + +export interface TableProps extends Pick { headings?: string[]; - elevation?: number; } -const Table: React.FC = ({ headings, children, elevation = 1, ...props }) => { - let localHeadings = []; - if (headings) { - localHeadings = [...headings]; - } +export const Table: React.FC = ({ headings, children, ...props }) => { + const localHeadings = headings ? [...headings] : []; return ( - // n.b. material ui doesn't use the component prop to determine the prop types. - // @ts-ignore - + {localHeadings.length !== 0 && ( - - - {localHeadings.shift()} - + {localHeadings.map(heading => ( - - {heading} - + + {heading} + ))} - + )} {children} @@ -51,25 +53,15 @@ const Table: React.FC = ({ headings, children, elevation = 1, ...pro ); }; -interface RowProps extends TableRowProps { - data: any[]; +export interface TableRowProps { + children?: React.ReactNode; } -const Row: React.FC = ({ data, ...props }) => { - const rowData = data ? [...data] : []; - const headerValue = rowData.shift(); - return ( - - - {headerValue} - - {rowData.map(value => ( - - {value} - - ))} - - ); -}; - -export { Row, Table, TablePaper }; +export const TableRow = ({ children = [] }: TableRowProps) => ( + + {React.Children.map(children, (value, index) => ( + // eslint-disable-next-line react/no-array-index-key + {value} + ))} + +);