Skip to content

Commit 85f08a2

Browse files
rkristelijnbharatkashyapapedroferreira
authored
[DashboardLayout] Allow full customization for dashboard header (#4820)
Signed-off-by: Remi Kristelijn <rkristelijn@gmail.com> Co-authored-by: Bharat Kashyap <bharatkashyap@outlook.com> Co-authored-by: Pedro Ferreira <10789765+apedroferreira@users.noreply.github.com>
1 parent e9bb63a commit 85f08a2

23 files changed

Lines changed: 587 additions & 145 deletions

File tree

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutAccountSidebar.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { createTheme } from '@mui/material/styles';
1313
import DashboardIcon from '@mui/icons-material/Dashboard';
1414
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
1515
import { AppProvider } from '@toolpad/core/AppProvider';
16-
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
16+
import { DashboardLayout, ThemeSwitcher } from '@toolpad/core/DashboardLayout';
1717
import {
1818
Account,
1919
AccountPreview,
@@ -56,6 +56,14 @@ const demoTheme = createTheme({
5656
},
5757
});
5858

59+
function CustomToolbarActions() {
60+
return (
61+
<Stack direction="row" alignItems="center">
62+
<ThemeSwitcher />
63+
</Stack>
64+
);
65+
}
66+
5967
function DemoPageContent({ pathname }) {
6068
return (
6169
<Box
@@ -281,7 +289,10 @@ function DashboardLayoutAccountSidebar(props) {
281289
>
282290
{/* preview-start */}
283291
<DashboardLayout
284-
slots={{ toolbarAccount: () => null, sidebarFooter: SidebarFooterAccount }}
292+
slots={{
293+
toolbarActions: CustomToolbarActions,
294+
sidebarFooter: SidebarFooterAccount,
295+
}}
285296
>
286297
<DemoPageContent pathname={pathname} />
287298
</DashboardLayout>

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutAccountSidebar.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { createTheme } from '@mui/material/styles';
1212
import DashboardIcon from '@mui/icons-material/Dashboard';
1313
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
1414
import { AppProvider } from '@toolpad/core/AppProvider';
15-
import { DashboardLayout, SidebarFooterProps } from '@toolpad/core/DashboardLayout';
15+
import {
16+
DashboardLayout,
17+
SidebarFooterProps,
18+
ThemeSwitcher,
19+
} from '@toolpad/core/DashboardLayout';
1620
import {
1721
Account,
1822
AccountPreview,
@@ -56,6 +60,14 @@ const demoTheme = createTheme({
5660
},
5761
});
5862

63+
function CustomToolbarActions() {
64+
return (
65+
<Stack direction="row" alignItems="center">
66+
<ThemeSwitcher />
67+
</Stack>
68+
);
69+
}
70+
5971
function DemoPageContent({ pathname }: { pathname: string }) {
6072
return (
6173
<Box
@@ -267,7 +279,10 @@ export default function DashboardLayoutAccountSidebar(props: DemoProps) {
267279
>
268280
{/* preview-start */}
269281
<DashboardLayout
270-
slots={{ toolbarAccount: () => null, sidebarFooter: SidebarFooterAccount }}
282+
slots={{
283+
toolbarActions: CustomToolbarActions,
284+
sidebarFooter: SidebarFooterAccount,
285+
}}
271286
>
272287
<DemoPageContent pathname={pathname} />
273288
</DashboardLayout>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<DashboardLayout
2-
slots={{ toolbarAccount: () => null, sidebarFooter: SidebarFooterAccount }}
2+
slots={{
3+
toolbarActions: CustomToolbarActions,
4+
sidebarFooter: SidebarFooterAccount,
5+
}}
36
>
47
<DemoPageContent pathname={pathname} />
58
</DashboardLayout>

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutCustomThemeSwitcher.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import IconButton from '@mui/material/IconButton';
88
import Popover from '@mui/material/Popover';
99
import Radio from '@mui/material/Radio';
1010
import RadioGroup from '@mui/material/RadioGroup';
11+
import Stack from '@mui/material/Stack';
1112
import Tooltip from '@mui/material/Tooltip';
1213
import Typography from '@mui/material/Typography';
1314
import { createTheme, useColorScheme } from '@mui/material/styles';
@@ -16,6 +17,7 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
1617
import SettingsIcon from '@mui/icons-material/Settings';
1718
import { AppProvider } from '@toolpad/core/AppProvider';
1819
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
20+
import { Account } from '@toolpad/core/Account';
1921
import { DemoProvider, useDemoRouter } from '@toolpad/core/internal';
2022

2123
const NAVIGATION = [
@@ -131,6 +133,15 @@ function CustomThemeSwitcher() {
131133
);
132134
}
133135

136+
function CustomToolbarActions() {
137+
return (
138+
<Stack direction="row" alignItems="center">
139+
<CustomThemeSwitcher />
140+
<Account />
141+
</Stack>
142+
);
143+
}
144+
134145
function DashboardLayoutCustomThemeSwitcher(props) {
135146
const { window } = props;
136147

@@ -151,7 +162,7 @@ function DashboardLayoutCustomThemeSwitcher(props) {
151162
{/* preview-start */}
152163
<DashboardLayout
153164
slots={{
154-
toolbarActions: CustomThemeSwitcher,
165+
toolbarActions: CustomToolbarActions,
155166
}}
156167
>
157168
<DemoPageContent pathname={router.pathname} />

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutCustomThemeSwitcher.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import IconButton from '@mui/material/IconButton';
77
import Popover from '@mui/material/Popover';
88
import Radio from '@mui/material/Radio';
99
import RadioGroup from '@mui/material/RadioGroup';
10+
import Stack from '@mui/material/Stack';
1011
import Tooltip from '@mui/material/Tooltip';
1112
import Typography from '@mui/material/Typography';
1213
import { createTheme, useColorScheme } from '@mui/material/styles';
@@ -15,6 +16,7 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
1516
import SettingsIcon from '@mui/icons-material/Settings';
1617
import { AppProvider, type Navigation } from '@toolpad/core/AppProvider';
1718
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
19+
import { Account } from '@toolpad/core/Account';
1820
import { DemoProvider, useDemoRouter } from '@toolpad/core/internal';
1921

2022
const NAVIGATION: Navigation = [
@@ -126,6 +128,15 @@ function CustomThemeSwitcher() {
126128
);
127129
}
128130

131+
function CustomToolbarActions() {
132+
return (
133+
<Stack direction="row" alignItems="center">
134+
<CustomThemeSwitcher />
135+
<Account />
136+
</Stack>
137+
);
138+
}
139+
129140
interface DemoProps {
130141
/**
131142
* Injected by the documentation to work in an iframe.
@@ -154,7 +165,7 @@ export default function DashboardLayoutCustomThemeSwitcher(props: DemoProps) {
154165
{/* preview-start */}
155166
<DashboardLayout
156167
slots={{
157-
toolbarActions: CustomThemeSwitcher,
168+
toolbarActions: CustomToolbarActions,
158169
}}
159170
>
160171
<DemoPageContent pathname={router.pathname} />

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutCustomThemeSwitcher.tsx.preview

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<DashboardLayout
22
slots={{
3-
toolbarActions: CustomThemeSwitcher,
3+
toolbarActions: CustomToolbarActions,
44
}}
55
>
66
<DemoPageContent pathname={router.pathname} />

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutSlots.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import CheckCircleIcon from '@mui/icons-material/CheckCircle';
1515
import SearchIcon from '@mui/icons-material/Search';
1616
import { AppProvider } from '@toolpad/core/AppProvider';
1717
import { DashboardLayout, ThemeSwitcher } from '@toolpad/core/DashboardLayout';
18+
import { Account } from '@toolpad/core/Account';
1819
import { DemoProvider, useDemoRouter } from '@toolpad/core/internal';
1920

2021
const NAVIGATION = [
@@ -103,6 +104,7 @@ function ToolbarActionsSearch() {
103104
sx={{ display: { xs: 'none', md: 'inline-block' }, mr: 1 }}
104105
/>
105106
<ThemeSwitcher />
107+
<Account />
106108
</Stack>
107109
);
108110
}

docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutSlots.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ThemeSwitcher,
1919
type SidebarFooterProps,
2020
} from '@toolpad/core/DashboardLayout';
21+
import { Account } from '@toolpad/core/Account';
2122
import { DemoProvider, useDemoRouter } from '@toolpad/core/internal';
2223

2324
const NAVIGATION: Navigation = [
@@ -102,6 +103,7 @@ function ToolbarActionsSearch() {
102103
sx={{ display: { xs: 'none', md: 'inline-block' }, mr: 1 }}
103104
/>
104105
<ThemeSwitcher />
106+
<Account />
105107
</Stack>
106108
);
107109
}

docs/data/toolpad/core/components/dashboard-layout/dashboard-layout.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
productId: toolpad-core
33
title: Dashboard Layout
4-
components: AppProvider, DashboardLayout, ToolbarActions, ThemeSwitcher, Account, DashboardSidebarPageItem
4+
components: AppProvider, DashboardLayout, DashboardHeader, ToolbarActions, ThemeSwitcher, Account, DashboardSidebarPageItem
55
---
66

77
# Dashboard Layout
@@ -164,9 +164,11 @@ Some possibly useful slots:
164164

165165
- `appTitle`: allows you to customize the app title section in the layout header.
166166

167-
- `toolbarActions`: allows you to add new items to the toolbar in the header, such as a search bar or button. The default `ThemeSwitcher` component can be imported and used if you wish to do so, as shown in the example below.
167+
- `toolbarActions`: allows you to add new items to the toolbar in the header, such as a search bar or button. The default `ThemeSwitcher` and `Account` components can be imported and used if you wish to do so, as shown in the example below.
168168

169-
- `sidebarFooter`: allows you to add footer content in the sidebar.
169+
- `header`: allows you to fully replace and customize the layout header.
170+
171+
- `sidebarFooter`: allows you to add a footer to the sidebar.
170172

171173
{{"demo": "DashboardLayoutSlots.js", "height": 400, "iframe": true}}
172174

docs/data/toolpad/core/pagesApi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default [
88
{ pathname: '/toolpad/core/api/crud' },
99
{ pathname: '/toolpad/core/api/crud-form' },
1010
{ pathname: '/toolpad/core/api/crud-provider' },
11+
{ pathname: '/toolpad/core/api/dashboard-header' },
1112
{ pathname: '/toolpad/core/api/dashboard-layout' },
1213
{ pathname: '/toolpad/core/api/dashboard-sidebar-page-item' },
1314
{ pathname: '/toolpad/core/api/dialogs-provider' },

0 commit comments

Comments
 (0)