-
-
Notifications
You must be signed in to change notification settings - Fork 333
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 theme switcher to dashboard layout #3674
Changes from 35 commits
072423a
1ef6319
7e2f32a
0322f9d
b00118f
1d1c03f
a3d4e6f
16b3ac5
45f8500
eae3fdf
71d3f7f
42d208a
9ab2a87
3002ae7
7209a12
d80a4e0
02a044e
e77313d
1ac0a63
3445321
47b4c12
a5b37f9
4b368ef
be375fd
d4c85ce
08da901
5681e95
36143ae
0a7f4ca
ad9bddb
ee74f01
65716ad
bc791cf
f512ebb
b56f240
6d0556b
7994b5a
d9b5e17
ab10cf4
6fe1368
f4aa0a3
41a64df
297e858
a336c06
6312d3a
8b19306
3290982
36fe9ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ import Box from '@mui/material/Box'; | |
import Typography from '@mui/material/Typography'; | ||
import DashboardIcon from '@mui/icons-material/Dashboard'; | ||
import TimelineIcon from '@mui/icons-material/Timeline'; | ||
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 { baseDarkTheme, baseLightTheme } from '@toolpad/core/themes'; | ||
import type { Navigation, Router } from '@toolpad/core'; | ||
|
||
const NAVIGATION: Navigation = [ | ||
{ | ||
|
@@ -17,14 +18,29 @@ const NAVIGATION: Navigation = [ | |
title: 'Page', | ||
icon: <DashboardIcon />, | ||
}, | ||
// Add the following new item: | ||
{ | ||
slug: '/page-2', | ||
title: 'Page 2', | ||
icon: <TimelineIcon />, | ||
}, | ||
]; | ||
|
||
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> | ||
); | ||
} | ||
|
||
export default function AppProviderBasic() { | ||
const [pathname, setPathname] = React.useState('/page'); | ||
|
||
|
@@ -38,18 +54,13 @@ export default function AppProviderBasic() { | |
|
||
return ( | ||
// preview-start | ||
<AppProvider navigation={NAVIGATION} router={router}> | ||
<AppProvider | ||
navigation={NAVIGATION} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the navigation I also see // Add the following new item: I presume we don't need that comment in the context of this demo? |
||
router={router} | ||
theme={{ light: baseLightTheme, dark: baseDarkTheme }} | ||
> | ||
<DashboardLayout> | ||
<Box | ||
sx={{ | ||
py: 4, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography>Dashboard content for {pathname}</Typography> | ||
</Box> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
<AppProvider navigation={NAVIGATION} router={router}> | ||
<AppProvider | ||
navigation={NAVIGATION} | ||
router={router} | ||
theme={{ light: baseLightTheme, dark: baseDarkTheme }} | ||
> | ||
<DashboardLayout> | ||
<Box | ||
sx={{ | ||
py: 4, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography>Dashboard content for {pathname}</Typography> | ||
</Box> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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 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 />, | ||
}, | ||
]; | ||
|
||
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, | ||
}; | ||
|
||
const customTheme = createTheme({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up PR: Would it make sense to make this a CSS vars theme and provide custom dark and light color schemes? We do want to promote this method over the legacy theme. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could do it, it's actually a small change so might include it in this PR. |
||
palette: { | ||
mode: 'dark', | ||
background: { | ||
default: '#2A4364', | ||
paper: '#112E4D', | ||
}, | ||
}, | ||
}); | ||
|
||
export default function AppProviderTheme() { | ||
const [pathname, setPathname] = React.useState('/page'); | ||
|
||
const router = React.useMemo(() => { | ||
return { | ||
pathname, | ||
searchParams: new URLSearchParams(), | ||
navigate: (path) => setPathname(String(path)), | ||
}; | ||
}, [pathname]); | ||
|
||
return ( | ||
// preview-start | ||
<AppProvider navigation={NAVIGATION} router={router} theme={customTheme}> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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 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 />, | ||
}, | ||
]; | ||
|
||
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> | ||
); | ||
} | ||
|
||
const customTheme = createTheme({ | ||
palette: { | ||
mode: 'dark', | ||
background: { | ||
default: '#2A4364', | ||
paper: '#112E4D', | ||
}, | ||
}, | ||
}); | ||
|
||
export default function AppProviderTheme() { | ||
const [pathname, setPathname] = React.useState('/page'); | ||
|
||
const router = React.useMemo<Router>(() => { | ||
return { | ||
pathname, | ||
searchParams: new URLSearchParams(), | ||
navigate: (path) => setPathname(String(path)), | ||
}; | ||
}, [pathname]); | ||
|
||
return ( | ||
// preview-start | ||
<AppProvider navigation={NAVIGATION} router={router} theme={customTheme}> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<AppProvider navigation={NAVIGATION} router={router} theme={customTheme}> | ||
<DashboardLayout> | ||
<DemoPageContent pathname={pathname} /> | ||
</DashboardLayout> | ||
</AppProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to note, these comments are not absolutely necessary, the script would likely output the same content automatically in this demo.