@mui/system 5.4.3 → 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.
@@ -25,8 +25,8 @@ export default function createCssVarsProvider(options) {
25
25
  theme: baseTheme = {},
26
26
  defaultMode: desisgnSystemMode = 'light',
27
27
  defaultColorScheme: designSystemColorScheme,
28
- disableTransitionOnChange = false,
29
- enableColorScheme = true,
28
+ disableTransitionOnChange: designSystemTransitionOnChange = false,
29
+ enableColorScheme: designSystemEnableColorScheme = true,
30
30
  prefix: designSystemPrefix = '',
31
31
  shouldSkipGeneratingVar,
32
32
  resolveTheme
@@ -57,16 +57,14 @@ export default function createCssVarsProvider(options) {
57
57
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
58
58
  attribute = DEFAULT_ATTRIBUTE,
59
59
  defaultMode = desisgnSystemMode,
60
- defaultColorScheme = designSystemColorScheme
60
+ defaultColorScheme = designSystemColorScheme,
61
+ disableTransitionOnChange = designSystemTransitionOnChange,
62
+ enableColorScheme = designSystemEnableColorScheme
61
63
  }) {
62
- // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
63
- // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
64
- const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
65
-
66
64
  const {
67
65
  colorSchemes: baseColorSchemes = {}
68
- } = clonedBaseTheme,
69
- restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
66
+ } = baseTheme,
67
+ restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
70
68
 
