-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Add theme switcher to dashboard layout (#3674)
- Loading branch information
1 parent
9dad773
commit 98b87ad
Showing
50 changed files
with
1,802 additions
and
908 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
13 changes: 2 additions & 11 deletions
13
docs/data/toolpad/core/components/app-provider/AppProviderBasic.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 |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<AppProvider navigation={NAVIGATION} router={router}> | ||
<AppProvider navigation={NAVIGATION} router={router} window={demoWindow}> | ||
<DashboardLayout> | ||
<Box | ||
sx={{ | ||
py: 4, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography>Dashboard content for {pathname}</Typography> | ||
</Box> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> |
109 changes: 109 additions & 0 deletions
109
docs/data/toolpad/core/components/app-provider/AppProviderTheme.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,109 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import { extendTheme } from '@mui/material/styles'; | ||
import DashboardIcon from '@mui/icons-material/Dashboard'; | ||
import TimelineIcon from '@mui/icons-material/Timeline'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { DashboardLayout } from '@toolpad/core/DashboardLayout'; | ||
|
||
const NAVIGATION = [ | ||
{ | ||
kind: 'header', | ||
title: 'Main items', | ||
}, | ||
{ | ||
slug: '/page', | ||
title: 'Page', | ||
icon: <DashboardIcon />, | ||
}, | ||
{ | ||
slug: '/page-2', | ||
title: 'Page 2', | ||
icon: <TimelineIcon />, | ||
}, | ||
]; | ||
|
||
const customTheme = extendTheme({ | ||
colorSchemes: { | ||
light: { | ||
palette: { | ||
background: { | ||
default: '#E2FAFF', | ||
paper: '#D9FAFF', | ||
}, | ||
}, | ||
}, | ||
dark: { | ||
palette: { | ||
background: { | ||
default: '#2A4364', | ||
paper: '#112E4D', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
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 AppProviderTheme(props) { | ||
const { window } = props; | ||
|
||
const [pathname, setPathname] = React.useState('/page'); | ||
|
||
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 ( | ||
// preview-start | ||
<AppProvider | ||
navigation={NAVIGATION} | ||
router={router} | ||
theme={customTheme} | ||
window={demoWindow} | ||
> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} | ||
|
||
AppProviderTheme.propTypes = { | ||
/** | ||
* Injected by the documentation to work in an iframe. | ||
* Remove this when copying and pasting into your project. | ||
*/ | ||
window: PropTypes.func, | ||
}; | ||
|
||
export default AppProviderTheme; |
103 changes: 103 additions & 0 deletions
103
docs/data/toolpad/core/components/app-provider/AppProviderTheme.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,103 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import { extendTheme } from '@mui/material/styles'; | ||
import DashboardIcon from '@mui/icons-material/Dashboard'; | ||
import TimelineIcon from '@mui/icons-material/Timeline'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { DashboardLayout } from '@toolpad/core/DashboardLayout'; | ||
import type { Navigation, Router } from '@toolpad/core'; | ||
|
||
const NAVIGATION: Navigation = [ | ||
{ | ||
kind: 'header', | ||
title: 'Main items', | ||
}, | ||
{ | ||
slug: '/page', | ||
title: 'Page', | ||
icon: <DashboardIcon />, | ||
}, | ||
{ | ||
slug: '/page-2', | ||
title: 'Page 2', | ||
icon: <TimelineIcon />, | ||
}, | ||
]; | ||
|
||
const customTheme = extendTheme({ | ||
colorSchemes: { | ||
light: { | ||
palette: { | ||
background: { | ||
default: '#E2FAFF', | ||
paper: '#D9FAFF', | ||
}, | ||
}, | ||
}, | ||
dark: { | ||
palette: { | ||
background: { | ||
default: '#2A4364', | ||
paper: '#112E4D', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
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 AppProviderTheme(props: DemoProps) { | ||
const { window } = props; | ||
|
||
const [pathname, setPathname] = React.useState('/page'); | ||
|
||
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 ( | ||
// preview-start | ||
<AppProvider | ||
navigation={NAVIGATION} | ||
router={router} | ||
theme={customTheme} | ||
window={demoWindow} | ||
> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
Oops, something went wrong.