@mui/system 5.10.16 → 5.10.17
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 +74 -0
- package/Container/Container.d.ts +13 -13
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/createContainer.d.ts +18 -18
- package/Stack/Stack.d.ts +13 -13
- package/Stack/StackProps.d.ts +42 -42
- package/Stack/createStack.d.ts +21 -21
- package/Stack/index.d.ts +5 -5
- package/Stack/stackClasses.d.ts +8 -8
- package/Unstable_Grid/Grid.d.ts +12 -12
- package/Unstable_Grid/GridProps.d.ts +162 -162
- package/Unstable_Grid/createGrid.d.ts +11 -11
- package/Unstable_Grid/gridClasses.d.ts +20 -20
- package/Unstable_Grid/gridGenerator.d.ts +29 -29
- package/Unstable_Grid/index.d.ts +5 -5
- package/colorManipulator.d.ts +10 -0
- package/colorManipulator.js +57 -1
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +54 -1
- package/cssVars/createCssVarsProvider.js +47 -13
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +63 -63
- package/cssVars/getInitColorSchemeScript.d.ts +42 -42
- package/cssVars/index.d.ts +3 -3
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/esm/colorManipulator.js +50 -0
- package/esm/cssVars/createCssVarsProvider.js +47 -13
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/colorManipulator.js +50 -0
- package/legacy/cssVars/createCssVarsProvider.js +47 -11
- package/legacy/index.js +1 -1
- package/modern/colorManipulator.js +50 -0
- package/modern/cssVars/createCssVarsProvider.js +47 -13
- package/modern/index.js +1 -1
- package/package.json +1 -1
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -6,6 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
|
+
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
9
10
|
import cssVarsParser from './cssVarsParser';
|
|
10
11
|
import ThemeProvider from '../ThemeProvider';
|
|
11
12
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
@@ -50,9 +51,14 @@ export default function createCssVarsProvider(options) {
|
|
|
50
51
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
51
52
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
52
53
|
colorSchemeSelector = ':root',
|
|
53
|
-
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
54
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
|
|
55
|
+
disableNestedContext = false,
|
|
56
|
+
disableStyleSheetGeneration = false
|
|
54
57
|
}) {
|
|
55
58
|
const hasMounted = React.useRef(false);
|
|
59
|
+
const upperTheme = muiUseTheme();
|
|
60
|
+
const ctx = React.useContext(ColorSchemeContext);
|
|
61
|
+
const nested = !!ctx && !disableNestedContext;
|
|
56
62
|
const {
|
|
57
63
|
colorSchemes = {},
|
|
58
64
|
components = {},
|
|
@@ -65,12 +71,12 @@ export default function createCssVarsProvider(options) {
|
|
|
65
71
|
|
|
66
72
|
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
67
73
|
const {
|
|
68
|
-
mode,
|
|
74
|
+
mode: stateMode,
|
|
69
75
|
setMode,
|
|
70
76
|
systemMode,
|
|
71
77
|
lightColorScheme,
|
|
72
78
|
darkColorScheme,
|
|
73
|
-
colorScheme,
|
|
79
|
+
colorScheme: stateColorScheme,
|
|
74
80
|
setColorScheme
|
|
75
81
|
} = useCurrentColorScheme({
|
|
76
82
|
supportedColorSchemes: allColorSchemes,
|
|
@@ -81,6 +87,12 @@ export default function createCssVarsProvider(options) {
|
|
|
81
87
|
defaultMode,
|
|
82
88
|
storageWindow
|
|
83
89
|
});
|
|
90
|
+
let mode = stateMode;
|
|
91
|
+
let colorScheme = stateColorScheme;
|
|
92
|
+
if (nested) {
|
|
93
|
+
mode = ctx.mode;
|
|
94
|
+
colorScheme = ctx.colorScheme;
|
|
95
|
+
}
|
|
84
96
|
const calculatedMode = (() => {
|
|
85
97
|
if (!mode) {
|
|
86
98
|
// This scope occurs on the server
|
|
@@ -217,21 +229,33 @@ export default function createCssVarsProvider(options) {
|
|
|
217
229
|
setColorScheme,
|
|
218
230
|
allColorSchemes
|
|
219
231
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
let shouldGenerateStyleSheet = true;
|
|
233
|
+
if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
|
|
234
|
+
shouldGenerateStyleSheet = false;
|
|
235
|
+
}
|
|
236
|
+
const element = /*#__PURE__*/_jsxs(React.Fragment, {
|
|
237
|
+
children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
238
|
+
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
239
|
+
styles: {
|
|
240
|
+
[colorSchemeSelector]: rootCss
|
|
241
|
+
}
|
|
242
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
243
|
+
styles: defaultColorSchemeStyleSheet
|
|
244
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
245
|
+
styles: otherColorSchemesStyleSheet
|
|
246
|
+
})]
|
|
230
247
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
231
248
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
232
249
|
children: children
|
|
233
250
|
})]
|
|
234
251
|
});
|
|
252
|
+
if (nested) {
|
|
253
|
+
return element;
|
|
254
|
+
}
|
|
255
|
+
return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
|
|
256
|
+
value: contextValue,
|
|
257
|
+
children: element
|
|
258
|
+
});
|
|
235
259
|
}
|
|
236
260
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
237
261
|
/**
|
|
@@ -262,6 +286,16 @@ export default function createCssVarsProvider(options) {
|
|
|
262
286
|
* The initial mode used.
|
|
263
287
|
*/
|
|
264
288
|
defaultMode: PropTypes.string,
|
|
289
|
+
/**
|
|
290
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
291
|
+
*/
|
|
292
|
+
disableNestedContext: PropTypes.bool,
|
|
293
|
+
/**
|
|
294
|
+
* If `true`, the style sheet won't be generated.
|
|
295
|
+
*
|
|
296
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
297
|
+
*/
|
|
298
|
+
disableStyleSheetGeneration: PropTypes.bool,
|
|
265
299
|
/**
|
|
266
300
|
* Disable CSS transitions when switching between modes or color schemes
|
|
267
301
|
*/
|
package/index.js
CHANGED
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -96,6 +96,16 @@ export var colorChannel = function colorChannel(color) {
|
|
|
96
96
|
return decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? "".concat(val, "%") : val;
|
|
97
97
|
}).join(' ');
|
|
98
98
|
};
|
|
99
|
+
export var private_safeColorChannel = function private_safeColorChannel(color, warning) {
|
|
100
|
+
try {
|
|
101
|
+
return colorChannel(color);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
104
|
+
console.warn(warning);
|
|
105
|
+
}
|
|
106
|
+
return color;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
99
109
|
|
|
100
110
|
/**
|
|
101
111
|
* Converts a color object with type and values to a string.
|
|
@@ -227,6 +237,16 @@ export function alpha(color, value) {
|
|
|
227
237
|
}
|
|
228
238
|
return recomposeColor(color);
|
|
229
239
|
}
|
|
240
|
+
export function private_safeAlpha(color, value, warning) {
|
|
241
|
+
try {
|
|
242
|
+
return alpha(color, value);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
245
|
+
console.warn(warning);
|
|
246
|
+
}
|
|
247
|
+
return color;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
230
250
|
|
|
231
251
|
/**
|
|
232
252
|
* Darkens a color.
|
|
@@ -246,6 +266,16 @@ export function darken(color, coefficient) {
|
|
|
246
266
|
}
|
|
247
267
|
return recomposeColor(color);
|
|
248
268
|
}
|
|
269
|
+
export function private_safeDarken(color, coefficient, warning) {
|
|
270
|
+
try {
|
|
271
|
+
return darken(color, coefficient);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
274
|
+
console.warn(warning);
|
|
275
|
+
}
|
|
276
|
+
return color;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
249
279
|
|
|
250
280
|
/**
|
|
251
281
|
* Lightens a color.
|
|
@@ -269,6 +299,16 @@ export function lighten(color, coefficient) {
|
|
|
269
299
|
}
|
|
270
300
|
return recomposeColor(color);
|
|
271
301
|
}
|
|
302
|
+
export function private_safeLighten(color, coefficient, warning) {
|
|
303
|
+
try {
|
|
304
|
+
return lighten(color, coefficient);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
307
|
+
console.warn(warning);
|
|
308
|
+
}
|
|
309
|
+
return color;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
272
312
|
|
|
273
313
|
/**
|
|
274
314
|
* Darken or lighten a color, depending on its luminance.
|
|
@@ -280,4 +320,14 @@ export function lighten(color, coefficient) {
|
|
|
280
320
|
export function emphasize(color) {
|
|
281
321
|
var coefficient = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.15;
|
|
282
322
|
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
323
|
+
}
|
|
324
|
+
export function private_safeEmphasize(color, coefficient, warning) {
|
|
325
|
+
try {
|
|
326
|
+
return private_safeEmphasize(color, coefficient);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
329
|
+
console.warn(warning);
|
|
330
|
+
}
|
|
331
|
+
return color;
|
|
332
|
+
}
|
|
283
333
|
}
|
|
@@ -8,6 +8,7 @@ import * as React from 'react';
|
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import { deepmerge } from '@mui/utils';
|
|
10
10
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
11
|
+
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
11
12
|
import cssVarsParser from './cssVarsParser';
|
|
12
13
|
import ThemeProvider from '../ThemeProvider';
|
|
13
14
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
@@ -68,8 +69,15 @@ export default function createCssVarsProvider(options) {
|
|
|
68
69
|
_ref$colorSchemeSelec = _ref.colorSchemeSelector,
|
|
69
70
|
colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec,
|
|
70
71
|
_ref$shouldSkipGenera = _ref.shouldSkipGeneratingVar,
|
|
71
|
-
shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera
|
|
72
|
+
shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera,
|
|
73
|
+
_ref$disableNestedCon = _ref.disableNestedContext,
|
|
74
|
+
disableNestedContext = _ref$disableNestedCon === void 0 ? false : _ref$disableNestedCon,
|
|
75
|
+
_ref$disableStyleShee = _ref.disableStyleSheetGeneration,
|
|
76
|
+
disableStyleSheetGeneration = _ref$disableStyleShee === void 0 ? false : _ref$disableStyleShee;
|
|
72
77
|
var hasMounted = React.useRef(false);
|
|
78
|
+
var upperTheme = muiUseTheme();
|
|
79
|
+
var ctx = React.useContext(ColorSchemeContext);
|
|
80
|
+
var nested = !!ctx && !disableNestedContext;
|
|
73
81
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
74
82
|
colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
75
83
|
_themeProp$components = themeProp.components,
|
|
@@ -90,13 +98,19 @@ export default function createCssVarsProvider(options) {
|
|
|
90
98
|
defaultMode: defaultMode,
|
|
91
99
|
storageWindow: storageWindow
|
|
92
100
|
}),
|
|
93
|
-
|
|
101
|
+
stateMode = _useCurrentColorSchem.mode,
|
|
94
102
|
setMode = _useCurrentColorSchem.setMode,
|
|
95
103
|
systemMode = _useCurrentColorSchem.systemMode,
|
|
96
104
|
lightColorScheme = _useCurrentColorSchem.lightColorScheme,
|
|
97
105
|
darkColorScheme = _useCurrentColorSchem.darkColorScheme,
|
|
98
|
-
|
|
106
|
+
stateColorScheme = _useCurrentColorSchem.colorScheme,
|
|
99
107
|
setColorScheme = _useCurrentColorSchem.setColorScheme;
|
|
108
|
+
var mode = stateMode;
|
|
109
|
+
var colorScheme = stateColorScheme;
|
|
110
|
+
if (nested) {
|
|
111
|
+
mode = ctx.mode;
|
|
112
|
+
colorScheme = ctx.colorScheme;
|
|
113
|
+
}
|
|
100
114
|
var calculatedMode = function () {
|
|
101
115
|
if (!mode) {
|
|
102
116
|
// This scope occurs on the server
|
|
@@ -238,19 +252,31 @@ export default function createCssVarsProvider(options) {
|
|
|
238
252
|
allColorSchemes: allColorSchemes
|
|
239
253
|
};
|
|
240
254
|
}, [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
255
|
+
var shouldGenerateStyleSheet = true;
|
|
256
|
+
if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
|
|
257
|
+
shouldGenerateStyleSheet = false;
|
|
258
|
+
}
|
|
259
|
+
var element = /*#__PURE__*/_jsxs(React.Fragment, {
|
|
260
|
+
children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
261
|
+
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
262
|
+
styles: _defineProperty({}, colorSchemeSelector, rootCss)
|
|
263
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
264
|
+
styles: defaultColorSchemeStyleSheet
|
|
265
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
266
|
+
styles: otherColorSchemesStyleSheet
|
|
267
|
+
})]
|
|
249
268
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
250
269
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
251
270
|
children: children
|
|
252
271
|
})]
|
|
253
272
|
});
|
|
273
|
+
if (nested) {
|
|
274
|
+
return element;
|
|
275
|
+
}
|
|
276
|
+
return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
|
|
277
|
+
value: contextValue,
|
|
278
|
+
children: element
|
|
279
|
+
});
|
|
254
280
|
}
|
|
255
281
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
256
282
|
/**
|
|
@@ -281,6 +307,16 @@ export default function createCssVarsProvider(options) {
|
|
|
281
307
|
* The initial mode used.
|
|
282
308
|
*/
|
|
283
309
|
defaultMode: PropTypes.string,
|
|
310
|
+
/**
|
|
311
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
312
|
+
*/
|
|
313
|
+
disableNestedContext: PropTypes.bool,
|
|
314
|
+
/**
|
|
315
|
+
* If `true`, the style sheet won't be generated.
|
|
316
|
+
*
|
|
317
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
318
|
+
*/
|
|
319
|
+
disableStyleSheetGeneration: PropTypes.bool,
|
|
284
320
|
/**
|
|
285
321
|
* Disable CSS transitions when switching between modes or color schemes
|
|
286
322
|
*/
|
package/legacy/index.js
CHANGED
|
@@ -90,6 +90,16 @@ export const colorChannel = color => {
|
|
|
90
90
|
const decomposedColor = decomposeColor(color);
|
|
91
91
|
return decomposedColor.values.slice(0, 3).map((val, idx) => decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? `${val}%` : val).join(' ');
|
|
92
92
|
};
|
|
93
|
+
export const private_safeColorChannel = (color, warning) => {
|
|
94
|
+
try {
|
|
95
|
+
return colorChannel(color);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
98
|
+
console.warn(warning);
|
|
99
|
+
}
|
|
100
|
+
return color;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
93
103
|
|
|
94
104
|
/**
|
|
95
105
|
* Converts a color object with type and values to a string.
|
|
@@ -220,6 +230,16 @@ export function alpha(color, value) {
|
|
|
220
230
|
}
|
|
221
231
|
return recomposeColor(color);
|
|
222
232
|
}
|
|
233
|
+
export function private_safeAlpha(color, value, warning) {
|
|
234
|
+
try {
|
|
235
|
+
return alpha(color, value);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
238
|
+
console.warn(warning);
|
|
239
|
+
}
|
|
240
|
+
return color;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
223
243
|
|
|
224
244
|
/**
|
|
225
245
|
* Darkens a color.
|
|
@@ -239,6 +259,16 @@ export function darken(color, coefficient) {
|
|
|
239
259
|
}
|
|
240
260
|
return recomposeColor(color);
|
|
241
261
|
}
|
|
262
|
+
export function private_safeDarken(color, coefficient, warning) {
|
|
263
|
+
try {
|
|
264
|
+
return darken(color, coefficient);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
267
|
+
console.warn(warning);
|
|
268
|
+
}
|
|
269
|
+
return color;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
242
272
|
|
|
243
273
|
/**
|
|
244
274
|
* Lightens a color.
|
|
@@ -262,6 +292,16 @@ export function lighten(color, coefficient) {
|
|
|
262
292
|
}
|
|
263
293
|
return recomposeColor(color);
|
|
264
294
|
}
|
|
295
|
+
export function private_safeLighten(color, coefficient, warning) {
|
|
296
|
+
try {
|
|
297
|
+
return lighten(color, coefficient);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
300
|
+
console.warn(warning);
|
|
301
|
+
}
|
|
302
|
+
return color;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
265
305
|
|
|
266
306
|
/**
|
|
267
307
|
* Darken or lighten a color, depending on its luminance.
|
|
@@ -272,4 +312,14 @@ export function lighten(color, coefficient) {
|
|
|
272
312
|
*/
|
|
273
313
|
export function emphasize(color, coefficient = 0.15) {
|
|
274
314
|
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
315
|
+
}
|
|
316
|
+
export function private_safeEmphasize(color, coefficient, warning) {
|
|
317
|
+
try {
|
|
318
|
+
return private_safeEmphasize(color, coefficient);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
321
|
+
console.warn(warning);
|
|
322
|
+
}
|
|
323
|
+
return color;
|
|
324
|
+
}
|
|
275
325
|
}
|
|
@@ -6,6 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
|
+
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
9
10
|
import cssVarsParser from './cssVarsParser';
|
|
10
11
|
import ThemeProvider from '../ThemeProvider';
|
|
11
12
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
@@ -50,9 +51,14 @@ export default function createCssVarsProvider(options) {
|
|
|
50
51
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
51
52
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
52
53
|
colorSchemeSelector = ':root',
|
|
53
|
-
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
54
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
|
|
55
|
+
disableNestedContext = false,
|
|
56
|
+
disableStyleSheetGeneration = false
|
|
54
57
|
}) {
|
|
55
58
|
const hasMounted = React.useRef(false);
|
|
59
|
+
const upperTheme = muiUseTheme();
|
|
60
|
+
const ctx = React.useContext(ColorSchemeContext);
|
|
61
|
+
const nested = !!ctx && !disableNestedContext;
|
|
56
62
|
const {
|
|
57
63
|
colorSchemes = {},
|
|
58
64
|
components = {},
|
|
@@ -65,12 +71,12 @@ export default function createCssVarsProvider(options) {
|
|
|
65
71
|
|
|
66
72
|
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
67
73
|
const {
|
|
68
|
-
mode,
|
|
74
|
+
mode: stateMode,
|
|
69
75
|
setMode,
|
|
70
76
|
systemMode,
|
|
71
77
|
lightColorScheme,
|
|
72
78
|
darkColorScheme,
|
|
73
|
-
colorScheme,
|
|
79
|
+
colorScheme: stateColorScheme,
|
|
74
80
|
setColorScheme
|
|
75
81
|
} = useCurrentColorScheme({
|
|
76
82
|
supportedColorSchemes: allColorSchemes,
|
|
@@ -81,6 +87,12 @@ export default function createCssVarsProvider(options) {
|
|
|
81
87
|
defaultMode,
|
|
82
88
|
storageWindow
|
|
83
89
|
});
|
|
90
|
+
let mode = stateMode;
|
|
91
|
+
let colorScheme = stateColorScheme;
|
|
92
|
+
if (nested) {
|
|
93
|
+
mode = ctx.mode;
|
|
94
|
+
colorScheme = ctx.colorScheme;
|
|
95
|
+
}
|
|
84
96
|
const calculatedMode = (() => {
|
|
85
97
|
if (!mode) {
|
|
86
98
|
// This scope occurs on the server
|
|
@@ -217,21 +229,33 @@ export default function createCssVarsProvider(options) {
|
|
|
217
229
|
setColorScheme,
|
|
218
230
|
allColorSchemes
|
|
219
231
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
let shouldGenerateStyleSheet = true;
|
|
233
|
+
if (disableStyleSheetGeneration || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
|
|
234
|
+
shouldGenerateStyleSheet = false;
|
|
235
|
+
}
|
|
236
|
+
const element = /*#__PURE__*/_jsxs(React.Fragment, {
|
|
237
|
+
children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
238
|
+
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
239
|
+
styles: {
|
|
240
|
+
[colorSchemeSelector]: rootCss
|
|
241
|
+
}
|
|
242
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
243
|
+
styles: defaultColorSchemeStyleSheet
|
|
244
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
245
|
+
styles: otherColorSchemesStyleSheet
|
|
246
|
+
})]
|
|
230
247
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
231
248
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
232
249
|
children: children
|
|
233
250
|
})]
|
|
234
251
|
});
|
|
252
|
+
if (nested) {
|
|
253
|
+
return element;
|
|
254
|
+
}
|
|
255
|
+
return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
|
|
256
|
+
value: contextValue,
|
|
257
|
+
children: element
|
|
258
|
+
});
|
|
235
259
|
}
|
|
236
260
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
237
261
|
/**
|
|
@@ -262,6 +286,16 @@ export default function createCssVarsProvider(options) {
|
|
|
262
286
|
* The initial mode used.
|
|
263
287
|
*/
|
|
264
288
|
defaultMode: PropTypes.string,
|
|
289
|
+
/**
|
|
290
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
291
|
+
*/
|
|
292
|
+
disableNestedContext: PropTypes.bool,
|
|
293
|
+
/**
|
|
294
|
+
* If `true`, the style sheet won't be generated.
|
|
295
|
+
*
|
|
296
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
297
|
+
*/
|
|
298
|
+
disableStyleSheetGeneration: PropTypes.bool,
|
|
265
299
|
/**
|
|
266
300
|
* Disable CSS transitions when switching between modes or color schemes
|
|
267
301
|
*/
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|