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] Add theme switcher to dashboard layout #3674

Merged
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
072423a
Add theme switcher
apedroferreira Jun 12, 2024
1ef6319
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira Jun 12, 2024
7e2f32a
Use CSS vars themes (in progress)
apedroferreira Jun 14, 2024
0322f9d
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira Jun 25, 2024
b00118f
Fix remaining issues and warnings
apedroferreira Jun 25, 2024
1d1c03f
Hybrid theming solution but still has a mismatch in SSR
apedroferreira Jun 26, 2024
a3d4e6f
Was facing weird problems with circular dependencies, restructured to…
apedroferreira Jun 27, 2024
16b3ac5
Finally found fix for dark theme console errors
apedroferreira Jun 27, 2024
45f8500
Adjustments
apedroferreira Jun 27, 2024
eae3fdf
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira Jun 27, 2024
71d3f7f
Improve AppProvider docs in general
apedroferreira Jun 28, 2024
42d208a
Improve docs more, document theming, still need to fix theme and them…
apedroferreira Jul 1, 2024
9ab2a87
Add missing changes outside docs
apedroferreira Jul 1, 2024
3002ae7
👍👍👍👍👍👍👍👍👍👍👍
apedroferreira Jul 2, 2024
7209a12
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira Jul 2, 2024
d80a4e0
Add theme example that doesn't crash
apedroferreira Jul 2, 2024
02a044e
Fix theme switching in docs demos
apedroferreira Jul 2, 2024
e77313d
Run docs formatter
apedroferreira Jul 2, 2024
1ac0a63
Add theme switcher unit test
apedroferreira Jul 2, 2024
3445321
dedupe -.-
apedroferreira Jul 2, 2024
47b4c12
Conditional mock
apedroferreira Jul 2, 2024
a5b37f9
Make themes consistent
apedroferreira Jul 3, 2024
4b368ef
Improve wording a bit and seeing if CI passes
apedroferreira Jul 3, 2024
be375fd
Docs pages self-review
apedroferreira Jul 3, 2024
d4c85ce
Address review feedback except slots which should probably be done se…
apedroferreira Jul 8, 2024
08da901
Run docs scripts
apedroferreira Jul 8, 2024
5681e95
Conflitinhos
apedroferreira Jul 8, 2024
36143ae
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira Jul 8, 2024
0a7f4ca
Fix and improve a bunch of theming issues
apedroferreira Jul 9, 2024
ad9bddb
Update some examples/tutorials
apedroferreira Jul 9, 2024
ee74f01
Small improvements
apedroferreira Jul 11, 2024
65716ad
Oops
apedroferreira Jul 11, 2024
bc791cf
I thinkt this is the same
apedroferreira Jul 11, 2024
f512ebb
Dedupes
apedroferreira Jul 12, 2024
b56f240
Better ordering in theme example
apedroferreira Jul 12, 2024
6d0556b
Suggestions so far
apedroferreira Jul 18, 2024
7994b5a
Adjust demos more
apedroferreira Jul 18, 2024
d9b5e17
Fix tests in browser mode
apedroferreira Jul 18, 2024
ab10cf4
Fix headless test with CSS variables
apedroferreira Jul 18, 2024
6fe1368
Update Toolpad Core to V6, update accordingly
apedroferreira Jul 19, 2024
f4aa0a3
Fix example
apedroferreira Jul 19, 2024
41a64df
Re-add types
apedroferreira Jul 19, 2024
297e858
More updates to v6 except AppBar console error
apedroferreira Jul 19, 2024
a336c06
Merge remote-tracking branch 'upstream/master' into add-dashboard-lay…
apedroferreira Jul 19, 2024
6312d3a
Remove DataGrid and LineChart
apedroferreira Jul 19, 2024
8b19306
Restore unneeded useLocalStorageState from toolpad/utils
apedroferreira Jul 19, 2024
3290982
Don't change these files
apedroferreira Jul 19, 2024
36fe9ae
Fix types
apedroferreira Jul 19, 2024
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
40 changes: 28 additions & 12 deletions docs/data/toolpad/core/components/app-provider/AppProviderBasic.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as React from 'react';
import PropTypes from 'prop-types';
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 } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { baseDarkTheme, baseLightTheme } from '@toolpad/core/themes';

const NAVIGATION = [
{
Expand All @@ -16,14 +18,33 @@ const NAVIGATION = [
title: 'Page',
icon: <DashboardIcon />,
},
// Add the following new item:
{
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,
};

export default function AppProviderBasic() {
const [pathname, setPathname] = React.useState('/page');

Expand All @@ -37,18 +58,13 @@ export default function AppProviderBasic() {

return (
// preview-start
<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>
// preview-end
Expand Down
39 changes: 25 additions & 14 deletions docs/data/toolpad/core/components/app-provider/AppProviderBasic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -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');

Expand All @@ -38,18 +54,13 @@ export default function AppProviderBasic() {

return (
// preview-start
Copy link
Member

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.

<AppProvider navigation={NAVIGATION} router={router}>
<AppProvider
navigation={NAVIGATION}
Copy link
Member

@Janpot Janpot Jul 3, 2024

Choose a reason for hiding this comment

The 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
Expand Down
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>
78 changes: 78 additions & 0 deletions docs/data/toolpad/core/components/app-provider/AppProviderTheme.js
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({
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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>
Loading