@mui/system 5.15.6 → 5.15.8

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.
@@ -1,11 +1,12 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
1
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["ownerState"],
4
+ _excluded2 = ["variants"],
5
+ _excluded3 = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
4
6
  /* eslint-disable no-underscore-dangle */
5
7
  import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
6
- import { getDisplayName, unstable_capitalize as capitalize, isPlainObject, deepmerge } from '@mui/utils';
8
+ import { getDisplayName, unstable_capitalize as capitalize, isPlainObject } from '@mui/utils';
7
9
  import createTheme from './createTheme';
8
- import propsToClassKey from './propsToClassKey';
9
10
  import styleFunctionSx from './styleFunctionSx';
10
11
  function isEmpty(obj) {
11
12
  return Object.keys(obj).length === 0;
@@ -19,73 +20,6 @@ function isStringTag(tag) {
19
20
  // it's a lowercase character
20
21
  tag.charCodeAt(0) > 96;
21
22
  }
22
- const getStyleOverrides = (name, theme) => {
23
- if (theme.components && theme.components[name] && theme.components[name].styleOverrides) {
24
- return theme.components[name].styleOverrides;
25
- }
26
- return null;
27
- };
28
- const transformVariants = variants => {
29
- let numOfCallbacks = 0;
30
- const variantsStyles = {};
31
- if (variants) {
32
- variants.forEach(definition => {
33
- let key = '';
34
- if (typeof definition.props === 'function') {
35
- key = `callback${numOfCallbacks}`;
36
- numOfCallbacks += 1;
37
- } else {
38
- key = propsToClassKey(definition.props);
39
- }
40
- variantsStyles[key] = definition.style;
41
- });
42
- }
43
- return variantsStyles;
44
- };
45
- const getVariantStyles = (name, theme) => {
46
- let variants = [];
47
- if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
48
- variants = theme.components[name].variants;
49
- }
50
- return transformVariants(variants);
51
- };
52
- const variantsResolver = (props, styles, variants) => {
53
- const {
54
- ownerState = {}
55
- } = props;
56
- const variantsStyles = [];
57
- let numOfCallbacks = 0;
58
- if (variants) {
59
- variants.forEach(variant => {
60
- let isMatch = true;
61
- if (typeof variant.props === 'function') {
62
- const propsToCheck = _extends({}, props, ownerState);
63
- isMatch = variant.props(propsToCheck);
64
- } else {
65
- Object.keys(variant.props).forEach(key => {
66
- if (ownerState[key] !== variant.props[key] && props[key] !== variant.props[key]) {
67
- isMatch = false;
68
- }
69
- });
70
- }
71
- if (isMatch) {
72
- if (typeof variant.props === 'function') {
73
- variantsStyles.push(styles[`callback${numOfCallbacks}`]);
74
- } else {
75
- variantsStyles.push(styles[propsToClassKey(variant.props)]);
76
- }
77
- }
78
- if (typeof variant.props === 'function') {
79
- numOfCallbacks += 1;
80
- }
81
- });
82
- }
83
- return variantsStyles;
84
- };
85
- const themeVariantsResolver = (props, styles, theme, name) => {
86
- const themeVariants = theme?.components?.[name]?.variants;
87
- return variantsResolver(props, styles, themeVariants);
88
- };
89
23
 
90
24
  // Update /system/styled/#api in case if this changes
91
25
  export function shouldForwardProp(prop) {
@@ -111,29 +45,51 @@ function defaultOverridesResolver(slot) {
111
45
  }
112
46
  return (props, styles) => styles[slot];
113
47
  }
