@mui/system 5.2.1 → 5.2.2
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/CHANGELOG.md +65 -1
- package/cssVars/createCssVarsProvider.d.ts +11 -1
- package/cssVars/createCssVarsProvider.js +60 -4
- package/cssVars/cssVarsParser.js +1 -1
- package/esm/cssVars/createCssVarsProvider.js +57 -4
- package/esm/cssVars/cssVarsParser.js +1 -1
- package/index.js +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +58 -3
- package/legacy/cssVars/cssVarsParser.js +1 -1
- package/legacy/index.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +57 -4
- package/modern/cssVars/cssVarsParser.js +1 -1
- package/modern/index.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
### [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.2.2
|
|
4
|
+
|
|
5
|
+
<!-- generated comparing v5.2.1..master -->
|
|
6
|
+
|
|
7
|
+
_Nov 29, 2021_
|
|
8
|
+
|
|
9
|
+
A big thanks to the 9 contributors who made this release possible. Here are some highlights ✨:
|
|
10
|
+
|
|
11
|
+
- ♿️ Improved accessibility of `Snackbar` and `TextField` in `@mui/material` (#29782) (#29850) (#29852) @eps1lon.
|
|
12
|
+
- 🎉 Added support for `sx` syntax inside `styled()` utility (#29833) @mnajdova.
|
|
13
|
+
- 🎉 Added support for more options for `createCssVarsProvider` in `@mui/system` (#29845) (#29857) @hbjORbj.
|
|
14
|
+
- And many more 🐛 bug fixes and 📚 improvements.
|
|
15
|
+
|
|
16
|
+
### `@mui/material@5.2.2`
|
|
17
|
+
|
|
18
|
+
- ​<!-- 14 -->[MenuList] Add component prop (#29882) @Harshikerfuffle
|
|
19
|
+
- ​<!-- 13 -->[Snackbar] Interrupt auto-hide on keyboard interaction (#29852) @eps1lon
|
|
20
|
+
- ​<!-- 12 -->[Snackbar] Dismiss on Escape press (#29850) @eps1lon
|
|
21
|
+
- ​<!-- 06 -->[TextField] Associate accessible name and description by default (#29782) @eps1lon
|
|
22
|
+
|
|
23
|
+
### `@mui/joy@5.0.0-alpha.4`
|
|
24
|
+
|
|
25
|
+
- ​<!-- 15 -->[Joy] Add `Button` - 1st iteration (#29464) @siriwatknp
|
|
26
|
+
|
|
27
|
+
### `@mui/codemod@5.2.1`
|
|
28
|
+
|
|
29
|
+
- ​<!-- 28 -->[codemod] Fix alias import for box-sx-prop (#29902) @siriwatknp
|
|
30
|
+
|
|
31
|
+
### `@mui/system@5.2.2`
|
|
32
|
+
|
|
33
|
+
- ​<!-- 11 -->[system] CSSVarsProvider cleans up `html[style]` when unmounting (#29946) @eps1lon
|
|
34
|
+
- ​<!-- 10 -->[system] Add support for `disableTransitionOnChange` in `createCssVarsProvider` (#29857) @hbjORbj
|
|
35
|
+
- ​<!-- 09 -->[system] Add support for `enableColorScheme` in `createCssVarsProvider` (#29845) @hbjORbj
|
|
36
|
+
|
|
37
|
+
### `@mui/utils@5.2.2`
|
|
38
|
+
|
|
39
|
+
- ​<!-- 05 -->[useId] Trade random collisions for collisions on overflow (#29781) @eps1lon
|
|
40
|
+
- ​<!-- 04 -->[useIsFocusVisible] Convert to TypeScript (#29779) @eps1lon
|
|
41
|
+
|
|
42
|
+
### Docs
|
|
43
|
+
|
|
44
|
+
- ​<!-- 24 -->[docs] Fix v5-beta confusing example description (#29932) @oliviertassinari
|
|
45
|
+
- ​<!-- 23 -->[docs] Apply the z-index on the right DOM element (#29934) @oliviertassinari
|
|
46
|
+
- ​<!-- 22 -->[docs] Improve git diff format (#29935) @oliviertassinari
|
|
47
|
+
- ​<!-- 21 -->[docs] Fix typo (#29866) @sinclairity
|
|
48
|
+
- ​<!-- 20 -->[docs] Fix key display (#29933) @oliviertassinari
|
|
49
|
+
- ​<!-- 19 -->[docs] Fix outdated link to next/link docs (#29937) @radlinskii
|
|
50
|
+
- ​<!-- 18 -->[docs] Add how to pass `sx` prop (#29905) @siriwatknp
|
|
51
|
+
- ​<!-- 17 -->[docs] Fix typo in notifications @mbrookes
|
|
52
|
+
- ​<!-- 16 -->[docs] Black Friday sale notification @mbrookes
|
|
53
|
+
- ​<!-- 03 -->[website] Fix canonical links (#29938) @oliviertassinari
|
|
54
|
+
- ​<!-- 02 -->[website] Fix SEO issues (#29939) @oliviertassinari
|
|
55
|
+
- ​<!-- 01 -->[website] Improvements to the /x product page (#28964) @danilo-leal
|
|
56
|
+
|
|
57
|
+
### Core
|
|
58
|
+
|
|
59
|
+
- ​<!-- 27 -->[core] Remove dead code (#29940) @oliviertassinari
|
|
60
|
+
- ​<!-- 26 -->[core] Move benchmark CI job from AZP to CircleCI (#29894) @eps1lon
|
|
61
|
+
- ​<!-- 25 -->[core] Fix PR detection pattern in test_bundle_size_monitor (#29895) @eps1lon
|
|
62
|
+
- ​<!-- 08 -->[test] Fix browser tests (#29929) @eps1lon
|
|
63
|
+
- ​<!-- 07 -->[test] Reject shorthand properties in style matchers (#29893) @eps1lon
|
|
64
|
+
|
|
65
|
+
All contributors of this release in alphabetical order: @danilo-leal, @eps1lon, @Harshikerfuffle, @hbjORbj, @mbrookes, @oliviertassinari, @radlinskii, @sinclairity, @siriwatknp
|
|
66
|
+
|
|
3
67
|
## 5.2.1
|
|
4
68
|
|
|
5
69
|
<!-- generated comparing v5.2.0..master -->
|
|
@@ -2004,7 +2068,7 @@ _May 31, 2021_
|
|
|
2004
2068
|
A big thanks to the 14 contributors who made this release possible. Here are some highlights ✨:
|
|
2005
2069
|
|
|
2006
2070
|
- 👩🎤 We have completed the migration to emotion of all the components (`@material-ui/core` and `@material-ui/lab`) @siriwatknp, @mnajdova.
|
|
2007
|
-
- 📦 Save [10 kB gzipped](https://bundlephobia.com/
|
|
2071
|
+
- 📦 Save [10 kB gzipped](https://bundlephobia.com/package/@material-ui/core@5.0.0-alpha.34) by removing the dependency on `@material-ui/styles` (JSS) from the core and the lab (#26377, #26382, #26376) @mnajdova.
|
|
2008
2072
|
- ⚒️ Add many new [codemods](https://github.com/mui-org/material-ui/blob/HEAD/packages/mui-codemod/README.md) to automate the migration from v4 to v5 (#24867) @mbrookes.
|
|
2009
2073
|
- And many more 🐛 bug fixes and 📚 improvements.
|
|
2010
2074
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Mode, Result } from './useCurrentColorScheme';
|
|
3
3
|
|
|
4
4
|
type RequiredDeep<T> = {
|
|
5
5
|
[K in keyof T]-?: RequiredDeep<T[K]>;
|
|
@@ -70,6 +70,16 @@ export default function createCssVarsProvider<
|
|
|
70
70
|
* @default 'light'
|
|
71
71
|
*/
|
|
72
72
|
defaultMode?: Mode;
|
|
73
|
+
/**
|
|
74
|
+
* Disable CSS transitions when switching between modes or color schemes
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
disableTransitionOnChange?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
enableColorScheme?: boolean;
|
|
73
83
|
/**
|
|
74
84
|
* CSS variable prefix
|
|
75
85
|
* @default ''
|
|
@@ -5,6 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.DISABLE_CSS_TRANSITION = void 0;
|
|
8
9
|
exports.default = createCssVarsProvider;
|
|
9
10
|
|
|
10
11
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
@@ -30,17 +31,23 @@ var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorSc
|
|
|
30
31
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
31
32
|
|
|
32
33
|
const _excluded = ["colorSchemes"],
|
|
33
|
-
_excluded2 = ["colorSchemes"]
|
|
34
|
+
_excluded2 = ["colorSchemes"],
|
|
35
|
+
_excluded3 = ["components"];
|
|
34
36
|
|
|
35
37
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
36
38
|
|
|
37
39
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
38
40
|
|
|
41
|
+
const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
42
|
+
exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
|
|
43
|
+
|
|
39
44
|
function createCssVarsProvider(options) {
|
|
40
45
|
const {
|
|
41
46
|
theme: baseTheme = {},
|
|
42
47
|
defaultMode: desisgnSystemMode = 'light',
|
|
43
48
|
defaultColorScheme: designSystemColorScheme,
|
|
49
|
+
disableTransitionOnChange = false,
|
|
50
|
+
enableColorScheme = true,
|
|
44
51
|
prefix: designSystemPrefix = '',
|
|
45
52
|
shouldSkipGeneratingVar
|
|
46
53
|
} = options;
|
|
@@ -78,7 +85,14 @@ function createCssVarsProvider(options) {
|
|
|
78
85
|
colorSchemes: colorSchemesProp = {}
|
|
79
86
|
} = themeProp,
|
|
80
87
|
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded2);
|
|
81
|
-
|
|
88
|
+
const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
89
|
+
|
|
90
|
+
let _deepmerge = (0, _utils.deepmerge)(restBaseTheme, restThemeProp),
|
|
91
|
+
{
|
|
92
|
+
components = {}
|
|
93
|
+
} = _deepmerge,
|
|
94
|
+
mergedTheme = (0, _objectWithoutPropertiesLoose2.default)(_deepmerge, _excluded3);
|
|
95
|
+
|
|
82
96
|
const colorSchemes = (0, _utils.deepmerge)(baseColorSchemes, colorSchemesProp);
|
|
83
97
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
84
98
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -86,6 +100,7 @@ function createCssVarsProvider(options) {
|
|
|
86
100
|
const {
|
|
87
101
|
mode,
|
|
88
102
|
setMode,
|
|
103
|
+
systemMode,
|
|
89
104
|
lightColorScheme,
|
|
90
105
|
darkColorScheme,
|
|
91
106
|
colorScheme,
|
|
@@ -121,6 +136,7 @@ function createCssVarsProvider(options) {
|
|
|
121
136
|
shouldSkipGeneratingVar
|
|
122
137
|
});
|
|
123
138
|
mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
139
|
+
components,
|
|
124
140
|
colorSchemes,
|
|
125
141
|
vars: rootVars
|
|
126
142
|
});
|
|
@@ -159,6 +175,46 @@ function createCssVarsProvider(options) {
|
|
|
159
175
|
document.body.setAttribute(attribute, colorScheme);
|
|
160
176
|
}
|
|
161
177
|
}, [colorScheme, attribute]);
|
|
178
|
+
React.useEffect(() => {
|
|
179
|
+
if (!mode || !enableColorScheme) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
184
|
+
|
|
185
|
+
if (mode === 'system') {
|
|
186
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
187
|
+
} else {
|
|
188
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return () => {
|
|
192
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
193
|
+
};
|
|
194
|
+
}, [mode, systemMode]);
|
|
195
|
+
React.useEffect(() => {
|
|
196
|
+
let timer;
|
|
197
|
+
|
|
198
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
199
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
200
|
+
const css = document.createElement('style');
|
|
201
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
202
|
+
document.head.appendChild(css); // Force browser repaint
|
|
203
|
+
|
|
204
|
+
(() => window.getComputedStyle(document.body))();
|
|
205
|
+
|
|
206
|
+
timer = setTimeout(() => {
|
|
207
|
+
document.head.removeChild(css);
|
|
208
|
+
}, 1);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return () => {
|
|
212
|
+
clearTimeout(timer);
|
|
213
|
+
};
|
|
214
|
+
}, [colorScheme]);
|
|
215
|
+
React.useEffect(() => {
|
|
216
|
+
hasMounted.current = true;
|
|
217
|
+
}, []);
|
|
162
218
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ColorSchemeContext.Provider, {
|
|
163
219
|
value: {
|
|
164
220
|
mode,
|
|
@@ -189,7 +245,7 @@ function createCssVarsProvider(options) {
|
|
|
189
245
|
attribute: _propTypes.default.string,
|
|
190
246
|
|
|
191
247
|
/**
|
|
192
|
-
*
|
|
248
|
+
* The component tree.
|
|
193
249
|
*/
|
|
194
250
|
children: _propTypes.default.node,
|
|
195
251
|
|
|
@@ -209,7 +265,7 @@ function createCssVarsProvider(options) {
|
|
|
209
265
|
modeStorageKey: _propTypes.default.string,
|
|
210
266
|
|
|
211
267
|
/**
|
|
212
|
-
*
|
|
268
|
+
* CSS variable prefix.
|
|
213
269
|
*/
|
|
214
270
|
prefix: _propTypes.default.string,
|
|
215
271
|
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -80,7 +80,7 @@ exports.walkObjectDeep = walkObjectDeep;
|
|
|
80
80
|
const getCssValue = (keys, value) => {
|
|
81
81
|
if (typeof value === 'number') {
|
|
82
82
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
|
|
83
|
-
//
|
|
83
|
+
// CSS property that are unitless
|
|
84
84
|
return value;
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -2,7 +2,8 @@ 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';
|
|
@@ -13,11 +14,14 @@ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY }
|
|
|
13
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
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
18
|
export default function createCssVarsProvider(options) {
|
|
17
19
|
const {
|
|
18
20
|
theme: baseTheme = {},
|
|
19
21
|
defaultMode: desisgnSystemMode = 'light',
|
|
20
22
|
defaultColorScheme: designSystemColorScheme,
|
|
23
|
+
disableTransitionOnChange = false,
|
|
24
|
+
enableColorScheme = true,
|
|
21
25
|
prefix: designSystemPrefix = '',
|
|
22
26
|
shouldSkipGeneratingVar
|
|
23
27
|
} = options;
|
|
@@ -57,7 +61,14 @@ export default function createCssVarsProvider(options) {
|
|
|
57
61
|
} = themeProp,
|
|
58
62
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
65
|
+
|
|
66
|
+
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
67
|
+
{
|
|
68
|
+
components = {}
|
|
69
|
+
} = _deepmerge,
|
|
70
|
+
mergedTheme = _objectWithoutPropertiesLoose(_deepmerge, _excluded3);
|
|
71
|
+
|
|
61
72
|
const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
62
73
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
63
74
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -65,6 +76,7 @@ export default function createCssVarsProvider(options) {
|
|
|
65
76
|
const {
|
|
66
77
|
mode,
|
|
67
78
|
setMode,
|
|
79
|
+
systemMode,
|
|
68
80
|
lightColorScheme,
|
|
69
81
|
darkColorScheme,
|
|
70
82
|
colorScheme,
|
|
@@ -100,6 +112,7 @@ export default function createCssVarsProvider(options) {
|
|
|
100
112
|
shouldSkipGeneratingVar
|
|
101
113
|
});
|
|
102
114
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
115
|
+
components,
|
|
103
116
|
colorSchemes,
|
|
104
117
|
vars: rootVars
|
|
105
118
|
});
|
|
@@ -138,6 +151,46 @@ export default function createCssVarsProvider(options) {
|
|
|
138
151
|
document.body.setAttribute(attribute, colorScheme);
|
|
139
152
|
}
|
|
140
153
|
}, [colorScheme, attribute]);
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
if (!mode || !enableColorScheme) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
160
|
+
|
|
161
|
+
if (mode === 'system') {
|
|
162
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
163
|
+
} else {
|
|
164
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return () => {
|
|
168
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
169
|
+
};
|
|
170
|
+
}, [mode, systemMode]);
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
let timer;
|
|
173
|
+
|
|
174
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
175
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
176
|
+
const css = document.createElement('style');
|
|
177
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
178
|
+
document.head.appendChild(css); // Force browser repaint
|
|
179
|
+
|
|
180
|
+
(() => window.getComputedStyle(document.body))();
|
|
181
|
+
|
|
182
|
+
timer = setTimeout(() => {
|
|
183
|
+
document.head.removeChild(css);
|
|
184
|
+
}, 1);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return () => {
|
|
188
|
+
clearTimeout(timer);
|
|
189
|
+
};
|
|
190
|
+
}, [colorScheme]);
|
|
191
|
+
React.useEffect(() => {
|
|
192
|
+
hasMounted.current = true;
|
|
193
|
+
}, []);
|
|
141
194
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
142
195
|
value: {
|
|
143
196
|
mode,
|
|
@@ -168,7 +221,7 @@ export default function createCssVarsProvider(options) {
|
|
|
168
221
|
attribute: PropTypes.string,
|
|
169
222
|
|
|
170
223
|
/**
|
|
171
|
-
*
|
|
224
|
+
* The component tree.
|
|
172
225
|
*/
|
|
173
226
|
children: PropTypes.node,
|
|
174
227
|
|
|
@@ -188,7 +241,7 @@ export default function createCssVarsProvider(options) {
|
|
|
188
241
|
modeStorageKey: PropTypes.string,
|
|
189
242
|
|
|
190
243
|
/**
|
|
191
|
-
*
|
|
244
|
+
* CSS variable prefix.
|
|
192
245
|
*/
|
|
193
246
|
prefix: PropTypes.string,
|
|
194
247
|
|
|
@@ -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
|
|
package/index.js
CHANGED
|
@@ -13,12 +13,17 @@ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY }
|
|
|
13
13
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
16
17
|
export default function createCssVarsProvider(options) {
|
|
17
18
|
var _options$theme = options.theme,
|
|
18
19
|
baseTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
19
20
|
_options$defaultMode = options.defaultMode,
|
|
20
21
|
desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
21
22
|
designSystemColorScheme = options.defaultColorScheme,
|
|
23
|
+
_options$disableTrans = options.disableTransitionOnChange,
|
|
24
|
+
disableTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
25
|
+
_options$enableColorS = options.enableColorScheme,
|
|
26
|
+
enableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
|
|
22
27
|
_options$prefix = options.prefix,
|
|
23
28
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
24
29
|
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
|
|
@@ -62,7 +67,13 @@ export default function createCssVarsProvider(options) {
|
|
|
62
67
|
colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
63
68
|
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes"]);
|
|
64
69
|
|
|
65
|
-
var
|
|
70
|
+
var hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
71
|
+
|
|
72
|
+
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
73
|
+
_deepmerge$components = _deepmerge.components,
|
|
74
|
+
components = _deepmerge$components === void 0 ? {} : _deepmerge$components,
|
|
75
|
+
mergedTheme = _objectWithoutProperties(_deepmerge, ["components"]);
|
|
76
|
+
|
|
66
77
|
var colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
67
78
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
68
79
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -77,6 +88,7 @@ export default function createCssVarsProvider(options) {
|
|
|
77
88
|
}),
|
|
78
89
|
mode = _useCurrentColorSchem.mode,
|
|
79
90
|
setMode = _useCurrentColorSchem.setMode,
|
|
91
|
+
systemMode = _useCurrentColorSchem.systemMode,
|
|
80
92
|
lightColorScheme = _useCurrentColorSchem.lightColorScheme,
|
|
81
93
|
darkColorScheme = _useCurrentColorSchem.darkColorScheme,
|
|
82
94
|
colorScheme = _useCurrentColorSchem.colorScheme,
|
|
@@ -105,6 +117,7 @@ export default function createCssVarsProvider(options) {
|
|
|
105
117
|
rootVars = _cssVarsParser.vars;
|
|
106
118
|
|
|
107
119
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
120
|
+
components: components,
|
|
108
121
|
colorSchemes: colorSchemes,
|
|
109
122
|
vars: rootVars
|
|
110
123
|
});
|
|
@@ -147,6 +160,48 @@ export default function createCssVarsProvider(options) {
|
|
|
147
160
|
document.body.setAttribute(attribute, colorScheme);
|
|
148
161
|
}
|
|
149
162
|
}, [colorScheme, attribute]);
|
|
163
|
+
React.useEffect(function () {
|
|
164
|
+
if (!mode || !enableColorScheme) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
169
|
+
|
|
170
|
+
if (mode === 'system') {
|
|
171
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
172
|
+
} else {
|
|
173
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return function () {
|
|
177
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
178
|
+
};
|
|
179
|
+
}, [mode, systemMode]);
|
|
180
|
+
React.useEffect(function () {
|
|
181
|
+
var timer;
|
|
182
|
+
|
|
183
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
184
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
185
|
+
var css = document.createElement('style');
|
|
186
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
187
|
+
document.head.appendChild(css); // Force browser repaint
|
|
188
|
+
|
|
189
|
+
(function () {
|
|
190
|
+
return window.getComputedStyle(document.body);
|
|
191
|
+
})();
|
|
192
|
+
|
|
193
|
+
timer = setTimeout(function () {
|
|
194
|
+
document.head.removeChild(css);
|
|
195
|
+
}, 1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return function () {
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
};
|
|
201
|
+
}, [colorScheme]);
|
|
202
|
+
React.useEffect(function () {
|
|
203
|
+
hasMounted.current = true;
|
|
204
|
+
}, []);
|
|
150
205
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
151
206
|
value: {
|
|
152
207
|
mode: mode,
|
|
@@ -177,7 +232,7 @@ export default function createCssVarsProvider(options) {
|
|
|
177
232
|
attribute: PropTypes.string,
|
|
178
233
|
|
|
179
234
|
/**
|
|
180
|
-
*
|
|
235
|
+
* The component tree.
|
|
181
236
|
*/
|
|
182
237
|
children: PropTypes.node,
|
|
183
238
|
|
|
@@ -197,7 +252,7 @@ export default function createCssVarsProvider(options) {
|
|
|
197
252
|
modeStorageKey: PropTypes.string,
|
|
198
253
|
|
|
199
254
|
/**
|
|
200
|
-
*
|
|
255
|
+
* CSS variable prefix.
|
|
201
256
|
*/
|
|
202
257
|
prefix: PropTypes.string,
|
|
203
258
|
|
|
@@ -75,7 +75,7 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
75
75
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(function (prop) {
|
|
76
76
|
return keys.includes(prop);
|
|
77
77
|
})) {
|
|
78
|
-
//
|
|
78
|
+
// CSS property that are unitless
|
|
79
79
|
return value;
|
|
80
80
|
}
|
|
81
81
|
|
package/legacy/index.js
CHANGED
|
@@ -2,7 +2,8 @@ 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';
|
|
@@ -13,11 +14,14 @@ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY }
|
|
|
13
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
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
18
|
export default function createCssVarsProvider(options) {
|
|
17
19
|
const {
|
|
18
20
|
theme: baseTheme = {},
|
|
19
21
|
defaultMode: desisgnSystemMode = 'light',
|
|
20
22
|
defaultColorScheme: designSystemColorScheme,
|
|
23
|
+
disableTransitionOnChange = false,
|
|
24
|
+
enableColorScheme = true,
|
|
21
25
|
prefix: designSystemPrefix = '',
|
|
22
26
|
shouldSkipGeneratingVar
|
|
23
27
|
} = options;
|
|
@@ -57,7 +61,14 @@ export default function createCssVarsProvider(options) {
|
|
|
57
61
|
} = themeProp,
|
|
58
62
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
65
|
+
|
|
66
|
+
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
67
|
+
{
|
|
68
|
+
components = {}
|
|
69
|
+
} = _deepmerge,
|
|
70
|
+
mergedTheme = _objectWithoutPropertiesLoose(_deepmerge, _excluded3);
|
|
71
|
+
|
|
61
72
|
const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
62
73
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
63
74
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -65,6 +76,7 @@ export default function createCssVarsProvider(options) {
|
|
|
65
76
|
const {
|
|
66
77
|
mode,
|
|
67
78
|
setMode,
|
|
79
|
+
systemMode,
|
|
68
80
|
lightColorScheme,
|
|
69
81
|
darkColorScheme,
|
|
70
82
|
colorScheme,
|
|
@@ -100,6 +112,7 @@ export default function createCssVarsProvider(options) {
|
|
|
100
112
|
shouldSkipGeneratingVar
|
|
101
113
|
});
|
|
102
114
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
115
|
+
components,
|
|
103
116
|
colorSchemes,
|
|
104
117
|
vars: rootVars
|
|
105
118
|
});
|
|
@@ -138,6 +151,46 @@ export default function createCssVarsProvider(options) {
|
|
|
138
151
|
document.body.setAttribute(attribute, colorScheme);
|
|
139
152
|
}
|
|
140
153
|
}, [colorScheme, attribute]);
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
if (!mode || !enableColorScheme) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
160
|
+
|
|
161
|
+
if (mode === 'system') {
|
|
162
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
163
|
+
} else {
|
|
164
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return () => {
|
|
168
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
169
|
+
};
|
|
170
|
+
}, [mode, systemMode]);
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
let timer;
|
|
173
|
+
|
|
174
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
175
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
176
|
+
const css = document.createElement('style');
|
|
177
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
178
|
+
document.head.appendChild(css); // Force browser repaint
|
|
179
|
+
|
|
180
|
+
(() => window.getComputedStyle(document.body))();
|
|
181
|
+
|
|
182
|
+
timer = setTimeout(() => {
|
|
183
|
+
document.head.removeChild(css);
|
|
184
|
+
}, 1);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return () => {
|
|
188
|
+
clearTimeout(timer);
|
|
189
|
+
};
|
|
190
|
+
}, [colorScheme]);
|
|
191
|
+
React.useEffect(() => {
|
|
192
|
+
hasMounted.current = true;
|
|
193
|
+
}, []);
|
|
141
194
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
142
195
|
value: {
|
|
143
196
|
mode,
|
|
@@ -168,7 +221,7 @@ export default function createCssVarsProvider(options) {
|
|
|
168
221
|
attribute: PropTypes.string,
|
|
169
222
|
|
|
170
223
|
/**
|
|
171
|
-
*
|
|
224
|
+
* The component tree.
|
|
172
225
|
*/
|
|
173
226
|
children: PropTypes.node,
|
|
174
227
|
|
|
@@ -188,7 +241,7 @@ export default function createCssVarsProvider(options) {
|
|
|
188
241
|
modeStorageKey: PropTypes.string,
|
|
189
242
|
|
|
190
243
|
/**
|
|
191
|
-
*
|
|
244
|
+
* CSS variable prefix.
|
|
192
245
|
*/
|
|
193
246
|
prefix: PropTypes.string,
|
|
194
247
|
|
|
@@ -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
|
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
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.16.3",
|
|
47
|
-
"@mui/private-theming": "^5.2.
|
|
47
|
+
"@mui/private-theming": "^5.2.2",
|
|
48
48
|
"@mui/styled-engine": "^5.2.0",
|
|
49
49
|
"@mui/types": "^7.1.0",
|
|
50
|
-
"@mui/utils": "^5.2.
|
|
50
|
+
"@mui/utils": "^5.2.2",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
52
|
"csstype": "^3.0.10",
|
|
53
53
|
"prop-types": "^15.7.2"
|