a b/src/components/Layout/Sidebar.tsx
1
import React from 'react';
2
import {
3
  Drawer,
4
  List,
5
  ListItem,
6
  ListItemIcon,
7
  ListItemText,
8
  Divider,
9
  styled,
10
} from '@mui/material';
11
import {
12
  Science,
13
  Timeline,
14
  Biotech,
15
  Dashboard,
16
  CloudQueue,
17
  Settings,
18
} from '@mui/icons-material';
19
import { useNavigate } from 'react-router-dom';
20
21
const drawerWidth = 240;
22
23
const StyledDrawer = styled(Drawer)({
24
  width: drawerWidth,
25
  flexShrink: 0,
26
  '& .MuiDrawer-paper': {
27
    width: drawerWidth,
28
    boxSizing: 'border-box',
29
  },
30
});
31
32
interface SidebarProps {
33
  open: boolean;
34
  onClose: () => void;
35
}
36
37
const menuItems = [
38
  { text: 'Dashboard', icon: <Dashboard />, path: '/' },
39
  { text: 'Experiments', icon: <Science />, path: '/experiments' },
40
  { text: 'Gene Analysis', icon: <Biotech />, path: '/gene-analysis' },
41
  { text: 'Simulations', icon: <Timeline />, path: '/simulations' },
42
  { text: 'IoT Monitoring', icon: <CloudQueue />, path: '/monitoring' },
43
  { text: 'Settings', icon: <Settings />, path: '/settings' },
44
];
45
46
export const Sidebar: React.FC<SidebarProps> = ({ open, onClose }) => {
47
  const navigate = useNavigate();
48
49
  const handleNavigation = (path: string) => {
50
    navigate(path);
51
    onClose();
52
  };
53
54
  return (
55
    <StyledDrawer
56
      variant="temporary"
57
      anchor="left"
58
      open={open}
59
      onClose={onClose}
60
      ModalProps={{
61
        keepMounted: true, // Better mobile performance
62
      }}
63
    >
64
      <List>
65
        {menuItems.map((item) => (
66
          <React.Fragment key={item.text}>
67
            <ListItem onClick={() => handleNavigation(item.path)} sx={{ cursor: 'pointer' }}>
68
              <ListItemIcon>{item.icon}</ListItemIcon>
69
              <ListItemText primary={item.text} />
70
            </ListItem>
71
            {item.text === 'Dashboard' && <Divider />}
72
          </React.Fragment>
73
        ))}
74
      </List>
75
    </StyledDrawer>
76
  );
77
};