mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import type { FC } from 'react';
|
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
|
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
|
import MenuIcon from '@mui/icons-material/Menu';
|
|
import { AppBar, IconButton, Toolbar, Typography } from '@mui/material';
|
|
|
|
export const DRAWER_WIDTH = 210;
|
|
|
|
interface LayoutAppBarProps {
|
|
title: string;
|
|
onToggleDrawer: () => void;
|
|
}
|
|
|
|
const LayoutAppBar: FC<LayoutAppBarProps> = ({ title, onToggleDrawer }) => {
|
|
const pathnames = useLocation()
|
|
.pathname.split('/')
|
|
.filter((x) => x);
|
|
const show_back = pathnames.length > 1;
|
|
|
|
const navigate = useNavigate();
|
|
|
|
return (
|
|
<AppBar
|
|
position="fixed"
|
|
sx={{
|
|
width: { md: `calc(100% - ${DRAWER_WIDTH}px)` },
|
|
ml: { md: `${DRAWER_WIDTH}px` },
|
|
boxShadow: 'none',
|
|
backgroundColor: '#2e586a'
|
|
}}
|
|
>
|
|
<Toolbar>
|
|
<IconButton
|
|
color="inherit"
|
|
edge="start"
|
|
onClick={onToggleDrawer}
|
|
sx={{ mr: 2, display: { md: 'none' } }}
|
|
>
|
|
<MenuIcon />
|
|
</IconButton>
|
|
|
|
{show_back && (
|
|
<IconButton
|
|
color="inherit"
|
|
edge="start"
|
|
onClick={() => navigate(pathnames[0])}
|
|
>
|
|
<ArrowBackIcon />
|
|
</IconButton>
|
|
)}
|
|
|
|
<Typography variant="h6" noWrap component="div">
|
|
{title}
|
|
</Typography>
|
|
</Toolbar>
|
|
</AppBar>
|
|
);
|
|
};
|
|
|
|
export default LayoutAppBar;
|