Skip to content

Commit 60d5bfc

Browse files
authored
Merge pull request #629 from sudhanshutech/datatable/theme
Add theme for tables
2 parents 271b953 + 46caf4b commit 60d5bfc

File tree

2 files changed

+135
-10
lines changed

2 files changed

+135
-10
lines changed

src/custom/ResponsiveDataTable.tsx

+128-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,124 @@
1+
import { Theme, ThemeProvider, createTheme } from '@mui/material';
12
import MUIDataTable from 'mui-datatables';
23
import React, { useCallback } from 'react';
34

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+
4122
export interface Column {
5123
name: string;
6124
label: string;
@@ -130,14 +248,16 @@ const ResponsiveDataTable = ({
130248
};
131249

132250
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>
141261
);
142262
};
143263

src/theme/palette.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ declare module '@mui/material/styles' {
3333
constant?: {
3434
disabled: string;
3535
white: string;
36+
table: string;
3637
};
3738
inverse?: string;
3839
brand?: Interactiveness;
@@ -84,6 +85,7 @@ declare module '@mui/material/styles' {
8485
constant?: {
8586
white: string;
8687
disabled: string;
88+
table: string;
8789
};
8890
inverse?: string;
8991
brand?: Interactiveness;
@@ -116,6 +118,7 @@ declare module '@mui/material/styles' {
116118
constant?: {
117119
white: string;
118120
disabled: string;
121+
table: string;
119122
};
120123
inverse?: string;
121124
brand?: Interactiveness;
@@ -252,7 +255,8 @@ export const lightModePalette: PaletteOptions = {
252255
code: Colors.charcoal[90],
253256
constant: {
254257
white: Colors.accentGrey[100],
255-
disabled: Colors.charcoal[70]
258+
disabled: Colors.charcoal[70],
259+
table: Colors.charcoal[100]
256260
},
257261
surfaces: Colors.accentGrey[100]
258262
},
@@ -365,7 +369,8 @@ export const darkModePalette: PaletteOptions = {
365369
code: Colors.accentGrey[90],
366370
constant: {
367371
white: Colors.accentGrey[100],
368-
disabled: Colors.charcoal[70]
372+
disabled: Colors.charcoal[70],
373+
table: '#363636'
369374
},
370375
surfaces: Colors.accentGrey[10]
371376
},

0 commit comments

Comments
 (0)