71
69
  const {
72
70
  colorSchemes: colorSchemesProp = {}
@@ -117,13 +115,14 @@ export default function createCssVarsProvider(options) {
117
115
 
118
116
  const {
119
117
  css: rootCss,
120
- vars: rootVars
118
+ vars: rootVars,
119
+ parsedTheme
121
120
  } = cssVarsParser(mergedTheme, {
122
121
  prefix,
123
122
  basePrefix: designSystemPrefix,
124
123
  shouldSkipGeneratingVar
125
124
  });
126
- mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
125
+ mergedTheme = _extends({}, parsedTheme, {
127
126
  components,
128
127
  colorSchemes,
129
128
  prefix,
@@ -136,7 +135,8 @@ export default function createCssVarsProvider(options) {
136
135
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
137
136
  const {
138
137
  css,
139
- vars
138
+ vars,
139
+ parsedTheme: parsedScheme
140
140
  } = cssVarsParser(scheme, {
141
141
  prefix,
142
142
  basePrefix: designSystemPrefix,
@@ -144,6 +144,10 @@ export default function createCssVarsProvider(options) {
144
144
  });
145
145
  mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
146
146
 
147
+ if (key === resolvedColorScheme) {
148
+ mergedTheme = _extends({}, mergedTheme, parsedScheme);
149
+ }
150
+
147
151
  const resolvedDefaultColorScheme = (() => {
148
152
  if (typeof defaultColorScheme === 'string') {
149
153
  return defaultColorScheme;
@@ -184,7 +188,7 @@ export default function createCssVarsProvider(options) {
184
188
  return () => {
185
189
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
186
190
  };
187
- }, [mode, systemMode]);
191
+ }, [mode, systemMode, enableColorScheme]);
188
192
  React.useEffect(() => {
189
193
  let timer;
190
194
 
@@ -204,7 +208,7 @@ export default function createCssVarsProvider(options) {
204
208
  return () => {
205
209
  clearTimeout(timer);
206
210
  };
207
- }, [colorScheme]);
211
+ }, [colorScheme, disableTransitionOnChange]);
208
212
  React.useEffect(() => {
209
213
  hasMounted.current = true;
210
214
  return () => {
@@ -255,6 +259,16 @@ export default function createCssVarsProvider(options) {
255
259
  */
256
260
  defaultMode: PropTypes.string,
257
261
 
262
+ /**
263
+ * Disable CSS transitions when switching between modes or color schemes
264
+ */
265
+ disableTransitionOnChange: PropTypes.bool,
266
+
267
+ /**
268
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
269
+ */
270
+ enableColorScheme: PropTypes.bool,
271
+
258
272
  /**
259
273
  * The key in the local storage used to store current color scheme.
260
274
  */
@@ -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,21 +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
-
113
+ const parsedTheme = {};
114
+ walkObjectDeep(theme, (keys, value) => {
115
+ if (typeof value === 'string' || typeof value === 'number') {
116
116
  if (typeof value === 'string' && value.match(/var\(\s*--/)) {
117
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
117
+ // for CSS variable, apply prefix or remove basePrefix from the variable
118
118
  if (!basePrefix && prefix) {
119
119
  value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
120
120
  } else {
121
121
  value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
122
122
  : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
123
- } // scope is the deepest object in the tree, keys is the theme path keys
124
-
125
-
126
- scope[keys.slice(-1)[0]] = value;
123
+ }
127
124
  }
128
125
 
129
126
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -135,10 +132,13 @@ export default function cssVarsParser(theme, options) {
135
132
  assignNestedKeys(vars, keys, `var(${cssVar})`);
136
133
  }
137
134
  }
135
+
136
+ assignNestedKeys(parsedTheme, keys, value);
138
137
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
139
138
  );
140
139
  return {
141
140
  css,
142
- vars
141
+ vars,
142
+ parsedTheme
143
143
  };
144
144
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.3
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.
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -181,7 +181,11 @@ export default function createStyled() {
181
181
 
182
182
  transformedStyleArg = [].concat(_toConsumableArray(styleArg), _toConsumableArray(placeholders));
183
183
  transformedStyleArg.raw = [].concat(_toConsumableArray(styleArg.raw), _toConsumableArray(placeholders));
184
- } else if (typeof styleArg === 'function') {
184
+ } else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
185
+ // component stays as a function. This condition makes sure that we do not interpolate functions
186
+ // which are basically components used as a selectors.
187
+ // eslint-disable-next-line no-underscore-dangle
188
+ styleArg.__emotion_real !== styleArg) {
185
189
  // If the type is function, we need to define the default theme.
186
190
  transformedStyleArg = function transformedStyleArg(_ref4) {
187
191
  var themeInput = _ref4.theme,
@@ -26,9 +26,9 @@ export default function createCssVarsProvider(options) {
26
26
  desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
27
27
  designSystemColorScheme = options.defaultColorScheme,
28
28
  _options$disableTrans = options.disableTransitionOnChange,
29
- disableTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
29
+ designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
30
30
  _options$enableColorS = options.enableColorScheme,
31
- enableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
31
+ designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
32
32
  _options$prefix = options.prefix,
33
33
  designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
34
34
  shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
@@ -65,16 +65,15 @@ export default function createCssVarsProvider(options) {
65
65
  _ref$defaultMode = _ref.defaultMode,
66
66
  defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
67
67
  _ref$defaultColorSche = _ref.defaultColorScheme,
68
- defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche;
69
- // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
70
- // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
71
- var clonedBaseTheme = React.useMemo(function () {
72
- return JSON.parse(JSON.stringify(baseTheme));
73
- }, []);
68
+ defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche,
69
+ _ref$disableTransitio = _ref.disableTransitionOnChange,
70
+ disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
71
+ _ref$enableColorSchem = _ref.enableColorScheme,
72
+ enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem;
74
73
 
75
- var _clonedBaseTheme$colo = clonedBaseTheme.colorSchemes,
76
- baseColorSchemes = _clonedBaseTheme$colo === void 0 ? {} : _clonedBaseTheme$colo,
77
- restBaseTheme = _objectWithoutProperties(clonedBaseTheme, ["colorSchemes"]);
74
+ var _baseTheme$colorSchem = baseTheme.colorSchemes,
75
+ baseColorSchemes = _baseTheme$colorSchem === void 0 ? {} : _baseTheme$colorSchem,
76
+ restBaseTheme = _objectWithoutProperties(baseTheme, ["colorSchemes"]);
78
77
 
79
78
  var _themeProp$colorSchem = themeProp.colorSchemes,
80
79
  colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
@@ -127,9 +126,10 @@ export default function createCssVarsProvider(options) {
127
126
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
128
127
  }),
129
128
  rootCss = _cssVarsParser.css,
130
- rootVars = _cssVarsParser.vars;
129
+ rootVars = _cssVarsParser.vars,
130
+ parsedTheme = _cssVarsParser.parsedTheme;
131
131
 
132
- mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
132
+ mergedTheme = _extends({}, parsedTheme, {
133
133
  components: components,
134
134
  colorSchemes: colorSchemes,
135
135
  prefix: prefix,
@@ -150,10 +150,15 @@ export default function createCssVarsProvider(options) {
150
150
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
151
151
  }),
152
152
  css = _cssVarsParser2.css,
153
- vars = _cssVarsParser2.vars;
153
+ vars = _cssVarsParser2.vars,
154
+ parsedScheme = _cssVarsParser2.parsedTheme;
154
155
 
155
156
  mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
156
157
 
158
+ if (key === resolvedColorScheme) {
159
+ mergedTheme = _extends({}, mergedTheme, parsedScheme);
160
+ }
161
+
157
162
  var resolvedDefaultColorScheme = function () {
158
163
  if (typeof defaultColorScheme === 'string') {
159
164
  return defaultColorScheme;
@@ -194,7 +199,7 @@ export default function createCssVarsProvider(options) {
194
199
  return function () {
195
200
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
196
201
  };
197
- }, [mode, systemMode]);
202
+ }, [mode, systemMode, enableColorScheme]);
198
203
  React.useEffect(function () {
199
204
  var timer;
200
205
 
@@ -216,7 +221,7 @@ export default function createCssVarsProvider(options) {
216
221
  return function () {
217
222
  clearTimeout(timer);
218
223
  };
219
- }, [colorScheme]);
224
+ }, [colorScheme, disableTransitionOnChange]);
220
225
  React.useEffect(function () {
221
226
  hasMounted.current = true;
222
227
  return function () {
@@ -267,6 +272,16 @@ export default function createCssVarsProvider(options) {
267
272
  */
268
273
  defaultMode: PropTypes.string,
269
274
 
275
+ /**
276
+ * Disable CSS transitions when switching between modes or color schemes
277
+ */
278
+ disableTransitionOnChange: PropTypes.bool,
279
+
280
+ /**
281
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
282
+ */
283
+ enableColorScheme: PropTypes.bool,
284
+
270
285
  /**
271
286
  * The key in the local storage used to store current color scheme.
272
287
  */
@@ -98,19 +98,20 @@ var getCssValue = function getCssValue(keys, value) {
98
98
  * `basePrefix`: defined by design system.
99
99
  * `prefix`: defined by application
100
100
  *
101
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
101
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
102
102
  *
103
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
103
+ * @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.
104
104
  *
105
105
  * @example
106
- * const { css, vars } = parser({
106
+ * const { css, vars, parsedTheme } = parser({
107
107
  * fontSize: 12,
108
108
  * lineHeight: 1.2,
109
- * palette: { primary: { 500: '#000000' } }
110
- * })
109
+ * palette: { primary: { 500: 'var(--color)' } }
110
+ * }, { prefix: 'foo' })
111
111
  *
112
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
113
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
112
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
113
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
114
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
114
115
  */
115
116
 
116
117
 
@@ -123,38 +124,37 @@ export default function cssVarsParser(theme, options) {
123
124
 
124
125
  var css = {};
125
126
  var vars = {};
126
- walkObjectDeep(theme, function (keys, val, scope) {
127
- if (typeof val === 'string' || typeof val === 'number') {
128
- var _value = val;
129
-
130
- if (typeof _value === 'string' && _value.match(/var\(\s*--/)) {
131
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
127
+ var parsedTheme = {};
128
+ walkObjectDeep(theme, function (keys, value) {
129
+ if (typeof value === 'string' || typeof value === 'number') {
130
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
131
+ // for CSS variable, apply prefix or remove basePrefix from the variable
132
132
  if (!basePrefix && prefix) {
133
- _value = _value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
133
+ value = value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
134
134
  } else {
135
- _value = prefix ? _value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
136
- : _value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
137
- } // scope is the deepest object in the tree, keys is the theme path keys
138
-
139
-
140
- scope[keys.slice(-1)[0]] = _value;
135
+ value = prefix ? value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
136
+ : value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
137
+ }
141
138
  }
142
139
 
143
- if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, _value)) {
140
+ if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
144
141
  // only create css & var if `shouldSkipGeneratingVar` return false
145
142
  var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
146
143
 
147
- _extends(css, _defineProperty({}, cssVar, getCssValue(keys, _value)));
144
+ _extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
148
145
 
149
146
  assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
150
147
  }
151
148
  }
149
+
150
+ assignNestedKeys(parsedTheme, keys, value);
152
151
  }, function (keys) {
153
152
  return keys[0] === 'vars';
154
153
  } // skip 'vars/*' paths
155
154
  );
156
155
  return {
157
156
  css: css,
158
- vars: vars
157
+ vars: vars,
158
+ parsedTheme: parsedTheme
159
159
  };
160
160
  }
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.3
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.
@@ -172,7 +172,11 @@ export default function createStyled(input = {}) {
172
172
 
173
173
  transformedStyleArg = [...styleArg, ...placeholders];
174
174
  transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
175
- } else if (typeof styleArg === 'function') {
175
+ } else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
176
+ // component stays as a function. This condition makes sure that we do not interpolate functions
177
+ // which are basically components used as a selectors.
178
+ // eslint-disable-next-line no-underscore-dangle
179
+ styleArg.__emotion_real !== styleArg) {
176
180
  // If the type is function, we need to define the default theme.
177
181
  transformedStyleArg = _ref2 => {
178
182
  let {
@@ -23,8 +23,8 @@ export default function createCssVarsProvider(options) {
23
23
  theme: baseTheme = {},
24
24
  defaultMode: desisgnSystemMode = 'light',
25
25
  defaultColorScheme: designSystemColorScheme,
26
- disableTransitionOnChange = false,
27
- enableColorScheme = true,
26
+ disableTransitionOnChange: designSystemTransitionOnChange = false,
27
+ enableColorScheme: designSystemEnableColorScheme = true,
28
28
  prefix: designSystemPrefix = '',
29
29
  shouldSkipGeneratingVar,
30
30
  resolveTheme
@@ -55,16 +55,14 @@ export default function createCssVarsProvider(options) {
55
55
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
56
56
  attribute = DEFAULT_ATTRIBUTE,
57
57
  defaultMode = desisgnSystemMode,
58
- defaultColorScheme = designSystemColorScheme
58
+ defaultColorScheme = designSystemColorScheme,
59
+ disableTransitionOnChange = designSystemTransitionOnChange,
60
+ enableColorScheme = designSystemEnableColorScheme
59
61
  }) {
60
- // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
61
- // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
62
- const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
63
-
64
62
  const {
65
63
  colorSchemes: baseColorSchemes = {}
66
- } = clonedBaseTheme,
67
- restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
64
+ } = baseTheme,
65
+ restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
68
66
 
69
67
  const {
70
68
  colorSchemes: colorSchemesProp = {}
@@ -115,13 +113,14 @@ export default function createCssVarsProvider(options) {
115
113
 
116
114
  const {
117
115
  css: rootCss,
118
- vars: rootVars
116
+ vars: rootVars,
117
+ parsedTheme
119
118
  } = cssVarsParser(mergedTheme, {
120
119
  prefix,
121
120
  basePrefix: designSystemPrefix,
122
121
  shouldSkipGeneratingVar
123
122
  });
124
- mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
123
+ mergedTheme = _extends({}, parsedTheme, {
125
124
  components,
126
125
  colorSchemes,
127
126
  prefix,
@@ -134,7 +133,8 @@ export default function createCssVarsProvider(options) {
134
133
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
135
134
  const {
136
135
  css,
137
- vars
136
+ vars,
137
+ parsedTheme: parsedScheme
138
138
  } = cssVarsParser(scheme, {
139
139
  prefix,
140
140
  basePrefix: designSystemPrefix,
@@ -142,6 +142,10 @@ export default function createCssVarsProvider(options) {
142
142
  });
143
143
  mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
144
144
 
145
+ if (key === resolvedColorScheme) {
146
+ mergedTheme = _extends({}, mergedTheme, parsedScheme);
147
+ }
148
+
145
149
  const resolvedDefaultColorScheme = (() => {
146
150
  if (typeof defaultColorScheme === 'string') {
147
151
  return defaultColorScheme;
@@ -182,7 +186,7 @@ export default function createCssVarsProvider(options) {
182
186
  return () => {
183
187
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
184
188
  };
185
- }, [mode, systemMode]);
189
+ }, [mode, systemMode, enableColorScheme]);
186
190
  React.useEffect(() => {
187
191
  let timer;
188
192
 
@@ -202,7 +206,7 @@ export default function createCssVarsProvider(options) {
202
206
  return () => {
203
207
  clearTimeout(timer);
204
208
  };
205
- }, [colorScheme]);
209
+ }, [colorScheme, disableTransitionOnChange]);
206
210
  React.useEffect(() => {
207
211
  hasMounted.current = true;
208
212
  return () => {
@@ -253,6 +257,16 @@ export default function createCssVarsProvider(options) {
253
257
  */
254
258
  defaultMode: PropTypes.string,
255
259
 
260
+ /**
261
+ * Disable CSS transitions when switching between modes or color schemes
262
+ */
263
+ disableTransitionOnChange: PropTypes.bool,
264
+
265
+ /**
266
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
267
+ */
268
+ enableColorScheme: PropTypes.bool,
269
+
256
270
  /**
257
271
  * The key in the local storage used to store current color scheme.
258
272
  */
@@ -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,21 +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
-
113
+ const parsedTheme = {};
114
+ walkObjectDeep(theme, (keys, value) => {
115
+ if (typeof value === 'string' || typeof value === 'number') {
116
116
  if (typeof value === 'string' && value.match(/var\(\s*--/)) {
117
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
117
+ // for CSS variable, apply prefix or remove basePrefix from the variable
118
118
  if (!basePrefix && prefix) {
119
119
  value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
120
120
  } else {
121
121
  value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
122
122
  : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
123
- } // scope is the deepest object in the tree, keys is the theme path keys
124
-
125
-
126
- scope[keys.slice(-1)[0]] = value;
123
+ }
127
124
  }
128
125
 
129
126
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -135,10 +132,13 @@ export default function cssVarsParser(theme, options) {
135
132
  assignNestedKeys(vars, keys, `var(${cssVar})`);
136
133
  }
137
134
  }
135
+
136
+ assignNestedKeys(parsedTheme, keys, value);
138
137
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
139
138
  );
140
139
  return {
141
140
  css,
142
- vars
141
+ vars,
142
+ parsedTheme
143
143
  };
144
144
  }
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.3
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.4.3",
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.2",
48
- "@mui/styled-engine": "^5.4.2",
46
+ "@babel/runtime": "^7.17.2",
47
+ "@mui/private-theming": "^5.4.4",
48
+ "@mui/styled-engine": "^5.4.4",
49
49
  "@mui/types": "^7.1.2",
50
- "@mui/utils": "^5.4.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"
@@ -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
  /**
@@ -1 +1 @@
1
- export {};
1
+ export {};