@mui/system 5.4.1 → 5.4.4

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 (60) hide show
  1. package/Box/Box.d.ts +1 -1
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/CHANGELOG.md +177 -0
  4. package/createBox.d.ts +2 -0
  5. package/createBox.js +3 -2
  6. package/createBox.spec.d.ts +1 -1
  7. package/createStyled.d.ts +2 -1
  8. package/createStyled.js +12 -6
  9. package/createTheme/createBreakpoints.js +21 -6
  10. package/createTheme/createSpacing.d.ts +10 -10
  11. package/cssVars/createCssVarsProvider.d.ts +59 -95
  12. package/cssVars/createCssVarsProvider.js +32 -15
  13. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  14. package/cssVars/createGetCssVar.d.ts +5 -5
  15. package/cssVars/createGetCssVar.js +7 -1
  16. package/cssVars/cssVarsParser.d.ts +70 -68
  17. package/cssVars/cssVarsParser.js +21 -20
  18. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  19. package/cssVars/index.d.ts +1 -2
  20. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  21. package/esm/createBox.js +3 -2
  22. package/esm/createStyled.js +10 -4
  23. package/esm/createTheme/createBreakpoints.js +20 -4
  24. package/esm/cssVars/createCssVarsProvider.js +32 -16
  25. package/esm/cssVars/createGetCssVar.js +7 -1
  26. package/esm/cssVars/cssVarsParser.js +21 -20
  27. package/esm/getThemeValue.js +1 -1
  28. package/esm/index.js +1 -1
  29. package/esm/styleFunctionSx/index.js +1 -0
  30. package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
  31. package/getThemeValue.js +2 -1
  32. package/index.d.ts +1 -0
  33. package/index.js +8 -1
  34. package/index.spec.d.ts +1 -1
  35. package/legacy/createBox.js +4 -2
  36. package/legacy/createStyled.js +11 -4
  37. package/legacy/createTheme/createBreakpoints.js +23 -4
  38. package/legacy/cssVars/createCssVarsProvider.js +35 -18
  39. package/legacy/cssVars/createGetCssVar.js +7 -1
  40. package/legacy/cssVars/cssVarsParser.js +23 -22
  41. package/legacy/getThemeValue.js +1 -1
  42. package/legacy/index.js +2 -2
  43. package/legacy/styleFunctionSx/index.js +1 -0
  44. package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
  45. package/modern/createBox.js +3 -2
  46. package/modern/createStyled.js +10 -4
  47. package/modern/createTheme/createBreakpoints.js +20 -4
  48. package/modern/cssVars/createCssVarsProvider.js +32 -16
  49. package/modern/cssVars/createGetCssVar.js +7 -1
  50. package/modern/cssVars/cssVarsParser.js +21 -20
  51. package/modern/getThemeValue.js +1 -1
  52. package/modern/index.js +2 -2
  53. package/modern/styleFunctionSx/index.js +1 -0
  54. package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
  55. package/package.json +6 -6
  56. package/style.d.ts +1 -1
  57. package/styleFunctionSx/index.js +12 -2
  58. package/styleFunctionSx/styleFunctionSx.d.ts +25 -3
  59. package/styleFunctionSx/styleFunctionSx.js +79 -54
  60. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -26,12 +26,13 @@ export default function createCssVarsProvider(options) {
26
26
  desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
27
27
  designSystemColorScheme = options.defaultColorScheme,
28
28
  _options$disableTrans = options.disableTransitionOnChange,
29
- disableTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
29
+ designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
30
30
  _options$enableColorS = options.enableColorScheme,
31
- enableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
31
+ designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
32
32
  _options$prefix = options.prefix,
33
33
  designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
34
- shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
34
+ shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
35
+ resolveTheme = options.resolveTheme;
35
36
  var systemSpacing = createSpacing(baseTheme.spacing);
36
37
  var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
37
38
 
@@ -64,16 +65,15 @@ export default function createCssVarsProvider(options) {
64
65
  _ref$defaultMode = _ref.defaultMode,
65
66
  defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
66
67
  _ref$defaultColorSche = _ref.defaultColorScheme,
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
- }, []);
68
+ defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche,
69
+ _ref$disableTransitio = _ref.disableTransitionOnChange,
70
+ disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
71
+ _ref$enableColorSchem = _ref.enableColorScheme,
72
+ enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem;
73
73
 
