-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[material-ui][docs] Open Material UI template with CodeSandbox/StackBlitz #43604
Merged
Merged
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
b48eb9e
poc AppTheme + TemplateFrame
siriwatknp c982bbf
add codesandbox button
siriwatknp 033443d
move AppTheme to
siriwatknp 0e236e1
update TemplateFrame to use button
siriwatknp 52ee07e
fix dark mode flicker issue
siriwatknp f2ef7f2
switch back to TemplateName
siriwatknp 63baeff
use branding theme
siriwatknp e6eb4a1
replace file with module
siriwatknp b12cbf6
run docs:format
siriwatknp 411a832
Merge branch 'master' of https://github.com/mui/material-ui into poc/…
siriwatknp 8b59da7
add StackBlitz
siriwatknp 0e98e5c
move ToggleColorMode to shared-theme
siriwatknp 39ed005
fix tests
siriwatknp fa891f7
fix typo
siriwatknp eefecad
remove updateTemplates check
siriwatknp 7b8a931
fix dark mode flicker at the toolbar
siriwatknp 20cfc8e
remove unnecessary comment
siriwatknp bfc116a
Merge branch 'master' of https://github.com/mui/material-ui into poc/…
siriwatknp 1c377a9
fix the toolbar
siriwatknp ad00393
comment commitRef
siriwatknp 0385f86
make Dashboard work with new structure
siriwatknp 16b2e23
remove unused files
siriwatknp 2d0ce45
add contributing guide
siriwatknp cb7823e
typescript format
siriwatknp d080e3f
fix experiment dashboard
siriwatknp a269533
fix non-breaking space
siriwatknp bb3e39f
Merge branch 'master' of https://github.com/mui/material-ui into poc/…
siriwatknp 494bc92
Add visual separator between items
zanivan f3a1537
Fix layout shift
zanivan 8dd2969
wip
siriwatknp 3cb513f
Merge branch 'master' of https://github.com/mui/material-ui into poc/…
siriwatknp 469338c
make the generateTemplate works with the new structure
siriwatknp eac95f9
Merge branch 'poc/template-theme' of github.com:siriwatknp/material-u…
siriwatknp 63778ad
switch back to headless mode
siriwatknp 185cbfd
move contributing to faq
siriwatknp f4e1ae9
Merge branch 'master' of https://github.com/mui/material-ui into poc/…
siriwatknp 046339e
add disableTransitionOnChange
siriwatknp 5f501ea
docs:ts format
siriwatknp 3361f4a
Add link to contribution guide
zanivan dd74af9
Merge branch 'poc/template-theme' of https://github.com/siriwatknp/ma…
zanivan b01d202
Tweaks to the text
zanivan 9dd82c4
fix non-breaking space
siriwatknp 8c64407
fix data-screenshot="toggle-mode"
siriwatknp 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
111 changes: 45 additions & 66 deletions
111
docs/data/material/getting-started/templates/dashboard/Dashboard.js
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,81 +1,60 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider, alpha } from '@mui/material/styles'; | ||
|
||
import { alpha } from '@mui/material/styles'; | ||
import CssBaseline from '@mui/material/CssBaseline'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import getDashboardTheme from './theme/getDashboardTheme'; | ||
import AppNavbar from './components/AppNavbar'; | ||
import Header from './components/Header'; | ||
import MainGrid from './components/MainGrid'; | ||
import SideMenu from './components/SideMenu'; | ||
import TemplateFrame from './TemplateFrame'; | ||
|
||
export default function Dashboard() { | ||
const [mode, setMode] = React.useState('light'); | ||
const [showCustomTheme, setShowCustomTheme] = React.useState(true); | ||
const dashboardTheme = createTheme(getDashboardTheme(mode)); | ||
const defaultTheme = createTheme({ palette: { mode } }); | ||
// This code only runs on the client side, to determine the system color preference | ||
React.useEffect(() => { | ||
// Check if there is a preferred mode in localStorage | ||
const savedMode = localStorage.getItem('themeMode'); | ||
if (savedMode) { | ||
setMode(savedMode); | ||
} else { | ||
// If no preference is found, it uses system preference | ||
const systemPrefersDark = window.matchMedia( | ||
'(prefers-color-scheme: dark)', | ||
).matches; | ||
setMode(systemPrefersDark ? 'dark' : 'light'); | ||
} | ||
}, []); | ||
|
||
const toggleColorMode = () => { | ||
const newMode = mode === 'dark' ? 'light' : 'dark'; | ||
setMode(newMode); | ||
localStorage.setItem('themeMode', newMode); // Save the selected mode to localStorage | ||
}; | ||
import AppTheme from '../shared-theme/AppTheme'; | ||
import { | ||
chartsCustomizations, | ||
dataGridCustomizations, | ||
datePickersCustomizations, | ||
treeViewCustomizations, | ||
} from './theme/customizations'; | ||
|
||
const toggleCustomTheme = () => { | ||
setShowCustomTheme((prev) => !prev); | ||
}; | ||
const xThemeComponents = { | ||
...chartsCustomizations, | ||
...dataGridCustomizations, | ||
...datePickersCustomizations, | ||
...treeViewCustomizations, | ||
}; | ||
|
||
export default function Dashboard(props) { | ||
return ( | ||
<TemplateFrame | ||
toggleCustomTheme={toggleCustomTheme} | ||
showCustomTheme={showCustomTheme} | ||
mode={mode} | ||
toggleColorMode={toggleColorMode} | ||
> | ||
<ThemeProvider theme={showCustomTheme ? dashboardTheme : defaultTheme}> | ||
<CssBaseline enableColorScheme /> | ||
<Box sx={{ display: 'flex' }}> | ||
<SideMenu /> | ||
<AppNavbar /> | ||
{/* Main content */} | ||
<Box | ||
component="main" | ||
sx={(theme) => ({ | ||
flexGrow: 1, | ||
backgroundColor: alpha(theme.palette.background.default, 1), | ||
overflow: 'auto', | ||
})} | ||
<AppTheme {...props} themeComponents={xThemeComponents}> | ||
<CssBaseline enableColorScheme /> | ||
<Box sx={{ display: 'flex' }}> | ||
<SideMenu /> | ||
<AppNavbar /> | ||
{/* Main content */} | ||
<Box | ||
component="main" | ||
sx={(theme) => ({ | ||
flexGrow: 1, | ||
backgroundColor: theme.vars | ||
? `rgba(${theme.vars.palette.background.defaultChannel} / 1)` | ||
: alpha(theme.palette.background.default, 1), | ||
overflow: 'auto', | ||
})} | ||
> | ||
<Stack | ||
spacing={2} | ||
sx={{ | ||
alignItems: 'center', | ||
mx: 3, | ||
pb: 10, | ||
mt: { xs: 8, md: 0 }, | ||
}} | ||
> | ||
<Stack | ||
spacing={2} | ||
sx={{ | ||
alignItems: 'center', | ||
mx: 3, | ||
pb: 10, | ||
mt: { xs: 8, md: 0 }, | ||
}} | ||
> | ||
<Header /> | ||
<MainGrid /> | ||
</Stack> | ||
</Box> | ||
<Header /> | ||
<MainGrid /> | ||
</Stack> | ||
</Box> | ||
</ThemeProvider> | ||
</TemplateFrame> | ||
</Box> | ||
</AppTheme> | ||
); | ||
} |
119 changes: 48 additions & 71 deletions
119
docs/data/material/getting-started/templates/dashboard/Dashboard.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 |
---|---|---|
@@ -1,86 +1,63 @@ | ||
import * as React from 'react'; | ||
import { | ||
PaletteMode, | ||
createTheme, | ||
ThemeProvider, | ||
alpha, | ||
} from '@mui/material/styles'; | ||
import type {} from '@mui/x-date-pickers/themeAugmentation'; | ||
import type {} from '@mui/x-charts/themeAugmentation'; | ||
import type {} from '@mui/x-data-grid/themeAugmentation'; | ||
import type {} from '@mui/x-tree-view/themeAugmentation'; | ||
import { alpha } from '@mui/material/styles'; | ||
import CssBaseline from '@mui/material/CssBaseline'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import getDashboardTheme from './theme/getDashboardTheme'; | ||
import AppNavbar from './components/AppNavbar'; | ||
import Header from './components/Header'; | ||
import MainGrid from './components/MainGrid'; | ||
import SideMenu from './components/SideMenu'; | ||
import TemplateFrame from './TemplateFrame'; | ||
|
||
export default function Dashboard() { | ||
const [mode, setMode] = React.useState<PaletteMode>('light'); | ||
const [showCustomTheme, setShowCustomTheme] = React.useState(true); | ||
const dashboardTheme = createTheme(getDashboardTheme(mode)); | ||
const defaultTheme = createTheme({ palette: { mode } }); | ||
// This code only runs on the client side, to determine the system color preference | ||
React.useEffect(() => { | ||
// Check if there is a preferred mode in localStorage | ||
const savedMode = localStorage.getItem('themeMode') as PaletteMode | null; | ||
if (savedMode) { | ||
setMode(savedMode); | ||
} else { | ||
// If no preference is found, it uses system preference | ||
const systemPrefersDark = window.matchMedia( | ||
'(prefers-color-scheme: dark)', | ||
).matches; | ||
setMode(systemPrefersDark ? 'dark' : 'light'); | ||
} | ||
}, []); | ||
|
||
const toggleColorMode = () => { | ||
const newMode = mode === 'dark' ? 'light' : 'dark'; | ||
setMode(newMode); | ||
localStorage.setItem('themeMode', newMode); // Save the selected mode to localStorage | ||
}; | ||
import AppTheme from '../shared-theme/AppTheme'; | ||
import { | ||
chartsCustomizations, | ||
dataGridCustomizations, | ||
datePickersCustomizations, | ||
treeViewCustomizations, | ||
} from './theme/customizations'; | ||
|
||
const toggleCustomTheme = () => { | ||
setShowCustomTheme((prev) => !prev); | ||
}; | ||
const xThemeComponents = { | ||
...chartsCustomizations, | ||
...dataGridCustomizations, | ||
...datePickersCustomizations, | ||
...treeViewCustomizations, | ||
}; | ||
|
||
export default function Dashboard(props: { disableCustomTheme?: boolean }) { | ||
return ( | ||
<TemplateFrame | ||
toggleCustomTheme={toggleCustomTheme} | ||
showCustomTheme={showCustomTheme} | ||
mode={mode} | ||
toggleColorMode={toggleColorMode} | ||
> | ||
<ThemeProvider theme={showCustomTheme ? dashboardTheme : defaultTheme}> | ||
<CssBaseline enableColorScheme /> | ||
<Box sx={{ display: 'flex' }}> | ||
<SideMenu /> | ||
<AppNavbar /> | ||
{/* Main content */} | ||
<Box | ||
component="main" | ||
sx={(theme) => ({ | ||
flexGrow: 1, | ||
backgroundColor: alpha(theme.palette.background.default, 1), | ||
overflow: 'auto', | ||
})} | ||
<AppTheme {...props} themeComponents={xThemeComponents}> | ||
<CssBaseline enableColorScheme /> | ||
<Box sx={{ display: 'flex' }}> | ||
<SideMenu /> | ||
<AppNavbar /> | ||
{/* Main content */} | ||
<Box | ||
component="main" | ||
sx={(theme) => ({ | ||
flexGrow: 1, | ||
backgroundColor: theme.vars | ||
? `rgba(${theme.vars.palette.background.defaultChannel} / 1)` | ||
: alpha(theme.palette.background.default, 1), | ||
overflow: 'auto', | ||
})} | ||
> | ||
<Stack | ||
spacing={2} | ||
sx={{ | ||
alignItems: 'center', | ||
mx: 3, | ||
pb: 10, | ||
mt: { xs: 8, md: 0 }, | ||
}} | ||
> | ||
<Stack | ||
spacing={2} | ||
sx={{ | ||
alignItems: 'center', | ||
mx: 3, | ||
pb: 10, | ||
mt: { xs: 8, md: 0 }, | ||
}} | ||
> | ||
<Header /> | ||
<MainGrid /> | ||
</Stack> | ||
</Box> | ||
<Header /> | ||
<MainGrid /> | ||
</Stack> | ||
</Box> | ||
</ThemeProvider> | ||
</TemplateFrame> | ||
</Box> | ||
</AppTheme> | ||
); | ||
} |
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.
No longer need to run the script. The shared theme is the source of truth and it will be bundled with the template when users open CodeSandbox or StackBlitz.