|
| 1 | +import { Theme, ThemeProvider, createTheme } from '@mui/material'; |
1 | 2 | import MUIDataTable from 'mui-datatables';
|
2 | 3 | import React, { useCallback } from 'react';
|
3 | 4 |
|
| 5 | +const dataTableTheme = (theme: Theme) => |
| 6 | + createTheme({ |
| 7 | + components: { |
| 8 | + MuiTable: { |
| 9 | + styleOverrides: { |
| 10 | + root: { |
| 11 | + // border: `2px solid ${theme.palette.border.normal}`, |
| 12 | + width: '-webkit-fill-available', |
| 13 | + '@media (max-width: 500px)': { |
| 14 | + wordWrap: 'break-word' |
| 15 | + }, |
| 16 | + background: theme.palette.background.constant?.table, |
| 17 | + color: theme.palette.text.default |
| 18 | + } |
| 19 | + } |
| 20 | + }, |
| 21 | + MUIDataTableHeadCell: { |
| 22 | + styleOverrides: { |
| 23 | + data: { |
| 24 | + fontWeight: 'bold', |
| 25 | + textTransform: 'uppercase', |
| 26 | + color: theme.palette.text.default |
| 27 | + }, |
| 28 | + root: { |
| 29 | + fontWeight: 'bold', |
| 30 | + textTransform: 'uppercase', |
| 31 | + color: theme.palette.text.default |
| 32 | + } |
| 33 | + } |
| 34 | + }, |
| 35 | + MUIDataTableSearch: { |
| 36 | + styleOverrides: { |
| 37 | + main: { |
| 38 | + '@media (max-width: 600px)': { |
| 39 | + justifyContent: 'center' |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + }, |
| 44 | + MuiCheckbox: { |
| 45 | + styleOverrides: { |
| 46 | + root: { |
| 47 | + intermediate: false, |
| 48 | + color: 'transparent', |
| 49 | + '&.Mui-checked': { |
| 50 | + color: theme.palette.text.default, |
| 51 | + '& .MuiSvgIcon-root': { |
| 52 | + width: '1.25rem', |
| 53 | + height: '1.25rem', |
| 54 | + borderColor: theme.palette.border.brand, |
| 55 | + marginLeft: '0px', |
| 56 | + padding: '0px' |
| 57 | + } |
| 58 | + }, |
| 59 | + '&.MuiCheckbox-indeterminate': { |
| 60 | + color: theme.palette.background.brand?.default |
| 61 | + }, |
| 62 | + '& .MuiSvgIcon-root': { |
| 63 | + width: '1.25rem', |
| 64 | + height: '1.25rem', |
| 65 | + border: `.75px solid ${theme.palette.border.strong}`, |
| 66 | + borderRadius: '2px', |
| 67 | + padding: '0px' |
| 68 | + }, |
| 69 | + '&:hover': { |
| 70 | + backgroundColor: 'transparent' |
| 71 | + }, |
| 72 | + '&.Mui-disabled': { |
| 73 | + '&:hover': { |
| 74 | + cursor: 'not-allowed' |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + }, |
| 80 | + MuiTableCell: { |
| 81 | + styleOverrides: { |
| 82 | + body: { |
| 83 | + color: theme.palette.text.default |
| 84 | + }, |
| 85 | + root: { |
| 86 | + borderBottom: `1px solid ${theme.palette.border.default}` |
| 87 | + } |
| 88 | + } |
| 89 | + }, |
| 90 | + MUIDataTablePagination: { |
| 91 | + styleOverrides: { |
| 92 | + toolbar: { |
| 93 | + color: theme.palette.text.default |
| 94 | + } |
| 95 | + } |
| 96 | + }, |
| 97 | + MUIDataTableSelectCell: { |
| 98 | + styleOverrides: { |
| 99 | + headerCell: { |
| 100 | + background: theme.palette.background.constant?.table |
| 101 | + } |
| 102 | + } |
| 103 | + }, |
| 104 | + MuiInput: { |
| 105 | + styleOverrides: { |
| 106 | + root: { |
| 107 | + '&:before': { |
| 108 | + borderBottom: `2px solid ${theme.palette.border.brand}` |
| 109 | + }, |
| 110 | + '&.Mui-focused:after': { |
| 111 | + borderBottom: `2px solid ${theme.palette.border.brand}` |
| 112 | + }, |
| 113 | + '&:hover:not(.Mui-disabled):before': { |
| 114 | + borderBottom: `2px solid ${theme.palette.border.brand}` |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + }); |
| 121 | + |
4 | 122 | export interface Column {
|
5 | 123 | name: string;
|
6 | 124 | label: string;
|
@@ -130,14 +248,16 @@ const ResponsiveDataTable = ({
|
130 | 248 | };
|
131 | 249 |
|
132 | 250 | return (
|
133 |
| - <MUIDataTable |
134 |
| - columns={tableCols ?? []} |
135 |
| - data={data || []} |
136 |
| - title={undefined} |
137 |
| - components={components} |
138 |
| - options={updatedOptions} |
139 |
| - {...props} |
140 |
| - /> |
| 251 | + <ThemeProvider theme={dataTableTheme}> |
| 252 | + <MUIDataTable |
| 253 | + columns={tableCols ?? []} |
| 254 | + data={data || []} |
| 255 | + title={undefined} |
| 256 | + components={components} |
| 257 | + options={updatedOptions} |
| 258 | + {...props} |
| 259 | + /> |
| 260 | + </ThemeProvider> |
141 | 261 | );
|
142 | 262 | };
|
143 | 263 |
|
|
0 commit comments