Files
react-test/docs/data/material/getting-started/templates/crud-dashboard/components/DashboardHeader.js
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

125 lines
3.6 KiB
JavaScript

import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import MuiAppBar from '@mui/material/AppBar';
import IconButton from '@mui/material/IconButton';
import Toolbar from '@mui/material/Toolbar';
import Tooltip from '@mui/material/Tooltip';
import Typography from '@mui/material/Typography';
import MenuIcon from '@mui/icons-material/Menu';
import MenuOpenIcon from '@mui/icons-material/MenuOpen';
import Stack from '@mui/material/Stack';
import { Link } from 'react-router';
import ThemeSwitcher from './ThemeSwitcher';
const AppBar = styled(MuiAppBar)(({ theme }) => ({
borderWidth: 0,
borderBottomWidth: 1,
borderStyle: 'solid',
borderColor: (theme.vars ?? theme).palette.divider,
boxShadow: 'none',
zIndex: theme.zIndex.drawer + 1,
}));
const LogoContainer = styled('div')({
position: 'relative',
height: 40,
display: 'flex',
alignItems: 'center',
'& img': {
maxHeight: 40,
},
});
function DashboardHeader({ logo, title, menuOpen, onToggleMenu }) {
const theme = useTheme();
const handleMenuOpen = React.useCallback(() => {
onToggleMenu(!menuOpen);
}, [menuOpen, onToggleMenu]);
const getMenuIcon = React.useCallback(
(isExpanded) => {
const expandMenuActionText = 'Expand';
const collapseMenuActionText = 'Collapse';
return (
<Tooltip
title={`${isExpanded ? collapseMenuActionText : expandMenuActionText} menu`}
enterDelay={1000}
>
<div>
<IconButton
size="small"
aria-label={`${isExpanded ? collapseMenuActionText : expandMenuActionText} navigation menu`}
onClick={handleMenuOpen}
>
{isExpanded ? <MenuOpenIcon /> : <MenuIcon />}
</IconButton>
</div>
</Tooltip>
);
},
[handleMenuOpen],
);
return (
<AppBar color="inherit" position="absolute" sx={{ displayPrint: 'none' }}>
<Toolbar sx={{ backgroundColor: 'inherit', mx: { xs: -0.75, sm: -1 } }}>
<Stack
direction="row"
justifyContent="space-between"
alignItems="center"
sx={{
flexWrap: 'wrap',
width: '100%',
}}
>
<Stack direction="row" alignItems="center">
<Box sx={{ mr: 1 }}>{getMenuIcon(menuOpen)}</Box>
<Link to="/" style={{ textDecoration: 'none' }}>
<Stack direction="row" alignItems="center">
{logo ? <LogoContainer>{logo}</LogoContainer> : null}
{title ? (
<Typography
variant="h6"
sx={{
color: (theme.vars ?? theme).palette.primary.main,
fontWeight: '700',
ml: 1,
whiteSpace: 'nowrap',
lineHeight: 1,
}}
>
{title}
</Typography>
) : null}
</Stack>
</Link>
</Stack>
<Stack
direction="row"
alignItems="center"
spacing={1}
sx={{ marginLeft: 'auto' }}
>
<Stack direction="row" alignItems="center">
<ThemeSwitcher />
</Stack>
</Stack>
</Stack>
</Toolbar>
</AppBar>
);
}
DashboardHeader.propTypes = {
logo: PropTypes.node,
menuOpen: PropTypes.bool.isRequired,
onToggleMenu: PropTypes.func.isRequired,
title: PropTypes.string,
};
export default DashboardHeader;