diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 09feabdc..0d9c4149 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -8,10 +8,13 @@ import Toolbar from "@mui/material/Toolbar"; import Typography from "@mui/material/Typography"; import InfoIcon from "@mui/icons-material/Info"; import GitHubIcon from "@mui/icons-material/GitHub"; -import { createTheme, ThemeProvider } from "@mui/material/styles"; +import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles"; import { makeStyles } from "@mui/styles"; import "fontsource-roboto"; import ReactGA from "react-ga4"; +import Brightness4Icon from "@mui/icons-material/Brightness4"; +import Brightness7Icon from "@mui/icons-material/Brightness7"; +import CssBaseline from "@mui/material/CssBaseline"; import { PlotSpectra } from "./components/PlotSpectra"; import { palette } from "./constants"; import logo from "./radis.png"; @@ -21,6 +24,12 @@ ReactGA.initialize("G-V67HS7VB4R"); ReactGA.send(window.location.pathname); /*#########INITIALIZING_GOOGLE_ANALYTICS###############*/ +const ColorModeContext = React.createContext({ + toggleColorMode: () => { + console.warn("toggleColorMode has no implementation"); + }, +}); + export const theme = createTheme({ palette, }); @@ -93,6 +102,8 @@ const InfoPopover = () => { const Header: React.FC = () => { const classes = useStyles(); + const theme = useTheme(); + const colorMode = React.useContext(ColorModeContext); return ( @@ -111,6 +122,17 @@ const Header: React.FC = () => { } /> + + {theme.palette.mode === "dark" ? ( + + ) : ( + + )} + @@ -120,9 +142,11 @@ const Header: React.FC = () => { function App(): React.ReactElement { const classes = useStyles(); + const theme = useTheme(); return (
+
@@ -134,4 +158,34 @@ function App(): React.ReactElement { ); } -export default App; //export +// export default App; + +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 ( + + + + + + ); +}