-
-
Notifications
You must be signed in to change notification settings - Fork 253
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 toolbarActions and toolbarAccount slots to DashboardLayout #3984
Merged
apedroferreira
merged 13 commits into
mui:master
from
apedroferreira:add-toolpad-actions-slot
Aug 29, 2024
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5b51a00
Add toolbarActions slot to DashboardLayout
apedroferreira 67ea17a
Isolate ThemeSwitcher component
apedroferreira f1f828a
dedupes
apedroferreira 722c837
Fix slots in docs API pages
apedroferreira 4160227
Export default slots components
apedroferreira 11588ce
Add comment
apedroferreira b2ea5c2
ugh
apedroferreira 610e1e1
Merge remote-tracking branch 'upstream/master' into add-toolpad-actio…
apedroferreira 91a04a9
oh come on
apedroferreira 2829cef
revert changes to context
apedroferreira 4d0bc46
Add search bar demo, make it 2 new slots instead of 1
apedroferreira af5abde
Merge remote-tracking branch 'upstream/master' into add-toolpad-actio…
apedroferreira 58825f4
Fix typo
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 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
11 changes: 9 additions & 2 deletions
11
docs/translations/api-docs/dashboard-layout/dashboard-layout.json
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,5 +1,12 @@ | ||
{ | ||
"componentDescription": "", | ||
"propDescriptions": { "children": { "description": "The content of the dashboard." } }, | ||
"classDescriptions": {} | ||
"propDescriptions": { | ||
"children": { "description": "The content of the dashboard." }, | ||
"slotProps": { "description": "The props used for each slot inside." }, | ||
"slots": { "description": "The components used for each slot inside." } | ||
}, | ||
"classDescriptions": {}, | ||
"slotDescriptions": { | ||
"toolbarActions": "The toolbar actions component used in the layout header." | ||
} | ||
} |
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
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
73 changes: 73 additions & 0 deletions
73
packages/toolpad-core/src/DashboardLayout/ThemeSwitcher.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,73 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { useTheme } from '@mui/material'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import DarkModeIcon from '@mui/icons-material/DarkMode'; | ||
import LightModeIcon from '@mui/icons-material/LightMode'; | ||
import useSsr from '@toolpad/utils/hooks/useSsr'; | ||
import { PaletteModeContext } from '../shared/context'; | ||
|
||
/** | ||
* @ignore - internal component. | ||
*/ | ||
function ThemeSwitcher() { | ||
const isSsr = useSsr(); | ||
const theme = useTheme(); | ||
|
||
const { paletteMode, setPaletteMode, isDualTheme } = React.useContext(PaletteModeContext); | ||
|
||
const toggleMode = React.useCallback(() => { | ||
setPaletteMode(paletteMode === 'dark' ? 'light' : 'dark'); | ||
}, [paletteMode, setPaletteMode]); | ||
|
||
return isDualTheme ? ( | ||
<Tooltip | ||
title={isSsr ? 'Switch mode' : `${paletteMode === 'dark' ? 'Light' : 'Dark'} mode`} | ||
enterDelay={1000} | ||
> | ||
<div> | ||
<IconButton | ||
aria-label={ | ||
isSsr | ||
? 'Switch theme mode' | ||
: `Switch to ${paletteMode === 'dark' ? 'light' : 'dark'} mode` | ||
} | ||
onClick={toggleMode} | ||
sx={{ | ||
color: (theme.vars ?? theme).palette.primary.dark, | ||
padding: 1, | ||
marginRight: 1, | ||
}} | ||
> | ||
{theme.getColorSchemeSelector ? ( | ||
<React.Fragment> | ||
<DarkModeIcon | ||
sx={{ | ||
display: 'inline', | ||
[theme.getColorSchemeSelector('dark')]: { | ||
display: 'none', | ||
}, | ||
}} | ||
/> | ||
<LightModeIcon | ||
sx={{ | ||
display: 'none', | ||
[theme.getColorSchemeSelector('dark')]: { | ||
display: 'inline', | ||
}, | ||
}} | ||
/> | ||
</React.Fragment> | ||
) : ( | ||
<React.Fragment> | ||
{isSsr || paletteMode !== 'dark' ? <DarkModeIcon /> : <LightModeIcon />} | ||
</React.Fragment> | ||
)} | ||
</IconButton> | ||
</div> | ||
</Tooltip> | ||
) : null; | ||
} | ||
|
||
export { ThemeSwitcher }; |
12 changes: 12 additions & 0 deletions
12
packages/toolpad-core/src/DashboardLayout/ToolbarActions.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,12 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { Account } from '../Account'; | ||
|
||
/** | ||
* @ignore - internal component. | ||
*/ | ||
function ToolbarActions() { | ||
return <Account />; | ||
} | ||
|
||
export { ToolbarActions }; |
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 +1,4 @@ | ||
export * from './DashboardLayout'; | ||
|
||
// Default slots components | ||
export * from './ToolbarActions'; |
Oops, something went wrong.
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.
Placeholder component for later, but could just be null directly too.