From 99f8361749f60083fb7790644919f430ef28244c Mon Sep 17 00:00:00 2001 From: JP Barela Date: Sat, 13 Mar 2021 23:39:27 -0700 Subject: [PATCH] Refinements based on storybook --- src/DataTable/index.jsx | 111 ++++++++++++++++++++++++---------------- src/Table/index.jsx | 39 +++++++++----- src/commonTypes.js | 2 + 3 files changed, 97 insertions(+), 55 deletions(-) create mode 100644 src/commonTypes.js diff --git a/src/DataTable/index.jsx b/src/DataTable/index.jsx index 0f477eb..9e13076 100644 --- a/src/DataTable/index.jsx +++ b/src/DataTable/index.jsx @@ -1,65 +1,90 @@ // @flow import * as React from "react"; -import { Table, TableBody, TableHeader, TableRow } from "../Table"; -import { createUseStyles } from "react-jss"; +import { + Table, + TableBody, + TableData, + TableHead, + TableHeader, + TableRow, +} from "../Table"; +import type { TextAlign } from "../commonTypes"; type DataTableProps = { - columns: Array, - data: Array, + columns: Array, + data: Array, + borderWidth?: string, }; type ColumnProps = { - header: string, - textAlign: TextAlign, - width: string, + header?: string, + textAlign?: TextAlign, + width?: string, }; -type TextAlign = "left" | "right" | "center"; - type DataElementProps = { - textAlign: TextAlign, - width: string, item: string, + borderWidth?: string, + textAlign?: TextAlign, + width?: string, }; -export function DataTable({ columns, data }: DataTableProps) { +export function DataTable({ + borderWidth, + columns, + data, +}: DataTableProps): React.Node { return ( - - {columns.map((columnProps) => ( - - ))} - - {data.map((row) => { - return ( - - {row.map((element, index) => ( - - ))} - - ); - })} + + + {columns.map((column, index) => ( + + ))} + + + + {data.map((row, i) => { + return ( + + {row.map((element, j) => ( + + ))} + + ); + })} +
); } -function ColumnHeader({ header }: ColumnProps) { - return {header}; +function ColumnHeader({ header, width }: ColumnProps) { + return ( + + {header} + + ); } -function DataElement({ item, textAlign, width }: DataTableProps) { - const useDataStyles = useDataTableStysles({ textAlign, width }); - - return {item}; +function DataElement({ + borderWidth, + item, + textAlign, + width, +}: DataElementProps) { + return ( + + {item} + + ); } - -const useDataTableStysles = createUseStyles({ - tableData: { - textAlign: ({ textAlign }) => textAlign, - width: ({ width }) => width, - }, -}); diff --git a/src/Table/index.jsx b/src/Table/index.jsx index a56ceee..9c107ea 100644 --- a/src/Table/index.jsx +++ b/src/Table/index.jsx @@ -1,16 +1,19 @@ // @flow import * as React from "react"; import { createUseStyles } from "react-jss"; +import type { TextAlign } from "../commonTypes"; type TableProps = { children?: React.Node, }; type TableDataProps = { - center?: boolean, + borderWidth?: string, colSpan?: number, rowSpan?: number, styles?: any, + textAlign?: TextAlign, + width?: string, children?: React.Node, }; @@ -19,7 +22,7 @@ type TableHeaderProps = TableDataProps & { }; export function Table({ children }: TableProps): React.Node { - const classes = useTableStyles(); + const classes = useTableStyles({}); return {children}
; } @@ -37,18 +40,19 @@ export function TableHead({ children }: TableProps): React.Node { } export function TableHeader({ - center, colSpan, rowSpan, scope, + textAlign, + width, children, styles, }: TableHeaderProps): React.Node { - const classes = useTableStyles(); + const classes = useTableStyles({ textAlign, width }); return ( borderWidth, borderStyle: "solid", margin: 0, padding: "5px 5px", + textAlign: ({ textAlign }) => textAlign, + width: ({ width }) => width, + }, + tableHeader: { + textAlign: ({ textAlign }) => textAlign, + width: ({ width }) => width, }, }); diff --git a/src/commonTypes.js b/src/commonTypes.js new file mode 100644 index 0000000..2bd582e --- /dev/null +++ b/src/commonTypes.js @@ -0,0 +1,2 @@ +// @flow +export type TextAlign = "left" | "right" | "center";