-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DashboardLayout] Support route patterns in navigation (#3991)
Signed-off-by: Pedro Ferreira <[email protected]> Co-authored-by: Jan Potoms <[email protected]>
- Loading branch information
1 parent
c5a7ced
commit eb60981
Showing
14 changed files
with
460 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutPattern.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import Stack from '@mui/material/Stack'; | ||
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 { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { DashboardLayout } from '@toolpad/core/DashboardLayout'; | ||
|
||
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, navigate }) { | ||
return ( | ||
<Box | ||
sx={{ | ||
py: 4, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
textAlign: 'center', | ||
}} | ||
> | ||
<Typography> | ||
<p>Dashboard content for {pathname}</p> | ||
</Typography> | ||
{pathname.startsWith('/orders') ? ( | ||
<Stack direction="row" spacing={1} sx={{ pt: 1 }}> | ||
<Button | ||
onClick={() => { | ||
navigate('/orders/1'); | ||
}} | ||
> | ||
Order 1 | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
navigate('/orders/2'); | ||
}} | ||
> | ||
Order 2 | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
navigate('/orders/3'); | ||
}} | ||
> | ||
Order 3 | ||
</Button> | ||
</Stack> | ||
) : null} | ||
</Box> | ||
); | ||
} | ||
|
||
DemoPageContent.propTypes = { | ||
navigate: PropTypes.func.isRequired, | ||
pathname: PropTypes.string.isRequired, | ||
}; | ||
|
||
function DashboardLayoutPattern(props) { | ||
const { window } = props; | ||
|
||
const [pathname, setPathname] = React.useState('/orders'); | ||
const navigate = React.useCallback((path) => setPathname(String(path)), []); | ||
|
||
const router = React.useMemo(() => { | ||
return { | ||
pathname, | ||
searchParams: new URLSearchParams(), | ||
navigate, | ||
}; | ||
}, [pathname, navigate]); | ||
|
||
// Remove this const when copying and pasting into your project. | ||
const demoWindow = window !== undefined ? window() : undefined; | ||
|
||
return ( | ||
// preview-start | ||
<AppProvider | ||
navigation={[ | ||
{ | ||
segment: 'dashboard', | ||
title: 'Dashboard', | ||
icon: <DashboardIcon />, | ||
}, | ||
{ | ||
segment: 'orders', | ||
title: 'Orders', | ||
icon: <ShoppingCartIcon />, | ||
pattern: '/orders{/:orderId}*', | ||
}, | ||
]} | ||
router={router} | ||
theme={demoTheme} | ||
window={demoWindow} | ||
> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} navigate={navigate} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} | ||
|
||
DashboardLayoutPattern.propTypes = { | ||
/** | ||
* Injected by the documentation to work in an iframe. | ||
* Remove this when copying and pasting into your project. | ||
*/ | ||
window: PropTypes.func, | ||
}; | ||
|
||
export default DashboardLayoutPattern; |
132 changes: 132 additions & 0 deletions
132
docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutPattern.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import Stack from '@mui/material/Stack'; | ||
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 { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { DashboardLayout } from '@toolpad/core/DashboardLayout'; | ||
import type { Router } from '@toolpad/core'; | ||
|
||
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, | ||
navigate, | ||
}: { | ||
pathname: string; | ||
navigate: (path: string | URL) => void; | ||
}) { | ||
return ( | ||
<Box | ||
sx={{ | ||
py: 4, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
textAlign: 'center', | ||
}} | ||
> | ||
<Typography> | ||
<p>Dashboard content for {pathname}</p> | ||
</Typography> | ||
{pathname.startsWith('/orders') ? ( | ||
<Stack direction="row" spacing={1} sx={{ pt: 1 }}> | ||
<Button | ||
onClick={() => { | ||
navigate('/orders/1'); | ||
}} | ||
> | ||
Order 1 | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
navigate('/orders/2'); | ||
}} | ||
> | ||
Order 2 | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
navigate('/orders/3'); | ||
}} | ||
> | ||
Order 3 | ||
</Button> | ||
</Stack> | ||
) : null} | ||
</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 DashboardLayoutPattern(props: DemoProps) { | ||
const { window } = props; | ||
|
||
const [pathname, setPathname] = React.useState('/orders'); | ||
const navigate = React.useCallback( | ||
(path: string | URL) => setPathname(String(path)), | ||
[], | ||
); | ||
|
||
const router = React.useMemo<Router>(() => { | ||
return { | ||
pathname, | ||
searchParams: new URLSearchParams(), | ||
navigate, | ||
}; | ||
}, [pathname, navigate]); | ||
|
||
// Remove this const when copying and pasting into your project. | ||
const demoWindow = window !== undefined ? window() : undefined; | ||
|
||
return ( | ||
// preview-start | ||
<AppProvider | ||
navigation={[ | ||
{ | ||
segment: 'dashboard', | ||
title: 'Dashboard', | ||
icon: <DashboardIcon />, | ||
}, | ||
{ | ||
segment: 'orders', | ||
title: 'Orders', | ||
icon: <ShoppingCartIcon />, | ||
pattern: '/orders{/:orderId}*', | ||
}, | ||
]} | ||
router={router} | ||
theme={demoTheme} | ||
window={demoWindow} | ||
> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} navigate={navigate} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutPattern.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<AppProvider | ||
navigation={[ | ||
{ | ||
segment: 'dashboard', | ||
title: 'Dashboard', | ||
icon: <DashboardIcon />, | ||
}, | ||
{ | ||
segment: 'orders', | ||
title: 'Orders', | ||
icon: <ShoppingCartIcon />, | ||
pattern: '/orders{/:orderId}*', | ||
}, | ||
]} | ||
router={router} | ||
theme={demoTheme} | ||
window={demoWindow} | ||
> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} navigate={navigate} /> | ||
</DashboardLayout> | ||
</AppProvider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.