1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
import React from 'react';
import { ReactNode, createContext, useMemo, useState } from 'react';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import type { PaletteMode } from '@mui/material';
type ThemeContextType = {
toggleColorMode: () => void;
};
type ThemeProviderProps = {
children: ReactNode;
};
export const ThemeContext = createContext<ThemeContextType>({
toggleColorMode: () => {},
});
function AppThemeProvider({ children }: ThemeProviderProps) {
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
const [mode, setMode] = useState<'light' | 'dark'>(
prefersDarkMode ? 'dark' : 'light'
);
const toggleColorMode = () => {
setMode((prevMode: PaletteMode) =>
prevMode === 'light' ? 'dark' : 'light'
);
};
const getDesignTokens = (mode: PaletteMode) => ({
palette: {
mode,
...(mode === 'light'
? {
primary: {
main: '#FFAB91',
},
}
: {
primary: {
main: '#FF8A65',
},
}),
},
});
const colorTheme = createTheme(getDesignTokens(mode));
const roboto = {
sx: {
fontFamily: 'Roboto, sans-serif',
},
};
const theme = useMemo(
() =>
createTheme({
...colorTheme,
typography: {
fontFamily: ['Playwrite US Trad', 'cursive'].join(','),
button: {
textTransform: 'none',
},
body1: {
lineHeight: 1.8,
},
},
components: {
MuiInputBase: {
defaultProps: roboto,
},
MuiInputLabel: {
defaultProps: roboto,
},
MuiAlert: {
defaultProps: roboto,
},
MuiFormHelperText: {
defaultProps: roboto,
},
},
}),
[mode]
);
return (
<ThemeContext.Provider value={{ toggleColorMode }}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</ThemeContext.Provider>
);
}
export default AppThemeProvider;
|