Files
react-test/docs/data/material/customization/dark-mode/DarkThemeWithCustomPalette.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-12-12 14:26:25 +09:00
import Box from '@mui/material/Box';
import { ThemeProvider, useTheme, createTheme } from '@mui/material/styles';
import { amber, deepOrange, grey } from '@mui/material/colors';
const getDesignTokens = (mode) => ({
palette: {
mode,
primary: {
...amber,
...(mode === 'dark' && {
main: amber[300],
}),
},
...(mode === 'dark' && {
background: {
default: deepOrange[900],
paper: deepOrange[900],
},
}),
text: {
...(mode === 'light'
? {
primary: grey[900],
secondary: grey[800],
}
: {
primary: '#fff',
secondary: grey[500],
}),
},
},
});
function MyApp() {
const theme = useTheme();
return (
<Box
sx={{
display: 'flex',
width: '100%',
alignItems: 'center',
justifyContent: 'center',
bgcolor: 'background.default',
color: 'text.primary',
borderRadius: 1,
p: 3,
}}
>
This is a {theme.palette.mode} mode theme with custom palette
</Box>
);
}
const darkModeTheme = createTheme(getDesignTokens('dark'));
export default function DarkThemeWithCustomPalette() {
return (
<ThemeProvider theme={darkModeTheme}>
<MyApp />
</ThemeProvider>
);
}