@mui/system 5.1.1 → 5.2.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.spec.d.ts +1 -1
- package/CHANGELOG.md +265 -3
- package/breakpoints.js +1 -1
- package/createBox.d.ts +3 -3
- package/createBox.js +1 -1
- package/createBox.spec.d.ts +1 -0
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +24 -10
- package/cssVars/createCssVarsProvider.js +80 -12
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/cssVarsParser.d.ts +68 -68
- package/cssVars/cssVarsParser.js +18 -17
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/getInitColorSchemeScript.js +7 -7
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/breakpoints.js +1 -1
- package/esm/createBox.js +1 -1
- package/esm/cssVars/createCssVarsProvider.js +76 -12
- package/esm/cssVars/cssVarsParser.js +18 -16
- package/esm/cssVars/getInitColorSchemeScript.js +7 -7
- package/esm/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +20 -18
- package/esm/sx/index.js +1 -0
- package/esm/sx/sx.js +12 -0
- package/esm/useThemeProps/getThemeProps.js +2 -17
- package/index.d.ts +2 -0
- package/index.js +10 -1
- package/index.spec.d.ts +1 -1
- package/legacy/breakpoints.js +1 -1
- package/legacy/createBox.js +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +79 -11
- package/legacy/cssVars/cssVarsParser.js +20 -14
- package/legacy/cssVars/getInitColorSchemeScript.js +2 -3
- package/legacy/index.js +2 -1
- package/legacy/styleFunctionSx/styleFunctionSx.js +19 -17
- package/legacy/sx/index.js +1 -0
- package/legacy/sx/sx.js +13 -0
- package/legacy/useThemeProps/getThemeProps.js +2 -17
- package/modern/breakpoints.js +1 -1
- package/modern/createBox.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +74 -12
- package/modern/cssVars/cssVarsParser.js +18 -16
- package/modern/cssVars/getInitColorSchemeScript.js +7 -7
- package/modern/index.js +2 -1
- package/modern/styleFunctionSx/styleFunctionSx.js +20 -18
- package/modern/sx/index.js +1 -0
- package/modern/sx/sx.js +12 -0
- package/modern/useThemeProps/getThemeProps.js +2 -17
- package/package.json +6 -6
- package/styleFunctionSx/styleFunctionSx.d.ts +1 -1
- package/styleFunctionSx/styleFunctionSx.js +20 -18
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
- package/sx/index.d.ts +1 -0
- package/sx/index.js +15 -0
- package/sx/package.json +6 -0
- package/sx/sx.d.ts +4 -0
- package/sx/sx.js +22 -0
- package/useThemeProps/getThemeProps.js +2 -17
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
var theme = params.theme,
|
|
6
4
|
name = params.name,
|
|
@@ -10,18 +8,5 @@ export default function getThemeProps(params) {
|
|
|
10
8
|
return props;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
// https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var defaultProps = theme.components[name].defaultProps;
|
|
18
|
-
var propName;
|
|
19
|
-
|
|
20
|
-
for (propName in defaultProps) {
|
|
21
|
-
if (output[propName] === undefined) {
|
|
22
|
-
output[propName] = defaultProps[propName];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return output;
|
|
11
|
+
return resolveProps(theme.components[name].defaultProps, props);
|
|
27
12
|
}
|
package/modern/breakpoints.js
CHANGED
|
@@ -93,7 +93,7 @@ export function createEmptyBreakpointObject(breakpointsInput = {}) {
|
|
|
93
93
|
export function removeUnusedBreakpoints(breakpointKeys, style) {
|
|
94
94
|
return breakpointKeys.reduce((acc, key) => {
|
|
95
95
|
const breakpointOutput = acc[key];
|
|
96
|
-
const isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
|
|
96
|
+
const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
|
|
97
97
|
|
|
98
98
|
if (isBreakpointUnused) {
|
|
99
99
|
delete acc[key];
|
package/modern/createBox.js
CHANGED
|
@@ -2,25 +2,33 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
4
|
const _excluded = ["colorSchemes"],
|
|
5
|
-
_excluded2 = ["colorSchemes"]
|
|
5
|
+
_excluded2 = ["colorSchemes"],
|
|
6
|
+
_excluded3 = ["components"];
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import PropTypes from 'prop-types';
|
|
8
9
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
10
|
import { deepmerge } from '@mui/utils';
|
|
11
|
+
import createSpacing from '../createTheme/createSpacing';
|
|
12
|
+
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
10
13
|
import cssVarsParser from './cssVarsParser';
|
|
11
14
|
import ThemeProvider from '../ThemeProvider';
|
|
12
15
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
16
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
16
20
|
export default function createCssVarsProvider(options) {
|
|
17
21
|
const {
|
|
18
22
|
theme: baseTheme = {},
|
|
19
23
|
defaultMode: desisgnSystemMode = 'light',
|
|
20
24
|
defaultColorScheme: designSystemColorScheme,
|
|
25
|
+
disableTransitionOnChange = false,
|
|
26
|
+
enableColorScheme = true,
|
|
21
27
|
prefix: designSystemPrefix = '',
|
|
22
28
|
shouldSkipGeneratingVar
|
|
23
29
|
} = options;
|
|
30
|
+
const systemSpacing = createSpacing(baseTheme.spacing);
|
|
31
|
+
const systemBreakpoints = createBreakpoints(baseTheme.breakpoints ?? {});
|
|
24
32
|
|
|
25
33
|
if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme?.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme?.dark]) {
|
|
26
34
|
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
@@ -47,17 +55,28 @@ export default function createCssVarsProvider(options) {
|
|
|
47
55
|
defaultMode = desisgnSystemMode,
|
|
48
56
|
defaultColorScheme = designSystemColorScheme
|
|
49
57
|
}) {
|
|
58
|
+
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
59
|
+
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
60
|
+
const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
|
|
61
|
+
|
|
50
62
|
const {
|
|
51
63
|
colorSchemes: baseColorSchemes = {}
|
|
52
|
-
} =
|
|
53
|
-
restBaseTheme = _objectWithoutPropertiesLoose(
|
|
64
|
+
} = clonedBaseTheme,
|
|
65
|
+
restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
|
|
54
66
|
|
|
55
67
|
const {
|
|
56
68
|
colorSchemes: colorSchemesProp = {}
|
|
57
69
|
} = themeProp,
|
|
58
70
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
59
71
|
|
|
60
|
-
|
|
72
|
+
const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
73
|
+
|
|
74
|
+
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
75
|
+
{
|
|
76
|
+
components = {}
|
|
77
|
+
} = _deepmerge,
|
|
78
|
+
mergedTheme = _objectWithoutPropertiesLoose(_deepmerge, _excluded3);
|
|
79
|
+
|
|
61
80
|
const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
62
81
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
63
82
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -65,6 +84,7 @@ export default function createCssVarsProvider(options) {
|
|
|
65
84
|
const {
|
|
66
85
|
mode,
|
|
67
86
|
setMode,
|
|
87
|
+
systemMode,
|
|
68
88
|
lightColorScheme,
|
|
69
89
|
darkColorScheme,
|
|
70
90
|
colorScheme,
|
|
@@ -100,7 +120,11 @@ export default function createCssVarsProvider(options) {
|
|
|
100
120
|
shouldSkipGeneratingVar
|
|
101
121
|
});
|
|
102
122
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
103
|
-
|
|
123
|
+
components,
|
|
124
|
+
colorSchemes,
|
|
125
|
+
vars: rootVars,
|
|
126
|
+
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
127
|
+
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
|
|
104
128
|
});
|
|
105
129
|
const styleSheet = {};
|
|
106
130
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -112,10 +136,7 @@ export default function createCssVarsProvider(options) {
|
|
|
112
136
|
basePrefix: designSystemPrefix,
|
|
113
137
|
shouldSkipGeneratingVar
|
|
114
138
|
});
|
|
115
|
-
|
|
116
|
-
if (key === resolvedColorScheme) {
|
|
117
|
-
mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
|
|
118
|
-
}
|
|
139
|
+
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
119
140
|
|
|
120
141
|
const resolvedDefaultColorScheme = (() => {
|
|
121
142
|
if (typeof defaultColorScheme === 'string') {
|
|
@@ -137,9 +158,50 @@ export default function createCssVarsProvider(options) {
|
|
|
137
158
|
});
|
|
138
159
|
React.useEffect(() => {
|
|
139
160
|
if (colorScheme) {
|
|
140
|
-
|
|
161
|
+
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
162
|
+
document.documentElement.setAttribute(attribute, colorScheme);
|
|
141
163
|
}
|
|
142
164
|
}, [colorScheme, attribute]);
|
|
165
|
+
React.useEffect(() => {
|
|
166
|
+
if (!mode || !enableColorScheme) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
171
|
+
|
|
172
|
+
if (mode === 'system') {
|
|
173
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
174
|
+
} else {
|
|
175
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
180
|
+
};
|
|
181
|
+
}, [mode, systemMode]);
|
|
182
|
+
React.useEffect(() => {
|
|
183
|
+
let timer;
|
|
184
|
+
|
|
185
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
186
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
187
|
+
const css = document.createElement('style');
|
|
188
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
189
|
+
document.head.appendChild(css); // Force browser repaint
|
|
190
|
+
|
|
191
|
+
(() => window.getComputedStyle(document.body))();
|
|
192
|
+
|
|
193
|
+
timer = setTimeout(() => {
|
|
194
|
+
document.head.removeChild(css);
|
|
195
|
+
}, 1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return () => {
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
};
|
|
201
|
+
}, [colorScheme]);
|
|
202
|
+
React.useEffect(() => {
|
|
203
|
+
hasMounted.current = true;
|
|
204
|
+
}, []);
|
|
143
205
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
144
206
|
value: {
|
|
145
207
|
mode,
|
|
@@ -170,7 +232,7 @@ export default function createCssVarsProvider(options) {
|
|
|
170
232
|
attribute: PropTypes.string,
|
|
171
233
|
|
|
172
234
|
/**
|
|
173
|
-
*
|
|
235
|
+
* The component tree.
|
|
174
236
|
*/
|
|
175
237
|
children: PropTypes.node,
|
|
176
238
|
|
|
@@ -190,7 +252,7 @@ export default function createCssVarsProvider(options) {
|
|
|
190
252
|
modeStorageKey: PropTypes.string,
|
|
191
253
|
|
|
192
254
|
/**
|
|
193
|
-
*
|
|
255
|
+
* CSS variable prefix.
|
|
194
256
|
*/
|
|
195
257
|
prefix: PropTypes.string,
|
|
196
258
|
|
|
@@ -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 (
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
//
|
|
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(
|
|
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
|
-
|
|
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
|
|
@@ -5,7 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
|
|
8
|
+
enableSystem,
|
|
9
9
|
defaultLightColorScheme = 'light',
|
|
10
10
|
defaultDarkColorScheme = 'dark',
|
|
11
11
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -18,23 +18,23 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
18
|
__html: `(function() { try {
|
|
19
19
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
20
20
|
var colorScheme = '';
|
|
21
|
-
if (mode === 'system' || (!mode &&
|
|
21
|
+
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
22
22
|
// handle system mode
|
|
23
23
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
24
24
|
if (mql.matches) {
|
|
25
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${
|
|
25
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
26
26
|
} else {
|
|
27
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${
|
|
27
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (mode === 'light') {
|
|
31
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultLightColorScheme};
|
|
31
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
32
32
|
}
|
|
33
33
|
if (mode === 'dark') {
|
|
34
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultDarkColorScheme};
|
|
34
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
35
|
}
|
|
36
36
|
if (colorScheme) {
|
|
37
|
-
document.
|
|
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.
|
|
1
|
+
/** @license MUI v5.2.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.
|
|
@@ -27,6 +27,7 @@ export { default as style, getPath } from './style';
|
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
29
|
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
|
+
export { default as experimental_sx } from './sx';
|
|
30
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
31
32
|
export { default as Box } from './Box';
|
|
32
33
|
export { default as createBox } from './createBox';
|
|
@@ -44,27 +44,29 @@ function styleFunctionSx(props) {
|
|
|
44
44
|
Object.keys(sxObject).forEach(styleKey => {
|
|
45
45
|
const value = callIfFn(sxObject[styleKey], theme);
|
|
46
46
|
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const breakpointsValues = handleBreakpoints({
|
|
52
|
-
theme
|
|
53
|
-
}, value, x => ({
|
|
54
|
-
[styleKey]: x
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
58
|
-
css[styleKey] = styleFunctionSx({
|
|
59
|
-
sx: value,
|
|
60
|
-
theme
|
|
61
|
-
});
|
|
47
|
+
if (value !== null && value !== undefined) {
|
|
48
|
+
if (typeof value === 'object') {
|
|
49
|
+
if (propToStyleFunction[styleKey]) {
|
|
50
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
62
51
|
} else {
|
|
63
|
-
|
|
52
|
+
const breakpointsValues = handleBreakpoints({
|
|
53
|
+
theme
|
|
54
|
+
}, value, x => ({
|
|
55
|
+
[styleKey]: x
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
59
|
+
css[styleKey] = styleFunctionSx({
|
|
60
|
+
sx: value,
|
|
61
|
+
theme
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
css = merge(css, breakpointsValues);
|
|
65
|
+
}
|
|
64
66
|
}
|
|
67
|
+
} else {
|
|
68
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
65
69
|
}
|
|
66
|
-
} else {
|
|
67
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/modern/sx/sx.js
ADDED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "5.2.3",
|
|
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/
|
|
26
|
+
"url": "https://opencollective.com/mui"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@emotion/react": "^11.5.0",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.16.3",
|
|
47
|
-
"@mui/private-theming": "^5.
|
|
48
|
-
"@mui/styled-engine": "^5.
|
|
47
|
+
"@mui/private-theming": "^5.2.3",
|
|
48
|
+
"@mui/styled-engine": "^5.2.0",
|
|
49
49
|
"@mui/types": "^7.1.0",
|
|
50
|
-
"@mui/utils": "^5.
|
|
50
|
+
"@mui/utils": "^5.2.3",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
|
-
"csstype": "^3.0.
|
|
52
|
+
"csstype": "^3.0.10",
|
|
53
53
|
"prop-types": "^15.7.2"
|
|
54
54
|
},
|
|
55
55
|
"sideEffects": false,
|
|
@@ -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;
|
|
@@ -59,27 +59,29 @@ function styleFunctionSx(props) {
|
|
|
59
59
|
Object.keys(sxObject).forEach(styleKey => {
|
|
60
60
|
const value = callIfFn(sxObject[styleKey], theme);
|
|
61
61
|
|
|
62
|
-
if (
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const breakpointsValues = (0, _breakpoints.handleBreakpoints)({
|
|
67
|
-
theme
|
|
68
|
-
}, value, x => ({
|
|
69
|
-
[styleKey]: x
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
73
|
-
css[styleKey] = styleFunctionSx({
|
|
74
|
-
sx: value,
|
|
75
|
-
theme
|
|
76
|
-
});
|
|
62
|
+
if (value !== null && value !== undefined) {
|
|
63
|
+
if (typeof value === 'object') {
|
|
64
|
+
if (_getThemeValue.propToStyleFunction[styleKey]) {
|
|
65
|
+
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
77
66
|
} else {
|
|
78
|
-
|
|
67
|
+
const breakpointsValues = (0, _breakpoints.handleBreakpoints)({
|
|
68
|
+
theme
|
|
69
|
+
}, value, x => ({
|
|
70
|
+
[styleKey]: x
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
74
|
+
css[styleKey] = styleFunctionSx({
|
|
75
|
+
sx: value,
|
|
76
|
+
theme
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
css = (0, _merge.default)(css, breakpointsValues);
|
|
80
|
+
}
|
|
79
81
|
}
|
|
82
|
+
} else {
|
|
83
|
+
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
80
84
|
}
|
|
81
|
-
} else {
|
|
82
|
-
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
83
85
|
}
|
|
84
86
|
});
|
|
85
87
|
return (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/sx/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/sx/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _sx.default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
package/sx/package.json
ADDED
package/sx/sx.d.ts
ADDED
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
|
|
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
|
-
|
|
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
|
}
|