@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.
Files changed (52) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +257 -10
  3. package/breakpoints.js +1 -1
  4. package/createBox.js +1 -1
  5. package/createTheme/createSpacing.d.ts +10 -10
  6. package/cssVars/createCssVarsProvider.d.ts +11 -1
  7. package/cssVars/createCssVarsProvider.js +62 -8
  8. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  9. package/cssVars/cssVarsParser.d.ts +68 -68
  10. package/cssVars/cssVarsParser.js +1 -1
  11. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  12. package/cssVars/getInitColorSchemeScript.js +6 -6
  13. package/cssVars/index.d.ts +2 -2
  14. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  15. package/esm/breakpoints.js +1 -1
  16. package/esm/createBox.js +1 -1
  17. package/esm/cssVars/createCssVarsProvider.js +59 -8
  18. package/esm/cssVars/cssVarsParser.js +1 -1
  19. package/esm/cssVars/getInitColorSchemeScript.js +6 -6
  20. package/esm/index.js +1 -0
  21. package/esm/styleFunctionSx/styleFunctionSx.js +20 -18
  22. package/esm/sx/index.js +1 -0
  23. package/esm/sx/sx.js +12 -0
  24. package/index.d.ts +2 -0
  25. package/index.js +10 -1
  26. package/index.spec.d.ts +1 -1
  27. package/legacy/breakpoints.js +1 -1
  28. package/legacy/createBox.js +1 -1
  29. package/legacy/cssVars/createCssVarsProvider.js +60 -6
  30. package/legacy/cssVars/cssVarsParser.js +1 -1
  31. package/legacy/cssVars/getInitColorSchemeScript.js +2 -3
  32. package/legacy/index.js +2 -1
  33. package/legacy/styleFunctionSx/styleFunctionSx.js +19 -17
  34. package/legacy/sx/index.js +1 -0
  35. package/legacy/sx/sx.js +13 -0
  36. package/modern/breakpoints.js +1 -1
  37. package/modern/createBox.js +1 -1
  38. package/modern/cssVars/createCssVarsProvider.js +59 -8
  39. package/modern/cssVars/cssVarsParser.js +1 -1
  40. package/modern/cssVars/getInitColorSchemeScript.js +6 -6
  41. package/modern/index.js +2 -1
  42. package/modern/styleFunctionSx/styleFunctionSx.js +20 -18
  43. package/modern/sx/index.js +1 -0
  44. package/modern/sx/sx.js +12 -0
  45. package/package.json +6 -6
  46. package/styleFunctionSx/styleFunctionSx.js +20 -18
  47. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  48. package/sx/index.d.ts +1 -0
  49. package/sx/index.js +15 -0
  50. package/sx/package.json +6 -0
  51. package/sx/sx.d.ts +4 -0
  52. package/sx/sx.js +22 -0
@@ -52,7 +52,7 @@ export default function createBox() {
52
52
  /**
53
53
  * @ignore
54
54
  */
55
- sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
55
+ sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func])
56
56
  } : void 0;
57
57
  return Box;
58
58
  }
@@ -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 mergedTheme = deepmerge(restBaseTheme, restThemeProp);
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
- if (key === resolvedColorScheme) {
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
- * Your component tree.
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
- * css variable prefix
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
- // css property that are unitless
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
- _ref$defaultMode = _ref.defaultMode,
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(defaultMode, " === 'system')) {\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(defaultLightColorScheme, ";\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || ").concat(defaultDarkColorScheme, ";\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) {} })();")
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.0
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 (_typeof(value) === 'object') {
58
- if (propToStyleFunction[styleKey]) {
59
- css = merge(css, getThemeValue(styleKey, value, theme));
60
- } else {
61
- var breakpointsValues = handleBreakpoints({
62
- theme: theme
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
- } else {
73
- css = merge(css, breakpointsValues);
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';
@@ -0,0 +1,13 @@
1
+ import styleFunctionSx from '../styleFunctionSx';
2
+
3
+ function sx(styles) {
4
+ return function (_ref) {
5
+ var theme = _ref.theme;
6
+ return styleFunctionSx({
7
+ sx: styles,
8
+ theme: theme
9
+ });
10
+ };
11
+ }
12
+
13
+ export default sx;
@@ -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];
@@ -54,7 +54,7 @@ export default function createBox(options = {}) {
54
54
  /**
55
55
  * @ignore
56
56
  */
57
- sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
57
+ sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func])
58
58
  } : void 0;
59
59
  return Box;
60
60
  }
@@ -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
- let mergedTheme = deepmerge(restBaseTheme, restThemeProp);
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
- * Your component tree.
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
- * css variable prefix
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
- // css property that are unitless
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
- defaultMode = 'light',
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 && ${defaultMode} === 'system')) {
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') || ${defaultLightColorScheme};
25
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
26
26
  } else {
27
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultDarkColorScheme};
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.0
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 (typeof value === 'object') {
48
- if (propToStyleFunction[styleKey]) {
49
- css = merge(css, getThemeValue(styleKey, value, theme));
50
- } else {
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
- css = merge(css, breakpointsValues);
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';
@@ -0,0 +1,12 @@
1
+ import styleFunctionSx from '../styleFunctionSx';
2
+
3
+ function sx(styles) {
4
+ return ({
5
+ theme
6
+ }) => styleFunctionSx({
7
+ sx: styles,
8
+ theme
9
+ });
10
+ }
11
+
12
+ export default sx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.1.0",
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.0",
47
- "@mui/private-theming": "^5.1.0",
48
- "@mui/styled-engine": "^5.1.0",
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.1.0",
50
+ "@mui/utils": "^5.2.2",
51
51
  "clsx": "^1.1.1",
52
- "csstype": "^3.0.9",
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 (typeof value === 'object') {
63
- if (_getThemeValue.propToStyleFunction[styleKey]) {
64
- css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
65
- } else {
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
- css = (0, _merge.default)(css, breakpointsValues);
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"));
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/sx/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
package/sx/sx.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { CSSObject } from '@mui/styled-engine';
2
+ import { SxProps } from '../styleFunctionSx';
3
+
4
+ export default function sx<T extends object = {}>(styles: SxProps<T>): CSSObject;