From 3cd59266c23f34158e4ef1aa2c4922d568a74a11 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Thu, 16 Jan 2025 17:55:49 +0100 Subject: [PATCH] feat: theme switcher --- src/pages/App.tsx | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 55a2c27..e6786a0 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -7,6 +7,7 @@ import { Box, createTheme, Drawer, + FormControlLabel, Icon, IconButton, List, @@ -14,10 +15,12 @@ import { ListItemButton, ListItemIcon, ListItemText, + Switch, ThemeProvider, Toolbar, Tooltip, Typography, + useColorScheme, } from "@mui/material"; import * as Icons from "@mui/icons-material"; import { useState } from "react"; @@ -40,7 +43,7 @@ const sidebarItems: Item[] = [ const drawerWidth = 240; -const darkTheme = createTheme({ +const theme = createTheme({ colorSchemes: { dark: true, }, @@ -48,9 +51,14 @@ const darkTheme = createTheme({ function App({ error }: { error?: boolean }) { const [isOpen, setOpen] = useState(false); + const { mode, setMode } = useColorScheme(); + + if (!mode) { + return null; + } return ( - + <> theme.zIndex.drawer + 1 }} @@ -67,6 +75,23 @@ function App({ error }: { error?: boolean }) { DLinux + } + label="Automatic theme" + labelPlacement="start" + onChange={() => setMode(mode === "system" ? "light" : "system")} + /> + {mode != "system" && ( + setMode(mode === "dark" ? "light" : "dark")} + > + {mode === "dark" ? ( + + ) : ( + + )} + + )} } {localStorage.getItem("key") ? : } - + ); } -export default App; +export default function ToggleColorMode() { + return ( + + + + ); +}