@mui/system 5.3.0 → 5.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Box/Box.d.ts +1 -1
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +347 -28
- package/ThemeProvider/ThemeProvider.d.ts +1 -1
- package/createBox.d.ts +2 -0
- package/createBox.js +3 -2
- package/createBox.spec.d.ts +1 -1
- package/createStyled.d.ts +2 -1
- package/createStyled.js +7 -5
- package/createTheme/createBreakpoints.js +21 -6
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +34 -94
- package/cssVars/createCssVarsProvider.js +4 -2
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +7 -1
- package/cssVars/cssVarsParser.d.ts +68 -68
- package/cssVars/cssVarsParser.js +4 -3
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +1 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/createBox.js +3 -2
- package/esm/createStyled.js +5 -3
- package/esm/createTheme/createBreakpoints.js +20 -4
- package/esm/cssVars/createCssVarsProvider.js +4 -2
- package/esm/cssVars/createGetCssVar.js +7 -1
- package/esm/cssVars/cssVarsParser.js +4 -3
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +1 -1
- package/esm/styleFunctionSx/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
- package/getThemeValue.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +8 -1
- package/index.spec.d.ts +1 -1
- package/legacy/createBox.js +4 -2
- package/legacy/createStyled.js +6 -3
- package/legacy/createTheme/createBreakpoints.js +23 -4
- package/legacy/cssVars/createCssVarsProvider.js +4 -2
- package/legacy/cssVars/createGetCssVar.js +7 -1
- package/legacy/cssVars/cssVarsParser.js +4 -3
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +2 -2
- package/legacy/styleFunctionSx/index.js +1 -0
- package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
- package/modern/createBox.js +3 -2
- package/modern/createStyled.js +5 -3
- package/modern/createTheme/createBreakpoints.js +20 -4
- package/modern/cssVars/createCssVarsProvider.js +4 -2
- package/modern/cssVars/createGetCssVar.js +7 -1
- package/modern/cssVars/cssVarsParser.js +4 -3
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +2 -2
- package/modern/styleFunctionSx/index.js +1 -0
- package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
- package/package.json +8 -8
- package/style.d.ts +1 -1
- package/styleFunctionSx/index.js +12 -2
- package/styleFunctionSx/styleFunctionSx.d.ts +12 -1
- package/styleFunctionSx/styleFunctionSx.js +79 -54
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -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
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
42
|
-
var
|
|
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 (
|
|
45
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
103
|
+
});
|
|
104
|
+
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
83
108
|
}
|
|
84
109
|
|
|
85
|
-
return
|
|
110
|
+
return styleFunctionSx;
|
|
86
111
|
}
|
|
87
|
-
|
|
112
|
+
var styleFunctionSx = unstable_createStyleFunctionSx();
|
|
88
113
|
styleFunctionSx.filterProps = ['sx'];
|
|
89
114
|
export default styleFunctionSx;
|
package/modern/createBox.js
CHANGED
|
@@ -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
|
|
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) {
|
package/modern/createStyled.js
CHANGED
|
@@ -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 {
|
|
@@ -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'];
|
|
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
|
|
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,
|
|
@@ -26,7 +26,8 @@ export default function createCssVarsProvider(options) {
|
|
|
26
26
|
disableTransitionOnChange = false,
|
|
27
27
|
enableColorScheme = 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 ?? {});
|
|
@@ -123,6 +124,7 @@ export default function createCssVarsProvider(options) {
|
|
|
123
124
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
124
125
|
components,
|
|
125
126
|
colorSchemes,
|
|
127
|
+
prefix,
|
|
126
128
|
vars: rootVars,
|
|
127
129
|
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
128
130
|
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
@@ -224,7 +226,7 @@ export default function createCssVarsProvider(options) {
|
|
|
224
226
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
225
227
|
styles: styleSheet
|
|
226
228
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
227
|
-
theme: mergedTheme,
|
|
229
|
+
theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
|
|
228
230
|
children: children
|
|
229
231
|
})]
|
|
230
232
|
});
|
|
@@ -8,7 +8,13 @@ export default function createGetCssVar(prefix = '') {
|
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
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
|
|
|
@@ -113,12 +113,13 @@ export default function cssVarsParser(theme, options) {
|
|
|
113
113
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
114
114
|
let value = val;
|
|
115
115
|
|
|
116
|
-
if (typeof value === 'string' && value.
|
|
116
|
+
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
117
117
|
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
118
118
|
if (!basePrefix && prefix) {
|
|
119
|
-
value = value.replace(/var\(
|
|
119
|
+
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
120
120
|
} else {
|
|
121
|
-
value = prefix ? value.replace(new RegExp(basePrefix
|
|
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(--');
|
|
122
123
|
} // scope is the deepest object in the tree, keys is the theme path keys
|
|
123
124
|
|
|
124
125
|
|
package/modern/getThemeValue.js
CHANGED
package/modern/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.3
|
|
1
|
+
/** @license MUI v5.4.3
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import merge from '../merge';
|
|
2
|
-
import
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
32
|
-
|
|
35
|
+
function styleFunctionSx(props) {
|
|
36
|
+
const {
|
|
37
|
+
sx,
|
|
38
|
+
theme = {}
|
|
39
|
+
} = props || {};
|
|
33
40
|
|
|
34
|
-
if (
|
|
35
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
+
});
|
|
96
|
+
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
73
100
|
}
|
|
74
101
|
|
|
75
|
-
return
|
|
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.3
|
|
3
|
+
"version": "5.4.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
],
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/mui
|
|
16
|
+
"url": "https://github.com/mui/material-ui.git",
|
|
17
17
|
"directory": "packages/mui-system"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"bugs": {
|
|
21
|
-
"url": "https://github.com/mui
|
|
21
|
+
"url": "https://github.com/mui/material-ui/issues"
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://mui.com/system/basics/",
|
|
24
24
|
"funding": {
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@babel/runtime": "^7.
|
|
47
|
-
"@mui/private-theming": "^5.
|
|
48
|
-
"@mui/styled-engine": "^5.
|
|
49
|
-
"@mui/types": "^7.1.
|
|
50
|
-
"@mui/utils": "^5.
|
|
46
|
+
"@babel/runtime": "^7.17.0",
|
|
47
|
+
"@mui/private-theming": "^5.4.2",
|
|
48
|
+
"@mui/styled-engine": "^5.4.2",
|
|
49
|
+
"@mui/types": "^7.1.2",
|
|
50
|
+
"@mui/utils": "^5.4.2",
|
|
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[] };
|
package/styleFunctionSx/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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; }
|
|
@@ -60,5 +60,16 @@ export type SxProps<Theme extends object = {}> =
|
|
|
60
60
|
| ((theme: Theme) => SystemStyleObject<Theme>)
|
|
61
61
|
| Array<boolean | SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
|
|
62
62
|
|
|
63
|
+
export interface StyleFunctionSx {
|
|
64
|
+
(props: object): object;
|
|
65
|
+
filterProps?: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
|
-
export
|
|
69
|
+
export function unstable_createStyleFunctionSx(
|
|
70
|
+
styleFunctionMapping: Record<string, StyleFunctionSx>,
|
|
71
|
+
): StyleFunctionSx;
|
|
72
|
+
|
|
73
|
+
declare const styleFunctionSx: StyleFunctionSx;
|
|
74
|
+
|
|
75
|
+
export default styleFunctionSx;
|