feat(web): adapt to horizontal config structure
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user