@mui/system 5.2.2 → 5.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +271 -0
- package/createBox.d.ts +3 -3
- package/createBox.spec.d.ts +1 -0
- package/createTheme/createBreakpoints.d.ts +6 -0
- package/createTheme/createBreakpoints.js +16 -0
- package/cssVars/createCssVarsProvider.d.ts +13 -9
- package/cssVars/createCssVarsProvider.js +26 -6
- package/cssVars/createGetThemeVar.d.ts +1 -0
- package/cssVars/createGetThemeVar.js +22 -0
- package/cssVars/cssVarsParser.d.ts +1 -1
- package/cssVars/cssVarsParser.js +17 -16
- package/cssVars/getInitColorSchemeScript.js +1 -1
- package/esm/createTheme/createBreakpoints.js +16 -0
- package/esm/cssVars/createCssVarsProvider.js +25 -7
- package/esm/cssVars/createGetThemeVar.js +15 -0
- package/esm/cssVars/cssVarsParser.js +17 -15
- package/esm/cssVars/getInitColorSchemeScript.js +1 -1
- package/esm/index.js +2 -1
- package/esm/useThemeProps/getThemeProps.js +2 -17
- package/index.d.ts +1 -0
- package/index.js +11 -2
- package/legacy/createTheme/createBreakpoints.js +16 -0
- package/legacy/cssVars/createCssVarsProvider.js +27 -8
- package/legacy/cssVars/createGetThemeVar.js +26 -0
- package/legacy/cssVars/cssVarsParser.js +19 -13
- package/legacy/cssVars/getInitColorSchemeScript.js +1 -1
- package/legacy/index.js +3 -2
- package/legacy/useThemeProps/getThemeProps.js +2 -17
- package/modern/createTheme/createBreakpoints.js +16 -0
- package/modern/cssVars/createCssVarsProvider.js +23 -7
- package/modern/cssVars/createGetThemeVar.js +15 -0
- package/modern/cssVars/cssVarsParser.js +17 -15
- package/modern/cssVars/getInitColorSchemeScript.js +1 -1
- package/modern/index.js +3 -2
- package/modern/useThemeProps/getThemeProps.js +2 -17
- package/package.json +5 -5
- package/styleFunctionSx/styleFunctionSx.d.ts +1 -1
- package/useThemeProps/getThemeProps.js +2 -17
|
@@ -7,15 +7,20 @@ const _excluded = ["colorSchemes"],
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
10
|
-
import { deepmerge } from '@mui/utils';
|
|
10
|
+
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
11
|
+
import createSpacing from '../createTheme/createSpacing';
|
|
12
|
+
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
11
13
|
import cssVarsParser from './cssVarsParser';
|
|
12
14
|
import ThemeProvider from '../ThemeProvider';
|
|
13
15
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
14
16
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
17
|
+
import createGetThemeVar from './createGetThemeVar';
|
|
15
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
20
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
18
21
|
export default function createCssVarsProvider(options) {
|
|
22
|
+
var _baseTheme$breakpoint;
|
|
23
|
+
|
|
19
24
|
const {
|
|
20
25
|
theme: baseTheme = {},
|
|
21
26
|
defaultMode: desisgnSystemMode = 'light',
|
|
@@ -25,6 +30,8 @@ export default function createCssVarsProvider(options) {
|
|
|
25
30
|
prefix: designSystemPrefix = '',
|
|
26
31
|
shouldSkipGeneratingVar
|
|
27
32
|
} = options;
|
|
33
|
+
const systemSpacing = createSpacing(baseTheme.spacing);
|
|
34
|
+
const systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
28
35
|
|
|
29
36
|
if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
30
37
|
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
@@ -51,17 +58,21 @@ export default function createCssVarsProvider(options) {
|
|
|
51
58
|
defaultMode = desisgnSystemMode,
|
|
52
59
|
defaultColorScheme = designSystemColorScheme
|
|
53
60
|
}) {
|
|
61
|
+
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
62
|
+
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
63
|
+
const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
|
|
64
|
+
|
|
54
65
|
const {
|
|
55
66
|
colorSchemes: baseColorSchemes = {}
|
|
56
|
-
} =
|
|
57
|
-
restBaseTheme = _objectWithoutPropertiesLoose(
|
|
67
|
+
} = clonedBaseTheme,
|
|
68
|
+
restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
|
|
58
69
|
|
|
59
70
|
const {
|
|
60
71
|
colorSchemes: colorSchemesProp = {}
|
|
61
72
|
} = themeProp,
|
|
62
73
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
63
74
|
|
|
64
|
-
const hasMounted = React.useRef(
|
|
75
|
+
const hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
65
76
|
|
|
66
77
|
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
67
78
|
{
|
|
@@ -114,7 +125,10 @@ export default function createCssVarsProvider(options) {
|
|
|
114
125
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
115
126
|
components,
|
|
116
127
|
colorSchemes,
|
|
117
|
-
vars: rootVars
|
|
128
|
+
vars: rootVars,
|
|
129
|
+
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
130
|
+
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
131
|
+
getThemeVar: createGetThemeVar(prefix)
|
|
118
132
|
});
|
|
119
133
|
const styleSheet = {};
|
|
120
134
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -148,10 +162,11 @@ export default function createCssVarsProvider(options) {
|
|
|
148
162
|
});
|
|
149
163
|
React.useEffect(() => {
|
|
150
164
|
if (colorScheme) {
|
|
151
|
-
|
|
165
|
+
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
166
|
+
document.documentElement.setAttribute(attribute, colorScheme);
|
|
152
167
|
}
|
|
153
168
|
}, [colorScheme, attribute]);
|
|
154
|
-
|
|
169
|
+
useEnhancedEffect(() => {
|
|
155
170
|
if (!mode || !enableColorScheme) {
|
|
156
171
|
return undefined;
|
|
157
172
|
}
|
|
@@ -190,6 +205,9 @@ export default function createCssVarsProvider(options) {
|
|
|
190
205
|
}, [colorScheme]);
|
|
191
206
|
React.useEffect(() => {
|
|
192
207
|
hasMounted.current = true;
|
|
208
|
+
return () => {
|
|
209
|
+
hasMounted.current = false;
|
|
210
|
+
};
|
|
193
211
|
}, []);
|
|
194
212
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
195
213
|
value: {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default function createGetThemeVar(prefix = '') {
|
|
2
|
+
function appendVar(...vars) {
|
|
3
|
+
if (!vars.length) {
|
|
4
|
+
return '';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const getThemeVar = (field, ...vars) => {
|
|
11
|
+
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...vars)})`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return getThemeVar;
|
|
15
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* This function create an object from keys, value and then assign to target
|
|
5
3
|
*
|
|
@@ -45,14 +43,16 @@ export const assignNestedKeys = (obj, keys, value) => {
|
|
|
45
43
|
* // ['palette', 'primary', 'main'] '#000000'
|
|
46
44
|
*/
|
|
47
45
|
|
|
48
|
-
export const walkObjectDeep = (obj, callback) => {
|
|
46
|
+
export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
49
47
|
function recurse(object, parentKeys = []) {
|
|
50
48
|
Object.entries(object).forEach(([key, value]) => {
|
|
51
|
-
if (
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
|
|
50
|
+
if (value !== undefined && value !== null) {
|
|
51
|
+
if (typeof value === 'object' && Object.keys(value).length > 0) {
|
|
52
|
+
recurse(value, [...parentKeys, key]);
|
|
53
|
+
} else {
|
|
54
|
+
callback([...parentKeys, key], value, object);
|
|
55
|
+
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -102,10 +102,6 @@ const getCssValue = (keys, value) => {
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
export default function cssVarsParser(theme, options) {
|
|
105
|
-
const clonedTheme = _extends({}, theme);
|
|
106
|
-
|
|
107
|
-
delete clonedTheme.vars; // remove 'vars' from the structure
|
|
108
|
-
|
|
109
105
|
const {
|
|
110
106
|
prefix,
|
|
111
107
|
basePrefix = '',
|
|
@@ -113,13 +109,18 @@ export default function cssVarsParser(theme, options) {
|
|
|
113
109
|
} = options || {};
|
|
114
110
|
const css = {};
|
|
115
111
|
const vars = {};
|
|
116
|
-
walkObjectDeep(
|
|
112
|
+
walkObjectDeep(theme, (keys, val, scope) => {
|
|
117
113
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
118
114
|
let value = val;
|
|
119
115
|
|
|
120
116
|
if (typeof value === 'string' && value.startsWith('var')) {
|
|
121
117
|
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
122
|
-
|
|
118
|
+
if (!basePrefix && prefix) {
|
|
119
|
+
value = value.replace(/var\(--/g, `var(--${prefix}-`);
|
|
120
|
+
} else {
|
|
121
|
+
value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
|
|
122
|
+
} // scope is the deepest object in the tree, keys is the theme path keys
|
|
123
|
+
|
|
123
124
|
|
|
124
125
|
scope[keys.slice(-1)[0]] = value;
|
|
125
126
|
}
|
|
@@ -133,7 +134,8 @@ export default function cssVarsParser(theme, options) {
|
|
|
133
134
|
assignNestedKeys(vars, keys, `var(${cssVar})`);
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
}
|
|
137
|
+
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
138
|
+
);
|
|
137
139
|
return {
|
|
138
140
|
css,
|
|
139
141
|
vars
|
|
@@ -34,7 +34,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
34
34
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
35
|
}
|
|
36
36
|
if (colorScheme) {
|
|
37
|
-
document.
|
|
37
|
+
document.documentElement.setAttribute('${attribute}', colorScheme);
|
|
38
38
|
}
|
|
39
39
|
} catch (e) {} })();`
|
|
40
40
|
}
|
package/esm/index.js
CHANGED
|
@@ -38,4 +38,5 @@ export { default as useTheme } from './useTheme';
|
|
|
38
38
|
export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
|
|
39
39
|
export * from './colorManipulator';
|
|
40
40
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
41
|
-
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
41
|
+
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
42
|
+
export { default as unstable_createGetThemeVar } from './cssVars/createGetThemeVar';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-restricted-syntax */
|
|
1
|
+
import { internal_resolveProps as resolveProps } from '@mui/utils';
|
|
4
2
|
export default function getThemeProps(params) {
|
|
5
3
|
const {
|
|
6
4
|
theme,
|
|
@@ -12,18 +10,5 @@ export default function getThemeProps(params) {
|
|
|
12
10
|
return props;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
// https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const defaultProps = theme.components[name].defaultProps;
|
|
20
|
-
let propName;
|
|
21
|
-
|
|
22
|
-
for (propName in defaultProps) {
|
|
23
|
-
if (output[propName] === undefined) {
|
|
24
|
-
output[propName] = defaultProps[propName];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return output;
|
|
13
|
+
return resolveProps(theme.components[name].defaultProps, props);
|
|
29
14
|
}
|
package/index.d.ts
CHANGED
|
@@ -161,4 +161,5 @@ export { default as ThemeProvider } from './ThemeProvider';
|
|
|
161
161
|
export * from './ThemeProvider';
|
|
162
162
|
|
|
163
163
|
export { default as unstable_createCssVarsProvider } from './cssVars';
|
|
164
|
+
export { default as unstable_createGetThemeVar } from './cssVars/createGetThemeVar';
|
|
164
165
|
export * from './cssVars';
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.2.
|
|
1
|
+
/** @license MUI v5.2.6
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -49,7 +49,8 @@ var _exportNames = {
|
|
|
49
49
|
useTheme: true,
|
|
50
50
|
useThemeWithoutDefault: true,
|
|
51
51
|
ThemeProvider: true,
|
|
52
|
-
unstable_createCssVarsProvider: true
|
|
52
|
+
unstable_createCssVarsProvider: true,
|
|
53
|
+
unstable_createGetThemeVar: true
|
|
53
54
|
};
|
|
54
55
|
Object.defineProperty(exports, "Box", {
|
|
55
56
|
enumerable: true,
|
|
@@ -243,6 +244,12 @@ Object.defineProperty(exports, "unstable_createCssVarsProvider", {
|
|
|
243
244
|
return _createCssVarsProvider.default;
|
|
244
245
|
}
|
|
245
246
|
});
|
|
247
|
+
Object.defineProperty(exports, "unstable_createGetThemeVar", {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
get: function () {
|
|
250
|
+
return _createGetThemeVar.default;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
246
253
|
Object.defineProperty(exports, "unstable_extendSxProp", {
|
|
247
254
|
enumerable: true,
|
|
248
255
|
get: function () {
|
|
@@ -468,6 +475,8 @@ var _ThemeProvider = _interopRequireDefault(require("./ThemeProvider"));
|
|
|
468
475
|
|
|
469
476
|
var _createCssVarsProvider = _interopRequireDefault(require("./cssVars/createCssVarsProvider"));
|
|
470
477
|
|
|
478
|
+
var _createGetThemeVar = _interopRequireDefault(require("./cssVars/createGetThemeVar"));
|
|
479
|
+
|
|
471
480
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
472
481
|
|
|
473
482
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -49,6 +49,21 @@ export default function createBreakpoints(breakpoints) {
|
|
|
49
49
|
return up(key);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function not(key) {
|
|
53
|
+
// handle first and last key separately, for better readability
|
|
54
|
+
var keyIndex = keys.indexOf(key);
|
|
55
|
+
|
|
56
|
+
if (keyIndex === 0) {
|
|
57
|
+
return up(keys[1]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (keyIndex === keys.length - 1) {
|
|
61
|
+
return down(keys[keyIndex]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
return _extends({
|
|
53
68
|
keys: keys,
|
|
54
69
|
values: values,
|
|
@@ -56,6 +71,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
56
71
|
down: down,
|
|
57
72
|
between: between,
|
|
58
73
|
only: only,
|
|
74
|
+
not: not,
|
|
59
75
|
unit: unit
|
|
60
76
|
}, other);
|
|
61
77
|
}
|
|
@@ -6,15 +6,20 @@ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
|
-
import { deepmerge } from '@mui/utils';
|
|
9
|
+
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
10
|
+
import createSpacing from '../createTheme/createSpacing';
|
|
11
|
+
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
10
12
|
import cssVarsParser from './cssVarsParser';
|
|
11
13
|
import ThemeProvider from '../ThemeProvider';
|
|
12
14
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
15
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
16
|
+
import createGetThemeVar from './createGetThemeVar';
|
|
14
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
19
|
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
17
20
|
export default function createCssVarsProvider(options) {
|
|
21
|
+
var _baseTheme$breakpoint;
|
|
22
|
+
|
|
18
23
|
var _options$theme = options.theme,
|
|
19
24
|
baseTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
20
25
|
_options$defaultMode = options.defaultMode,
|
|
@@ -27,6 +32,8 @@ export default function createCssVarsProvider(options) {
|
|
|
27
32
|
_options$prefix = options.prefix,
|
|
28
33
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
29
34
|
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
|
|
35
|
+
var systemSpacing = createSpacing(baseTheme.spacing);
|
|
36
|
+
var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
30
37
|
|
|
31
38
|
if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
32
39
|
console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
|
|
@@ -58,16 +65,21 @@ export default function createCssVarsProvider(options) {
|
|
|
58
65
|
defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
|
|
59
66
|
_ref$defaultColorSche = _ref.defaultColorScheme,
|
|
60
67
|
defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche;
|
|
68
|
+
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
69
|
+
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
70
|
+
var clonedBaseTheme = React.useMemo(function () {
|
|
71
|
+
return JSON.parse(JSON.stringify(baseTheme));
|
|
72
|
+
}, []);
|
|
61
73
|
|
|
62
|
-
var
|
|
63
|
-
baseColorSchemes =
|
|
64
|
-
restBaseTheme = _objectWithoutProperties(
|
|
74
|
+
var _clonedBaseTheme$colo = clonedBaseTheme.colorSchemes,
|
|
75
|
+
baseColorSchemes = _clonedBaseTheme$colo === void 0 ? {} : _clonedBaseTheme$colo,
|
|
76
|
+
restBaseTheme = _objectWithoutProperties(clonedBaseTheme, ["colorSchemes"]);
|
|
65
77
|
|
|
66
78
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
67
79
|
colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
68
80
|
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes"]);
|
|
69
81
|
|
|
70
|
-
var hasMounted = React.useRef(
|
|
82
|
+
var hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
71
83
|
|
|
72
84
|
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
73
85
|
_deepmerge$components = _deepmerge.components,
|
|
@@ -119,7 +131,10 @@ export default function createCssVarsProvider(options) {
|
|
|
119
131
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
120
132
|
components: components,
|
|
121
133
|
colorSchemes: colorSchemes,
|
|
122
|
-
vars: rootVars
|
|
134
|
+
vars: rootVars,
|
|
135
|
+
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
136
|
+
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
137
|
+
getThemeVar: createGetThemeVar(prefix)
|
|
123
138
|
});
|
|
124
139
|
var styleSheet = {};
|
|
125
140
|
Object.entries(colorSchemes).forEach(function (_ref2) {
|
|
@@ -157,10 +172,11 @@ export default function createCssVarsProvider(options) {
|
|
|
157
172
|
});
|
|
158
173
|
React.useEffect(function () {
|
|
159
174
|
if (colorScheme) {
|
|
160
|
-
|
|
175
|
+
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
176
|
+
document.documentElement.setAttribute(attribute, colorScheme);
|
|
161
177
|
}
|
|
162
178
|
}, [colorScheme, attribute]);
|
|
163
|
-
|
|
179
|
+
useEnhancedEffect(function () {
|
|
164
180
|
if (!mode || !enableColorScheme) {
|
|
165
181
|
return undefined;
|
|
166
182
|
}
|
|
@@ -201,6 +217,9 @@ export default function createCssVarsProvider(options) {
|
|
|
201
217
|
}, [colorScheme]);
|
|
202
218
|
React.useEffect(function () {
|
|
203
219
|
hasMounted.current = true;
|
|
220
|
+
return function () {
|
|
221
|
+
hasMounted.current = false;
|
|
222
|
+
};
|
|
204
223
|
}, []);
|
|
205
224
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
206
225
|
value: {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
export default function createGetThemeVar() {
|
|
3
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
4
|
+
|
|
5
|
+
function appendVar() {
|
|
6
|
+
for (var _len = arguments.length, vars = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
|
+
vars[_key] = arguments[_key];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!vars.length) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(vars[0]).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var getThemeVar = function getThemeVar(field) {
|
|
18
|
+
for (var _len2 = arguments.length, vars = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
19
|
+
vars[_key2 - 1] = arguments[_key2];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0, vars), ")");
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return getThemeVar;
|
|
26
|
+
}
|
|
@@ -49,7 +49,7 @@ export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
|
|
|
49
49
|
* // ['palette', 'primary', 'main'] '#000000'
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
export var walkObjectDeep = function walkObjectDeep(obj, callback) {
|
|
52
|
+
export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPaths) {
|
|
53
53
|
function recurse(object) {
|
|
54
54
|
var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
55
55
|
Object.entries(object).forEach(function (_ref) {
|
|
@@ -57,11 +57,13 @@ export var walkObjectDeep = function walkObjectDeep(obj, callback) {
|
|
|
57
57
|
key = _ref2[0],
|
|
58
58
|
value = _ref2[1];
|
|
59
59
|
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([].concat(_toConsumableArray(parentKeys), [key]))) {
|
|
61
|
+
if (value !== undefined && value !== null) {
|
|
62
|
+
if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
|
|
63
|
+
recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
|
|
64
|
+
} else {
|
|
65
|
+
callback([].concat(_toConsumableArray(parentKeys), [key]), value, object);
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
});
|
|
@@ -113,10 +115,6 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
113
115
|
|
|
114
116
|
|
|
115
117
|
export default function cssVarsParser(theme, options) {
|
|
116
|
-
var clonedTheme = _extends({}, theme);
|
|
117
|
-
|
|
118
|
-
delete clonedTheme.vars; // remove 'vars' from the structure
|
|
119
|
-
|
|
120
118
|
var _ref3 = options || {},
|
|
121
119
|
prefix = _ref3.prefix,
|
|
122
120
|
_ref3$basePrefix = _ref3.basePrefix,
|
|
@@ -125,13 +123,18 @@ export default function cssVarsParser(theme, options) {
|
|
|
125
123
|
|
|
126
124
|
var css = {};
|
|
127
125
|
var vars = {};
|
|
128
|
-
walkObjectDeep(
|
|
126
|
+
walkObjectDeep(theme, function (keys, val, scope) {
|
|
129
127
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
130
128
|
var _value = val;
|
|
131
129
|
|
|
132
130
|
if (typeof _value === 'string' && _value.startsWith('var')) {
|
|
133
131
|
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
134
|
-
|
|
132
|
+
if (!basePrefix && prefix) {
|
|
133
|
+
_value = _value.replace(/var\(--/g, "var(--".concat(prefix, "-"));
|
|
134
|
+
} else {
|
|
135
|
+
_value = prefix ? _value.replace(new RegExp(basePrefix, 'g'), prefix) : _value.replace(new RegExp("".concat(basePrefix, "-"), 'g'), '');
|
|
136
|
+
} // scope is the deepest object in the tree, keys is the theme path keys
|
|
137
|
+
|
|
135
138
|
|
|
136
139
|
scope[keys.slice(-1)[0]] = _value;
|
|
137
140
|
}
|
|
@@ -145,7 +148,10 @@ export default function cssVarsParser(theme, options) {
|
|
|
145
148
|
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
|
-
})
|
|
151
|
+
}, function (keys) {
|
|
152
|
+
return keys[0] === 'vars';
|
|
153
|
+
} // skip 'vars/*' paths
|
|
154
|
+
);
|
|
149
155
|
return {
|
|
150
156
|
css: css,
|
|
151
157
|
vars: vars
|
|
@@ -20,7 +20,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
20
20
|
return /*#__PURE__*/_jsx("script", {
|
|
21
21
|
// eslint-disable-next-line react/no-danger
|
|
22
22
|
dangerouslySetInnerHTML: {
|
|
23
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n document.
|
|
23
|
+
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n document.documentElement.setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
}
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.2.
|
|
1
|
+
/** @license MUI v5.2.6
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -43,4 +43,5 @@ export { default as useTheme } from './useTheme';
|
|
|
43
43
|
export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
|
|
44
44
|
export * from './colorManipulator';
|
|
45
45
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
46
|
-
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
46
|
+
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
47
|
+
export { default as unstable_createGetThemeVar } from './cssVars/createGetThemeVar';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-restricted-syntax */
|
|
1
|
+
import { internal_resolveProps as resolveProps } from '@mui/utils';
|
|
4
2
|
export default function getThemeProps(params) {
|
|
5
3
|
var theme = params.theme,
|
|
6
4
|
name = params.name,
|
|
@@ -10,18 +8,5 @@ export default function getThemeProps(params) {
|
|
|
10
8
|
return props;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
// https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var defaultProps = theme.components[name].defaultProps;
|
|
18
|
-
var propName;
|
|
19
|
-
|
|
20
|
-
for (propName in defaultProps) {
|
|
21
|
-
if (output[propName] === undefined) {
|
|
22
|
-
output[propName] = defaultProps[propName];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return output;
|
|
11
|
+
return resolveProps(theme.components[name].defaultProps, props);
|
|
27
12
|
}
|
|
@@ -51,6 +51,21 @@ export default function createBreakpoints(breakpoints) {
|
|
|
51
51
|
return up(key);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function not(key) {
|
|
55
|
+
// handle first and last key separately, for better readability
|
|
56
|
+
const keyIndex = keys.indexOf(key);
|
|
57
|
+
|
|
58
|
+
if (keyIndex === 0) {
|
|
59
|
+
return up(keys[1]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (keyIndex === keys.length - 1) {
|
|
63
|
+
return down(keys[keyIndex]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
return _extends({
|
|
55
70
|
keys,
|
|
56
71
|
values,
|
|
@@ -58,6 +73,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
58
73
|
down,
|
|
59
74
|
between,
|
|
60
75
|
only,
|
|
76
|
+
not,
|
|
61
77
|
unit
|
|
62
78
|
}, other);
|
|
63
79
|
}
|