1 |
41a11178
|
Vaclav Honzik
|
import { PaletteMode } from '@mui/material'
|
2 |
0d90d67b
|
Vaclav Honzik
|
import { createTheme, Theme, ThemeProvider } from '@mui/material/styles'
|
3 |
41a11178
|
Vaclav Honzik
|
import { FunctionComponent, ReactNode, useEffect, useState } from 'react'
|
4 |
|
|
import { useSelector } from 'react-redux'
|
5 |
|
|
import { RootState } from '../redux/store'
|
6 |
0d90d67b
|
Vaclav Honzik
|
|
7 |
|
|
export interface ThemeWrapperProps {
|
8 |
|
|
children: ReactNode
|
9 |
|
|
}
|
10 |
|
|
|
11 |
56018f1c
|
Vaclav Honzik
|
export const lightThemePalette = {
|
12 |
|
|
primary: {
|
13 |
|
|
main: '#A28253',
|
14 |
|
|
},
|
15 |
|
|
secondary: {
|
16 |
|
|
main: '#E3DBCF',
|
17 |
|
|
},
|
18 |
|
|
selected: {
|
19 |
|
|
main: '#C0C0C0',
|
20 |
|
|
},
|
21 |
|
|
}
|
22 |
41a11178
|
Vaclav Honzik
|
|
23 |
56018f1c
|
Vaclav Honzik
|
export const darkThemePalette = {
|
24 |
|
|
primary: {
|
25 |
|
|
main: '#e0bb84',
|
26 |
|
|
},
|
27 |
|
|
secondary: {
|
28 |
|
|
main: '#E3DBCF',
|
29 |
|
|
},
|
30 |
|
|
}
|
31 |
41a11178
|
Vaclav Honzik
|
|
32 |
56018f1c
|
Vaclav Honzik
|
export const getPalette = (paletteMode: PaletteMode) => {
|
33 |
|
|
switch (paletteMode) {
|
34 |
|
|
case 'light':
|
35 |
|
|
return lightThemePalette
|
36 |
|
|
case 'dark':
|
37 |
|
|
return darkThemePalette
|
38 |
|
|
default:
|
39 |
|
|
return lightThemePalette
|
40 |
41a11178
|
Vaclav Honzik
|
}
|
41 |
56018f1c
|
Vaclav Honzik
|
}
|
42 |
41a11178
|
Vaclav Honzik
|
|
43 |
56018f1c
|
Vaclav Honzik
|
export const buildTheme = (paletteMode: PaletteMode) =>
|
44 |
0d90d67b
|
Vaclav Honzik
|
createTheme({
|
45 |
|
|
palette: {
|
46 |
|
|
mode: paletteMode,
|
47 |
41a11178
|
Vaclav Honzik
|
...getPalette(paletteMode),
|
48 |
0d90d67b
|
Vaclav Honzik
|
},
|
49 |
|
|
shape: {
|
50 |
41a11178
|
Vaclav Honzik
|
borderRadius: 8,
|
51 |
0d90d67b
|
Vaclav Honzik
|
},
|
52 |
|
|
typography: {
|
53 |
|
|
fontFamily: [
|
54 |
|
|
'-apple-system',
|
55 |
|
|
'BlinkMacSystemFont',
|
56 |
|
|
'"Segoe UI"',
|
57 |
|
|
'Roboto',
|
58 |
|
|
'"Helvetica Neue"',
|
59 |
|
|
'Arial',
|
60 |
|
|
'sans-serif',
|
61 |
|
|
'"Apple Color Emoji"',
|
62 |
|
|
'"Segoe UI Emoji"',
|
63 |
|
|
'"Segoe UI Symbol"',
|
64 |
|
|
].join(','),
|
65 |
|
|
},
|
66 |
|
|
})
|
67 |
|
|
|
68 |
56018f1c
|
Vaclav Honzik
|
const ThemeWrapper: FunctionComponent<ThemeWrapperProps> = ({ children }) => {
|
69 |
|
|
|
70 |
|
|
|
71 |
0d90d67b
|
Vaclav Honzik
|
const paletteMode = useSelector(
|
72 |
|
|
(state: RootState) => state.theme.paletteMode
|
73 |
|
|
)
|
74 |
|
|
|
75 |
|
|
const [theme, setTheme] = useState<Theme>(buildTheme(paletteMode))
|
76 |
|
|
useEffect(() => {
|
77 |
|
|
setTheme(() => {
|
78 |
|
|
return buildTheme(paletteMode)
|
79 |
|
|
})
|
80 |
|
|
}, [paletteMode])
|
81 |
|
|
|
82 |
41a11178
|
Vaclav Honzik
|
return <ThemeProvider theme={theme}>{children}</ThemeProvider>
|
83 |
0d90d67b
|
Vaclav Honzik
|
}
|
84 |
|
|
|
85 |
41a11178
|
Vaclav Honzik
|
export default ThemeWrapper
|