1 | import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
|
2 | import deepmerge from '@mui/utils/deepmerge';
|
3 | import styleFunctionSx, { unstable_defaultSxConfig as defaultSxConfig } from '@mui/system/styleFunctionSx';
|
4 | import systemCreateTheme from '@mui/system/createTheme';
|
5 | import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
6 | import createMixins from "./createMixins.js";
|
7 | import createPalette from "./createPalette.js";
|
8 | import createTypography from "./createTypography.js";
|
9 | import shadows from "./shadows.js";
|
10 | import createTransitions from "./createTransitions.js";
|
11 | import zIndex from "./zIndex.js";
|
12 | import { stringifyTheme } from "./stringifyTheme.js";
|
13 | function createThemeNoVars(options = {}, ...args) {
|
14 | const {
|
15 | breakpoints: breakpointsInput,
|
16 | mixins: mixinsInput = {},
|
17 | spacing: spacingInput,
|
18 | palette: paletteInput = {},
|
19 | transitions: transitionsInput = {},
|
20 | typography: typographyInput = {},
|
21 | shape: shapeInput,
|
22 | ...other
|
23 | } = options;
|
24 | if (options.vars) {
|
25 | throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: `vars` is a private field used for CSS variables support.\n' + 'Please use another name.' : _formatMuiErrorMessage(20));
|
26 | }
|
27 | const palette = createPalette(paletteInput);
|
28 | const systemTheme = systemCreateTheme(options);
|
29 | let muiTheme = deepmerge(systemTheme, {
|
30 | mixins: createMixins(systemTheme.breakpoints, mixinsInput),
|
31 | palette,
|
32 |
|
33 | shadows: shadows.slice(),
|
34 | typography: createTypography(palette, typographyInput),
|
35 | transitions: createTransitions(transitionsInput),
|
36 | zIndex: {
|
37 | ...zIndex
|
38 | }
|
39 | });
|
40 | muiTheme = deepmerge(muiTheme, other);
|
41 | muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
42 | if (process.env.NODE_ENV !== 'production') {
|
43 |
|
44 | const stateClasses = ['active', 'checked', 'completed', 'disabled', 'error', 'expanded', 'focused', 'focusVisible', 'required', 'selected'];
|
45 | const traverse = (node, component) => {
|
46 | let key;
|
47 |
|
48 |
|
49 | for (key in node) {
|
50 | const child = node[key];
|
51 | if (stateClasses.includes(key) && Object.keys(child).length > 0) {
|
52 | if (process.env.NODE_ENV !== 'production') {
|
53 | const stateClass = generateUtilityClass('', key);
|
54 | console.error([`MUI: The \`${component}\` 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 '&.${stateClass}' syntax:`, JSON.stringify({
|
55 | root: {
|
56 | [`&.${stateClass}`]: child
|
57 | }
|
58 | }, null, 2), '', 'https://mui.com/r/state-classes-guide'].join('\n'));
|
59 | }
|
60 |
|
61 | node[key] = {};
|
62 | }
|
63 | }
|
64 | };
|
65 | Object.keys(muiTheme.components).forEach(component => {
|
66 | const styleOverrides = muiTheme.components[component].styleOverrides;
|
67 | if (styleOverrides && component.startsWith('Mui')) {
|
68 | traverse(styleOverrides, component);
|
69 | }
|
70 | });
|
71 | }
|
72 | muiTheme.unstable_sxConfig = {
|
73 | ...defaultSxConfig,
|
74 | ...other?.unstable_sxConfig
|
75 | };
|
76 | muiTheme.unstable_sx = function sx(props) {
|
77 | return styleFunctionSx({
|
78 | sx: props,
|
79 | theme: this
|
80 | });
|
81 | };
|
82 | muiTheme.toRuntimeSource = stringifyTheme;
|
83 |
|
84 | return muiTheme;
|
85 | }
|
86 | let warnedOnce = false;
|
87 | export function createMuiTheme(...args) {
|
88 | if (process.env.NODE_ENV !== 'production') {
|
89 | if (!warnedOnce) {
|
90 | warnedOnce = true;
|
91 | console.error(['MUI: the createMuiTheme function was renamed to createTheme.', '', "You should use `import { createTheme } from '@mui/material/styles'`"].join('\n'));
|
92 | }
|
93 | }
|
94 | return createThemeNoVars(...args);
|
95 | }
|
96 | export default createThemeNoVars; |
\ | No newline at end of file |