All files / src/shared/SidePanel/components/SidePanelHeader SidePanelHeader.tsx

79.16% Statements 19/24
46.66% Branches 7/15
66.66% Functions 6/9
85.71% Lines 18/21

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 187 188 189 190 191 192 193 194                                  74x           730x 730x   730x   730x                                                   74x         689x     689x                                         74x                                 803x 803x                                                                                                           74x                           74x           74x 2410x     1533x                   74x 74x      
import { Box, Grid, Stack, SxProps } from "@mui/material";
import { Children, ReactNode } from "react";
import { SidePanelButton, SidePanelName } from "./SidePanelHeaderAtoms";
import { useSidePanelHeaderContext } from "./SidePanelHeaderContext";
import { styled, useAppTheme } from "@theme/v2/Provider";
import ProgressBar from "./ProgressBar";
import ContextualMenu from "@shared/ContextualMenu/ContextualMenu";
import GiveText from "@shared/Text/GiveText";
import { TabsDataTypes } from "features/Merchants/MerchantSidePanel/AgreementAndSnapshot/agreements.types";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { Container, MainActionsContainer } from "./SidePanelHeader.styles";
import GiveLineTab from "@shared/Tabs/GiveLineTab";
 
interface Props {
  children: ReactNode | ReactNode[];
}
 
const SidePanelHeader = ({ children }: Props) => {
  const {
    actions,
    anchorEl,
    onCloseMenu,
    isLoading = false,
  } = useSidePanelHeaderContext();
  const { isMobileView } = useCustomThemeV2();
 
  const childrenArr = Children.toArray(children);
 
  return (
    <Stack position="sticky" top="0px" zIndex={100}>
      <StyledBox>
        <Container>
          <Grid container alignItems="center" gap="8px">
            {childrenArr[0]}
          </Grid>
          <MainActionsContainer>
            <Stack direction="row" gap="16px">
              {childrenArr[1]}
            </Stack>
          </MainActionsContainer>
        </Container>
        <ContextualMenu
          handleClose={onCloseMenu}
          anchorEl={anchorEl}
          color={isMobileView ? "primary" : "tertiary"}
          texture={isMobileView ? "solid" : "blurred"}
          options={actions}
        />
      </StyledBox>
      <ProgressBar isLoading={isLoading} />
    </Stack>
  );
};
 
export const SidePanelFooterContainer = ({
  children,
}: {
  children: React.ReactElement;
}) => {
  return <StyledFooter>{children}</StyledFooter>;
};
 
const StyledFooter = styled(Stack)(({ theme }) => ({
  padding: "16px",
  gap: "12px",
  borderTop: `1px solid ${theme.palette.border?.primary}`,
  flexDirection: "row",
  alignItems: "center",
  justifyContent: "flex-end",
  background: theme.palette.surface?.["secondary-transparent"],
  backdropFilter: "blur(25px)",
  width: "100%",
  maxWidth: 500,
  [theme.breakpoints.down("v2_sm")]: {
    maxWidth: "unset",
  },
  flexShrink: 0,
  marginTop: "auto",
 
  position: "sticky",
  bottom: 0,
  zIndex: 10,
}));
export const SidePanelHeaderBase = ({
  children,
  leftItems,
  rightItems,
  tabsData,
  noBorderBottom,
  showGradientTabs,
  sx,
}: {
  children?: ReactNode;
  leftItems: ReactNode;
  rightItems: ReactNode;
  tabsData?: TabsDataTypes[];
  noBorderBottom?: boolean;
  showGradientTabs?: boolean;
  sx?: SxProps;
}) => {
  const { palette } = useAppTheme();
  return (
    <Stack position="sticky" top="0px" zIndex={100} sx={sx}>
      <StyledBox noBorderBottom={noBorderBottom}>
        <Container>
          <Grid container alignItems="center" gap="8px">
            {leftItems}
          </Grid>
          <MainActionsContainer>
            <Stack direction="row" gap="16px">
              {rightItems}
            </Stack>
          </MainActionsContainer>
        </Container>
 
        {children}
      </StyledBox>
      {tabsData && (
        <TabContainer>
          {tabsData?.map(({ label, isActive, onClick }) => {
            if (showGradientTabs) {
              return (
                <GiveLineTab
                  key={label}
                  label={label}
                  value={label}
                  selected={isActive}
                  onClick={onClick}
                  dataTestId={`give-tab-${label}`}
                  applyGradient
                />
              );
            }
 
            return (
              <CustomText
                key={label}
                onClick={onClick}
                color={isActive ? "primary" : "secondary"}
                sx={{
                  ...(isActive && {
                    borderBottom: `1px solid ${palette?.border?.active}`,
                  }),
                }}
              >
                {label}
              </CustomText>
            );
          })}
        </TabContainer>
      )}
    </Stack>
  );
};
 
const TabContainer = styled(Stack)(({ theme }) => ({
  paddingTop: "20px",
  borderBottom: `1px solid ${theme.palette?.border?.primary}`,
  backgroundColor: theme.palette?.surface?.["secondary-transparent"],
  backdropFilter: "blur(25px)",
  flexDirection: "row",
  alignItems: "baseline",
  margin: "0 16px",
  gap: "20px",
  overflowX: "auto",
  whiteSpace: "nowrap",
  scrollbarWidth: "none",
}));
 
const CustomText = styled(GiveText)(({ theme }) => ({
  paddingBottom: "16px",
  cursor: "pointer",
  whiteSpace: "nowrap",
}));
 
const StyledBox = styled(Box, {
  shouldForwardProp: (prop) => prop !== "noBorderBottom",
})<{
  noBorderBottom?: boolean;
}>(({ noBorderBottom, theme }) => ({
  paddingBlock: "16px",
  paddingInline: "20px",
  ...(!noBorderBottom && {
    borderBottom: `1px solid ${theme.palette?.border?.primary}`,
  }),
  backgroundColor: theme.palette?.surface?.["secondary-transparent"],
  backdropFilter: "blur(25px)",
}));
 
SidePanelHeader.Button = SidePanelButton;
SidePanelHeader.Name = SidePanelName;
 
export default SidePanelHeader;