-
-
Notifications
You must be signed in to change notification settings - Fork 410
[core] Add theme switcher to dashboard layout #3674
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
Merged
apedroferreira
merged 48 commits into
mui:master
from
apedroferreira:add-dashboard-layout-theme-switcher
Jul 19, 2024
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
072423a
Add theme switcher
apedroferreira 1ef6319
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira 7e2f32a
Use CSS vars themes (in progress)
apedroferreira 0322f9d
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira b00118f
Fix remaining issues and warnings
apedroferreira 1d1c03f
Hybrid theming solution but still has a mismatch in SSR
apedroferreira a3d4e6f
Was facing weird problems with circular dependencies, restructured to…
apedroferreira 16b3ac5
Finally found fix for dark theme console errors
apedroferreira 45f8500
Adjustments
apedroferreira eae3fdf
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira 71d3f7f
Improve AppProvider docs in general
apedroferreira 42d208a
Improve docs more, document theming, still need to fix theme and them…
apedroferreira 9ab2a87
Add missing changes outside docs
apedroferreira 3002ae7
👍👍👍👍👍👍👍👍👍👍👍
apedroferreira 7209a12
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira d80a4e0
Add theme example that doesn't crash
apedroferreira 02a044e
Fix theme switching in docs demos
apedroferreira e77313d
Run docs formatter
apedroferreira 1ac0a63
Add theme switcher unit test
apedroferreira 3445321
dedupe -.-
apedroferreira 47b4c12
Conditional mock
apedroferreira a5b37f9
Make themes consistent
apedroferreira 4b368ef
Improve wording a bit and seeing if CI passes
apedroferreira be375fd
Docs pages self-review
apedroferreira d4c85ce
Address review feedback except slots which should probably be done se…
apedroferreira 08da901
Run docs scripts
apedroferreira 5681e95
Conflitinhos
apedroferreira 36143ae
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira 0a7f4ca
Fix and improve a bunch of theming issues
apedroferreira ad9bddb
Update some examples/tutorials
apedroferreira ee74f01
Small improvements
apedroferreira 65716ad
Oops
apedroferreira bc791cf
I thinkt this is the same
apedroferreira f512ebb
Dedupes
apedroferreira b56f240
Better ordering in theme example
apedroferreira 6d0556b
Suggestions so far
apedroferreira 7994b5a
Adjust demos more
apedroferreira d9b5e17
Fix tests in browser mode
apedroferreira ab10cf4
Fix headless test with CSS variables
apedroferreira 6fe1368
Update Toolpad Core to V6, update accordingly
apedroferreira f4aa0a3
Fix example
apedroferreira 41a64df
Re-add types
apedroferreira 297e858
More updates to v6 except AppBar console error
apedroferreira a336c06
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira 6312d3a
Remove DataGrid and LineChart
apedroferreira 8b19306
Restore unneeded useLocalStorageState from toolpad/utils
apedroferreira 3290982
Don't change these files
apedroferreira 36fe9ae
Fix types
apedroferreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.