index.jsx 1.85 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3
import PropTypes from "prop-types";
// @mui
import {
wuhao's avatar
wuhao committed
4
  AppBar,
wuhao's avatar
wuhao committed
5
  Box,
wuhao's avatar
wuhao committed
6
  IconButton,
wuhao's avatar
wuhao committed
7 8 9 10
  Stack,
  Toolbar,
  useTheme,
} from "@mui/material";
wuhao's avatar
wuhao committed
11
import { styled } from "@mui/material/styles";
wuhao's avatar
wuhao committed
12 13 14 15
// utils
import { bgBlur } from "@/utils/cssStyles";
// components
import Iconify from "@/components/iconify";
wuhao's avatar
wuhao committed
16 17
import { useModel } from "@umijs/max";

wuhao's avatar
wuhao committed
18
import AccountPopover from "./AccountPopover";
wuhao's avatar
wuhao committed
19
import Searchbar from "./Searchbar";
wuhao's avatar
wuhao committed
20

wuhao's avatar
wuhao committed
21
//----------------------------------------------------------------------//
wuhao's avatar
wuhao committed
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

const HEADER_MOBILE = 64;

const HEADER_DESKTOP = 64;

const StyledRoot = styled(AppBar)(({ theme }) => ({
  ...bgBlur({ color: theme.palette.background.default }),
  boxShadow: "none",
}));

const StyledToolbar = styled(Toolbar)(({ theme }) => ({
  minHeight: HEADER_MOBILE,
  [theme.breakpoints.up("lg")]: {
    minHeight: HEADER_DESKTOP,
    padding: theme.spacing(0, 2),
  },
}));

// ----------------------------------------------------------------------

Header.propTypes = {
  onOpenNav: PropTypes.func,
};

export default function Header({ onOpenNav }) {
wuhao's avatar
wuhao committed
47 48 49
  const {
    initialState: { nav },
  } = useModel("@@initialState");
wuhao's avatar
wuhao committed
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
  const theme = useTheme();

  return (
    <StyledRoot
      sx={{
        [theme.breakpoints.up("lg")]: {
          width: `calc(100% - ${nav + 1}px)`,
        },
      }}
    >
      <StyledToolbar>
        <IconButton
          onClick={onOpenNav}
          sx={{
            mr: 1,
            color: "text.primary",
            display: { lg: "none" },
          }}
        >
          <Iconify icon="eva:menu-2-fill" />
        </IconButton>

        <Searchbar />
        <Box sx={{ flexGrow: 1 }} />

        <Stack
          direction="row"
          alignItems="center"
          spacing={{
            xs: 0.5,
            sm: 1,
          }}
        >
          <AccountPopover />
        </Stack>
      </StyledToolbar>
    </StyledRoot>
  );
}