Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Add mini drawer variant to DashboardLayout #4017

Merged
merged 33 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
050221d
Add mini drawer variant to DashboardLayout
apedroferreira Aug 29, 2024
469190e
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Aug 29, 2024
e4da862
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Aug 29, 2024
7b8f70e
Document
apedroferreira Aug 29, 2024
8cf75aa
Implement most suggestions (wip)
apedroferreira Sep 2, 2024
5020a1a
I guess this is it, clean up later
apedroferreira Sep 2, 2024
5a1fe75
Cleanup and fixes
apedroferreira Sep 3, 2024
a947bb9
Update docs
apedroferreira Sep 3, 2024
8da3a9f
Smaller preview
apedroferreira Sep 3, 2024
e525111
Self-review
apedroferreira Sep 3, 2024
fe27462
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Sep 3, 2024
d41a251
Had removed wrong key
apedroferreira Sep 3, 2024
b070512
Use two states for navigation expanded
apedroferreira Sep 3, 2024
5844808
Try to make transition work with this sidebar
apedroferreira Sep 4, 2024
c77df5f
Adjust header and divider to this new design without the very problem…
apedroferreira Sep 4, 2024
8034ca6
Adjust docs and some more touchups
apedroferreira Sep 4, 2024
5d87d5f
Another fix for mobile views
apedroferreira Sep 4, 2024
afbb890
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Sep 4, 2024
3a37323
SSR fixes as I try to fix tests
apedroferreira Sep 4, 2024
0edfc0f
Unable to fix tests for now
apedroferreira Sep 4, 2024
f460448
Fix some issues seen in docs demos
apedroferreira Sep 4, 2024
9921dfc
A most ingenuous solution
apedroferreira Sep 6, 2024
03ceafd
pnpnpnpnm
apedroferreira Sep 6, 2024
555f66a
more pnpm
apedroferreira Sep 6, 2024
be7df50
awesomeee pnpm ohyeah
apedroferreira Sep 6, 2024
b7a03f9
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Sep 6, 2024
e8cea09
Update documentation
apedroferreira Sep 6, 2024
db97c18
Jan 1-on-1 suggestions
apedroferreira Sep 11, 2024
b37e5f1
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Sep 12, 2024
5908413
More feedback and fixes
apedroferreira Sep 12, 2024
f40a3e8
Restore behavior with transition, fix margin change without transitio…
apedroferreira Sep 12, 2024
c0a492d
Merge remote-tracking branch 'upstream/master' into mini-drawer-sidebar
apedroferreira Sep 12, 2024
394513c
Fix shift in mobile view
apedroferreira Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { createTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import BarChartIcon from '@mui/icons-material/BarChart';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';

const NAVIGATION = [
{
segment: 'dashboard',
title: 'Dashboard',
icon: <DashboardIcon />,
},
{
segment: 'orders',
title: 'Orders',
icon: <ShoppingCartIcon />,
},
{
segment: 'reports',
title: 'Reports',
icon: <BarChartIcon />,
},
];

const demoTheme = createTheme({
cssVariables: {
colorSchemeSelector: 'data-toolpad-color-scheme',
},
colorSchemes: { light: true, dark: true },
breakpoints: {
values: {
xs: 0,
sm: 600,
md: 600,
lg: 1200,
xl: 1536,
},
},
});

function DemoPageContent({ pathname }) {
return (
<Box
sx={{
py: 4,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center',
}}
>
<Typography>Dashboard content for {pathname}</Typography>
</Box>
);
}

DemoPageContent.propTypes = {
pathname: PropTypes.string.isRequired,
};

function DashboardLayoutNoMiniSidebar(props) {
const { window } = props;

const [pathname, setPathname] = React.useState('/dashboard');

const router = React.useMemo(() => {
return {
pathname,
searchParams: new URLSearchParams(),
navigate: (path) => setPathname(String(path)),
};
}, [pathname]);

// Remove this const when copying and pasting into your project.
const demoWindow = window !== undefined ? window() : undefined;

return (
<AppProvider
navigation={NAVIGATION}
router={router}
theme={demoTheme}
window={demoWindow}
>
<DashboardLayout disableCollapsibleSidebar>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</AppProvider>
);
}

DashboardLayoutNoMiniSidebar.propTypes = {
/**
* Injected by the documentation to work in an iframe.
* Remove this when copying and pasting into your project.
*/
window: PropTypes.func,
};

export default DashboardLayoutNoMiniSidebar;
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { createTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import BarChartIcon from '@mui/icons-material/BarChart';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router, Navigation } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
segment: 'dashboard',
title: 'Dashboard',
icon: <DashboardIcon />,
},
{
segment: 'orders',
title: 'Orders',
icon: <ShoppingCartIcon />,
},
{
segment: 'reports',
title: 'Reports',
icon: <BarChartIcon />,
},
];

const demoTheme = createTheme({
cssVariables: {
colorSchemeSelector: 'data-toolpad-color-scheme',
},
colorSchemes: { light: true, dark: true },
breakpoints: {
values: {
xs: 0,
sm: 600,
md: 600,
lg: 1200,
xl: 1536,
},
},
});

function DemoPageContent({ pathname }: { pathname: string }) {
return (
<Box
sx={{
py: 4,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center',
}}
>
<Typography>Dashboard content for {pathname}</Typography>
</Box>
);
}

interface DemoProps {
/**
* Injected by the documentation to work in an iframe.
* Remove this when copying and pasting into your project.
*/
window?: () => Window;
}

export default function DashboardLayoutNoMiniSidebar(props: DemoProps) {
const { window } = props;

const [pathname, setPathname] = React.useState('/dashboard');

const router = React.useMemo<Router>(() => {
return {
pathname,
searchParams: new URLSearchParams(),
navigate: (path) => setPathname(String(path)),
};
}, [pathname]);

// Remove this const when copying and pasting into your project.
const demoWindow = window !== undefined ? window() : undefined;

return (
<AppProvider
navigation={NAVIGATION}
router={router}
theme={demoTheme}
window={demoWindow}
>
<DashboardLayout disableCollapsibleSidebar>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<DashboardLayout disableCollapsibleSidebar>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ This feature is built on top of the [path-to-regexp](https://www.npmjs.com/packa

{{"demo": "DashboardLayoutPattern.js", "height": 400, "iframe": true}}

### Disabling collapsible sidebar

The layout sidebar is collapsible to a mini-drawer (with icons only) in desktop and tablet viewports. This behavior can be disabled with the `disableCollapsibleSidebar` prop.

{{"demo": "DashboardLayoutNoMiniSidebar.js", "height": 400, "iframe": true}}

## Account

The `DashboardLayout` comes integrated with the [`<Account />`](/toolpad/core/react-account/) component. It renders as an account management menu when a user is signed in – a `session` object is present – and a button when not.
Expand Down
1 change: 1 addition & 0 deletions docs/pages/toolpad/core/api/dashboard-layout.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"props": {
"children": { "type": { "name": "node" }, "required": true },
"disableCollapsibleSidebar": { "type": { "name": "bool" }, "default": "false" },
"slotProps": {
"type": {
"name": "shape",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"componentDescription": "",
"propDescriptions": {
"children": { "description": "The content of the dashboard." },
"disableCollapsibleSidebar": {
"description": "Whether the sidebar should not be collapsible to a mini variant in desktop and tablet viewports."
},
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." }
},
Expand Down
Loading
Loading