Skip to content
Permalink
Newer
Older
100644 105 lines (95 sloc) 3.19 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 { duration, easing, create, getAutoHeightDuration } from './transitions';
10
import zIndex from './zIndex';
11
12
function createMuiTheme(options = {}, ...args) {
13
const {
14
breakpoints: breakpointsInput = {},
15
mixins: mixinsInput = {},
16
palette: paletteInput = {},
17
spacing: spacingInput,
18
typography: typographyInput = {},
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 definitions
32
palette,
33
// Don't use [...shadows] until you've verified its transpiled code is not invoking the iterator protocol.
34
shadows: shadows.slice(),
35
typography: createTypography(palette, typographyInput),
36
spacing,
38
transitions: { duration, easing, create, getAutoHeightDuration },
40
},
41
other,
42
);
43
44
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
46
if (process.env.NODE_ENV !== 'production') {
47
const pseudoClasses = [
48
'checked',
49
'disabled',
50
'error',
51
'focused',
52
'focusVisible',
53
'required',
54
'expanded',
55
'selected',
56
];
57
const traverse = (node, component) => {
58
let key;
59
60
// eslint-disable-next-line guard-for-in, no-restricted-syntax
61
for (key in node) {
62
const child = node[key];
63
if (pseudoClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
64
if (process.env.NODE_ENV !== 'production') {
65
console.error(
66
[
67
`Material-UI: The \`${component}\` component increases ` +
68
`the CSS specificity of the \`${key}\` internal state.`,
69
'You can not override it like this: ',
70
JSON.stringify(node, null, 2),
71
'',
72
'Instead, you need to use the $ruleName syntax:',
73
JSON.stringify(
74
{
75
root: {
76
[`&$${key}`]: child,
77
},
79
null,
80
2,
81
),
82
'',
83
'https://material-ui.com/r/pseudo-classes-guide',
84
].join('\n'),
85
);
86
}
87
// Remove the style to prevent global conflicts.
88
node[key] = {};
93
Object.keys(muiTheme.components).forEach((component) => {
94
const styleOverrides = muiTheme.components[component].styleOverrides;
96
if (styleOverrides && component.indexOf('Mui') === 0) {
97
traverse(styleOverrides, component);
103
}
104
105
export default createMuiTheme;