Skip to content

Commit 7bed955

Browse files
committed
feat(core): adds ccs variables support
1 parent c51524e commit 7bed955

File tree

5 files changed

+102
-21
lines changed

5 files changed

+102
-21
lines changed

apps/react-kit-demo/src/main.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { StrictMode } from 'react';
22
import * as ReactDOM from 'react-dom/client';
33
import { RouterProvider } from 'react-router-dom';
44
import { router } from './routes/Routes';
5+
import { CssBaseline, ThemeProvider } from '@mui/material';
6+
import theme from './theme';
57

68
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
79

810
root.render(
911
<StrictMode>
10-
<RouterProvider router={router} />
12+
<ThemeProvider theme={theme}>
13+
<CssBaseline />
14+
<RouterProvider router={router} />
15+
</ThemeProvider>
1116
</StrictMode>
1217
);

apps/react-kit-demo/src/styles.scss

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
/* You can add global styles to this file, and also import other style files */
1+
:root {
2+
--primary-color: #153d77;
3+
--secondary-color: #607d8b;
4+
--success-color: #198754;
5+
--error-color: #ff1744;
6+
--white-color: #fff;
7+
--background-color: #dedede;
8+
--pdf-color: #f40f02;
9+
--word-document-color: #2b579a;
10+
}
11+
12+
213
/* The sidebar menu */
314
.sidenav {
415
height: 100%; /* Full-height: remove this if you want "auto" height */
@@ -23,3 +34,4 @@
2334
font-size: 20px;
2435
display: block;
2536
}
37+

apps/react-kit-demo/src/theme.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { createTheme } from '@mui/material/styles';
2+
import { getCssVariable } from './utils/CssUtils';
3+
4+
declare module '@mui/material/styles' {
5+
interface BreakpointOverrides {
6+
xs: true;
7+
sm: true;
8+
md: true;
9+
lg: true;
10+
xl: true;
11+
xxl: true;
12+
xxxl: true;
13+
}
14+
}
15+
16+
// A custom theme for this app
17+
const theme = createTheme({
18+
cssVariables: { cssVarPrefix: '' },
19+
breakpoints: {
20+
values: {
21+
xs: 0,
22+
sm: 600,
23+
md: 900,
24+
lg: 1200,
25+
xl: 1536,
26+
xxl: 1920,
27+
xxxl: 2200,
28+
},
29+
},
30+
palette: {
31+
primary: {
32+
main: getCssVariable('--primary-color'),
33+
},
34+
secondary: {
35+
main: getCssVariable('--secondary-color'),
36+
},
37+
success: {
38+
main: getCssVariable('--success-color'),
39+
},
40+
error: {
41+
main: getCssVariable('--error-color'),
42+
},
43+
background: {
44+
default: getCssVariable('--background-color'),
45+
},
46+
},
47+
components: {
48+
// @ts-ignore
49+
MuiDataGrid: {
50+
styleOverrides: {
51+
root: {
52+
'--DataGrid-containerBackground': '#FFFFFF',
53+
},
54+
},
55+
},
56+
},
57+
});
58+
59+
export default theme;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Get the value of a CSS variable
3+
*
4+
* @param variable The name of the CSS variable
5+
*
6+
* @returns The value of the CSS variable
7+
*
8+
* @author Pavan Kumar Jadda
9+
* @since 1.6.0
10+
*/
11+
export function getCssVariable(variable: string): string {
12+
return getComputedStyle(document.documentElement).getPropertyValue(variable).trim();
13+
}
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
/* Define global variables */
22

3-
$primary-color: #153d77;
4-
$secondary-color: #607d8b;
5-
$success-color: #198754;
6-
$error-color: #ff1744;
7-
$white-color: #fff;
8-
$background-color: #dedede;
9-
$pdf-color: #f40f02;
10-
$word-document-color: #2b579a;
3+
:root {
4+
--primary-color: #153d77;
5+
--secondary-color: #607d8b;
6+
--success-color: #198754;
7+
--error-color: #ff1744;
8+
--white-color: #fff;
9+
--background-color: #dedede;
10+
--pdf-color: #f40f02;
11+
--word-document-color: #2b579a;
12+
}
13+
1114

12-
/* Export the variables so that they can be used in the app */
13-
:export {
14-
primaryColor: $primary-color;
15-
secondaryColor: $secondary-color;
16-
successColor: $success-color;
17-
errorColor: $error-color;
18-
whiteColor: $white-color;
19-
backgroundColor: $background-color;
20-
pdfDocumentColor: $pdf-color;
21-
wordDocumentColor: $word-document-color;
22-
}

0 commit comments

Comments
 (0)