@mui/system 5.10.8 → 5.10.9
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 +117 -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/createGrid.js +1 -1
- package/Unstable_Grid/gridClasses.d.ts +20 -20
- package/Unstable_Grid/gridGenerator.d.ts +28 -26
- package/Unstable_Grid/gridGenerator.js +16 -2
- package/Unstable_Grid/index.d.ts +5 -5
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +0 -5
- package/cssVars/createCssVarsProvider.js +45 -44
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +65 -65
- package/cssVars/getInitColorSchemeScript.d.ts +42 -47
- package/cssVars/getInitColorSchemeScript.js +0 -4
- package/cssVars/index.d.ts +3 -3
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/esm/Unstable_Grid/createGrid.js +2 -2
- package/esm/Unstable_Grid/gridGenerator.js +11 -0
- package/esm/cssVars/createCssVarsProvider.js +47 -45
- package/esm/cssVars/getInitColorSchemeScript.js +0 -4
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/Unstable_Grid/createGrid.js +2 -2
- package/legacy/Unstable_Grid/gridGenerator.js +17 -0
- package/legacy/cssVars/createCssVarsProvider.js +45 -47
- package/legacy/cssVars/getInitColorSchemeScript.js +1 -3
- package/legacy/index.js +1 -1
- package/modern/Unstable_Grid/createGrid.js +2 -2
- package/modern/Unstable_Grid/gridGenerator.js +11 -0
- package/modern/cssVars/createCssVarsProvider.js +47 -45
- package/modern/cssVars/getInitColorSchemeScript.js +0 -4
- package/modern/index.js +1 -1
- package/package.json +3 -3
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -4,7 +4,7 @@ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
|
4
4
|
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import { deepmerge
|
|
7
|
+
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import cssVarsParser from './cssVarsParser';
|
|
10
10
|
import ThemeProvider from '../ThemeProvider';
|
|
@@ -19,10 +19,9 @@ export default function createCssVarsProvider(options) {
|
|
|
19
19
|
attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
|
|
20
20
|
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
21
21
|
colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
22
|
-
defaultMode:
|
|
22
|
+
defaultMode: designSystemMode = 'light',
|
|
23
23
|
defaultColorScheme: designSystemColorScheme,
|
|
24
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
25
|
-
enableColorScheme: designSystemEnableColorScheme = true,
|
|
26
25
|
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
27
26
|
resolveTheme,
|
|
28
27
|
excludeVariablesFromRoot
|
|
@@ -50,10 +49,9 @@ export default function createCssVarsProvider(options) {
|
|
|
50
49
|
modeStorageKey = defaultModeStorageKey,
|
|
51
50
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
52
51
|
attribute = defaultAttribute,
|
|
53
|
-
defaultMode =
|
|
52
|
+
defaultMode = designSystemMode,
|
|
54
53
|
defaultColorScheme = designSystemColorScheme,
|
|
55
54
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
56
|
-
enableColorScheme = designSystemEnableColorScheme,
|
|
57
55
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
58
56
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
59
57
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
@@ -71,7 +69,8 @@ export default function createCssVarsProvider(options) {
|
|
|
71
69
|
|
|
72
70
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
73
71
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
74
|
-
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
72
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
73
|
+
|
|
75
74
|
const {
|
|
76
75
|
mode,
|
|
77
76
|
setMode,
|
|
@@ -90,36 +89,54 @@ export default function createCssVarsProvider(options) {
|
|
|
90
89
|
storageWindow
|
|
91
90
|
});
|
|
92
91
|
|
|
93
|
-
const
|
|
92
|
+
const calculatedMode = (() => {
|
|
93
|
+
if (!mode) {
|
|
94
|
+
// This scope occurs on the server
|
|
95
|
+
if (defaultMode === 'system') {
|
|
96
|
+
return designSystemMode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return defaultMode;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return mode;
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
const calculatedColorScheme = (() => {
|
|
94
106
|
if (!colorScheme) {
|
|
95
107
|
// This scope occurs on the server
|
|
96
|
-
if (
|
|
108
|
+
if (calculatedMode === 'dark') {
|
|
97
109
|
return defaultDarkColorScheme;
|
|
98
|
-
} // use light color scheme, if default mode is 'light' | '
|
|
110
|
+
} // use light color scheme, if default mode is 'light' | 'system'
|
|
99
111
|
|
|
100
112
|
|
|
101
113
|
return defaultLightColorScheme;
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
return colorScheme;
|
|
105
|
-
})();
|
|
117
|
+
})(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
118
|
+
|
|
106
119
|
|
|
107
|
-
let theme = restThemeProp;
|
|
108
120
|
const {
|
|
109
121
|
css: rootCss,
|
|
110
122
|
vars: rootVars,
|
|
111
123
|
parsedTheme
|
|
112
|
-
} = cssVarsParser(
|
|
124
|
+
} = cssVarsParser(restThemeProp, {
|
|
113
125
|
prefix: cssVarPrefix,
|
|
114
126
|
shouldSkipGeneratingVar
|
|
115
|
-
});
|
|
116
|
-
|
|
127
|
+
}); // 3. Start composing the theme object
|
|
128
|
+
|
|
129
|
+
let theme = _extends({}, parsedTheme, {
|
|
117
130
|
components,
|
|
118
131
|
colorSchemes,
|
|
119
132
|
cssVarPrefix,
|
|
120
133
|
vars: rootVars,
|
|
121
134
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
122
|
-
});
|
|
135
|
+
}); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
136
|
+
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
137
|
+
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
138
|
+
|
|
139
|
+
|
|
123
140
|
const defaultColorSchemeStyleSheet = {};
|
|
124
141
|
const otherColorSchemesStyleSheet = {};
|
|
125
142
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -133,13 +150,12 @@ export default function createCssVarsProvider(options) {
|
|
|
133
150
|
});
|
|
134
151
|
theme.vars = deepmerge(theme.vars, vars);
|
|
135
152
|
|
|
136
|
-
if (key ===
|
|
153
|
+
if (key === calculatedColorScheme) {
|
|
154
|
+
// 4.1 Merge the selected color scheme to the theme
|
|
137
155
|
theme = _extends({}, theme, parsedScheme);
|
|
138
156
|
|
|
139
157
|
if (theme.palette) {
|
|
140
|
-
|
|
141
|
-
theme.palette.mode = mode;
|
|
142
|
-
theme.palette.colorScheme = resolvedColorScheme;
|
|
158
|
+
theme.palette.colorScheme = key;
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
|
|
@@ -169,35 +185,21 @@ export default function createCssVarsProvider(options) {
|
|
|
169
185
|
} else {
|
|
170
186
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
171
187
|
}
|
|
172
|
-
});
|
|
188
|
+
}); // 5. Declaring effects
|
|
189
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
190
|
+
|
|
173
191
|
React.useEffect(() => {
|
|
174
192
|
if (colorScheme && colorSchemeNode) {
|
|
175
193
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
176
194
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
177
195
|
}
|
|
178
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
179
|
-
|
|
180
|
-
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
185
|
-
|
|
186
|
-
if (mode === 'system') {
|
|
187
|
-
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
188
|
-
} else {
|
|
189
|
-
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
190
|
-
}
|
|
196
|
+
}, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
197
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
191
198
|
|
|
192
|
-
return () => {
|
|
193
|
-
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
194
|
-
};
|
|
195
|
-
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
196
199
|
React.useEffect(() => {
|
|
197
200
|
let timer;
|
|
198
201
|
|
|
199
202
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
200
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
201
203
|
const css = documentNode.createElement('style');
|
|
202
204
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
203
205
|
documentNode.head.appendChild(css); // Force browser repaint
|
|
@@ -222,6 +224,7 @@ export default function createCssVarsProvider(options) {
|
|
|
222
224
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
223
225
|
value: {
|
|
224
226
|
mode,
|
|
227
|
+
systemMode,
|
|
225
228
|
setMode,
|
|
226
229
|
lightColorScheme,
|
|
227
230
|
darkColorScheme,
|
|
@@ -290,11 +293,6 @@ export default function createCssVarsProvider(options) {
|
|
|
290
293
|
*/
|
|
291
294
|
documentNode: PropTypes.any,
|
|
292
295
|
|
|
293
|
-
/**
|
|
294
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
295
|
-
*/
|
|
296
|
-
enableColorScheme: PropTypes.bool,
|
|
297
|
-
|
|
298
296
|
/**
|
|
299
297
|
* The key in the local storage used to store current color scheme.
|
|
300
298
|
*/
|
|
@@ -316,12 +314,16 @@ export default function createCssVarsProvider(options) {
|
|
|
316
314
|
*/
|
|
317
315
|
theme: PropTypes.object
|
|
318
316
|
} : void 0;
|
|
317
|
+
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
318
|
+
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
319
319
|
|
|
320
320
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
321
321
|
attribute: defaultAttribute,
|
|
322
322
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
defaultMode: designSystemMode,
|
|
324
|
+
defaultLightColorScheme,
|
|
325
|
+
defaultDarkColorScheme,
|
|
326
|
+
modeStorageKey: defaultModeStorageKey
|
|
325
327
|
}, params));
|
|
326
328
|
|
|
327
329
|
return {
|
|
@@ -5,7 +5,6 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
enableColorScheme = true,
|
|
9
8
|
defaultMode = 'light',
|
|
10
9
|
defaultLightColorScheme = 'light',
|
|
11
10
|
defaultDarkColorScheme = 'dark',
|
|
@@ -41,9 +40,6 @@ export default function getInitColorSchemeScript(options) {
|
|
|
41
40
|
if (colorScheme) {
|
|
42
41
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
43
42
|
}
|
|
44
|
-
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
-
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
-
}
|
|
47
43
|
} catch (e) {} })();`
|
|
48
44
|
}
|
|
49
45
|
});
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.19.0",
|
|
47
|
-
"@mui/private-theming": "^5.10.
|
|
47
|
+
"@mui/private-theming": "^5.10.9",
|
|
48
48
|
"@mui/styled-engine": "^5.10.8",
|
|
49
49
|
"@mui/types": "^7.2.0",
|
|
50
|
-
"@mui/utils": "^5.10.
|
|
50
|
+
"@mui/utils": "^5.10.9",
|
|
51
51
|
"clsx": "^1.2.1",
|
|
52
52
|
"csstype": "^3.1.1",
|
|
53
53
|
"prop-types": "^15.8.1"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|