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] Agnostic DashboardLayout component #3831

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -7,9 +7,9 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import BarChartIcon from '@mui/icons-material/BarChart';
import DescriptionIcon from '@mui/icons-material/Description';
import LayersIcon from '@mui/icons-material/Layers';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Navigation } from '@toolpad/core';
import type { Navigation, Router } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Navigation } from '@toolpad/core';
import type { Navigation, Router } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import CallIcon from '@mui/icons-material/Call';
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
import CallMadeIcon from '@mui/icons-material/CallMade';
import CallReceivedIcon from '@mui/icons-material/CallReceived';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Typography from '@mui/material/Typography';
import { extendTheme } from '@mui/material/styles';
import DescriptionIcon from '@mui/icons-material/Description';
import FolderIcon from '@mui/icons-material/Folder';
import { AppProvider, Router } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Router } from '@toolpad/core';

const demoTheme = extendTheme({
breakpoints: {
Expand Down
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 { CssVarsProvider, extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import type { Navigation, Router } from '@toolpad/core';

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

const demoTheme = extendTheme({
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 DashboardLayoutStandalone(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 (
<CssVarsProvider
theme={demoTheme}
documentNode={demoWindow?.document}
colorSchemeNode={demoWindow?.document?.body}
colorSchemeStorageKey="mui-toolpad-color-scheme"
modeStorageKey="mui-toolpad-mode"
>
<DashboardLayout
navigation={NAVIGATION}
branding={{
logo: <img src="https://mui.com/static/logo.png" alt="MUI logo" />,
title: 'MUI',
}}
colorScheme={}
onColorSchemeChange={}
router={router}
window={demoWindow}
>
<DemoPageContent pathname={pathname} />
</DashboardLayout>
</CssVarsProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ components: AppProvider, DashboardLayout

The `DashboardLayout` component is a quick, easy way to provide a standard full-screen layout with a header and sidebar to any dashboard page, as well as ready-to-use and easy to customize navigation and branding.

Many features of this component are configurable through the [AppProvider](https://mui.com/toolpad/core/react-app-provider/) component that should wrap it.
Many features of this component are configurable through the [AppProvider](https://mui.com/toolpad/core/react-app-provider/) component that should wrap it, which is the recommended approach for a Toolpad app.
However, it is also possible to use the `DashboardLayout` as a standalone component by setting those configurations with the component props themselves.

## Demo

Expand Down Expand Up @@ -50,3 +51,9 @@ The main navigation items that can be used are:
Navigation links have an optional `action` prop that can be used to render any content on the right-side of the respective list item, such as badges with numbers, or buttons to toggle a popover menu.

{{"demo": "DashboardLayoutNavigationActions.js", "height": 500, "iframe": true}}

## Standalone Usage

The component branding, navigation, theme switching and routing can also be set via component props themselves instead of indirectly through an `AppProvider`.

{{"demo": "DashboardLayoutStandalone.js", "height": 500, "iframe": true}}
3 changes: 2 additions & 1 deletion docs/data/toolpad/core/introduction/TutorialDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import { AppProvider, Navigation } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';
import { useDemoRouter } from '@toolpad/core/internals/demo';
import type { Navigation } from '@toolpad/core';

const NAVIGATION: Navigation = [
{
Expand Down
3 changes: 2 additions & 1 deletion docs/data/toolpad/core/introduction/TutorialPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import * as React from 'react';
import { extendTheme } from '@mui/material/styles';
import DashboardIcon from '@mui/icons-material/Dashboard';
import TimelineIcon from '@mui/icons-material/Timeline';
import { AppProvider, Navigation } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { useDemoRouter } from '@toolpad/core/internals/demo';
import { PageContainer } from '@toolpad/core/PageContainer';
import type { Navigation } from '@toolpad/core';
import { Typography } from '@mui/material';

const NAVIGATION: Navigation = [
Expand Down
18 changes: 17 additions & 1 deletion docs/pages/toolpad/core/api/dashboard-layout.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"props": { "children": { "type": { "name": "node" }, "required": true } },
"props": {
"children": { "type": { "name": "node" }, "required": true },
"branding": {
"type": { "name": "shape", "description": "{ logo?: node, title?: string }" },
"default": "null"
},
"colorScheme": { "type": { "name": "enum", "description": "'dark'<br>&#124;&nbsp;'light'" } },
"navigation": {
"type": {
"name": "arrayOf",
"description": "Array&lt;{ action?: node, children?: Array&lt;object<br>&#124;&nbsp;{ kind: 'header', title: string }<br>&#124;&nbsp;{ kind: 'divider' }&gt;, icon?: node, kind?: 'page', segment: string, title?: string }<br>&#124;&nbsp;{ kind: 'header', title: string }<br>&#124;&nbsp;{ kind: 'divider' }&gt;"
},
"default": "[]"
},
"onColorSchemeChange": { "type": { "name": "func" } },
"window": { "type": { "name": "object" }, "default": "window" }
},
"name": "DashboardLayout",
"imports": [
"import { DashboardLayout } from '@toolpad-core/DashboardLayout';",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"componentDescription": "",
"propDescriptions": { "children": { "description": "The content of the dashboard." } },
"propDescriptions": {
"branding": { "description": "Branding options for the layout." },
"children": { "description": "The content of the dashboard." },
"colorScheme": { "description": "Active color scheme in theme." },
"navigation": { "description": "Navigation definition for the layout." },
"onColorSchemeChange": {
"description": "Callback to run when the theme color scheme is changed."
},
"window": {
"description": "The window where the layout is rendered. This is needed when rendering the layout inside an iframe, for example."
}
},
"classDescriptions": {}
}
Loading
Loading