// src/components/layouts/Layout.tsx import React, { ReactNode } from 'react'; import { styled, useColorScheme } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Drawer from '@mui/material/Drawer'; import AppBar from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; import List from '@mui/material/List'; import Typography from '@mui/material/Typography'; import Divider from '@mui/material/Divider'; import IconButton from '@mui/material/IconButton'; import MenuIcon from '@mui/icons-material/Menu'; import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'; import ListItem from '@mui/material/ListItem'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import DashboardIcon from '@mui/icons-material/Dashboard'; import DirectionsCarIcon from '@mui/icons-material/DirectionsCar'; import PeopleIcon from '@mui/icons-material/People'; import { Link as RouterLink } from 'react-router-dom'; import Select, { SelectChangeEvent } from '@mui/material/Select'; import MenuItem from '@mui/material/MenuItem'; import FormControl from '@mui/material/FormControl'; import InputLabel from '@mui/material/InputLabel'; // Constants const drawerWidth = 240; // Styled components const DrawerHeader = styled('div')(({ theme }) => ({ display: 'flex', alignItems: 'center', padding: theme.spacing(0, 1), ...theme.mixins.toolbar, justifyContent: 'flex-end', })); const Main = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })<{ open?: boolean; }>(({ theme, open }) => ({ flexGrow: 1, padding: theme.spacing(3), transition: theme.transitions.create(['margin', 'width', 'padding'], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.enteringScreen, }), marginLeft: "0px !important", // Force remove any margin on the left marginRight: "0px !important", // Force remove any margin on the left ...(open && {/*Opened specific types go here*/}), ...(!open && {/*closed specific styles go here*/}) })); interface LayoutProps { children: ReactNode; } const Layout = ({ children }: LayoutProps) => { const [open, setOpen] = React.useState(false); const { mode, setMode } = useColorScheme(); // MUI v6 hook for theme switching const iconButtonRef = React.useRef(null) const handleDrawerOpen = () => { setOpen(true); sendResize(); }; const handleDrawerClose = () => { setOpen(false); sendResize(); }; const sendResize = () => { //// Force window resize event after drawer state changes //setTimeout(() => { // window.dispatchEvent(new Event("resize")); //}); // Delay slightly to ensure UI updates }; const handleThemeChange = (event: SelectChangeEvent) => { setMode(event.target.value as 'light' | 'dark'); if (iconButtonRef.current) { const selectElement = iconButtonRef.current; if (selectElement) { if (selectElement instanceof HTMLElement) { setTimeout(() => { selectElement.focus(); // Blur the focusable input }, 0); } } } }; return ( {/* App Bar */} ({ zIndex: theme.zIndex.drawer + 1, transition: theme.transitions.create(['width', 'margin','padding'], { easing: theme.transitions.easing.easeInOut, duration: theme.transitions.duration.leavingScreen, }), ...(open && { width: `calc(100% - ${drawerWidth}px)`, ml: `${drawerWidth}px`, transition: theme.transitions.create(['width', 'margin', 'padding'], { easing: theme.transitions.easing.easeInOut, duration: theme.transitions.duration.enteringScreen, }), }), })} > Surge365 Dashboard Theme {/* Sidebar */} {[ { text: 'Home', icon: , path: '/home' }, { text: 'Targets', icon: , path: '/targets' }, { text: 'Templates', icon: , path: '/templates' }, ].map((item) => ( {item.icon} ))} {/* Main Content */}
{children}
); }; export default Layout;