aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/theme/ThemeProvider.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-12 19:54:46 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-12 19:54:46 +0200
commitd22c3b0c257f5daf5b401988a35ab9ce981a2341 (patch)
tree0a661c927c37b52197326d1c05e211daf9bd19e5 /subprojects/frontend/src/theme/ThemeProvider.tsx
parentfix(language): rule parsing test (diff)
downloadrefinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.tar.gz
refinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.tar.zst
refinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.zip
refactor(frontend): move from Webpack to Vite
Also overhaulds the building and linting for frontend assets.
Diffstat (limited to 'subprojects/frontend/src/theme/ThemeProvider.tsx')
-rw-r--r--subprojects/frontend/src/theme/ThemeProvider.tsx61
1 files changed, 54 insertions, 7 deletions
diff --git a/subprojects/frontend/src/theme/ThemeProvider.tsx b/subprojects/frontend/src/theme/ThemeProvider.tsx
index c6194c69..cf18e21c 100644
--- a/subprojects/frontend/src/theme/ThemeProvider.tsx
+++ b/subprojects/frontend/src/theme/ThemeProvider.tsx
@@ -1,15 +1,62 @@
1import {
2 createTheme,
3 responsiveFontSizes,
4 type ThemeOptions,
5 ThemeProvider as MaterialUiThemeProvider,
6} from '@mui/material/styles';
1import { observer } from 'mobx-react-lite'; 7import { observer } from 'mobx-react-lite';
2import { ThemeProvider as MaterialUiThemeProvider } from '@mui/material/styles';
3import React, { type ReactNode } from 'react'; 8import React, { type ReactNode } from 'react';
4 9
5import { useRootStore } from '../RootStore'; 10import { useRootStore } from '../RootStore';
6 11
7export const ThemeProvider: React.FC<{ children: ReactNode }> = observer(({ children }) => { 12import EditorTheme from './EditorTheme';
8 const { themeStore } = useRootStore(); 13
14function getMUIThemeOptions(currentTheme: EditorTheme): ThemeOptions {
15 switch (currentTheme) {
16 case EditorTheme.Light:
17 return {
18 palette: {
19 primary: {
20 main: '#56b6c2',
21 },
22 },
23 };
24 case EditorTheme.Dark:
25 return {
26 palette: {
27 primary: {
28 main: '#56b6c2',
29 },
30 },
31 };
32 default:
33 throw new Error(`Unknown theme: ${currentTheme}`);
34 }
35}
36
37function ThemeProvider({ children }: { children?: ReactNode }) {
38 const {
39 themeStore: { currentTheme, darkMode },
40 } = useRootStore();
41
42 const themeOptions = getMUIThemeOptions(currentTheme);
43 const theme = responsiveFontSizes(
44 createTheme({
45 ...themeOptions,
46 palette: {
47 mode: darkMode ? 'dark' : 'light',
48 ...(themeOptions.palette ?? {}),
49 },
50 }),
51 );
9 52
10 return ( 53 return (
11 <MaterialUiThemeProvider theme={themeStore.materialUiTheme}> 54 <MaterialUiThemeProvider theme={theme}>{children}</MaterialUiThemeProvider>
12 {children}
13 </MaterialUiThemeProvider>
14 ); 55 );
15}); 56}
57
58ThemeProvider.defaultProps = {
59 children: undefined,
60};
61
62export default observer(ThemeProvider);