114
- const muiStyledFunctionResolver = ({
115
- styledArg,
116
- props,
117
- defaultTheme,
118
- themeId
119
- }) => {
120
- const resolvedStyles = styledArg(_extends({}, props, {
121
- theme: resolveTheme(_extends({}, props, {
122
- defaultTheme,
123
- themeId
124
- }))
125
- }));
126
- let optionalVariants;
127
- if (resolvedStyles && resolvedStyles.variants) {
128
- optionalVariants = resolvedStyles.variants;
129
- delete resolvedStyles.variants;
48
+ function processStyleArg(callableStyle, _ref) {
49
+ let {
50
+ ownerState
51
+ } = _ref,
52
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
53
+ const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle(_extends({
54
+ ownerState
55
+ }, props)) : callableStyle;
56
+ if (Array.isArray(resolvedStylesArg)) {
57
+ return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, _extends({
58
+ ownerState
59
+ }, props)));
130
60
  }
131
- if (optionalVariants) {
132
- const variantsStyles = variantsResolver(props, transformVariants(optionalVariants), optionalVariants);
133
- return [resolvedStyles, ...variantsStyles];
61
+ if (!!resolvedStylesArg && typeof resolvedStylesArg === 'object' && Array.isArray(resolvedStylesArg.variants)) {
62
+ const {
63
+ variants = []
64
+ } = resolvedStylesArg,
65
+ otherStyles = _objectWithoutPropertiesLoose(resolvedStylesArg, _excluded2);
66
+ let result = otherStyles;
67
+ variants.forEach(variant => {
68
+ let isMatch = true;
69
+ if (typeof variant.props === 'function') {
70
+ isMatch = variant.props(_extends({
71
+ ownerState
72
+ }, props));
73
+ } else {
74
+ Object.keys(variant.props).forEach(key => {
75
+ if (ownerState?.[key] !== variant.props[key] && props[key] !== variant.props[key]) {
76
+ isMatch = false;
77
+ }
78
+ });
79
+ }
80
+ if (isMatch) {
81
+ if (!Array.isArray(result)) {
82
+ result = [result];
83
+ }
84
+ result.push(typeof variant.style === 'function' ? variant.style(_extends({
85
+ ownerState
86
+ }, props)) : variant.style);
87
+ }
88
+ });
89
+ return result;
134
90
  }
135
- return resolvedStyles;
136
- };
91
+ return resolvedStylesArg;
92
+ }
137
93
  export default function createStyled(input = {}) {
138
94
  const {
139
95
  themeId,
@@ -162,7 +118,7 @@ export default function createStyled(input = {}) {
162
118
  // For more details: https://github.com/mui/material-ui/pull/37908
163
119
  overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot))
164
120
  } = inputOptions,
165
- options = _objectWithoutPropertiesLoose(inputOptions, _excluded);
121
+ options = _objectWithoutPropertiesLoose(inputOptions, _excluded3);
166
122
 
167
123
  // if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
168
124
  const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
@@ -195,83 +151,42 @@ export default function createStyled(input = {}) {
195
151
  shouldForwardProp: shouldForwardPropOption,
196
152
  label
197
153
  }, options));
