diff options
author | 2022-02-04 20:18:20 +0100 | |
---|---|---|
committer | 2022-02-04 20:18:20 +0100 | |
commit | 42db1e8b4dcff3667c5f14e8dd464309c3c2f23e (patch) | |
tree | f5f5efe86fb352980cf144cceb68d1a1101b274f /subprojects/frontend/src/theme/ThemeStore.ts | |
parent | chore(web): fix Sonar issue (diff) | |
parent | chore(frontend): bump frontend dependencies (diff) | |
download | refinery-42db1e8b4dcff3667c5f14e8dd464309c3c2f23e.tar.gz refinery-42db1e8b4dcff3667c5f14e8dd464309c3c2f23e.tar.zst refinery-42db1e8b4dcff3667c5f14e8dd464309c3c2f23e.zip |
Merge pull request #18 from kris7t/releng-docs
Restructure project
Diffstat (limited to 'subprojects/frontend/src/theme/ThemeStore.ts')
-rw-r--r-- | subprojects/frontend/src/theme/ThemeStore.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/subprojects/frontend/src/theme/ThemeStore.ts b/subprojects/frontend/src/theme/ThemeStore.ts new file mode 100644 index 00000000..ffaf6dde --- /dev/null +++ b/subprojects/frontend/src/theme/ThemeStore.ts | |||
@@ -0,0 +1,64 @@ | |||
1 | import { makeAutoObservable } from 'mobx'; | ||
2 | import { | ||
3 | Theme, | ||
4 | createTheme, | ||
5 | responsiveFontSizes, | ||
6 | } from '@mui/material/styles'; | ||
7 | |||
8 | import { | ||
9 | EditorTheme, | ||
10 | EditorThemeData, | ||
11 | DEFAULT_THEME, | ||
12 | EDITOR_THEMES, | ||
13 | } from './EditorTheme'; | ||
14 | |||
15 | export class ThemeStore { | ||
16 | currentTheme: EditorTheme = DEFAULT_THEME; | ||
17 | |||
18 | constructor() { | ||
19 | makeAutoObservable(this); | ||
20 | } | ||
21 | |||
22 | toggleDarkMode(): void { | ||
23 | this.currentTheme = this.currentThemeData.toggleDarkMode; | ||
24 | } | ||
25 | |||
26 | private get currentThemeData(): EditorThemeData { | ||
27 | return EDITOR_THEMES[this.currentTheme]; | ||
28 | } | ||
29 | |||
30 | get materialUiTheme(): Theme { | ||
31 | const themeData = this.currentThemeData; | ||
32 | const materialUiTheme = createTheme({ | ||
33 | palette: { | ||
34 | mode: themeData.paletteMode, | ||
35 | background: { | ||
36 | default: themeData.background, | ||
37 | paper: themeData.background, | ||
38 | }, | ||
39 | primary: { | ||
40 | main: themeData.primary, | ||
41 | }, | ||
42 | secondary: { | ||
43 | main: themeData.secondary, | ||
44 | }, | ||
45 | error: { | ||
46 | main: themeData.secondary, | ||
47 | }, | ||
48 | text: { | ||
49 | primary: themeData.foregroundHighlight, | ||
50 | secondary: themeData.foreground, | ||
51 | }, | ||
52 | }, | ||
53 | }); | ||
54 | return responsiveFontSizes(materialUiTheme); | ||
55 | } | ||
56 | |||
57 | get darkMode(): boolean { | ||
58 | return this.currentThemeData.paletteMode === 'dark'; | ||
59 | } | ||
60 | |||
61 | get className(): string { | ||
62 | return this.currentThemeData.className; | ||
63 | } | ||
64 | } | ||