All files / src/components/common/EmptyState EmptyState.tsx

100% Statements 11/11
60.97% Branches 25/41
100% Functions 4/4
100% Lines 11/11

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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186                                                              160x                   74x 74x 74x                                                                                                       160x 530x 74x                                                                                                     160x 74x   74x                                                       74x            
import React from "react";
import { Button } from "@common/Button";
import { Text } from "@common/Text";
import { Stack, SxProps, styled } from "@mui/material";
import { palette } from "@palette";
import { ButtonProps } from "@common/Button/Button";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
import { ITextProps } from "@common/Text/Text";
 
type TTitle = {
  main: string | React.ReactNode;
  secondary?: string;
};
 
type TSize = "large" | "medium";
 
export type TEmptyStateAction = ButtonProps & {
  label: string | React.ReactNode;
};
 
export interface IEmptyStateProps {
  title: TTitle;
  action?: TEmptyStateAction;
  sx?: SxProps;
  size?: TSize;
  Icon?: JSX.Element;
  backgroundSrc?: string;
  height?: string;
  customSize?: TextPropsEntry;
}
 
const EmptyState = ({
  title,
  action,
  sx,
  size = "medium",
  Icon,
  backgroundSrc,
  height,
  customSize,
}: IEmptyStateProps) => {
  const { textProps: defaultTextProps } = useGetParams(size);
  const textProps = customSize || defaultTextProps;
  return (
    <Container sx={sx} size={size} height={height} data-testid="empty-state">
      {backgroundSrc && (
        <>
          <div className="video-overlay" />
          <video autoPlay muted loop playsInline>
            <source src={backgroundSrc} type="video/mp4" />
          </video>
        </>
      )}
      {size === "medium" && Icon}
      <Stack direction="column" alignItems="center" width="100%" zIndex={2}>
        {size === "large" && Icon}
        <Text
          fontWeight="light"
          color={palette.black[300]}
          align="center"
          {...textProps.main}
        >
          {title.main}
        </Text>
        <Text
          fontWeight="book"
          color={palette.neutral[70]}
          align="center"
          {...textProps.secondary}
        >
          {title.secondary}
        </Text>
      </Stack>
      {typeof action?.label === "string" ? (
        <Button
          background="primary"
          size="medium"
          {...action}
          sx={{
            fontSize: "18px",
            padding: "12px 24px",
            zIndex: 2,
            fontWeight: "normal",
            ...(action?.sx && action?.sx)
          }}
        >
          {action.label}
        </Button>
      ) : (
        action?.label || <></>
      )}
    </Container>
  );
};
 
const Container = styled(Stack, {
  shouldForwardProp: (prop) => prop !== "size",
})<{ size: TSize }>(({ theme, size }) => ({
  flexDirection: "column",
  gap: size === "medium" ? "24px" : "32px",
  alignItems: "center",
  justifyContent: "center",
  position: "relative",
  overflow: "hidden",
  userSelect: "none",
  paddingBlock: size === "large" ? "220px 180px" : "100px",
 
  "& > video": {
    width: "100%",
    height: "auto",
    position: "absolute",
    top: "50%",
    left: "50%",
    transform: "translate(-50%, -50%)",
    objectFit: "contain",
    zIndex: 0,
  },
  "& > .video-overlay": {
    background:
      "radial-gradient(40% 40% at 50% 50%, rgba(251, 251, 251, 0.30) 0%, #F7F7F7 100%)",
    width: "100%",
    height: "100%",
    position: "absolute",
    top: 0,
    left: 0,
    zIndex: 1,
  },
 
  [theme.breakpoints.down("sm")]: {
    paddingBlock: "50px",
    paddingInline: "16px",
    ...(size === "large" && {
      gap: "64px",
    }),
    "& > .video-overlay": {
      height: "340px",
      top: "50%",
      left: "50%",
      transform: "translate(-50%, -50%)",
      background:
        "radial-gradient(35% 35% at 50% 50%, rgba(251, 251, 251, 0.10) 0%, #F7F7F7 100%)",
    },
  },
}));
 
type TText = "main" | "secondary";
type TextPropsEntry = Record<TText, ITextProps>;
 
const useGetParams = (size: TSize, customSize?: TextPropsEntry) => {
  const { isMobileView } = useCustomTheme();
 
  const textProps: Record<TSize, TextPropsEntry> = {
    large: {
      main: {
        fontSize: isMobileView ? "24px" : "56px",
        lineHeight: isMobileView ? "32.4px" : "67.2px",
        letterSpacing: isMobileView ? "-0.24px" : "-1.68px",
        padding: isMobileView ? "24px 0px 12px" : "8px 0px",
      },
      secondary: {
        fontSize: isMobileView ? "14px" : "18px",
        lineHeight: isMobileView ? "16.8px" : "21.6px",
        letterSpacing: isMobileView ? undefined : "-0.18px",
      },
    },
    medium: {
      main: {
        fontSize: isMobileView ? "18px" : "24px",
        lineHeight: isMobileView ? "21.6px" : "32.4px",
        letterSpacing: isMobileView ? "-0.18px" : "-0.24px",
      },
      secondary: {
        fontSize: "14px",
        lineHeight: "16.8px",
        fontWeight: "book",
      },
    },
  };
 
  return {
    textProps: textProps[size],
  };
};
 
export default React.memo(EmptyState);