1
|
import { PaletteMode } from '@mui/material'
|
2
|
import { createTheme, Theme, ThemeProvider } from '@mui/material/styles'
|
3
|
import { FunctionComponent, ReactNode, useEffect, useState } from 'react'
|
4
|
import { useSelector } from 'react-redux'
|
5
|
import { RootState } from '../redux/store'
|
6
|
|
7
|
export interface ThemeWrapperProps {
|
8
|
children: ReactNode
|
9
|
}
|
10
|
|
11
|
export const lightThemePalette = {
|
12
|
primary: {
|
13
|
main: '#A28253',
|
14
|
},
|
15
|
secondary: {
|
16
|
main: '#E3DBCF',
|
17
|
},
|
18
|
selected: {
|
19
|
main: '#C0C0C0',
|
20
|
},
|
21
|
}
|
22
|
|
23
|
export const darkThemePalette = {
|
24
|
primary: {
|
25
|
main: '#e0bb84',
|
26
|
},
|
27
|
secondary: {
|
28
|
main: '#E3DBCF',
|
29
|
},
|
30
|
}
|
31
|
|
32
|
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
|
}
|
41
|
}
|
42
|
|
43
|
export const buildTheme = (paletteMode: PaletteMode) =>
|
44
|
createTheme({
|
45
|
palette: {
|
46
|
mode: paletteMode,
|
47
|
...getPalette(paletteMode),
|
48
|
},
|
49
|
shape: {
|
50
|
borderRadius: 8,
|
51
|
},
|
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
|
const ThemeWrapper: FunctionComponent<ThemeWrapperProps> = ({ children }) => {
|
69
|
|
70
|
|
71
|
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
|
return <ThemeProvider theme={theme}>{children}</ThemeProvider>
|
83
|
}
|
84
|
|
85
|
export default ThemeWrapper
|