Header.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import * as React from "react";
  2. import { makeStyles } from "@material-ui/styles";
  3. import Breadcrumbs from "@material-ui/core/Breadcrumbs";
  4. import Link from "@material-ui/core/Link";
  5. import Typography from "@material-ui/core/Typography";
  6. import { useLocation } from "react-router-dom";
  7. const useStyles = makeStyles({
  8. root: {
  9. alignItems: "center",
  10. display: "flex",
  11. flexFlow: "row",
  12. width: "100%",
  13. marginTop: "10px",
  14. },
  15. context: {
  16. flex: "1 0 auto",
  17. },
  18. actions: {
  19. flex: "0 0 auto",
  20. },
  21. });
  22. const Header = (props) => {
  23. const classes = useStyles();
  24. const { title, breadcrumbs } = props;
  25. const { pathname } = useLocation();
  26. const headerTitle = pathname === "/cloud" ? "Cloud Costs" : "Cost Allocation";
  27. return (
  28. <div className={classes.root}>
  29. <Typography variant="h3" style={{ marginBottom: "10px" }}>
  30. {headerTitle}
  31. </Typography>
  32. <div className={classes.context}>
  33. {title && (
  34. <Typography variant="h4" className={classes.title}>
  35. {props.title}
  36. </Typography>
  37. )}
  38. {breadcrumbs && breadcrumbs.length > 0 && (
  39. <Breadcrumbs aria-label="breadcrumb">
  40. {breadcrumbs.slice(0, breadcrumbs.length - 1).map((b) => (
  41. <Link color="inherit" href={b.href} key={b.name}>
  42. {b.name}
  43. </Link>
  44. ))}
  45. <Typography color="textPrimary">
  46. {breadcrumbs[breadcrumbs.length - 1].name}
  47. </Typography>
  48. </Breadcrumbs>
  49. )}
  50. </div>
  51. <div className={classes.actions}>{props.children}</div>
  52. </div>
  53. );
  54. };
  55. export default Header;