diff --git a/src_generic/components/AdminLayout.tsx b/src_generic/components/AdminLayout.tsx index 6e1daa1..414cdaf 100644 --- a/src_generic/components/AdminLayout.tsx +++ b/src_generic/components/AdminLayout.tsx @@ -12,15 +12,19 @@ import { ListItemIcon, ListItemText, CssBaseline, - IconButton + IconButton, + Tooltip, } from '@mui/material'; import TableViewIcon from '@mui/icons-material/TableView'; import DashboardIcon from '@mui/icons-material/Dashboard'; import LogoutIcon from '@mui/icons-material/Logout'; +import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'; +import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import { ResourceConfig } from '../types/config'; import { useLocation, useNavigate } from 'react-router-dom'; const drawerWidth = 240; +const collapsedWidth = 64; interface AdminLayoutProps { children: React.ReactNode; @@ -39,67 +43,148 @@ export default function AdminLayout({ }: AdminLayoutProps) { const location = useLocation(); const navigate = useNavigate(); + const [isCollapsed, setIsCollapsed] = React.useState(false); const activeResourceName = location.pathname.split('/')[1] || null; + // AUTO-TOGGLE LOGIC + React.useEffect(() => { + if (location.pathname === '/' || location.pathname === '') { + setIsCollapsed(false); + } else { + setIsCollapsed(true); + } + }, [location.pathname]); + + const currentWidth = isCollapsed ? collapsedWidth : drawerWidth; + + const handleToggle = () => { + setIsCollapsed(!isCollapsed); + }; + return ( - theme.zIndex.drawer + 1 }}> + theme.zIndex.drawer + 1, + backdropFilter: 'blur(8px)', + backgroundColor: 'rgba(255, 255, 255, 0.8)', // Adjust based on theme in real app + color: 'text.primary', + boxShadow: 'none', + borderBottom: '1px solid', + borderColor: 'divider', + }} + > - + Admin Panel - + {username} - - - + + + + + theme.transitions.create('width', { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen, + }), + [`& .MuiDrawer-paper`]: { + width: currentWidth, + boxSizing: 'border-box', + overflowX: 'hidden', + transition: (theme) => theme.transitions.create('width', { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen, + }), + }, }} > - + + + + {isCollapsed ? : } + + + - navigate('/')} - > - - - - - + + navigate('/')} + sx={{ + minHeight: 48, + justifyContent: isCollapsed ? 'center' : 'initial', + px: 2.5, + }} + > + + + + {!isCollapsed && } + + - + {resources.map((res) => ( - onSelectResource(res.name)} - > - - - - - + + onSelectResource(res.name)} + sx={{ + minHeight: 48, + justifyContent: isCollapsed ? 'center' : 'initial', + px: 2.5, + }} + > + + + + {!isCollapsed && } + + ))} - - + theme.transitions.create(['margin', 'width'], { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen, + }), + }} + > {children}