diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-08-12 19:54:46 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-08-12 19:54:46 +0200 |
commit | d22c3b0c257f5daf5b401988a35ab9ce981a2341 (patch) | |
tree | 0a661c927c37b52197326d1c05e211daf9bd19e5 /subprojects/frontend/src/theme/ThemeProvider.tsx | |
parent | fix(language): rule parsing test (diff) | |
download | refinery-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.tsx | 61 |
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 @@ | |||
1 | import { | ||
2 | createTheme, | ||
3 | responsiveFontSizes, | ||
4 | type ThemeOptions, | ||
5 | ThemeProvider as MaterialUiThemeProvider, | ||
6 | } from '@mui/material/styles'; | ||
1 | import { observer } from 'mobx-react-lite'; | 7 | import { observer } from 'mobx-react-lite'; |
2 | import { ThemeProvider as MaterialUiThemeProvider } from '@mui/material/styles'; | ||
3 | import React, { type ReactNode } from 'react'; | 8 | import React, { type ReactNode } from 'react'; |
4 | 9 | ||
5 | import { useRootStore } from '../RootStore'; | 10 | import { useRootStore } from '../RootStore'; |
6 | 11 | ||
7 | export const ThemeProvider: React.FC<{ children: ReactNode }> = observer(({ children }) => { | 12 | import EditorTheme from './EditorTheme'; |
8 | const { themeStore } = useRootStore(); | 13 | |
14 | function 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 | |||
37 | function 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 | |||
58 | ThemeProvider.defaultProps = { | ||
59 | children: undefined, | ||
60 | }; | ||
61 | |||
62 | export default observer(ThemeProvider); | ||