@mui/system 5.2.0 → 5.2.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 (52) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +244 -1
  3. package/createBox.d.ts +3 -3
  4. package/createBox.spec.d.ts +1 -0
  5. package/createTheme/createBreakpoints.d.ts +6 -0
  6. package/createTheme/createBreakpoints.js +16 -0
  7. package/createTheme/createSpacing.d.ts +10 -10
  8. package/cssVars/createCssVarsProvider.d.ts +24 -10
  9. package/cssVars/createCssVarsProvider.js +81 -8
  10. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  11. package/cssVars/cssVarsParser.d.ts +68 -68
  12. package/cssVars/cssVarsParser.js +18 -17
  13. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  14. package/cssVars/getInitColorSchemeScript.js +1 -1
  15. package/cssVars/index.d.ts +2 -2
  16. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  17. package/esm/createTheme/createBreakpoints.js +16 -0
  18. package/esm/cssVars/createCssVarsProvider.js +77 -8
  19. package/esm/cssVars/cssVarsParser.js +18 -16
  20. package/esm/cssVars/getInitColorSchemeScript.js +1 -1
  21. package/esm/index.js +1 -0
  22. package/esm/sx/index.js +1 -0
  23. package/esm/sx/sx.js +12 -0
  24. package/esm/useThemeProps/getThemeProps.js +2 -17
  25. package/index.d.ts +2 -0
  26. package/index.js +10 -1
  27. package/index.spec.d.ts +1 -1
  28. package/legacy/createTheme/createBreakpoints.js +16 -0
  29. package/legacy/cssVars/createCssVarsProvider.js +80 -8
  30. package/legacy/cssVars/cssVarsParser.js +20 -14
  31. package/legacy/cssVars/getInitColorSchemeScript.js +1 -1
  32. package/legacy/index.js +2 -1
  33. package/legacy/sx/index.js +1 -0
  34. package/legacy/sx/sx.js +13 -0
  35. package/legacy/useThemeProps/getThemeProps.js +2 -17
  36. package/modern/createTheme/createBreakpoints.js +16 -0
  37. package/modern/cssVars/createCssVarsProvider.js +75 -8
  38. package/modern/cssVars/cssVarsParser.js +18 -16
  39. package/modern/cssVars/getInitColorSchemeScript.js +1 -1
  40. package/modern/index.js +2 -1
  41. package/modern/sx/index.js +1 -0
  42. package/modern/sx/sx.js +12 -0
  43. package/modern/useThemeProps/getThemeProps.js +2 -17
  44. package/package.json +5 -5
  45. package/styleFunctionSx/styleFunctionSx.d.ts +1 -1
  46. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  47. package/sx/index.d.ts +1 -0
  48. package/sx/index.js +15 -0
  49. package/sx/package.json +6 -0
  50. package/sx/sx.d.ts +4 -0
  51. package/sx/sx.js +22 -0
  52. package/useThemeProps/getThemeProps.js +2 -17
@@ -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 (value !== undefined && value !== null) {
52
- if (typeof value === 'object' && Object.keys(value).length > 0) {
53
- recurse(value, [...parentKeys, key]);
54
- } else {
55
- callback([...parentKeys, key], value, object);
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
  });
@@ -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
 
@@ -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(clonedTheme, (keys, val, scope) => {
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
- value = prefix ? value.replace(basePrefix, prefix) : value.replace(`${basePrefix}-`, ''); // scope is the deepest object in the tree, keys is the theme path keys
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.body.setAttribute('${attribute}', colorScheme);
37
+ document.documentElement.setAttribute('${attribute}', colorScheme);
38
38
  }
39
39
  } catch (e) {} })();`
40
40
  }
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.2.0
1
+ /** @license MUI v5.2.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.
@@ -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';
@@ -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;
@@ -1,6 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
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
- const output = _extends({}, props); // Resolve default props, code borrow from React source.
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.2.0",
3
+ "version": "5.2.4",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "CSS utilities for rapidly laying out custom designs.",
@@ -23,7 +23,7 @@
23
23
  "homepage": "https://mui.com/system/basics/",
24
24
  "funding": {
25
25
  "type": "opencollective",
26
- "url": "https://opencollective.com/material-ui"
26
+ "url": "https://opencollective.com/mui"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@emotion/react": "^11.5.0",
@@ -44,10 +44,10 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.16.3",
47
- "@mui/private-theming": "^5.2.0",
48
- "@mui/styled-engine": "^5.2.0",
47
+ "@mui/private-theming": "^5.2.3",
48
+ "@mui/styled-engine": "^5.2.4",
49
49
  "@mui/types": "^7.1.0",
50
- "@mui/utils": "^5.2.0",
50
+ "@mui/utils": "^5.2.3",
51
51
  "clsx": "^1.1.1",
52
52
  "csstype": "^3.0.10",
53
53
  "prop-types": "^15.7.2"
@@ -57,7 +57,7 @@ export type SystemStyleObject<Theme extends object = {}> =
57
57
  export type SxProps<Theme extends object = {}> =
58
58
  | SystemStyleObject<Theme>
59
59
  | ((theme: Theme) => SystemStyleObject<Theme>)
60
- | Array<SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
60
+ | Array<boolean | SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
61
61
 
62
62
  // eslint-disable-next-line @typescript-eslint/naming-convention
63
63
  export default function unstable_styleFunctionSx(props: object): object;
@@ -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;
package/sx/sx.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _styleFunctionSx = _interopRequireDefault(require("../styleFunctionSx"));
11
+
12
+ function sx(styles) {
13
+ return ({
14
+ theme
15
+ }) => (0, _styleFunctionSx.default)({
16
+ sx: styles,
17
+ theme
18
+ });
19
+ }
20
+
21
+ var _default = sx;
22
+ exports.default = _default;
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = getThemeProps;
9
7
 
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
+ var _utils = require("@mui/utils");
11
9
 
12
- /* eslint-disable no-restricted-syntax */
13
10
  function getThemeProps(params) {
14
11
  const {
15
12
  theme,
@@ -21,17 +18,5 @@ function getThemeProps(params) {
21
18
  return props;
22
19
  }
23
20
 
24
- const output = (0, _extends2.default)({}, props); // Resolve default props, code borrow from React source.
25
- // https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
26
-
27
- const defaultProps = theme.components[name].defaultProps;
28
- let propName;
29
-
30
- for (propName in defaultProps) {
31
- if (output[propName] === undefined) {
32
- output[propName] = defaultProps[propName];
33
- }
34
- }
35
-
36
- return output;
21
+ return (0, _utils.internal_resolveProps)(theme.components[name].defaultProps, props);
37
22
  }