1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import { deepmerge } from '@material-ui/utils';
|
3 | import createBreakpoints from './createBreakpoints';
|
4 | import createMixins from './createMixins';
|
5 | import createPalette from './createPalette';
|
6 | import createTypography from './createTypography';
|
7 | import shadows from './shadows';
|
8 | import shape from './shape';
|
9 | import createSpacing from './createSpacing';
|
10 | import transitions from './transitions';
|
11 | import zIndex from './zIndex';
|
12 |
|
13 | function createTheme(options = {}, ...args) {
|
14 | const {
|
15 | breakpoints: breakpointsInput = {},
|
16 | mixins: mixinsInput = {},
|
17 | palette: paletteInput = {},
|
18 | spacing: spacingInput,
|
19 | typography: typographyInput = {}
|
20 | } = options,
|
21 | other = _objectWithoutPropertiesLoose(options, ["breakpoints", "mixins", "palette", "spacing", "typography"]);
|
22 |
|
23 | const palette = createPalette(paletteInput);
|
24 | const breakpoints = createBreakpoints(breakpointsInput);
|
25 | const spacing = createSpacing(spacingInput);
|
26 | let muiTheme = deepmerge({
|
27 | breakpoints,
|
28 | direction: 'ltr',
|
29 | mixins: createMixins(breakpoints, spacing, mixinsInput),
|
30 | overrides: {},
|
31 |
|
32 | palette,
|
33 | props: {},
|
34 |
|
35 | shadows,
|
36 | typography: createTypography(palette, typographyInput),
|
37 | spacing,
|
38 | shape,
|
39 | transitions,
|
40 | zIndex
|
41 | }, other);
|
42 | muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
43 |
|
44 | if (process.env.NODE_ENV !== 'production') {
|
45 | const pseudoClasses = ['checked', 'disabled', 'error', 'focused', 'focusVisible', 'required', 'expanded', 'selected'];
|
46 |
|
47 | const traverse = (node, parentKey, depth = 1) => {
|
48 | let key;
|
49 |
|
50 | for (key in node) {
|
51 | const child = node[key];
|
52 |
|
53 | if (depth === 1) {
|
54 | if (key.indexOf('Mui') === 0 && child) {
|
55 | traverse(child, key, depth + 1);
|
56 | }
|
57 | } else if (pseudoClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
|
58 | if (process.env.NODE_ENV !== 'production') {
|
59 | console.error([`Material-UI: The \`${parentKey}\` component increases ` + `the CSS specificity of the \`${key}\` internal state.`, 'You can not override it like this: ', JSON.stringify(node, null, 2), '', 'Instead, you need to use the $ruleName syntax:', JSON.stringify({
|
60 | root: {
|
61 | [`&$${key}`]: child
|
62 | }
|
63 | }, null, 2), '', 'https://material-ui.com/r/pseudo-classes-guide'].join('\n'));
|
64 | }
|
65 |
|
66 |
|
67 | node[key] = {};
|
68 | }
|
69 | }
|
70 | };
|
71 |
|
72 | traverse(muiTheme.overrides);
|
73 | }
|
74 |
|
75 | return muiTheme;
|
76 | }
|
77 |
|
78 | let warnedOnce = false;
|
79 | export function createMuiTheme(...args) {
|
80 | if (process.env.NODE_ENV !== 'production') {
|
81 | if (!warnedOnce) {
|
82 | warnedOnce = true;
|
83 | console.error(['Material-UI: the createMuiTheme function was renamed to createTheme.', '', "You should use `import { createTheme } from '@material-ui/core/styles'`"].join('\n'));
|
84 | }
|
85 | }
|
86 |
|
87 | return createTheme(...args);
|
88 | }
|
89 | export default createTheme; |
\ | No newline at end of file |