2021-04-29 09:24:39 +00:00
|
|
|
import { createMuiTheme } from '@material-ui/core/styles';
|
|
|
|
|
2022-08-01 07:04:23 +00:00
|
|
|
import { Theme } from './types';
|
2021-05-11 08:01:45 +00:00
|
|
|
import { createColorTokens } from './utils';
|
2021-04-29 09:24:39 +00:00
|
|
|
|
2022-08-01 07:04:23 +00:00
|
|
|
interface ThemeProps {
|
|
|
|
breakpoints: Object;
|
|
|
|
colorMap: Object;
|
|
|
|
colors: Object;
|
|
|
|
font: Object;
|
|
|
|
shape: Object;
|
|
|
|
spacing: Array<number>;
|
|
|
|
typography: Object;
|
|
|
|
}
|
|
|
|
|
2021-04-29 09:24:39 +00:00
|
|
|
/**
|
|
|
|
* Creates a MUI theme based on local UI tokens.
|
|
|
|
*
|
|
|
|
* @param {Object} arg - The ui tokens.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-08-01 07:04:23 +00:00
|
|
|
export function createWebTheme({ font, colors, colorMap, shape, spacing, typography, breakpoints }: ThemeProps): Theme {
|
2021-04-29 09:24:39 +00:00
|
|
|
return createMuiTheme({
|
|
|
|
props: {
|
|
|
|
// disable ripple effect on buttons globally
|
|
|
|
MuiButtonBase: {
|
|
|
|
disableRipple: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// use token spacing array
|
|
|
|
spacing
|
|
|
|
}, {
|
|
|
|
palette: createColorTokens(colorMap, colors),
|
|
|
|
shape,
|
|
|
|
typography: {
|
|
|
|
font,
|
|
|
|
...typography
|
2021-11-15 08:37:54 +00:00
|
|
|
},
|
|
|
|
breakpoints
|
2022-08-01 07:04:23 +00:00
|
|
|
}) as unknown as Theme;
|
2021-04-29 09:24:39 +00:00
|
|
|
}
|
2021-10-08 08:05:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats the common styles object to be interpreted as proper CSS.
|
|
|
|
*
|
|
|
|
* @param {Object} stylesObj - The styles object.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function formatCommonClasses(stylesObj: Object) {
|
2022-08-01 07:04:23 +00:00
|
|
|
const formatted: any = {};
|
2021-10-08 08:05:16 +00:00
|
|
|
|
|
|
|
for (const [ key, value ] of Object.entries(stylesObj)) {
|
|
|
|
formatted[`.${key}`] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return formatted;
|
|
|
|
}
|
2021-11-15 08:37:54 +00:00
|
|
|
|