198
- const muiStyledResolver = (styleArg, ...expressions) => {
199
- const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
200
- // On the server Emotion doesn't use React.forwardRef for creating components, so the created
201
- // component stays as a function. This condition makes sure that we do not interpolate functions
202
- // which are basically components used as a selectors.
203
- if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg) {
204
- return props => muiStyledFunctionResolver({
205
- styledArg: stylesArg,
206
- props,
207
- defaultTheme,
208
- themeId
209
- });
210
- }
211
- if (isPlainObject(stylesArg)) {
212
- let transformedStylesArg = stylesArg;
213
- let styledArgVariants;
214
- if (stylesArg && stylesArg.variants) {
215
- styledArgVariants = stylesArg.variants;
216
- delete transformedStylesArg.variants;
217
- transformedStylesArg = props => {
218
- let result = stylesArg;
219
- const variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
220
- variantStyles.forEach(variantStyle => {
221
- result = deepmerge(result, variantStyle);
222
- });
223
- return result;
224
- };
225
- }
226
- return transformedStylesArg;
227
- }
228
- return stylesArg;
229
- }) : [];
230
- let transformedStyleArg = styleArg;
231
- if (isPlainObject(styleArg)) {
232
- let styledArgVariants;
233
- if (styleArg && styleArg.variants) {
234
- styledArgVariants = styleArg.variants;
235
- delete transformedStyleArg.variants;
236
- transformedStyleArg = props => {
237
- let result = styleArg;
238
- const variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
239
- variantStyles.forEach(variantStyle => {
240
- result = deepmerge(result, variantStyle);
241
- });
242
- return result;
243
- };
244
- }
245
- } else if (typeof styleArg === 'function' &&
154
+ const transformStyleArg = stylesArg => {
246
155
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
247
156
  // component stays as a function. This condition makes sure that we do not interpolate functions
248
157
  // which are basically components used as a selectors.
249
- styleArg.__emotion_real !== styleArg) {
250
- // If the type is function, we need to define the default theme.
251
- transformedStyleArg = props => muiStyledFunctionResolver({
252
- styledArg: styleArg,
253
- props,
254
- defaultTheme,
255
- themeId
256
- });
158
+ if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
159
+ return props => processStyleArg(stylesArg, _extends({}, props, {
160
+ theme: resolveTheme({
161
+ theme: props.theme,
162
+ defaultTheme,
163
+ themeId
164
+ })
165
+ }));
257
166
  }
167
+ return stylesArg;
168
+ };
169
+ const muiStyledResolver = (styleArg, ...expressions) => {
170
+ let transformedStyleArg = transformStyleArg(styleArg);
171
+ const expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
258
172
  if (componentName && overridesResolver) {
259
173
  expressionsWithDefaultTheme.push(props => {
260
174
  const theme = resolveTheme(_extends({}, props, {
261
175
  defaultTheme,
262
176
  themeId
263
177
  }));
264
- const styleOverrides = getStyleOverrides(componentName, theme);
265
- if (styleOverrides) {
266
- const resolvedStyleOverrides = {};
267
- Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
268
- resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
269
- theme
270
- })) : slotStyle;
271
- });
272
- return overridesResolver(props, resolvedStyleOverrides);
178
+ if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
179
+ return null;
273
180
  }
274
- return null;
181
+ const styleOverrides = theme.components[componentName].styleOverrides;
182
+ const resolvedStyleOverrides = {};
183
+ // TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
184
+ Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
185
+ resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, _extends({}, props, {
186
+ theme
187
+ }));
188
+ });
189
+ return overridesResolver(props, resolvedStyleOverrides);
275
190
  });
276
191
  }
277
192
  if (componentName && !skipVariantsResolver) {
@@ -280,7 +195,12 @@ export default function createStyled(input = {}) {
280
195
  defaultTheme,
281
196
  themeId
282
197
  }));
283
- return themeVariantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
198
+ const themeVariants = theme?.components?.[componentName]?.variants;
199
+ return processStyleArg({
200
+ variants: themeVariants
201
+ }, _extends({}, props, {
202
+ theme
203
+ }));
284
204
  });
285
205
  }
