All files / src/components/UploadFile/Rebranded Layout.tsx

83.33% Statements 5/6
10% Branches 1/10
50% Functions 1/2
83.33% Lines 5/6

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            46x                                                             46x 17x 17x   17x                          
import { useTheme } from "@mui/material";
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
import useMediaQuery from "@mui/material/useMediaQuery";
import { ILayoutProps } from "react-dropzone-uploader";
 
const PreviewWrapper = ({ children, ...props }: any) => {
  return props.howManyFiles > 5 || !props.isDesktop ? (
    <>
      <Box
        sx={{
          display: "block",
          overflowY: "hidden",
          overflowX: props.howManyFiles > 5 ? "scroll" : "hidden",
          overscrollBehavior: "contain",
          textAlign: "center",
          height: "max-content",
        }}
      >
        {children}
      </Box>
    </>
  ) : (
    <>
      <Stack
        mt={2}
        width="100%"
        alignItems="center"
        justifyContent="center"
        direction={props.isDesktop ? "row" : "column"}
      >
        {children}
      </Stack>
    </>
  );
};
 
const Layout = ({ input, previews, dropzoneProps, files }: ILayoutProps) => {
  const theme = useTheme();
  const isDesktop = useMediaQuery(theme.breakpoints.up("lg"));
 
  return (
    <Box sx={{ maxWidth: "100%" }} {...dropzoneProps}>
      {input}
      {files.length > 0 && (
        <PreviewWrapper howManyFiles={files.length} isDesktop={isDesktop}>
          {previews}
        </PreviewWrapper>
      )}
    </Box>
  );
};
 
export default Layout;