All files / src/componentsV2/SideMenu/components MobileNavBar.tsx

100% Statements 17/17
80% Branches 20/25
100% Functions 4/4
100% Lines 16/16

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                                                        13x 4x 4x     4x         4x 4x         4x   4x                                                                                                                                                 13x   33x   4x                                   13x                   13x       13x               13x                         13x            
import { memo } from "react";
import { styled, useAppTheme } from "@theme/v2/Provider";
import {
  AppBar as AppBarMui,
  Box,
  IconButton,
  Stack,
  Toolbar,
  Skeleton,
} from "@mui/material";
import MenuTwo from "@assets/iconsV2/MenuTwo";
import GiveText from "@shared/Text/GiveText";
import UserSection from "./UserSection";
import { useBannerOffset } from "@hooks/common/useBannerOffset";
import { useMobileTableHeader } from "componentsV2/Table/MobileTableHeaderContext";
import { palette } from "@theme/colors";
import { useGetRebrandedTableBehaviour } from "components/CustomBreadcrumbsPage/hooks/useGetRebrandedTableBehaviour";
import { APP_BAR_HEIGHT } from "@constants/constants";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { BALANCE_MAINTENANCE_TOOLTIP_MESSAGE } from "@shared/constants";
import { parseAmount, parseToNumber } from "@utils/index";
import { CALCULATION_IN_PROGRESS } from "@constants/permissions";
 
type TParams = {
  toggleDrawer: () => void;
  availableBalance: string | number;
};
 
const MobileNavBar = ({ toggleDrawer, availableBalance }: TParams) => {
  const { palette } = useAppTheme();
  const bannerOffset = useBannerOffset();
 
  const { showMobileNavBarOverlay, isRebrandedSettings } =
    useGetRebrandedTableBehaviour();
 
  // TRA013: while the page's full banner is scrolled out of view, the current
  // table hands its compact head (title/stats + search + three-dots menu) up
  // here and the top bar expands to keep those actions reachable.
  const { compactHead, compactTitle, isActive } = useMobileTableHeader();
  const isCompactExpanded = isActive && !!compactHead;
  // Pages whose subject is a name rather than a set of stats hand it up with
  // the compact head and it takes the balance's place in this row while
  // scrolled — Event Detail, frame 8091-56253. Everything else keeps the
  // balance.
  const showCompactTitle = isCompactExpanded && !!compactTitle;
 
  return (
    <AppBar
      id="slide-me2"
      elevation={0}
      bannerOffset={bannerOffset}
      showMobileNavBarOverlay={showMobileNavBarOverlay && !isRebrandedSettings}
    >
      <Container>
        <TopRow direction="row" spacing="16px">
          <IconButton
            size="large"
            onClick={toggleDrawer}
            version="two"
            sx={{ padding: 0 }}
          >
            <MenuTwo fill={palette.text.primary} />
          </IconButton>
          {showCompactTitle && <CompactTitle>{compactTitle}</CompactTitle>}
          {!showCompactTitle && !isRebrandedSettings && (
            <Stack>
              {availableBalance === "-" ? (
                <GiveTooltip
                  title={BALANCE_MAINTENANCE_TOOLTIP_MESSAGE}
                  placement="top"
                  fluidWidth
                >
                  <Skeleton
                    variant="rounded"
                    width={100}
                    height={20}
                    sx={{
                      borderRadius: "40px",
                    }}
                  />
                </GiveTooltip>
              ) : (
                <GiveTooltip
                  title={
                    availableBalance === "-"
                      ? CALCULATION_IN_PROGRESS
                      : availableBalance.toLocaleString()
                  }
                  placement="bottom"
                  disableHoverListener={
                    availableBalance !== "-" &&
                    Math.abs(parseToNumber(availableBalance) || 0) < 1_000_000
                  }
                  fluidWidth
                >
                  <GiveText variant="bodyS" color="primary">
                    {parseAmount(availableBalance)}
                  </GiveText>
                </GiveTooltip>
              )}
              <GiveText variant="bodyXS" color="secondary">
                Balance (USD)
              </GiveText>
            </Stack>
          )}
        </TopRow>
        <UserSection isAppBar />
      </Container>
      <CompactHeadRow
        className={isCompactExpanded ? "compact-head-row--expanded" : undefined}
        aria-hidden={!isCompactExpanded}
      >
        <CompactHeadInner>{compactHead}</CompactHeadInner>
      </CompactHeadRow>
    </AppBar>
  );
};
export default memo(MobileNavBar);
 
const AppBar = styled(AppBarMui, {
  shouldForwardProp: (prop) =>
    prop !== "showMobileNavBarOverlay" && prop !== "bannerOffset",
})<{ bannerOffset: number; showMobileNavBarOverlay: boolean }>(
  ({ theme, bannerOffset, showMobileNavBarOverlay }) => ({
    top: `${bannerOffset}px`,
    minHeight: APP_BAR_HEIGHT,
    width: "100%",
    borderBottom: `1px solid transparent`,
    backgroundColor: showMobileNavBarOverlay
      ? palette.background.newWhite
      : theme.palette.surface?.primary,
    "&.overlay-enabled": {
      borderBottom: `1px solid ${theme.palette.border?.primary}`,
      backgroundColor: theme.palette.surface?.primary,
    },
    "&.noborder-overlay-enabled": {
      backgroundColor: theme.palette.surface?.primary,
    },
  }),
);
 
const Container = styled(Toolbar)({
  padding: "16px 20px",
  justifyContent: "space-between",
  alignItems: "center",
});
 
// A long subject name has to ellipsize inside the row rather than push
// UserSection off the right edge, which needs the shrinkable chain spelled out
// — `min-width: 0` here, `overflow: hidden` on the title box. Nothing else
// about the row changes, so the balance it normally holds is unaffected.
const TopRow = styled(Stack)({
  minWidth: 0,
});
 
const CompactTitle = styled(Box)({
  minWidth: 0,
  overflow: "hidden",
});
 
// Second row that grows in when the page's banner is scrolled away, revealing
// the compact head (search + three-dots menu). Animated via max-height so the
// top bar visibly enlarges rather than snapping.
const CompactHeadRow = styled(Box)(({ theme }) => ({
  overflow: "hidden",
  maxHeight: 0,
  opacity: 0,
  transition: "max-height 0.2s ease, opacity 0.2s ease",
  borderTop: `1px solid transparent`,
  "&.compact-head-row--expanded": {
    maxHeight: "80px",
    opacity: 1,
    borderTopColor: theme.palette.border?.primary,
  },
}));
 
const CompactHeadInner = styled(Box)({
  display: "flex",
  alignItems: "center",
  width: "100%",
  padding: "12px 20px",
});