@mui/system 5.1.0 → 5.2.2
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/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +257 -10
- package/breakpoints.js +1 -1
- package/createBox.js +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +11 -1
- package/cssVars/createCssVarsProvider.js +62 -8
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/cssVarsParser.d.ts +68 -68
- package/cssVars/cssVarsParser.js +1 -1
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/getInitColorSchemeScript.js +6 -6
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/breakpoints.js +1 -1
- package/esm/createBox.js +1 -1
- package/esm/cssVars/createCssVarsProvider.js +59 -8
- package/esm/cssVars/cssVarsParser.js +1 -1
- package/esm/cssVars/getInitColorSchemeScript.js +6 -6
- package/esm/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +20 -18
- package/esm/sx/index.js +1 -0
- package/esm/sx/sx.js +12 -0
- package/index.d.ts +2 -0
- package/index.js +10 -1
- package/index.spec.d.ts +1 -1
- package/legacy/breakpoints.js +1 -1
- package/legacy/createBox.js +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +60 -6
- package/legacy/cssVars/cssVarsParser.js +1 -1
- package/legacy/cssVars/getInitColorSchemeScript.js +2 -3
- package/legacy/index.js +2 -1
- package/legacy/styleFunctionSx/styleFunctionSx.js +19 -17
- package/legacy/sx/index.js +1 -0
- package/legacy/sx/sx.js +13 -0
- package/modern/breakpoints.js +1 -1
- package/modern/createBox.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +59 -8
- package/modern/cssVars/cssVarsParser.js +1 -1
- package/modern/cssVars/getInitColorSchemeScript.js +6 -6
- package/modern/index.js +2 -1
- package/modern/styleFunctionSx/styleFunctionSx.js +20 -18
- package/modern/sx/index.js +1 -0
- package/modern/sx/sx.js +12 -0
- package/package.json +6 -6
- package/styleFunctionSx/styleFunctionSx.js +20 -18
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
- package/sx/index.d.ts +1 -0
- package/sx/index.js +15 -0
- package/sx/package.json +6 -0
- package/sx/sx.d.ts +4 -0
- package/sx/sx.js +22 -0
package/legacy/createBox.js
CHANGED
|
@@ -13,12 +13,17 @@ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY }
|
|
|
13
13
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
16
17
|
export default function createCssVarsProvider(options) {
|
|
17
18
|
var _options$theme = options.theme,
|
|
18
19
|
baseTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
19
20
|
_options$defaultMode = options.defaultMode,
|
|
20
21
|
desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
21
22
|
designSystemColorScheme = options.defaultColorScheme,
|
|
23
|
+
_options$disableTrans = options.disableTransitionOnChange,
|
|
24
|
+
disableTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
25
|
+
_options$enableColorS = options.enableColorScheme,
|
|
26
|
+
enableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
|
|
22
27
|
_options$prefix = options.prefix,
|
|
23
28
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
24
29
|
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
|
|
@@ -62,7 +67,13 @@ export default function createCssVarsProvider(options) {
|
|
|
62
67
|
colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
63
68
|
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes"]);
|
|
64
69
|
|
|
65
|
-
var
|
|
70
|
+
var hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
71
|
+
|
|
72
|
+
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
73
|
+
_deepmerge$components = _deepmerge.components,
|
|
74
|
+
components = _deepmerge$components === void 0 ? {} : _deepmerge$components,
|
|
75
|
+
mergedTheme = _objectWithoutProperties(_deepmerge, ["components"]);
|
|
76
|
+
|
|
66
77
|
var colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
67
78
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
68
79
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -77,6 +88,7 @@ export default function createCssVarsProvider(options) {
|
|
|
77
88
|
}),
|
|
78
89
|
mode = _useCurrentColorSchem.mode,
|
|
79
90
|
setMode = _useCurrentColorSchem.setMode,
|
|
91
|
+
systemMode = _useCurrentColorSchem.systemMode,
|
|
80
92
|
lightColorScheme = _useCurrentColorSchem.lightColorScheme,
|
|
81
93
|
darkColorScheme = _useCurrentColorSchem.darkColorScheme,
|
|
82
94
|
colorScheme = _useCurrentColorSchem.colorScheme,
|
|
@@ -105,6 +117,8 @@ export default function createCssVarsProvider(options) {
|
|
|
105
117
|
rootVars = _cssVarsParser.vars;
|
|
106
118
|
|
|
107
119
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
120
|
+
components: components,
|
|
121
|
+
colorSchemes: colorSchemes,
|
|
108
122
|
vars: rootVars
|
|
109
123
|
});
|
|
110
124
|
var styleSheet = {};
|
|
@@ -121,9 +135,7 @@ export default function createCssVarsProvider(options) {
|
|
|
121
135
|
css = _cssVarsParser2.css,
|
|
122
136
|
vars = _cssVarsParser2.vars;
|
|
123
137
|
|
|
124
|
-
|
|
125
|
-
mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
|
|
126
|
-
}
|
|
138
|
+
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
127
139
|
|
|
128
140
|
var resolvedDefaultColorScheme = function () {
|
|
129
141
|
if (typeof defaultColorScheme === 'string') {
|
|
@@ -148,6 +160,48 @@ export default function createCssVarsProvider(options) {
|
|
|
148
160
|
document.body.setAttribute(attribute, colorScheme);
|
|
149
161
|
}
|
|
150
162
|
}, [colorScheme, attribute]);
|
|
163
|
+
React.useEffect(function () {
|
|
164
|
+
if (!mode || !enableColorScheme) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
169
|
+
|
|
170
|
+
if (mode === 'system') {
|
|
171
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
172
|
+
} else {
|
|
173
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return function () {
|
|
177
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
178
|
+
};
|
|
179
|
+
}, [mode, systemMode]);
|
|
180
|
+
React.useEffect(function () {
|
|
181
|
+
var timer;
|
|
182
|
+
|
|
183
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
184
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
185
|
+
var css = document.createElement('style');
|
|
186
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
187
|
+
document.head.appendChild(css); // Force browser repaint
|
|
188
|
+
|
|
189
|
+
(function () {
|
|
190
|
+
return window.getComputedStyle(document.body);
|
|
191
|
+
})();
|
|
192
|
+
|
|
193
|
+
timer = setTimeout(function () {
|
|
194
|
+
document.head.removeChild(css);
|
|
195
|
+
}, 1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return function () {
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
};
|
|
201
|
+
}, [colorScheme]);
|
|
202
|
+
React.useEffect(function () {
|
|
203
|
+
hasMounted.current = true;
|
|
204
|
+
}, []);
|
|
151
205
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
152
206
|
value: {
|
|
153
207
|
mode: mode,
|
|
@@ -178,7 +232,7 @@ export default function createCssVarsProvider(options) {
|
|
|
178
232
|
attribute: PropTypes.string,
|
|
179
233
|
|
|
180
234
|
/**
|
|
181
|
-
*
|
|
235
|
+
* The component tree.
|
|
182
236
|
*/
|
|
183
237
|
children: PropTypes.node,
|
|
184
238
|
|
|
@@ -198,7 +252,7 @@ export default function createCssVarsProvider(options) {
|
|
|
198
252
|
modeStorageKey: PropTypes.string,
|
|
199
253
|
|
|
200
254
|
/**
|
|
201
|
-
*
|
|
255
|
+
* CSS variable prefix.
|
|
202
256
|
*/
|
|
203
257
|
prefix: PropTypes.string,
|
|
204
258
|
|
|
@@ -75,7 +75,7 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
75
75
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(function (prop) {
|
|
76
76
|
return keys.includes(prop);
|
|
77
77
|
})) {
|
|
78
|
-
//
|
|
78
|
+
// CSS property that are unitless
|
|
79
79
|
return value;
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -5,8 +5,7 @@ export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export var DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
var _ref = options || {},
|
|
8
|
-
|
|
9
|
-
defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
|
|
8
|
+
enableSystem = _ref.enableSystem,
|
|
10
9
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
11
10
|
defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
|
|
12
11
|
_ref$defaultDarkColor = _ref.defaultDarkColorScheme,
|
|
@@ -21,7 +20,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
21
20
|
return /*#__PURE__*/_jsx("script", {
|
|
22
21
|
// eslint-disable-next-line react/no-danger
|
|
23
22
|
dangerouslySetInnerHTML: {
|
|
24
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && ").concat(
|
|
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.body.setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
}
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.2.2
|
|
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.
|
|
@@ -27,6 +27,7 @@ export { default as style, getPath } from './style';
|
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
29
|
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
|
+
export { default as experimental_sx } from './sx';
|
|
30
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
31
32
|
export { default as Box } from './Box';
|
|
32
33
|
export { default as createBox } from './createBox';
|
|
@@ -54,27 +54,29 @@ function styleFunctionSx(props) {
|
|
|
54
54
|
Object.keys(sxObject).forEach(function (styleKey) {
|
|
55
55
|
var value = callIfFn(sxObject[styleKey], theme);
|
|
56
56
|
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}, value, function (x) {
|
|
64
|
-
return _defineProperty({}, styleKey, x);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
68
|
-
css[styleKey] = styleFunctionSx({
|
|
69
|
-
sx: value,
|
|
57
|
+
if (value !== null && value !== undefined) {
|
|
58
|
+
if (_typeof(value) === 'object') {
|
|
59
|
+
if (propToStyleFunction[styleKey]) {
|
|
60
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
61
|
+
} else {
|
|
62
|
+
var breakpointsValues = handleBreakpoints({
|
|
70
63
|
theme: theme
|
|
64
|
+
}, value, function (x) {
|
|
65
|
+
return _defineProperty({}, styleKey, x);
|
|
71
66
|
});
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
|
|
68
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
69
|
+
css[styleKey] = styleFunctionSx({
|
|
70
|
+
sx: value,
|
|
71
|
+
theme: theme
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
css = merge(css, breakpointsValues);
|
|
75
|
+
}
|
|
74
76
|
}
|
|
77
|
+
} else {
|
|
78
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
75
79
|
}
|
|
76
|
-
} else {
|
|
77
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
78
80
|
}
|
|
79
81
|
});
|
|
80
82
|
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/legacy/sx/sx.js
ADDED
package/modern/breakpoints.js
CHANGED
|
@@ -93,7 +93,7 @@ export function createEmptyBreakpointObject(breakpointsInput = {}) {
|
|
|
93
93
|
export function removeUnusedBreakpoints(breakpointKeys, style) {
|
|
94
94
|
return breakpointKeys.reduce((acc, key) => {
|
|
95
95
|
const breakpointOutput = acc[key];
|
|
96
|
-
const isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
|
|
96
|
+
const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
|
|
97
97
|
|
|
98
98
|
if (isBreakpointUnused) {
|
|
99
99
|
delete acc[key];
|
package/modern/createBox.js
CHANGED
|
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
4
|
const _excluded = ["colorSchemes"],
|
|
5
|
-
_excluded2 = ["colorSchemes"]
|
|
5
|
+
_excluded2 = ["colorSchemes"],
|
|
6
|
+
_excluded3 = ["components"];
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import PropTypes from 'prop-types';
|
|
8
9
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
@@ -13,11 +14,14 @@ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY }
|
|
|
13
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
16
18
|
export default function createCssVarsProvider(options) {
|
|
17
19
|
const {
|
|
18
20
|
theme: baseTheme = {},
|
|
19
21
|
defaultMode: desisgnSystemMode = 'light',
|
|
20
22
|
defaultColorScheme: designSystemColorScheme,
|
|
23
|
+
disableTransitionOnChange = false,
|
|
24
|
+
enableColorScheme = true,
|
|
21
25
|
prefix: designSystemPrefix = '',
|
|
22
26
|
shouldSkipGeneratingVar
|
|
23
27
|
} = options;
|
|
@@ -57,7 +61,14 @@ export default function createCssVarsProvider(options) {
|
|
|
57
61
|
} = themeProp,
|
|
58
62
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
65
|
+
|
|
66
|
+
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
67
|
+
{
|
|
68
|
+
components = {}
|
|
69
|
+
} = _deepmerge,
|
|
70
|
+
mergedTheme = _objectWithoutPropertiesLoose(_deepmerge, _excluded3);
|
|
71
|
+
|
|
61
72
|
const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
62
73
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
63
74
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -65,6 +76,7 @@ export default function createCssVarsProvider(options) {
|
|
|
65
76
|
const {
|
|
66
77
|
mode,
|
|
67
78
|
setMode,
|
|
79
|
+
systemMode,
|
|
68
80
|
lightColorScheme,
|
|
69
81
|
darkColorScheme,
|
|
70
82
|
colorScheme,
|
|
@@ -100,6 +112,8 @@ export default function createCssVarsProvider(options) {
|
|
|
100
112
|
shouldSkipGeneratingVar
|
|
101
113
|
});
|
|
102
114
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
115
|
+
components,
|
|
116
|
+
colorSchemes,
|
|
103
117
|
vars: rootVars
|
|
104
118
|
});
|
|
105
119
|
const styleSheet = {};
|
|
@@ -112,10 +126,7 @@ export default function createCssVarsProvider(options) {
|
|
|
112
126
|
basePrefix: designSystemPrefix,
|
|
113
127
|
shouldSkipGeneratingVar
|
|
114
128
|
});
|
|
115
|
-
|
|
116
|
-
if (key === resolvedColorScheme) {
|
|
117
|
-
mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
|
|
118
|
-
}
|
|
129
|
+
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
119
130
|
|
|
120
131
|
const resolvedDefaultColorScheme = (() => {
|
|
121
132
|
if (typeof defaultColorScheme === 'string') {
|
|
@@ -140,6 +151,46 @@ export default function createCssVarsProvider(options) {
|
|
|
140
151
|
document.body.setAttribute(attribute, colorScheme);
|
|
141
152
|
}
|
|
142
153
|
}, [colorScheme, attribute]);
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
if (!mode || !enableColorScheme) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
160
|
+
|
|
161
|
+
if (mode === 'system') {
|
|
162
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
163
|
+
} else {
|
|
164
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return () => {
|
|
168
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
169
|
+
};
|
|
170
|
+
}, [mode, systemMode]);
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
let timer;
|
|
173
|
+
|
|
174
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
175
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
176
|
+
const css = document.createElement('style');
|
|
177
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
178
|
+
document.head.appendChild(css); // Force browser repaint
|
|
179
|
+
|
|
180
|
+
(() => window.getComputedStyle(document.body))();
|
|
181
|
+
|
|
182
|
+
timer = setTimeout(() => {
|
|
183
|
+
document.head.removeChild(css);
|
|
184
|
+
}, 1);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return () => {
|
|
188
|
+
clearTimeout(timer);
|
|
189
|
+
};
|
|
190
|
+
}, [colorScheme]);
|
|
191
|
+
React.useEffect(() => {
|
|
192
|
+
hasMounted.current = true;
|
|
193
|
+
}, []);
|
|
143
194
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
144
195
|
value: {
|
|
145
196
|
mode,
|
|
@@ -170,7 +221,7 @@ export default function createCssVarsProvider(options) {
|
|
|
170
221
|
attribute: PropTypes.string,
|
|
171
222
|
|
|
172
223
|
/**
|
|
173
|
-
*
|
|
224
|
+
* The component tree.
|
|
174
225
|
*/
|
|
175
226
|
children: PropTypes.node,
|
|
176
227
|
|
|
@@ -190,7 +241,7 @@ export default function createCssVarsProvider(options) {
|
|
|
190
241
|
modeStorageKey: PropTypes.string,
|
|
191
242
|
|
|
192
243
|
/**
|
|
193
|
-
*
|
|
244
|
+
* CSS variable prefix.
|
|
194
245
|
*/
|
|
195
246
|
prefix: PropTypes.string,
|
|
196
247
|
|
|
@@ -64,7 +64,7 @@ export const walkObjectDeep = (obj, callback) => {
|
|
|
64
64
|
const getCssValue = (keys, value) => {
|
|
65
65
|
if (typeof value === 'number') {
|
|
66
66
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
|
|
67
|
-
//
|
|
67
|
+
// CSS property that are unitless
|
|
68
68
|
return value;
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -5,7 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
|
|
8
|
+
enableSystem,
|
|
9
9
|
defaultLightColorScheme = 'light',
|
|
10
10
|
defaultDarkColorScheme = 'dark',
|
|
11
11
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -18,20 +18,20 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
18
|
__html: `(function() { try {
|
|
19
19
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
20
20
|
var colorScheme = '';
|
|
21
|
-
if (mode === 'system' || (!mode &&
|
|
21
|
+
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
22
22
|
// handle system mode
|
|
23
23
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
24
24
|
if (mql.matches) {
|
|
25
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${
|
|
25
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
26
26
|
} else {
|
|
27
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${
|
|
27
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (mode === 'light') {
|
|
31
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultLightColorScheme};
|
|
31
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
32
32
|
}
|
|
33
33
|
if (mode === 'dark') {
|
|
34
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultDarkColorScheme};
|
|
34
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
35
|
}
|
|
36
36
|
if (colorScheme) {
|
|
37
37
|
document.body.setAttribute('${attribute}', colorScheme);
|
package/modern/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.2.2
|
|
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.
|
|
@@ -27,6 +27,7 @@ export { default as style, getPath } from './style';
|
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
29
|
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
|
+
export { default as experimental_sx } from './sx';
|
|
30
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
31
32
|
export { default as Box } from './Box';
|
|
32
33
|
export { default as createBox } from './createBox';
|
|
@@ -44,27 +44,29 @@ function styleFunctionSx(props) {
|
|
|
44
44
|
Object.keys(sxObject).forEach(styleKey => {
|
|
45
45
|
const value = callIfFn(sxObject[styleKey], theme);
|
|
46
46
|
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const breakpointsValues = handleBreakpoints({
|
|
52
|
-
theme
|
|
53
|
-
}, value, x => ({
|
|
54
|
-
[styleKey]: x
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
58
|
-
css[styleKey] = styleFunctionSx({
|
|
59
|
-
sx: value,
|
|
60
|
-
theme
|
|
61
|
-
});
|
|
47
|
+
if (value !== null && value !== undefined) {
|
|
48
|
+
if (typeof value === 'object') {
|
|
49
|
+
if (propToStyleFunction[styleKey]) {
|
|
50
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
62
51
|
} else {
|
|
63
|
-
|
|
52
|
+
const breakpointsValues = handleBreakpoints({
|
|
53
|
+
theme
|
|
54
|
+
}, value, x => ({
|
|
55
|
+
[styleKey]: x
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
59
|
+
css[styleKey] = styleFunctionSx({
|
|
60
|
+
sx: value,
|
|
61
|
+
theme
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
css = merge(css, breakpointsValues);
|
|
65
|
+
}
|
|
64
66
|
}
|
|
67
|
+
} else {
|
|
68
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
65
69
|
}
|
|
66
|
-
} else {
|
|
67
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/modern/sx/sx.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@babel/runtime": "^7.16.
|
|
47
|
-
"@mui/private-theming": "^5.
|
|
48
|
-
"@mui/styled-engine": "^5.
|
|
46
|
+
"@babel/runtime": "^7.16.3",
|
|
47
|
+
"@mui/private-theming": "^5.2.2",
|
|
48
|
+
"@mui/styled-engine": "^5.2.0",
|
|
49
49
|
"@mui/types": "^7.1.0",
|
|
50
|
-
"@mui/utils": "^5.
|
|
50
|
+
"@mui/utils": "^5.2.2",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
|
-
"csstype": "^3.0.
|
|
52
|
+
"csstype": "^3.0.10",
|
|
53
53
|
"prop-types": "^15.7.2"
|
|
54
54
|
},
|
|
55
55
|
"sideEffects": false,
|
|
@@ -59,27 +59,29 @@ function styleFunctionSx(props) {
|
|
|
59
59
|
Object.keys(sxObject).forEach(styleKey => {
|
|
60
60
|
const value = callIfFn(sxObject[styleKey], theme);
|
|
61
61
|
|
|
62
|
-
if (
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const breakpointsValues = (0, _breakpoints.handleBreakpoints)({
|
|
67
|
-
theme
|
|
68
|
-
}, value, x => ({
|
|
69
|
-
[styleKey]: x
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
73
|
-
css[styleKey] = styleFunctionSx({
|
|
74
|
-
sx: value,
|
|
75
|
-
theme
|
|
76
|
-
});
|
|
62
|
+
if (value !== null && value !== undefined) {
|
|
63
|
+
if (typeof value === 'object') {
|
|
64
|
+
if (_getThemeValue.propToStyleFunction[styleKey]) {
|
|
65
|
+
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
77
66
|
} else {
|
|
78
|
-
|
|
67
|
+
const breakpointsValues = (0, _breakpoints.handleBreakpoints)({
|
|
68
|
+
theme
|
|
69
|
+
}, value, x => ({
|
|
70
|
+
[styleKey]: x
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
74
|
+
css[styleKey] = styleFunctionSx({
|
|
75
|
+
sx: value,
|
|
76
|
+
theme
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
css = (0, _merge.default)(css, breakpointsValues);
|
|
80
|
+
}
|
|
79
81
|
}
|
|
82
|
+
} else {
|
|
83
|
+
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
80
84
|
}
|
|
81
|
-
} else {
|
|
82
|
-
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
83
85
|
}
|
|
84
86
|
});
|
|
85
87
|
return (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/sx/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/sx/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _sx.default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
package/sx/package.json
ADDED
package/sx/sx.d.ts
ADDED