All files / src/sections/PayBuilder/Checkout/wrappers/BottomSheet index.tsx

94.73% Statements 18/19
70% Branches 21/30
85.71% Functions 6/7
94.73% Lines 18/19

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                                12x                 293x 293x   293x 33x 31x 31x 9x   22x     31x 31x         293x                 293x                                                                                               12x 1770x         293x                   12x   71x                              
import { Paper, Slide, Backdrop, Box, SxProps } from "@mui/material";
import { MobileLeftPanelMainHeader } from "@sections/PayBuilder/components/MobileLeftPanelMainHeader";
import { styled, useAppTheme } from "@theme/v2/Provider";
import { cloneElement, useEffect } from "react";
import useMasqueradeReducer from "@hooks/Reducers/useMasqueradeReducer";
 
interface Props {
  children: any;
  open?: boolean;
  onClose?: () => void;
  isMobile?: boolean;
  isPreviewMode?: boolean;
  showMobileHeader?: boolean;
  paperSx?: SxProps;
}
 
export const BottomSheet = ({
  children,
  open = true,
  isMobile,
  isPreviewMode,
  onClose = () => null,
  showMobileHeader = true,
  paperSx = {},
}: Props) => {
  const { customs, palette } = useAppTheme();
  const { masqueradeOffset } = useMasqueradeReducer();
 
  useEffect(() => {
    if (!isMobile) {
      const originalOverflow = document.body.style.overflowY;
      if (open) {
        document.body.style.overflowY = "hidden";
      } else {
        document.body.style.overflowY = "scroll";
      }
 
      return () => {
        document.body.style.overflowY = originalOverflow;
      };
    }
  }, [open]);
 
  const mainHeaderProps = isPreviewMode
    ? {
        color: palette.text.primary,
        backgroundColor: palette.common.white,
      }
    : {
        color: palette.common.white,
      };
 
  return (
    <>
      <BottomSheetBackdrop
        isPreviewMode={isPreviewMode}
        isMobile={isMobile}
        sx={{ alignItems: "flex-start" }}
        open={open}
        onClick={onClose}
      >
        {isMobile && showMobileHeader ? (
          <Box
            paddingTop={`${
              isPreviewMode ? (masqueradeOffset ? masqueradeOffset : 0) : 30
            }px`}
            sx={{
              width: "100%",
              display: "flex",
              alignItems: "center",
              justifyContent: "space-between",
            }}
          >
            {isPreviewMode ? (
              <MobileLeftPanelMainHeader {...mainHeaderProps} />
            ) : null}
          </Box>
        ) : null}
      </BottomSheetBackdrop>
 
      <Slide direction="up" in={open} mountOnEnter>
        <BottomSheetPaper
          elevation={4}
          sx={{
            position: isPreviewMode ? "absolute" : "fixed",
            ...paperSx,
          }}
        >
          {cloneElement(children, {
            sx: {
              marginTop: "0px !important",
              borderRadius: `${customs?.radius.medium}px ${customs?.radius.medium}px 0 0`,
            },
          })}
        </BottomSheetPaper>
      </Slide>
    </>
  );
};
 
const BottomSheetBackdrop = styled(Backdrop, {
  shouldForwardProp: (prop) => prop !== "isPreviewMode" && prop !== "isMobile",
})<{
  isPreviewMode?: boolean;
  isMobile?: boolean;
}>(({ theme, isPreviewMode, isMobile }) => {
  return {
    borderRadius: isMobile
      ? 0
      : `${theme.customs?.radius.medium}px ${theme.customs?.radius.medium}px 10px 10px`,
    zIndex: 8,
    position: isPreviewMode ? "absolute" : "fixed",
    backgroundColor: !isPreviewMode ? "rgba(0, 0, 0, 0.5)" : undefined,
  };
});
 
const BottomSheetPaper = styled(Paper)(
  ({ theme }) =>
    ({
      position: "absolute",
      bottom: 0,
      left: 0,
      right: 0,
      width: "100%",
      height: "87%",
      margin: "auto",
      padding: 0,
      borderTopLeftRadius: theme.customs?.radius.medium,
      borderTopRightRadius: theme.customs?.radius.medium,
      zIndex: 9,
      boxShadow: "none",
    } as any),
);