All files / app/components ResizeableDrawer.tsx

0% Statements 0/21
0% Branches 0/7
0% Functions 0/5
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                                                                                                                                                                                                     
import { KeyboardArrowLeft, KeyboardArrowRight } from "@mui/icons-material";
import { styled } from "@mui/material";
import { useTranslation } from "i18n";
import { GLOBAL } from "i18n/namespaces";
import React from "react";
import { theme } from "theme";
 
import IconButton from "./IconButton";
 
export const DEFAULT_DRAWER_WIDTH = 420;
 
interface ResizeableDrawerProps {
  children: React.ReactNode;
  nonScrollableChildren?: React.ReactNode;
  onDrawerWidthChange: (width: number) => void;
  showDragger?: boolean;
}
 
const DrawerContentWrapper = styled("div")(() => ({
  display: "flex",
  flexDirection: "row",
  height: "100%",
  width: "100%",
  position: "relative",
}));
 
const StyledDragger = styled("div")(({ theme }) => ({
  width: "8px",
  borderLeft: `1px solid ${theme.palette.divider}`,
  backgroundColor: theme.palette.grey[50],
  display: "flex",
  alignItems: "center",
  justifyContent: "center",
  position: "relative",
}));
 
const ScrollableContent = styled("div")(({ theme }) => ({
  overflowY: "auto",
  height: "100%",
  width: "100%",
}));
 
const FlexColumn = styled("div")({
  display: "flex",
  flexDirection: "column",
  height: "100%",
  width: "100%",
});
 
export default function ResizeableDrawer({
  children,
  nonScrollableChildren,
  onDrawerWidthChange,
  showDragger,
}: ResizeableDrawerProps) {
  const { t } = useTranslation([GLOBAL]);
 
  const [isExpanded, setIsExpanded] = React.useState(false);
 
  const handleDrawerExpansion = () => {
    setIsExpanded(!isExpanded);
 
    onDrawerWidthChange(
      isExpanded ? DEFAULT_DRAWER_WIDTH : Math.floor(window?.innerWidth * 0.6),
    );
  };
 
  return (
    <DrawerContentWrapper>
      <FlexColumn>
        <ScrollableContent>{children}</ScrollableContent>
        {nonScrollableChildren}
      </FlexColumn>
      {showDragger && (
        <StyledDragger>
          <IconButton
            onClick={handleDrawerExpansion}
            aria-label={t(`global:${isExpanded ? "retract" : "expand"}`)}
            sx={{
              fontSize: "24px",
              backgroundColor: theme.palette.common.white,
              border: `1px solid ${theme.palette.divider}`,
              height: "35px",
              width: "35px",
              zIndex: 100,
 
              "&:hover": {
                backgroundColor: theme.palette.common.white,
              },
            }}
          >
            {isExpanded ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
          </IconButton>
        </StyledDragger>
      )}
    </DrawerContentWrapper>
  );
}