All files / src/components/common/MobilePaymentForm Drawer.tsx

0% Statements 0/19
0% Branches 0/18
0% Functions 0/8
0% Lines 0/14

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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146                                                                                                                                                                                                                                                                                                   
import * as React from "react";
import { Global } from "@emotion/react";
import { styled } from "@mui/material/styles";
import CssBaseline from "@mui/material/CssBaseline";
import { grey } from "@mui/material/colors";
import Box from "@mui/material/Box";
import SwipeableDrawer from "@mui/material/SwipeableDrawer";
 
const drawerBleeding = 0;
 
interface Props {
  open: boolean;
  setOpen: React.Dispatch<React.SetStateAction<boolean>>;
  window?: () => Window;
  _renderFixedHeader?: () => React.ReactNode;
  _renderComponent?: () => React.ReactNode;
  _renderActions?: () => React.ReactNode;
}
 
const Root = styled("div")(({ theme }) => ({
  height: "100%",
  backgroundColor:
    theme.palette.mode === "light"
      ? grey[100]
      : theme.palette.background.default,
}));
 
const StyledBox = styled(Box)(({ theme }) => ({
  backgroundColor: theme.palette.mode === "light" ? "#fff" : grey[800],
}));
 
const Puller = styled(Box)(({ theme }) => ({
  width: 30,
  height: 6,
  backgroundColor: theme.palette.mode === "light" ? grey[300] : grey[900],
  borderRadius: 3,
  position: "absolute",
  top: 8,
  left: "calc(50% - 15px)",
}));
 
const Drawer = (props: Props) => {
  const {
    window,
    open: _open,
    _renderComponent,
    _renderActions,
    _renderFixedHeader,
  } = props;
  const [open, setOpen] = React.useState(false);
 
  React.useEffect(() => {
    setOpen(_open);
  }, [_open]);
 
  const toggleDrawer = (newOpen: boolean) => () => {
    setOpen(newOpen);
    props.setOpen(false);
  };
 
  const container =
    window !== undefined ? () => window().document.body : undefined;
 
  return (
    <Root
      sx={{
        borderRadius: "24px",
      }}
    >
      <CssBaseline />
      <Global
        styles={{
          ".MuiDrawer-root > .MuiPaper-root": {
            height: `calc(90% - ${drawerBleeding}px)`,
            overflow: "visible",
          },
        }}
      />
      <SwipeableDrawer
        container={container}
        anchor="bottom"
        open={open}
        onClose={toggleDrawer(false)}
        onOpen={toggleDrawer(true)}
        swipeAreaWidth={drawerBleeding}
        disableSwipeToOpen={false}
        PaperProps={{
          sx: {
            borderRadius: "24px 24px 0 0",
            backgroundColor: _renderFixedHeader ? "#F6F6F4" : undefined,
          },
        }}
        ModalProps={{
          keepMounted: true,
        }}
        slotProps={{
          backdrop: {
            sx: {
              backdropFilter: "blur(3px)",
              backgroundColor: "rgba(53, 53, 53, 0.15)",
            },
          },
        }}
      >
        {_renderFixedHeader && _renderFixedHeader()}
        <StyledBox
          sx={{
            position: "absolute",
            top: -drawerBleeding,
            borderTopLeftRadius: 8,
            borderTopRightRadius: 8,
            visibility: "visible",
            zIndex: 1,
            right: 0,
            left: 0,
          }}
        >
          <Puller />
        </StyledBox>
        <StyledBox
          sx={{
            px: 2,
            paddingTop: _renderFixedHeader ? 2 : 4,
            paddingBottom: 4,
            height: "100%",
            overflow: "auto",
            borderRadius: "24px 24px 0px 0px",
            backgroundColor: "#F6F6F4",
            "&::-webkit-scrollbar": {
              display: "none",
            },
            "&::-webkit-scrollbar-track": {
              display: "none",
            },
          }}
        >
          {_renderComponent && _renderComponent()}
        </StyledBox>
        {_renderActions && _renderActions()}
      </SwipeableDrawer>
    </Root>
  );
};
 
export default Drawer;