74
- var _clonedBaseTheme$colo = clonedBaseTheme.colorSchemes,
75
- baseColorSchemes = _clonedBaseTheme$colo === void 0 ? {} : _clonedBaseTheme$colo,
76
- restBaseTheme = _objectWithoutProperties(clonedBaseTheme, ["colorSchemes"]);
74
+ var _baseTheme$colorSchem = baseTheme.colorSchemes,
75
+ baseColorSchemes = _baseTheme$colorSchem === void 0 ? {} : _baseTheme$colorSchem,
76
+ restBaseTheme = _objectWithoutProperties(baseTheme, ["colorSchemes"]);
77
77
 
78
78
  var _themeProp$colorSchem = themeProp.colorSchemes,
79
79
  colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
@@ -126,11 +126,13 @@ export default function createCssVarsProvider(options) {
126
126
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
127
127
  }),
128
128
  rootCss = _cssVarsParser.css,
129
- rootVars = _cssVarsParser.vars;
129
+ rootVars = _cssVarsParser.vars,
130
+ parsedTheme = _cssVarsParser.parsedTheme;
130
131
 
131
- mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
132
+ mergedTheme = _extends({}, parsedTheme, {
132
133
  components: components,
133
134
  colorSchemes: colorSchemes,
135
+ prefix: prefix,
134
136
  vars: rootVars,
135
137
  spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
136
138
  breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
@@ -148,10 +150,15 @@ export default function createCssVarsProvider(options) {
148
150
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
149
151
  }),
150
152
  css = _cssVarsParser2.css,
151
- vars = _cssVarsParser2.vars;
153
+ vars = _cssVarsParser2.vars,
154
+ parsedScheme = _cssVarsParser2.parsedTheme;
152
155
 
153
156
  mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
154
157
 
158
+ if (key === resolvedColorScheme) {
159
+ mergedTheme = _extends({}, mergedTheme, parsedScheme);
160
+ }
161
+
155
162
  var resolvedDefaultColorScheme = function () {
156
163
  if (typeof defaultColorScheme === 'string') {
157
164
  return defaultColorScheme;
@@ -192,7 +199,7 @@ export default function createCssVarsProvider(options) {
192
199
  return function () {
193
200
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
194
201
  };
195
- }, [mode, systemMode]);
202
+ }, [mode, systemMode, enableColorScheme]);
196
203
  React.useEffect(function () {
197
204
  var timer;
198
205
 
@@ -214,7 +221,7 @@ export default function createCssVarsProvider(options) {
214
221
  return function () {
215
222
  clearTimeout(timer);
216
223
  };
217
- }, [colorScheme]);
224
+ }, [colorScheme, disableTransitionOnChange]);
218
225
  React.useEffect(function () {
219
226
  hasMounted.current = true;
220
227
  return function () {
@@ -238,7 +245,7 @@ export default function createCssVarsProvider(options) {
238
245
  }), /*#__PURE__*/_jsx(GlobalStyles, {
239
246
  styles: styleSheet
240
247
  }), /*#__PURE__*/_jsx(ThemeProvider, {
241
- theme: mergedTheme,
248
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
242
249
  children: children
243
250
  })]
244
251
  });
@@ -265,6 +272,16 @@ export default function createCssVarsProvider(options) {
265
272
  */
266
273
  defaultMode: PropTypes.string,
267
274
 
275
+ /**
276
+ * Disable CSS transitions when switching between modes or color schemes
277
+ */
278
+ disableTransitionOnChange: PropTypes.bool,
279
+
280
+ /**
281
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
282
+ */
283
+ enableColorScheme: PropTypes.bool,
284
+
268
285
  /**
269
286
  * The key in the local storage used to store current color scheme.
270
287
  */
@@ -16,7 +16,13 @@ export default function createGetCssVar() {
16
16
  return '';
17
17
  }
18
18
 
19
- return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(vars[0]).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
19
+ var value = vars[0];
20
+
21
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
22
+ return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(value).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
23
+ }
24
+
25
+ return ", ".concat(value);
20
26
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
21
27
 
22
28
 
