Permalink
material-ui/packages/material-ui/src/styles/createMuiTheme.js
Newer
100644
104 lines (94 sloc)
2.92 KB
1
import { deepmerge } from '@material-ui/utils';
2
import createBreakpoints from './createBreakpoints';
3
import createMixins from './createMixins';
4
import createPalette from './createPalette';
5
import createTypography from './createTypography';
8
import createSpacing from './createSpacing';
9
import transitions from './transitions';
13
const {
14
breakpoints: breakpointsInput = {},
15
mixins: mixinsInput = {},
19
...other
20
} = options;
21
22
const palette = createPalette(paletteInput);
23
const breakpoints = createBreakpoints(breakpointsInput);
24
const spacing = createSpacing(spacingInput);
26
let muiTheme = deepmerge(
27
{
28
breakpoints,
29
direction: 'ltr',
30
mixins: createMixins(breakpoints, spacing, mixinsInput),
31
components: {}, // Inject component overrides
32
palette,
33
shadows,
34
typography: createTypography(palette, typographyInput),
35
spacing,
36
shape,
37
transitions,
38
zIndex,
39
},
40
other,
41
);
42
43
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
45
if (process.env.NODE_ENV !== 'production') {
46
const pseudoClasses = [
47
'checked',
48
'disabled',
49
'error',
50
'focused',
51
'focusVisible',
52
'required',
53
'expanded',
54
'selected',
55
];
56
const traverse = (node, component) => {
57
let key;
58
59
// eslint-disable-next-line guard-for-in, no-restricted-syntax
60
for (key in node) {
61
const child = node[key];
62
if (pseudoClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
63
if (process.env.NODE_ENV !== 'production') {
64
console.error(
65
[
66
`Material-UI: The \`${component}\` component increases ` +
67
`the CSS specificity of the \`${key}\` internal state.`,
68
'You can not override it like this: ',
69
JSON.stringify(node, null, 2),
70
'',
71
'Instead, you need to use the $ruleName syntax:',
72
JSON.stringify(
73
{
74
root: {
75
[`&$${key}`]: child,
76
},
78
null,
79
2,
80
),
81
'',
82
'https://material-ui.com/r/pseudo-classes-guide',
83
].join('\n'),
84
);
85
}
86
// Remove the style to prevent global conflicts.
87
node[key] = {};
92
Object.keys(muiTheme.components).forEach((component) => {
93
const overrides = muiTheme.components[component].overrides;
94
95
if (overrides && component.indexOf('Mui') === 0) {
96
traverse(overrides, component);
97
}
98
});