Skip to content

Commit

Permalink
[DashboardLayout] Left-align header title in mobile viewport (#4346)
Browse files Browse the repository at this point in the history
  • Loading branch information
apedroferreira authored Nov 8, 2024
1 parent caf962e commit 8b2f4cc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 60 deletions.
97 changes: 47 additions & 50 deletions packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, useTheme, type Theme, SxProps } from '@mui/material';
import { styled, useTheme, SxProps } from '@mui/material';
import MuiAppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Drawer from '@mui/material/Drawer';
Expand Down Expand Up @@ -106,7 +106,7 @@ export interface DashboardLayoutProps {
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
sx?: SxProps;
}

/**
Expand Down Expand Up @@ -327,55 +327,52 @@ function DashboardLayout(props: DashboardLayoutProps) {
>
<AppBar color="inherit" position="absolute" sx={{ displayPrint: 'none' }}>
<Toolbar sx={{ backgroundColor: 'inherit', mx: { xs: -0.75, sm: -1.5 } }}>
{!hideNavigation ? (
<React.Fragment>
<Box
sx={{
mr: { sm: disableCollapsibleSidebar ? 0 : 1 },
display: { md: 'none' },
}}
>
{getMenuIcon(isMobileNavigationExpanded)}
</Box>
<Box
sx={{
display: { xs: 'none', md: disableCollapsibleSidebar ? 'none' : 'block' },
mr: disableCollapsibleSidebar ? 0 : 1,
}}
>
{getMenuIcon(isDesktopNavigationExpanded)}
</Box>
</React.Fragment>
) : null}

<Box
sx={{
position: { xs: 'absolute', md: 'static' },
left: { xs: '50%', md: 'auto' },
transform: { xs: 'translateX(-50%)', md: 'none' },
}}
<Stack
direction="row"
sx={{ flexWrap: 'wrap', justifyContent: 'space-between', width: '100%', py: 1.5 }}
>
<Link href="/" style={{ color: 'inherit', textDecoration: 'none' }}>
<Stack direction="row" alignItems="center">
<LogoContainer>{branding?.logo ?? <ToolpadLogo size={40} />}</LogoContainer>
<Typography
variant="h6"
sx={{
color: (theme.vars ?? theme).palette.primary.main,
fontWeight: '700',
ml: 0.5,
whiteSpace: 'nowrap',
}}
>
{applicationTitle}
</Typography>
</Stack>
</Link>
</Box>
<Box sx={{ flexGrow: 1 }} />
<Stack direction="row" spacing={1}>
<ToolbarActionsSlot {...slotProps?.toolbarActions} />
<ToolbarAccountSlot {...slotProps?.toolbarAccount} />
<Stack direction="row">
{!hideNavigation ? (
<React.Fragment>
<Box
sx={{
mr: { sm: disableCollapsibleSidebar ? 0 : 1 },
display: { md: 'none' },
}}
>
{getMenuIcon(isMobileNavigationExpanded)}
</Box>
<Box
sx={{
display: { xs: 'none', md: disableCollapsibleSidebar ? 'none' : 'block' },
mr: disableCollapsibleSidebar ? 0 : 1,
}}
>
{getMenuIcon(isDesktopNavigationExpanded)}
</Box>
</React.Fragment>
) : null}
<Link href="/" style={{ color: 'inherit', textDecoration: 'none' }}>
<Stack direction="row" alignItems="center">
<LogoContainer>{branding?.logo ?? <ToolpadLogo size={40} />}</LogoContainer>
<Typography
variant="h6"
sx={{
color: (theme.vars ?? theme).palette.primary.main,
fontWeight: '700',
ml: 0.5,
whiteSpace: 'nowrap',
}}
>
{applicationTitle}
</Typography>
</Stack>
</Link>
</Stack>
<Stack direction="row" spacing={1} sx={{ marginLeft: 'auto' }}>
<ToolbarActionsSlot {...slotProps?.toolbarActions} />
<ToolbarAccountSlot {...slotProps?.toolbarAccount} />
</Stack>
</Stack>
</Toolbar>
</AppBar>
Expand Down
22 changes: 14 additions & 8 deletions packages/toolpad-studio/src/runtime/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function AppLayout({

const hasLayout = hasLayoutProp && hasShell;

const { session, signOut } = React.useContext(AuthContext);
const { session, signOut, hasAuthentication } = React.useContext(AuthContext);

const navigation = React.useMemo(
() =>
Expand All @@ -63,9 +63,18 @@ export function AppLayout({
[pages, retainedSearch],
);

const signIn = React.useCallback(() => {
navigate('/signin');
}, [navigate]);
const authentication = React.useMemo(
() =>
hasAuthentication
? {
signIn: () => {
navigate('/signin');
},
signOut,
}
: undefined,
[hasAuthentication, navigate, signOut],
);

const layoutContent = (
<Box sx={{ minWidth: 0, flex: 1, position: 'relative', flexDirection: 'column' }}>
Expand All @@ -80,10 +89,7 @@ export function AppLayout({
branding={{
title: 'Toolpad Studio',
}}
authentication={{
signIn,
signOut,
}}
authentication={authentication}
session={session}
>
{hasLayout ? (
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b2f4cc

Please sign in to comment.