286
206
  if (!skipSx) {
@@ -0,0 +1,74 @@
1
+ /**
2
+ * A universal utility to style components with multiple color modes. Always use it from the theme object.
3
+ * It works with:
4
+ * - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
5
+ * - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
6
+ * - Zero-runtime engine
7
+ *
8
+ * Tips: Use an array over object spread and place `theme.applyStyles()` last.
9
+ *
10
+ * ✅ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })]
11
+ *
12
+ * 🚫 { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })}
13
+ *
14
+ * @example
15
+ * 1. using with `styled`:
16
+ * ```jsx
17
+ * const Component = styled('div')(({ theme }) => [
18
+ * { background: '#e5e5e5' },
19
+ * theme.applyStyles('dark', {
20
+ * background: '#1c1c1c',
21
+ * color: '#fff',
22
+ * }),
23
+ * ]);
24
+ * ```
25
+ *
26
+ * @example
27
+ * 2. using with `sx` prop:
28
+ * ```jsx
29
+ * <Box sx={theme => [
30
+ * { background: '#e5e5e5' },
31
+ * theme.applyStyles('dark', {
32
+ * background: '#1c1c1c',
33
+ * color: '#fff',
34
+ * }),
35
+ * ]}
36
+ * />
37
+ * ```
38
+ *
39
+ * @example
40
+ * 3. theming a component:
41
+ * ```jsx
42
+ * extendTheme({
43
+ * components: {
44
+ * MuiButton: {
45
+ * styleOverrides: {
46
+ * root: ({ theme }) => [
47
+ * { background: '#e5e5e5' },
48
+ * theme.applyStyles('dark', {
49
+ * background: '#1c1c1c',
50
+ * color: '#fff',
51
+ * }),
52
+ * ],
53
+ * },
54
+ * }
55
+ * }
56
+ * })
57
+ *```
58
+ */
59
+ export default function applyStyles(key, styles) {
60
+ // @ts-expect-error this is 'any' type
61
+ const theme = this;
62
+ if (theme.vars && typeof theme.getColorSchemeSelector === 'function') {
63
+ // If CssVarsProvider is used as a provider,
64
+ // returns '* :where([data-mui-color-scheme="light|dark"]) &'
65
+ const selector = theme.getColorSchemeSelector(key).replace(/(\[[^\]]+\])/, '*:where($1)');
66
+ return {
67
+ [selector]: styles
68
+ };
69
+ }
70
+ if (theme.palette.mode === key) {
71
+ return styles;
72
+ }
73
+ return {};
74
+ }
@@ -7,6 +7,7 @@ import shape from './shape';
7
7
  import createSpacing from './createSpacing';
8
8
  import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
9
9
  import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
10
+ import applyStyles from './applyStyles';
10
11
  function createTheme(options = {}, ...args) {
11
12
  const {
12
13
  breakpoints: breakpointsInput = {},
@@ -28,6 +29,7 @@ function createTheme(options = {}, ...args) {
28
29
  spacing,
29
30
  shape: _extends({}, shape, shapeInput)
30
31
  }, other);
32
+ muiTheme.applyStyles = applyStyles;
31
33
  muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
32
34
  muiTheme.unstable_sxConfig = _extends({}, defaultSxConfig, other?.unstable_sxConfig);
33
35
  muiTheme.unstable_sx = function sx(props) {
@@ -1,2 +1,3 @@
1
1
  export { default } from './createTheme';
2
- export { default as private_createBreakpoints } from './createBreakpoints';
2
+ export { default as private_createBreakpoints } from './createBreakpoints';
3
+ export { default as unstable_applyStyles } from './applyStyles';
package/modern/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  /**
2
- * @mui/system v5.15.6
2
+ * @mui/system v5.15.8
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- 'use client';
9
-
10
8
  import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
11
9
  export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
12
10
  export { default as GlobalStyles } from './GlobalStyles';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.15.6",
3
+ "version": "5.15.8",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "MUI System is a set of CSS utilities to help you build custom designs more efficiently. It makes it possible to rapidly lay out custom designs.",
@@ -26,14 +26,14 @@
26
26
  "url": "https://opencollective.com/mui-org"
27
27
  },
28
28
  "dependencies": {
29
- "@babel/runtime": "^7.23.8",
29
+ "@babel/runtime": "^7.23.9",
30
30
  "clsx": "^2.1.0",
31
31
  "csstype": "^3.1.2",
32
32
  "prop-types": "^15.8.1",
33
- "@mui/private-theming": "^5.15.6",
34
- "@mui/styled-engine": "^5.15.6",
33
+ "@mui/private-theming": "^5.15.8",
34
+ "@mui/styled-engine": "^5.15.8",
35
35
  "@mui/types": "^7.2.13",
36
- "@mui/utils": "^5.15.6"
36
+ "@mui/utils": "^5.15.8"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@emotion/react": "^11.5.0",