From efca0a745482a36b5008b53f05b57e1457f05759 Mon Sep 17 00:00:00 2001 From: Jonathan Fisher Date: Wed, 27 Dec 2023 11:01:31 -0800 Subject: [PATCH] Remove theme from Datatable --- src/components/DataTable/datatable.tsx | 367 +++++++++++-------------- 1 file changed, 168 insertions(+), 199 deletions(-) diff --git a/src/components/DataTable/datatable.tsx b/src/components/DataTable/datatable.tsx index 3a1b897..ac739a7 100644 --- a/src/components/DataTable/datatable.tsx +++ b/src/components/DataTable/datatable.tsx @@ -29,36 +29,8 @@ import Modal from "@mui/material/Modal" import Toolbar from "@mui/material/Toolbar" import Tooltip from "@mui/material/Tooltip" import { styled, alpha } from "@mui/material/styles" -import { createTheme, ThemeProvider } from "@mui/material/styles" import { Stack } from "@mui/material" -const theme = createTheme({ - palette: { - //For accessibility - contrastThreshold: 4.5, - }, - typography: { - fontFamily: "inherit", - }, - shape: { - borderRadius: 4, - }, - components: { - MuiTableCell: { - styleOverrides: { - head: { - fontWeight: "normal", - }, - }, - }, - MuiToolbar: { - styleOverrides: { - - } - } - }, -}) - //Styling for Search component const Search = styled("div")(({ theme }) => ({ position: "relative", @@ -117,7 +89,6 @@ const boxStyle = { p: 4, } -//const RangeSlider: React.FC = (props: SliderProps) => // function DataTable(props: DataTableProps): React.ReactElement> { const DataTable: React.FC> = (props: DataTableProps) => { // Sets default rows to display at 5 if unspecified @@ -239,182 +210,180 @@ const DataTable: React.FC> = (props: DataTableProps) => }, [state.columns, displayedRows]) return ( - - - - - + + + + {props.tableTitle} + {props.titleHoverInfo && ( + + + + )} + + {props.showMoreColumns && props.columns.length > (props.noOfDefaultColumns || 5) && ( + + )} + {props.searchable && ( + + + + + { dispatch({ - type: "modalChanged", - showAddColumnsModal: true, - }) + type: "searchChanged", + value: e.target.value, + }); + setPage(0); } - > - - Manage Columns - - )} - {props.searchable && ( - - - - - { - dispatch({ - type: "searchChanged", - value: e.target.value, - }); + } + /> + + )} + + + + + + {!props.hideHeader && ( + + + {state.columns.map((column, i) => ( + { + !column.unsortable && dispatch({ type: "sortChanged", sortColumn: i }); setPage(0); - } - } - /> - - )} - - - - -
- {!props.hideHeader && ( - - - {state.columns.map((column, i) => ( - { - !column.unsortable && dispatch({ type: "sortChanged", sortColumn: i }); - setPage(0); - }}> - - {column.HeaderRender ? : column.header} - - - - ))} + }}> + + {column.HeaderRender ? : column.header} + + + + ))} + + + )} + + {props.rows.length === 0 ? ( + + {props.emptyText || "No data available."} + {/* Render needed number of empty cells to fill row */} + {handleEmptyTable(props.columns.length)} + + ) : ( + displayedRows.slice(page * rowsPerPage, (page + 1) * rowsPerPage).map((row, i) => ( + props.onRowClick && props.onRowClick(row, i + page * rowsPerPage)} + sx={{ cursor: props.onRowClick ? "pointer" : "auto" }} + onMouseEnter={() => props.onRowMouseEnter && props.onRowMouseEnter(row, i + page * rowsPerPage)} + onMouseLeave={() => props.onRowMouseLeave && props.onRowMouseLeave()} + > + {state.columns.map((column, j) => { + return ( + props.onCellMouseEnter && props.onCellMouseEnter(column.value(row), i, j)} + onMouseLeave={() => props.onCellMouseLeave && props.onCellMouseLeave()} + > + {column.FunctionalRender ? () : column.render ? ( + column.render(row) + ) : ( + column.value(row) + )} + + ) + })} - + )) )} - - {props.rows.length === 0 ? ( - - {props.emptyText || "No data available."} - {/* Render needed number of empty cells to fill row */} - {handleEmptyTable(props.columns.length)} - - ) : ( - displayedRows.slice(page * rowsPerPage, (page + 1) * rowsPerPage).map((row, i) => ( - props.onRowClick && props.onRowClick(row, i + page * rowsPerPage)} - sx={{cursor: props.onRowClick ? "pointer" : "auto"}} - onMouseEnter={() => props.onRowMouseEnter && props.onRowMouseEnter(row, i + page * rowsPerPage)} - onMouseLeave={() => props.onRowMouseLeave && props.onRowMouseLeave()} - > - {state.columns.map((column, j) => { - return ( - props.onCellMouseEnter && props.onCellMouseEnter(column.value(row), i, j)} - onMouseLeave={() => props.onCellMouseLeave && props.onCellMouseLeave()} - > - {column.FunctionalRender ? () : column.render ? ( - column.render(row) - ) : ( - column.value(row) - )} - - ) - })} - - )) - )} - -
-
- {!props.hidePageMenu && ( - - - {displayedRows.length !== props.rows.length && `Showing ${displayedRows.length} matching rows of ${props.rows.length} total.`} - - - - )} - {/* Add columns modal */} - dispatch({ type: "modalChanged", showAddColumnsModal: false })}> - - Add Columns - {(props.defaultColumnsToShow - ? props.columns.filter((c) => !props.defaultColumnsToShow?.includes(c.header)) - //Why is this "or 5" here? Kinda makes no sense? - : props.columns.slice(props.noOfDefaultColumns || 5, props.columns.length) - ).map((col, i) => ( - - c.header === col.header) !== undefined} - onChange={(event) => { - if (event.target.checked && props.columns.find((c) => c.header === col.header)) - dispatch({ - type: "columnsChanged", - columns: [...state.columns, col], - }) - else - dispatch({ - type: "columnsChanged", - columns: state.columns.filter((u) => u.header !== col.header), - }) - }} - /> - } - label={col.header} - /> -
-
- ))} - -
-
-
-
+ + + + {!props.hidePageMenu && ( + + + {displayedRows.length !== props.rows.length && `Showing ${displayedRows.length} matching rows of ${props.rows.length} total.`} + + + + )} + {/* Add columns modal */} + dispatch({ type: "modalChanged", showAddColumnsModal: false })}> + + Add Columns + {(props.defaultColumnsToShow + ? props.columns.filter((c) => !props.defaultColumnsToShow?.includes(c.header)) + //Why is this "or 5" here? Kinda makes no sense? + : props.columns.slice(props.noOfDefaultColumns || 5, props.columns.length) + ).map((col, i) => ( + + c.header === col.header) !== undefined} + onChange={(event) => { + if (event.target.checked && props.columns.find((c) => c.header === col.header)) + dispatch({ + type: "columnsChanged", + columns: [...state.columns, col], + }) + else + dispatch({ + type: "columnsChanged", + columns: state.columns.filter((u) => u.header !== col.header), + }) + }} + /> + } + label={col.header} + /> +
+
+ ))} + +
+
+ ) } export default DataTable