SidebarNav.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import * as React from "react";
  2. import { Drawer, List } from "@material-ui/core";
  3. import { NavItem } from "./NavItem";
  4. import { BarChart } from "@material-ui/icons";
  5. import { Cloud } from "@material-ui/icons";
  6. import { makeStyles } from "@material-ui/styles";
  7. const DRAWER_WIDTH = 200;
  8. const SidebarNav = ({ active }) => {
  9. const useStyles = makeStyles({
  10. drawer: {
  11. width: DRAWER_WIDTH,
  12. flexShrink: 0,
  13. },
  14. drawerPaper: {
  15. backgroundColor: "inherit",
  16. border: 0,
  17. width: DRAWER_WIDTH,
  18. paddingTop: "2.5rem",
  19. },
  20. text: {
  21. overflow: "hidden",
  22. textOverflow: "ellipsis",
  23. whiteSpace: "nowrap",
  24. },
  25. });
  26. const classes = useStyles();
  27. const [init, setInit] = React.useState(false);
  28. React.useEffect(() => {
  29. if (!init) {
  30. setInit(true);
  31. }
  32. }, [init]);
  33. const top = [
  34. {
  35. name: "Cost Allocation",
  36. href: "allocation",
  37. icon: <BarChart />,
  38. },
  39. { name: "Cloud Costs", href: "cloud", icon: <Cloud /> },
  40. ];
  41. return (
  42. <Drawer
  43. anchor={"left"}
  44. className={classes.drawer}
  45. classes={{ paper: classes.drawerPaper }}
  46. variant={"permanent"}
  47. >
  48. <img
  49. src={require("../../images/logo.png")}
  50. alt="OpenCost"
  51. style={{ flexShrink: 1, padding: "1rem" }}
  52. />
  53. <List style={{ flexGrow: 1 }}>
  54. {top.map((l) => (
  55. <NavItem active={active === `/${l.href}`} key={l.name} {...l} />
  56. ))}
  57. </List>
  58. </Drawer>
  59. );
  60. };
  61. export { SidebarNav };