feat(web): adapt to horizontal config structure

This commit is contained in:
Ali BARIN
2024-09-20 10:44:34 +00:00
parent 8a17c5eaab
commit 89b1cb9353
3 changed files with 47 additions and 30 deletions

View File

@@ -2,7 +2,6 @@ import PropTypes from 'prop-types';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider as BaseThemeProvider } from '@mui/material/styles';
import clone from 'lodash/clone';
import get from 'lodash/get';
import set from 'lodash/set';
import * as React from 'react';
@@ -10,18 +9,33 @@ import useAutomatischInfo from 'hooks/useAutomatischInfo';
import useAutomatischConfig from 'hooks/useAutomatischConfig';
import { defaultTheme, mationTheme } from 'styles/theme';
const overrideIfGiven = (theme, key, value) => {
if (value) {
set(theme, key, value);
}
};
const customizeTheme = (theme, config) => {
// `clone` is needed so that the new theme reference triggers re-render
const shallowDefaultTheme = clone(theme);
for (const key in config) {
const value = config[key];
const exists = get(theme, key);
overrideIfGiven(
shallowDefaultTheme,
'palette.primary.main',
config.palettePrimaryMain,
);
if (exists) {
set(shallowDefaultTheme, key, value);
}
}
overrideIfGiven(
shallowDefaultTheme,
'palette.primary.light',
config.palettePrimaryLight,
);
overrideIfGiven(
shallowDefaultTheme,
'palette.primary.dark',
config.palettePrimaryDark,
);
return shallowDefaultTheme;
};