Skip to content

Commit

Permalink
Merge pull request #656 from codeSafari10/theming
Browse files Browse the repository at this point in the history
fix: enhance merging custom theme with basePallete
  • Loading branch information
aabidsofi19 authored Jun 21, 2024
2 parents 4bc0a4b + 7212454 commit 9300866
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/theme/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function SistentThemeProvider({
initialMode = 'light',
customTheme
}: SistentThemeProviderProps): JSX.Element {
const theme = React.useMemo<Theme>(() => createCustomTheme(initialMode), [initialMode]);
if (customTheme) {
theme.palette.background.brand = customTheme;
}
const theme = React.useMemo<Theme>(
() => createCustomTheme(initialMode, customTheme),
[initialMode, customTheme]
);
return (
<SistentThemeProviderContext.Provider value={{ emotionCache }}>
<ThemeProvider theme={theme}>
Expand Down
15 changes: 12 additions & 3 deletions src/theme/theme.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { PaletteMode, createTheme } from '@mui/material';
import { Interactiveness, PaletteMode, createTheme } from '@mui/material';
import { components } from './components';
import { darkModePalette, lightModePalette } from './palette';
import { typography } from './typography';

export const drawerWidth = 240;

export const createCustomTheme = (mode: PaletteMode) => {
export const createCustomTheme = (mode: PaletteMode, brandPalette?: Interactiveness) => {
const basePalette = mode == 'light' ? lightModePalette : darkModePalette;
const themePalette = brandPalette
? Object.assign({}, basePalette, {
background: {
brand: brandPalette
}
})
: basePalette;

return createTheme({
palette: {
mode,
...(mode === 'light' ? lightModePalette : darkModePalette)
...themePalette
},
components,
typography: typography(mode),
Expand Down

0 comments on commit 9300866

Please sign in to comment.