@@ -98,19 +98,20 @@ var getCssValue = function getCssValue(keys, value) {
98
98
  * `basePrefix`: defined by design system.
99
99
  * `prefix`: defined by application
100
100
  *
101
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
101
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
102
102
  *
103
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
103
+ * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
104
104
  *
105
105
  * @example
106
- * const { css, vars } = parser({
106
+ * const { css, vars, parsedTheme } = parser({
107
107
  * fontSize: 12,
108
108
  * lineHeight: 1.2,
109
- * palette: { primary: { 500: '#000000' } }
110
- * })
109
+ * palette: { primary: { 500: 'var(--color)' } }
110
+ * }, { prefix: 'foo' })
111
111
  *
112
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
113
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
112
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
113
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
114
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
114
115
  */
115
116
 
116
117
 
@@ -123,37 +124,37 @@ export default function cssVarsParser(theme, options) {
123
124
 
124
125
  var css = {};
125
126
  var vars = {};
126
- walkObjectDeep(theme, function (keys, val, scope) {
127
- if (typeof val === 'string' || typeof val === 'number') {
128
- var _value = val;
129
-
130
- if (typeof _value === 'string' && _value.startsWith('var')) {
131
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
127
+ var parsedTheme = {};
128
+ walkObjectDeep(theme, function (keys, value) {
129
+ if (typeof value === 'string' || typeof value === 'number') {
130
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
131
+ // for CSS variable, apply prefix or remove basePrefix from the variable
132
132
  if (!basePrefix && prefix) {
133
- _value = _value.replace(/var\(--/g, "var(--".concat(prefix, "-"));
133
+ value = value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
134
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
-
138
-
139
- scope[keys.slice(-1)[0]] = _value;
135
+ value = prefix ? value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
136
+ : value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
137
+ }
140
138
  }
141
139
 
142
- if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, _value)) {
140
+ if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
143
141
  // only create css & var if `shouldSkipGeneratingVar` return false
144
142
  var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
145
143
 
146
- _extends(css, _defineProperty({}, cssVar, getCssValue(keys, _value)));
144
+ _extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
147
145
 
148
146
  assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
149
147
  }
150
148
  }
149
+
150
+ assignNestedKeys(parsedTheme, keys, value);
151
151
  }, function (keys) {
152
152
  return keys[0] === 'vars';
153
153
  } // skip 'vars/*' paths
154
154
  );
155
155
  return {
156
156
  css: css,
157
- vars: vars
157
+ vars: vars,
158
+ parsedTheme: parsedTheme
158
159
  };
159
160
  }
@@ -21,7 +21,7 @@ var filterPropsMapping = {
21
21
  spacing: spacing.filterProps,
22
22
  typography: typography.filterProps
23
23
  };
24
- var styleFunctionMapping = {
24
+ export var styleFunctionMapping = {
25
25
  borders: borders,
26
26
  display: display,
27
27
  flexbox: flexbox,
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.1
1
+ /** @license MUI v5.4.4
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.
@@ -26,7 +26,7 @@ export * from './spacing';
26
26
  export { default as style, getPath } from './style';
27
27
  export { default as typography } from './typography';
28
28
  export * from './typography';
29
- export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
29
+ export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
30
30
  export { default as experimental_sx } from './sx';
31
31
  export { default as unstable_getThemeValue } from './getThemeValue';
32
32
  export { default as Box } from './Box';
@@ -1,2 +1,3 @@
1
1
  export { default } from './styleFunctionSx';
2
+ export { unstable_createStyleFunctionSx } from './styleFunctionSx';
2
3
  export { default as extendSxProp } from './extendSxProp';
@@ -1,7 +1,7 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
1
  import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
3
  import merge from '../merge';
4
- import getThemeValue, { propToStyleFunction } from '../getThemeValue';
4
+ import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
5
5
  import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
6
6
 
7
7
  function objectsHaveSameKeys() {
@@ -20,70 +20,95 @@ function objectsHaveSameKeys() {
20
20
 
21
21
  function callIfFn(maybeFn, arg) {
22
22
  return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
23
- }
23
+ } // eslint-disable-next-line @typescript-eslint/naming-convention
24
24
 
25
- function styleFunctionSx(props) {
26
- var _ref = props || {},
27
- sx = _ref.sx,
28
- _ref$theme = _ref.theme,
29
- theme = _ref$theme === void 0 ? {} : _ref$theme;
30
25
 
31
- if (!sx) {
32
- return null; // emotion & styled-components will neglect null
33
- }
34
- /*
35
- * Receive `sxInput` as object or callback
36
- * and then recursively check keys & values to create media query object styles.
37
- * (the result will be used in `styled`)
38
- */
26
+ export function unstable_createStyleFunctionSx() {
27
+ var styleFunctionMapping = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultStyleFunctionMapping;
28
+ var propToStyleFunction = Object.keys(styleFunctionMapping).reduce(function (acc, styleFnName) {
29
+ styleFunctionMapping[styleFnName].filterProps.forEach(function (propName) {
30
+ acc[propName] = styleFunctionMapping[styleFnName];
31
+ });
32
+ return acc;
33
+ }, {});
34
+
35
+ function getThemeValue(prop, value, theme) {
36
+ var _inputProps;
39
37
 
38
+ var inputProps = (_inputProps = {}, _defineProperty(_inputProps, prop, value), _defineProperty(_inputProps, "theme", theme), _inputProps);
39
+ var styleFunction = propToStyleFunction[prop];
40
+ return styleFunction ? styleFunction(inputProps) : _defineProperty({}, prop, value);
41
+ }
40
42
 
41
- function traverse(sxInput) {
42
- var sxObject = sxInput;
43
+ function styleFunctionSx(props) {
44
+ var _ref2 = props || {},
45
+ sx = _ref2.sx,
46
+ _ref2$theme = _ref2.theme,
47
+ theme = _ref2$theme === void 0 ? {} : _ref2$theme;
43
48
 
44
- if (typeof sxInput === 'function') {
45
- sxObject = sxInput(theme);
46
- } else if (_typeof(sxInput) !== 'object') {
47
- // value
48
- return sxInput;
49
+ if (!sx) {
50
+ return null; // emotion & styled-components will neglect null
49
51
  }
52
+ /*
53
+ * Receive `sxInput` as object or callback
54
+ * and then recursively check keys & values to create media query object styles.
55
+ * (the result will be used in `styled`)
56
+ */
50
57
 
51
- var emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
52
- var breakpointsKeys = Object.keys(emptyBreakpoints);
53
- var css = emptyBreakpoints;
54
- Object.keys(sxObject).forEach(function (styleKey) {
55
- var value = callIfFn(sxObject[styleKey], theme);
56
58
 
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({
63
- theme: theme
64
- }, value, function (x) {
65
- return _defineProperty({}, styleKey, x);
66
- });
67
-
68
- if (objectsHaveSameKeys(breakpointsValues, value)) {
69
- css[styleKey] = styleFunctionSx({
70
- sx: value,
59
+ function traverse(sxInput) {
60
+ var sxObject = sxInput;
61
+
62
+ if (typeof sxInput === 'function') {
63
+ sxObject = sxInput(theme);
64
+ } else if (_typeof(sxInput) !== 'object') {
65
+ // value
66
+ return sxInput;
67
+ }
68
+
69
+ if (!sxObject) {
70
+ return null;
71
+ }
72
+
73
+ var emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
74
+ var breakpointsKeys = Object.keys(emptyBreakpoints);
75
+ var css = emptyBreakpoints;
76
+ Object.keys(sxObject).forEach(function (styleKey) {
77
+ var value = callIfFn(sxObject[styleKey], theme);
78
+
79
+ if (value !== null && value !== undefined) {
80
+ if (_typeof(value) === 'object') {
81
+ if (propToStyleFunction[styleKey]) {
82
+ css = merge(css, getThemeValue(styleKey, value, theme));
83
+ } else {
84
+ var breakpointsValues = handleBreakpoints({
71
85
  theme: theme
86
+ }, value, function (x) {
87
+ return _defineProperty({}, styleKey, x);
72
88
  });
73
- } else {
74
- css = merge(css, breakpointsValues);
89
+
90
+ if (objectsHaveSameKeys(breakpointsValues, value)) {
91
+ css[styleKey] = styleFunctionSx({
92
+ sx: value,
93
+ theme: theme
94
+ });
95
+ } else {
96
+ css = merge(css, breakpointsValues);
97
+ }
75
98
  }
99
+ } else {
100
+ css = merge(css, getThemeValue(styleKey, value, theme));
76
101
  }
77
- } else {
78
- css = merge(css, getThemeValue(styleKey, value, theme));
79
102
  }
80
- }
81
- });
82
- return removeUnusedBreakpoints(breakpointsKeys, css);
103
+ });
104
+ return removeUnusedBreakpoints(breakpointsKeys, css);
105
+ }
106
+
107
+ return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
83
108
  }
84
109
 
85
- return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
110
+ return styleFunctionSx;
86
111
  }
87
-
112
+ var styleFunctionSx = unstable_createStyleFunctionSx();
88
113
  styleFunctionSx.filterProps = ['sx'];
89
114
  export default styleFunctionSx;
@@ -5,14 +5,15 @@ import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
7
7
  import styled from '@mui/styled-engine';
8
- import styleFunctionSx, { extendSxProp } from './styleFunctionSx';
8
+ import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
9
9
  import useTheme from './useTheme';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  export default function createBox(options = {}) {
12
12
  const {
13
13
  defaultTheme,
14
14
  defaultClassName = 'MuiBox-root',
15
- generateClassName
15
+ generateClassName,
16
+ styleFunctionSx = defaultStyleFunctionSx
16
17
  } = options;
17
18
  const BoxRoot = styled('div')(styleFunctionSx);
18
19
  const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
@@ -6,8 +6,8 @@ const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesR
6
6
  import styledEngineStyled from '@mui/styled-engine';
7
7
  import { getDisplayName } from '@mui/utils';
8
8
  import createTheme from './createTheme';
9
- import styleFunctionSx from './styleFunctionSx';
10
9
  import propsToClassKey from './propsToClassKey';
10
+ import defaultStyleFunctionSx from './styleFunctionSx';
11
11
 
12
12
  function isEmpty(obj) {
13
13
  return Object.keys(obj).length === 0;
@@ -59,7 +59,8 @@ const variantsResolver = (props, styles, theme, name) => {
59
59
  }
60
60
 
61
61
  return variantsStyles;
62
- };
62
+ }; // Update /system/styled/#api in case if this changes
63
+
63
64
 
64
65
  export function shouldForwardProp(prop) {
65
66
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
@@ -74,7 +75,8 @@ export default function createStyled(input = {}) {
74
75
  const {
75
76
  defaultTheme = systemDefaultTheme,
76
77
  rootShouldForwardProp = shouldForwardProp,
77
- slotShouldForwardProp = shouldForwardProp
78
+ slotShouldForwardProp = shouldForwardProp,
79
+ styleFunctionSx = defaultStyleFunctionSx
78
80
  } = input;
79
81
  return (tag, inputOptions = {}) => {
80
82
  const {
@@ -170,7 +172,11 @@ export default function createStyled(input = {}) {
170
172
 
171
173
  transformedStyleArg = [...styleArg, ...placeholders];
172
174
  transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
173
- } else if (typeof styleArg === 'function') {
175
+ } else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
176
+ // component stays as a function. This condition makes sure that we do not interpolate functions
177
+ // which are basically components used as a selectors.
178
+ // eslint-disable-next-line no-underscore-dangle
179
+ styleArg.__emotion_real !== styleArg) {
174
180
  // If the type is function, we need to define the default theme.
175
181
  transformedStyleArg = _ref2 => {
176
182
  let {
@@ -1,9 +1,24 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["values", "unit", "step"];
4
4
  // Sorted ASC by size. That's important.
5
5
  // It can't be configured as it's used statically for propTypes.
6
- export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
6
+ export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
7
+
8
+ const sortBreakpointsValues = values => {
9
+ const breakpointsAsArray = Object.keys(values).map(key => ({
10
+ key,
11
+ val: values[key]
12
+ })) || []; // Sort in ascending order
13
+
14
+ breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
15
+ return breakpointsAsArray.reduce((acc, obj) => {
16
+ return _extends({}, acc, {
17
+ [obj.key]: obj.val
18
+ });
19
+ }, {});
20
+ }; // Keep in mind that @media is inclusive by the CSS specification.
21
+
7
22
 
8
23
  export default function createBreakpoints(breakpoints) {
9
24
  const {
@@ -26,7 +41,8 @@ export default function createBreakpoints(breakpoints) {
26
41
  } = breakpoints,
27
42
  other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
28
43
 
29
- const keys = Object.keys(values);
44
+ const sortedValues = sortBreakpointsValues(values);
45
+ const keys = Object.keys(sortedValues);
30
46
 
31
47
  function up(key) {
32
48
  const value = typeof values[key] === 'number' ? values[key] : key;
@@ -68,7 +84,7 @@ export default function createBreakpoints(breakpoints) {
68
84
 
69
85
  return _extends({
70
86
  keys,
71
- values,
87
+ values: sortedValues,
72
88
  up,
73
89
  down,
74
90
  between,
@@ -23,10 +23,11 @@ export default function createCssVarsProvider(options) {
23
23
  theme: baseTheme = {},
24
24
  defaultMode: desisgnSystemMode = 'light',
25
25
  defaultColorScheme: designSystemColorScheme,
26
- disableTransitionOnChange = false,
27
- enableColorScheme = true,
26
+ disableTransitionOnChange: designSystemTransitionOnChange = false,
27
+ enableColorScheme: designSystemEnableColorScheme = true,
28
28
  prefix: designSystemPrefix = '',
29
- shouldSkipGeneratingVar
29
+ shouldSkipGeneratingVar,
30
+ resolveTheme
30
31
  } = options;
31
32
  const systemSpacing = createSpacing(baseTheme.spacing);
32
33
  const systemBreakpoints = createBreakpoints(baseTheme.breakpoints ?? {});
@@ -54,16 +55,14 @@ export default function createCssVarsProvider(options) {
54
55
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
55
56
  attribute = DEFAULT_ATTRIBUTE,
56
57
  defaultMode = desisgnSystemMode,
57
- defaultColorScheme = designSystemColorScheme
58
+ defaultColorScheme = designSystemColorScheme,
59
+ disableTransitionOnChange = designSystemTransitionOnChange,
60
+ enableColorScheme = designSystemEnableColorScheme
58
61
  }) {
59
- // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
60
- // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
61
- const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
62
-
63
62
  const {
64
63
  colorSchemes: baseColorSchemes = {}
65
- } = clonedBaseTheme,
66
- restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
64
+ } = baseTheme,
65
+ restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
67
66
 
68
67
  const {
69
68
  colorSchemes: colorSchemesProp = {}
@@ -114,15 +113,17 @@ export default function createCssVarsProvider(options) {
114
113
 
115
114
  const {
116
115
  css: rootCss,
117
- vars: rootVars
116
+ vars: rootVars,
117
+ parsedTheme
118
118
  } = cssVarsParser(mergedTheme, {
119
119
  prefix,
120
120
  basePrefix: designSystemPrefix,
121
121
  shouldSkipGeneratingVar
122
122
  });
123
- mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
123
+ mergedTheme = _extends({}, parsedTheme, {
124
124
  components,
125
125
  colorSchemes,
126
+ prefix,
126
127
  vars: rootVars,
127
128
  spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
128
129
  breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
@@ -132,7 +133,8 @@ export default function createCssVarsProvider(options) {
132
133
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
133
134
  const {
134
135
  css,
135
- vars
136
+ vars,
137
+ parsedTheme: parsedScheme
136
138
  } = cssVarsParser(scheme, {
137
139
  prefix,
138
140
  basePrefix: designSystemPrefix,
@@ -140,6 +142,10 @@ export default function createCssVarsProvider(options) {
140
142
  });
141
143
  mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
142
144
 
145
+ if (key === resolvedColorScheme) {
146
+ mergedTheme = _extends({}, mergedTheme, parsedScheme);
147
+ }
148
+
143
149
  const resolvedDefaultColorScheme = (() => {
144
150
  if (typeof defaultColorScheme === 'string') {
145
151
  return defaultColorScheme;
@@ -180,7 +186,7 @@ export default function createCssVarsProvider(options) {
180
186
  return () => {
181
187
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
182
188
  };
183
- }, [mode, systemMode]);
189
+ }, [mode, systemMode, enableColorScheme]);
184
190
  React.useEffect(() => {
185
191
  let timer;
186
192
 
@@ -200,7 +206,7 @@ export default function createCssVarsProvider(options) {
200
206
  return () => {
201
207
  clearTimeout(timer);
202
208
  };
203
- }, [colorScheme]);
209
+ }, [colorScheme, disableTransitionOnChange]);
204
210
  React.useEffect(() => {
205
211
  hasMounted.current = true;
206
212
  return () => {
@@ -224,7 +230,7 @@ export default function createCssVarsProvider(options) {
224
230
  }), /*#__PURE__*/_jsx(GlobalStyles, {
225
231
  styles: styleSheet
226
232
  }), /*#__PURE__*/_jsx(ThemeProvider, {
227
- theme: mergedTheme,
233
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
228
234
  children: children
229
235
  })]
230
236
  });
@@ -251,6 +257,16 @@ export default function createCssVarsProvider(options) {
251
257
  */
252
258
  defaultMode: PropTypes.string,
253
259
 
260
+ /**
261
+ * Disable CSS transitions when switching between modes or color schemes
262
+ */
263
+ disableTransitionOnChange: PropTypes.bool,
264
+
265
+ /**
266
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
267
+ */
268
+ enableColorScheme: PropTypes.bool,
269
+
254
270
  /**
255
271
  * The key in the local storage used to store current color scheme.
256
272
  */
@@ -8,7 +8,13 @@ export default function createGetCssVar(prefix = '') {
8
8
  return '';
9
9
  }
10
10
 
11
- return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
11
+ const value = vars[0];
12
+
13
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
14
+ return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
15
+ }
16
+
17
+ return `, ${value}`;
12
18
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
13
19
 
14
20