Skip to content

Commit

Permalink
Fix mode toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Dec 20, 2023
1 parent 8db4e21 commit 0ac3680
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 49 deletions.
16 changes: 10 additions & 6 deletions docs/data/material/getting-started/templates/album/Album.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CssBaseline from '@mui/material/CssBaseline';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
import { ThemeProvider } from '@mui/material/styles';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import Divider from '@mui/material/Divider';

import AppBar from './components/AppBar';
Expand All @@ -14,9 +14,8 @@ import Pricing from './components/Pricing';
import Features from './components/Features';
import Testimonials from './components/Testimonials';
import FAQ from './components/FAQ';
import { createContext, useState } from 'react';

import getAlbumTheme from './albumTheme';
import getAlbumTheme from './getAlbumTheme';

function Copyright() {
return (
Expand All @@ -36,10 +35,12 @@ interface ColorMode {
toggleColorMode: () => void;
}

export const ColorModeContext = createContext<ColorMode | undefined>(undefined);
export const ColorModeContext = React.createContext<ColorMode | undefined>(
undefined,
);

export default function Album() {
const [colorMode, setColorMode] = useState<ColorMode>({
const [colorMode, setColorMode] = React.useState<ColorMode>({
mode: 'light',
toggleColorMode: () => {
setColorMode((prevMode) => ({
Expand All @@ -49,7 +50,10 @@ export default function Album() {
},
});

const theme = React.useMemo(() => getAlbumTheme(colorMode.mode), [colorMode.mode]);
const theme = React.useMemo(
() => createTheme(getAlbumTheme(colorMode.mode)),
[colorMode.mode],
);

return (
<ColorModeContext.Provider value={colorMode}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createTheme } from '@mui/material/styles';
import { grey, red } from '@mui/material/colors';
import { PaletteMode } from '@mui/material';

Expand Down Expand Up @@ -77,32 +76,29 @@ const getDesignTokens = (mode: PaletteMode) => ({
},
});

const theme = createTheme({
palette: {
...getDesignTokens,
},
typography: {
fontFamily: "'Inter', sans-serif",
fontSize: 14,
fontWeightLight: 300,
fontWeightRegular: 400,
fontWeightMedium: 500,
},
});

const fontHeader = {
color: theme.palette.text.primary,
fontWeight: theme.typography.fontWeightMedium,
const typographyBase = {
fontFamily: "'Inter', sans-serif",
fontSize: 14,
fontWeightLight: 300,
fontWeightRegular: 400,
fontWeightMedium: 500,
};

export default function getAlbumTheme(mode: 'light' | 'dark') {
const modeDesignTokens = getDesignTokens(mode);

const fontHeader = {
color: modeDesignTokens.palette.text.primary,
fontWeight: typographyBase.fontWeightMedium,
fontFamily: "'Inter', sans-serif",
};

return {
...theme,
...modeDesignTokens,
palette: {
...theme.palette,
...modeDesignTokens.palette,
background: {
...theme.palette.background,
...modeDesignTokens.palette.background,
},
},
components: {
Expand All @@ -117,16 +113,17 @@ export default function getAlbumTheme(mode: 'light' | 'dark') {
},
MuiButton: {
styleOverrides: {
root: ({ ownerState }: { ownerState: { variant: string } }) => ({
boxShadow: 'none',
borderRadius: '8px',
root: ({ ownerState }: { ownerState: { variant?: string } }) =>
({
boxShadow: 'none',
borderRadius: '8px',

...(ownerState.variant === 'outlined' && {
border: '1px solid',
borderColor: '#C7DFF7',
}),
textTransform: 'none',
}),
...(ownerState.variant === 'outlined' && {
border: '1px solid',
borderColor: '#C7DFF7',
}),
textTransform: 'none',
} as const),
},
},
MuiLink: {
Expand Down Expand Up @@ -197,56 +194,46 @@ export default function getAlbumTheme(mode: 'light' | 'dark') {
},
},
typography: {
...theme.typography,
...typographyBase,
fontHeader,
h1: {
...theme.typography.h1,
...fontHeader,
letterSpacing: 0,
fontSize: 60,
},
h2: {
...theme.typography.h2,
...fontHeader,
fontSize: 48,
},
h3: {
...theme.typography.h3,
...fontHeader,
fontSize: 42,
},
h4: {
...theme.typography.h4,
...fontHeader,
fontSize: 36,
},
h5: {
...theme.typography.h5,
fontSize: 20,
fontWeight: theme.typography.fontWeightLight,
fontWeight: typographyBase.fontWeightLight,
},
h6: {
...theme.typography.h6,
...fontHeader,
fontSize: 18,
},
subtitle1: {
...theme.typography.subtitle1,
fontSize: 18,
},
subtitle2: {
...theme.typography.subtitle2,
fontSize: 16,
},
body1: {
...theme.typography.body2,
fontWeight: theme.typography.fontWeightRegular,
fontWeight: typographyBase.fontWeightRegular,
fontSize: 16,
},
body2: {
...theme.typography.body1,
fontSize: 14,
},
},
};
} as const;
}

0 comments on commit 0ac3680

Please sign in to comment.