index.tsx 1.56 KB
Newer Older
Ken's avatar
Ken committed
1 2 3 4 5 6 7 8 9 10 11
import React from "react";
import {
  Box,
  Divider,
  Drawer,
  List,
  ListItem,
  ListItemButton,
  ListItemText,
  Typography,
} from "@mui/material";
Ken's avatar
Ken committed
12
import { ICategory } from "components/interface";
13
import { useNavigate } from "react-router-dom";
Ken's avatar
Ken committed
14 15 16

type Props = {
  handleDrawerToggle: () => void;
Ken's avatar
Ken committed
17
  navItems: Array<ICategory>;
Ken's avatar
Ken committed
18 19 20 21 22
  mobileOpen: boolean;
};

const drawerWidth = 240;
const Sidenav = (props: Props) => {
23
  const navigate = useNavigate();
Ken's avatar
Ken committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  const { navItems, handleDrawerToggle, mobileOpen } = props;

  return (
    <Box component="nav">
      <Drawer
        variant="temporary"
        open={mobileOpen}
        onClose={handleDrawerToggle}
        ModalProps={{
          keepMounted: true, // Better open performance on mobile.
        }}
        sx={{
          "& .MuiDrawer-paper": {
            boxSizing: "border-box",
            width: drawerWidth,
          },
        }}
      >
        <Box onClick={handleDrawerToggle} sx={{ textAlign: "center" }}>
          <Typography variant="h6" sx={{ my: 2 }}>
Ken's avatar
Ken committed
44
            Newspaper
Ken's avatar
Ken committed
45 46 47 48
          </Typography>
          <Divider />
          <List>
            {navItems.map((item) => (
49 50 51 52 53
              <ListItem
                key={item.link}
                disablePadding
                onClick={() => navigate(item.link)}
              >
Ken's avatar
Ken committed
54
                <ListItemButton sx={{ textAlign: "center" }}>
Ken's avatar
Ken committed
55
                  <ListItemText primary={item.label} />
Ken's avatar
Ken committed
56 57 58 59 60 61 62 63 64 65 66
                </ListItemButton>
              </ListItem>
            ))}
          </List>
        </Box>
      </Drawer>
    </Box>
  );
};

export default Sidenav;