Skip to content
Permalink
Newer
Older
100644 104 lines (96 sloc) 2.88 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';
6
import shadows from './shadows';
7
import shape from './shape';
8
import createSpacing from './createSpacing';
9
import transitions from './transitions';
10
import zIndex from './zIndex';
11
12
function createMuiTheme(options = {}) {
13
const {
14
breakpoints: breakpointsInput = {},
15
mixins: mixinsInput = {},
16
palette: paletteInput = {},
17
shadows: shadowsInput,
18
spacing: spacingInput,
19
typography: typographyInput = {},
20
...other
21
} = options;
22
23
const palette = createPalette(paletteInput);
24
const breakpoints = createBreakpoints(breakpointsInput);
25
const spacing = createSpacing(spacingInput);
27
const muiTheme = {
28
breakpoints,
29
direction: 'ltr',
30
mixins: createMixins(breakpoints, spacing, mixinsInput),
31
overrides: {}, // Inject custom styles
32
palette,
33
props: {}, // Inject custom props
34
shadows: shadowsInput || shadows,
35
typography: createTypography(palette, typographyInput),
37
...deepmerge(
38
{
41
zIndex,
42
},
43
other,
44
),
47
if (process.env.NODE_ENV !== 'production') {
48
const pseudoClasses = [
49
'checked',
50
'disabled',
51
'error',
52
'focused',
53
'focusVisible',
54
'required',
55
'expanded',
56
'selected',
57
];
58
const traverse = (node, parentKey, depth = 1) => {
59
let key;
60
61
// eslint-disable-next-line guard-for-in, no-restricted-syntax
62
for (key in node) {
63
const child = node[key];
64
if (depth === 1) {
65
if (key.indexOf('Mui') === 0 && child) {
66
traverse(child, key, depth + 1);
67
}
68
} else if (pseudoClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
69
if (process.env.NODE_ENV !== 'production') {
70
console.error(
71
[
72
`Material-UI: the \`${parentKey}\` component increases ` +
73
`the CSS specificity of the \`${key}\` internal state.`,
74
'You can not override it like this: ',
75
JSON.stringify(node, null, 2),
76
'',
77
'Instead, you need to use the $ruleName syntax:',
78
JSON.stringify(
79
{
80
root: {
81
[`&$${key}`]: child,
82
},
84
null,
85
2,
86
),
87
'',
88
'https://material-ui.com/r/pseudo-classes-guide',
89
].join('\n'),
90
);
91
}
92
// Remove the style to prevent global conflicts.
93
node[key] = {};
98
traverse(muiTheme.overrides);
102
}
103
104
export default createMuiTheme;