♻️ refactor(AppBar): improve sizing on mobile

This commit is contained in:
2024-02-15 17:09:56 +01:00
parent ddd1d80554
commit ad9ab7df49
+9 -5
View File
@@ -2,6 +2,7 @@ import React from 'react'
import { Link as RouterLink } from 'react-router-dom' import { Link as RouterLink } from 'react-router-dom'
import { import {
AppBar, AppBar,
AppBarProps,
Box, Box,
Button, Button,
Divider, Divider,
@@ -35,10 +36,10 @@ const DrawerButton = styled(ListItemButton<typeof RouterLink>)(({ theme }) => ({
}, },
})) }))
type CustomToobarProps = { interface CustomToobarProps extends AppBarProps {
drawerWidth?: number drawerWidth?: number
} }
const CustomToobar: React.FC<CustomToobarProps> = ({ drawerWidth = 240 }) => { const CustomToobar: React.FC<CustomToobarProps> = ({ drawerWidth = 240, ...props }) => {
const [mobileOpen, setMobileOpen] = React.useState(false) const [mobileOpen, setMobileOpen] = React.useState(false)
const handleDrawerToggle = () => { const handleDrawerToggle = () => {
@@ -84,8 +85,11 @@ const CustomToobar: React.FC<CustomToobarProps> = ({ drawerWidth = 240 }) => {
return ( return (
<> <>
<AppBar <AppBar
elevation={0}
{...props}
sx={{ sx={{
backgroundColor: theme => (theme.palette.mode === 'dark' ? 'background.paper' : undefined), backgroundColor: theme => (theme.palette.mode === 'dark' ? 'background.paper' : undefined),
...props.sx,
}}> }}>
<Toolbar sx={{ display: 'flex' }}> <Toolbar sx={{ display: 'flex' }}>
<IconButton <IconButton
@@ -93,13 +97,13 @@ const CustomToobar: React.FC<CustomToobarProps> = ({ drawerWidth = 240 }) => {
aria-label="open drawer" aria-label="open drawer"
edge="start" edge="start"
onClick={handleDrawerToggle} onClick={handleDrawerToggle}
sx={{ mr: 2, display: { sm: 'none' }, position: 'absolute', backgroundColor: 'primary' }}> sx={{ mr: 2, display: { md: 'none' }, position: 'absolute', backgroundColor: 'primary' }}>
<MenuIcon /> <MenuIcon />
</IconButton> </IconButton>
<Typography variant="h6" component="div" sx={{ flexGrow: 1, textAlign: { xs: 'center', sm: 'left' } }}> <Typography variant="h6" component="div" sx={{ flexGrow: 1, textAlign: { xs: 'center', md: 'left' } }}>
Michele Tartari Michele Tartari
</Typography> </Typography>
<Stack component="div" direction="row" spacing={2} sx={{ display: { xs: 'none', sm: 'flex' } }}> <Stack component="div" direction="row" spacing={2} sx={{ display: { xs: 'none', md: 'flex' } }}>
<AppBarButton component={RouterLink} to="/"> <AppBarButton component={RouterLink} to="/">
<Typography variant="h6">Home</Typography> <Typography variant="h6">Home</Typography>
</AppBarButton> </AppBarButton>