@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
@@ -85,19 +85,20 @@ const getCssValue = (keys, value) => {
85
85
  * `basePrefix`: defined by design system.
86
86
  * `prefix`: defined by application
87
87
  *
88
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
88
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
89
89
  *
90
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
90
+ * @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.
91
91
  *
92
92
  * @example
93
- * const { css, vars } = parser({
93
+ * const { css, vars, parsedTheme } = parser({
94
94
  * fontSize: 12,
95
95
  * lineHeight: 1.2,
96
- * palette: { primary: { 500: '#000000' } }
97
- * })
96
+ * palette: { primary: { 500: 'var(--color)' } }
97
+ * }, { prefix: 'foo' })
98
98
  *
99
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
100
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
99
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
100
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
101
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
101
102
  */
102
103
 
103
104
 
@@ -109,20 +110,17 @@ export default function cssVarsParser(theme, options) {
109
110
  } = options || {};
110
111
  const css = {};
111
112
  const vars = {};
112
- walkObjectDeep(theme, (keys, val, scope) => {
113
- if (typeof val === 'string' || typeof val === 'number') {
114
- let value = val;
115
-
116
- if (typeof value === 'string' && value.startsWith('var')) {
117
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
113
+ const parsedTheme = {};
114
+ walkObjectDeep(theme, (keys, value) => {
115
+ if (typeof value === 'string' || typeof value === 'number') {
116
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
117
+ // for CSS variable, apply prefix or remove basePrefix from the variable
118
118
  if (!basePrefix && prefix) {
119
- value = value.replace(/var\(--/g, `var(--${prefix}-`);
119
+ value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
120
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
-
124
-
125
- scope[keys.slice(-1)[0]] = value;
121
+ value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
122
+ : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
123
+ }
126
124
  }
127
125
 
128
126
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -134,10 +132,13 @@ export default function cssVarsParser(theme, options) {
134
132
  assignNestedKeys(vars, keys, `var(${cssVar})`);
135
133
  }
136
134
  }
135
+
136
+ assignNestedKeys(parsedTheme, keys, value);
137
137
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
138
138
  );
139
139
  return {
140
140
  css,
141
- vars
141
+ vars,
142
+ parsedTheme
142
143
  };
143
144
  }
@@ -20,7 +20,7 @@ const filterPropsMapping = {
20
20
  spacing: spacing.filterProps,
21
21
  typography: typography.filterProps
22
22
  };
23
- const styleFunctionMapping = {
23
+ export const styleFunctionMapping = {
24
24
  borders,
25
25
  display,
26
26
  flexbox,
package/modern/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,5 +1,5 @@
1
1
  import merge from '../merge';
2
- import getThemeValue, { propToStyleFunction } from '../getThemeValue';
2
+ import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
3
3
  import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
4
4
 
5
5
  function objectsHaveSameKeys(...objects) {
@@ -10,70 +10,97 @@ function objectsHaveSameKeys(...objects) {
10
10
 
11
11
  function callIfFn(maybeFn, arg) {
12
12
  return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
13
- }
13
+ } // eslint-disable-next-line @typescript-eslint/naming-convention
14
14
 
15
- function styleFunctionSx(props) {
16
- const {
17
- sx,
18
- theme = {}
19
- } = props || {};
20
15
 
21
- if (!sx) {
22
- return null; // emotion & styled-components will neglect null
23
- }
24
- /*
25
- * Receive `sxInput` as object or callback
26
- * and then recursively check keys & values to create media query object styles.
27
- * (the result will be used in `styled`)
28
- */
16
+ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultStyleFunctionMapping) {
17
+ const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
18
+ styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
19
+ acc[propName] = styleFunctionMapping[styleFnName];
20
+ });
21
+ return acc;
22
+ }, {});
29
23
 
24
+ function getThemeValue(prop, value, theme) {
25
+ const inputProps = {
26
+ [prop]: value,
27
+ theme
28
+ };
29
+ const styleFunction = propToStyleFunction[prop];
30
+ return styleFunction ? styleFunction(inputProps) : {
31
+ [prop]: value
32
+ };
33
+ }
30
34
 
31
- function traverse(sxInput) {
32
- let sxObject = sxInput;
35
+ function styleFunctionSx(props) {
36
+ const {
37
+ sx,
38
+ theme = {}
39
+ } = props || {};
33
40
 
34
- if (typeof sxInput === 'function') {
35
- sxObject = sxInput(theme);
36
- } else if (typeof sxInput !== 'object') {
37
- // value
38
- return sxInput;
41
+ if (!sx) {
42
+ return null; // emotion & styled-components will neglect null
39
43
  }
44
+ /*
45
+ * Receive `sxInput` as object or callback
46
+ * and then recursively check keys & values to create media query object styles.
47
+ * (the result will be used in `styled`)
48
+ */
40
49
 
41
- const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
42
- const breakpointsKeys = Object.keys(emptyBreakpoints);
43
- let css = emptyBreakpoints;
44
- Object.keys(sxObject).forEach(styleKey => {
45
- const value = callIfFn(sxObject[styleKey], theme);
46
50
 
47
- if (value !== null && value !== undefined) {
48
- if (typeof value === 'object') {
49
- if (propToStyleFunction[styleKey]) {
50
- css = merge(css, getThemeValue(styleKey, value, theme));
51
- } else {
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
- });
51
+ function traverse(sxInput) {
52
+ let sxObject = sxInput;
53
+
54
+ if (typeof sxInput === 'function') {
55
+ sxObject = sxInput(theme);
56
+ } else if (typeof sxInput !== 'object') {
57
+ // value
58
+ return sxInput;
59
+ }
60
+
61
+ if (!sxObject) {
62
+ return null;
63
+ }
64
+
65
+ const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
66
+ const breakpointsKeys = Object.keys(emptyBreakpoints);
67
+ let css = emptyBreakpoints;
68
+ Object.keys(sxObject).forEach(styleKey => {
69
+ const value = callIfFn(sxObject[styleKey], theme);
70
+
71
+ if (value !== null && value !== undefined) {
72
+ if (typeof value === 'object') {
73
+ if (propToStyleFunction[styleKey]) {
74
+ css = merge(css, getThemeValue(styleKey, value, theme));
63
75
  } else {
64
- css = merge(css, breakpointsValues);
76
+ const breakpointsValues = handleBreakpoints({
77
+ theme
78
+ }, value, x => ({
79
+ [styleKey]: x
80
+ }));
81
+
82
+ if (objectsHaveSameKeys(breakpointsValues, value)) {
83
+ css[styleKey] = styleFunctionSx({
84
+ sx: value,
85
+ theme
86
+ });
87
+ } else {
88
+ css = merge(css, breakpointsValues);
89
+ }
65
90
  }
91
+ } else {
92
+ css = merge(css, getThemeValue(styleKey, value, theme));
66
93
  }
67
- } else {
68
- css = merge(css, getThemeValue(styleKey, value, theme));
69
94
  }
70
- }
71
- });
72
- return removeUnusedBreakpoints(breakpointsKeys, css);
95
+ });
96
+ return removeUnusedBreakpoints(breakpointsKeys, css);
97
+ }
98
+
99
+ return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
73
100
  }
74
101
 
75
- return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
102
+ return styleFunctionSx;
76
103
  }
77
-
104
+ const styleFunctionSx = unstable_createStyleFunctionSx();
78
105
  styleFunctionSx.filterProps = ['sx'];
79
106
  export default styleFunctionSx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.4.1",
3
+ "version": "5.4.4",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "CSS utilities for rapidly laying out custom designs.",
@@ -43,11 +43,11 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@babel/runtime": "^7.17.0",
47
- "@mui/private-theming": "^5.4.1",
48
- "@mui/styled-engine": "^5.4.1",
49
- "@mui/types": "^7.1.1",
50
- "@mui/utils": "^5.4.1",
46
+ "@babel/runtime": "^7.17.2",
47
+ "@mui/private-theming": "^5.4.4",
48
+ "@mui/styled-engine": "^5.4.4",
49
+ "@mui/types": "^7.1.2",
50
+ "@mui/utils": "^5.4.4",
51
51
  "clsx": "^1.1.1",
52
52
  "csstype": "^3.0.10",
53
53
  "prop-types": "^15.7.2"
package/style.d.ts CHANGED
@@ -12,4 +12,4 @@ export interface StyleOptions<PropKey> {
12
12
  }
13
13
  export function style<PropKey extends string, Theme extends object>(
14
14
  options: StyleOptions<PropKey>,
15
- ): StyleFunction<{ [K in PropKey]?: unknown } & { theme?: Theme }>;
15
+ ): StyleFunction<{ [K in PropKey]?: unknown } & { theme?: Theme }> & { filterProps: string[] };
@@ -17,7 +17,17 @@ Object.defineProperty(exports, "extendSxProp", {
17
17
  return _extendSxProp.default;
18
18
  }
19
19
  });
20
+ Object.defineProperty(exports, "unstable_createStyleFunctionSx", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _styleFunctionSx.unstable_createStyleFunctionSx;
24
+ }
25
+ });
26
+
27
+ var _styleFunctionSx = _interopRequireWildcard(require("./styleFunctionSx"));
28
+
29
+ var _extendSxProp = _interopRequireDefault(require("./extendSxProp"));
20
30
 
21
- var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
31
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
32
 
23
- var _extendSxProp = _interopRequireDefault(require("./extendSxProp"));
33
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -24,6 +24,18 @@ export interface CSSSelectorObject<Theme extends object = {}> {
24
24
  [cssSelector: string]: ((theme: Theme) => SystemStyleObject<Theme>) | SystemStyleObject<Theme>;
25
25
  }
26
26
 
27
+ type CssVariableType = string | number;
28
+
29
+ /**
30
+ * Map all nested selectors and CSS variables.
31
+ */
32
+ export interface CSSSelectorObjectOrCssVariables<Theme extends object = {}> {
33
+ [cssSelectorOrVariable: string]:
34
+ | ((theme: Theme) => SystemStyleObject<Theme> | string | number)
35
+ | SystemStyleObject<Theme>
36
+ | CssVariableType;
37
+ }
38
+
27
39
  /**
28
40
  * Map of all available CSS properties (including aliases) and their raw value.
29
41
  * Only used internally to map CSS properties to input types (responsive value,
@@ -48,8 +60,7 @@ export type SystemCssProperties<Theme extends object = {}> = {
48
60
  export type SystemStyleObject<Theme extends object = {}> =
49
61
  | SystemCssProperties<Theme>
50
62
  | CSSPseudoSelectorProps<Theme>
51
- | CSSSelectorObject<Theme>
52
- | { [cssVariable: string]: string | number }
63
+ | CSSSelectorObjectOrCssVariables<Theme>
53
64
  | null;
54
65
 
55
66
  /**
@@ -60,5 +71,16 @@ export type SxProps<Theme extends object = {}> =
60
71
  | ((theme: Theme) => SystemStyleObject<Theme>)
61
72
  | Array<boolean | SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
62
73
 
74
+ export interface StyleFunctionSx {
75
+ (props: object): object;
76
+ filterProps?: string[];
77
+ }
78
+
63
79
  // eslint-disable-next-line @typescript-eslint/naming-convention
64
- export default function unstable_styleFunctionSx(props: object): object;
80
+ export function unstable_createStyleFunctionSx(
81
+ styleFunctionMapping: Record<string, StyleFunctionSx>,
82
+ ): StyleFunctionSx;
83
+
84
+ declare const styleFunctionSx: StyleFunctionSx;
85
+
86
+ export default styleFunctionSx;
@@ -6,17 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
+ exports.unstable_createStyleFunctionSx = unstable_createStyleFunctionSx;
9
10
 
10
11
  var _merge = _interopRequireDefault(require("../merge"));
11
12
 
12
- var _getThemeValue = _interopRequireWildcard(require("../getThemeValue"));
13
+ var _getThemeValue = require("../getThemeValue");
13
14
 
14
15
  var _breakpoints = require("../breakpoints");
15
16
 
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
17
  function objectsHaveSameKeys(...objects) {
21
18
  const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
22
19
  const union = new Set(allKeys);
@@ -25,71 +22,99 @@ function objectsHaveSameKeys(...objects) {
25
22
 
26
23
  function callIfFn(maybeFn, arg) {
27
24
  return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
28
- }
25
+ } // eslint-disable-next-line @typescript-eslint/naming-convention
29
26
 
30
- function styleFunctionSx(props) {
31
- const {
32
- sx,
33
- theme = {}
34
- } = props || {};
35
27
 
36
- if (!sx) {
37
- return null; // emotion & styled-components will neglect null
28
+ function unstable_createStyleFunctionSx(styleFunctionMapping = _getThemeValue.styleFunctionMapping) {
29
+ const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
30
+ styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
31
+ acc[propName] = styleFunctionMapping[styleFnName];
32
+ });
33
+ return acc;
34
+ }, {});
35
+
36
+ function getThemeValue(prop, value, theme) {
37
+ const inputProps = {
38
+ [prop]: value,
39
+ theme
40
+ };
41
+ const styleFunction = propToStyleFunction[prop];
42
+ return styleFunction ? styleFunction(inputProps) : {
43
+ [prop]: value
44
+ };
38
45
  }
39
- /*
40
- * Receive `sxInput` as object or callback
41
- * and then recursively check keys & values to create media query object styles.
42
- * (the result will be used in `styled`)
43
- */
44
-
45
46
 
46
- function traverse(sxInput) {
47
- let sxObject = sxInput;
47
+ function styleFunctionSx(props) {
48
+ const {
49
+ sx,
50
+ theme = {}
51
+ } = props || {};
48
52
 
49
- if (typeof sxInput === 'function') {
50
- sxObject = sxInput(theme);
51
- } else if (typeof sxInput !== 'object') {
52
- // value
53
- return sxInput;
53
+ if (!sx) {
54
+ return null; // emotion & styled-components will neglect null
54
55
  }
56
+ /*
57
+ * Receive `sxInput` as object or callback
58
+ * and then recursively check keys & values to create media query object styles.
59
+ * (the result will be used in `styled`)
60
+ */
55
61
 
56
- const emptyBreakpoints = (0, _breakpoints.createEmptyBreakpointObject)(theme.breakpoints);
57
- const breakpointsKeys = Object.keys(emptyBreakpoints);
58
- let css = emptyBreakpoints;
59
- Object.keys(sxObject).forEach(styleKey => {
60
- const value = callIfFn(sxObject[styleKey], theme);
61
62
 
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));
66
- } else {
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
- });
63
+ function traverse(sxInput) {
64
+ let sxObject = sxInput;
65
+
66
+ if (typeof sxInput === 'function') {
67
+ sxObject = sxInput(theme);
68
+ } else if (typeof sxInput !== 'object') {
69
+ // value
70
+ return sxInput;
71
+ }
72
+
73
+ if (!sxObject) {
74
+ return null;
75
+ }
76
+
77
+ const emptyBreakpoints = (0, _breakpoints.createEmptyBreakpointObject)(theme.breakpoints);
78
+ const breakpointsKeys = Object.keys(emptyBreakpoints);
79
+ let css = emptyBreakpoints;
80
+ Object.keys(sxObject).forEach(styleKey => {
81
+ const value = callIfFn(sxObject[styleKey], theme);
82
+
83
+ if (value !== null && value !== undefined) {
84
+ if (typeof value === 'object') {
85
+ if (propToStyleFunction[styleKey]) {
86
+ css = (0, _merge.default)(css, getThemeValue(styleKey, value, theme));
78
87
  } else {
79
- css = (0, _merge.default)(css, breakpointsValues);
88
+ const breakpointsValues = (0, _breakpoints.handleBreakpoints)({
89
+ theme
90
+ }, value, x => ({
91
+ [styleKey]: x
92
+ }));
93
+
94
+ if (objectsHaveSameKeys(breakpointsValues, value)) {
95
+ css[styleKey] = styleFunctionSx({
96
+ sx: value,
97
+ theme
98
+ });
99
+ } else {
100
+ css = (0, _merge.default)(css, breakpointsValues);
101
+ }
80
102
  }
103
+ } else {
104
+ css = (0, _merge.default)(css, getThemeValue(styleKey, value, theme));
81
105
  }
82
- } else {
83
- css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
84
106
  }
85
- }
86
- });
87
- return (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css);
107
+ });
108
+ return (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css);
109
+ }
110
+
111
+ return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
88
112
  }
89
113
 
90
- return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
114
+ return styleFunctionSx;
91
115
  }
92
116
 
117
+ const styleFunctionSx = unstable_createStyleFunctionSx();
93
118
  styleFunctionSx.filterProps = ['sx'];
94
119
  var _default = styleFunctionSx;
95
120
  exports.default = _default;
@@ -1 +1 @@
1
- export {};
1
+ export {};