teste de mudança de tema para modo escuro
This commit is contained in:
parent
f7833e9dd0
commit
5daf95c99c
62
frontend/src/sections/settings/color-theme.js
Normal file
62
frontend/src/sections/settings/color-theme.js
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import IconButton from '@mui/material/IconButton';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import { useTheme, ThemeProvider, createTheme } from '@mui/material/styles';
|
||||||
|
import Brightness4Icon from '@mui/icons-material/Brightness4';
|
||||||
|
import Brightness7Icon from '@mui/icons-material/Brightness7';
|
||||||
|
|
||||||
|
const ColorModeContext = React.createContext({ toggleColorMode: () => {} });
|
||||||
|
|
||||||
|
function MyApp() {
|
||||||
|
const theme = useTheme();
|
||||||
|
const colorMode = React.useContext(ColorModeContext);
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
width: '100%',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
bgcolor: 'background.default',
|
||||||
|
color: 'text.primary',
|
||||||
|
borderRadius: 1,
|
||||||
|
p: 3,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{theme.palette.mode} mode
|
||||||
|
<IconButton sx={{ ml: 1 }} onClick={colorMode.toggleColorMode} color="inherit">
|
||||||
|
{theme.palette.mode === 'dark' ? <Brightness7Icon /> : <Brightness4Icon />}
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ToggleColorMode() {
|
||||||
|
const [mode, setMode] = React.useState<'light' | 'dark'>('light');
|
||||||
|
const colorMode = React.useMemo(
|
||||||
|
() => ({
|
||||||
|
toggleColorMode: () => {
|
||||||
|
setMode((prevMode) => (prevMode === 'light' ? 'dark' : 'light'));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const theme = React.useMemo(
|
||||||
|
() =>
|
||||||
|
createTheme({
|
||||||
|
palette: {
|
||||||
|
mode,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
[mode],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ColorModeContext.Provider value={colorMode}>
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<MyApp />
|
||||||
|
</ThemeProvider>
|
||||||
|
</ColorModeContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user