@mui/system 5.6.2 → 5.7.0
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.d.ts +18 -1
- package/Box/Box.js +26 -0
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +225 -0
- package/ThemeProvider/ThemeProvider.d.ts +7 -1
- package/ThemeProvider/ThemeProvider.js +9 -2
- package/createBox.js +0 -26
- package/createBox.spec.d.ts +1 -1
- package/createStyled.js +3 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +25 -0
- package/cssVars/createCssVarsProvider.js +74 -57
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +70 -70
- package/cssVars/cssVarsParser.js +11 -9
- package/cssVars/getInitColorSchemeScript.d.ts +40 -12
- package/cssVars/getInitColorSchemeScript.js +4 -3
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +53 -50
- package/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/Box/Box.js +25 -0
- package/esm/ThemeProvider/ThemeProvider.js +9 -2
- package/esm/createBox.js +0 -25
- package/esm/createStyled.js +3 -1
- package/esm/cssVars/createCssVarsProvider.js +76 -57
- package/esm/cssVars/cssVarsParser.js +11 -9
- package/esm/cssVars/getInitColorSchemeScript.js +4 -3
- package/esm/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/spacing.js +3 -1
- package/esm/style.js +7 -1
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/Box/Box.js +25 -0
- package/legacy/ThemeProvider/ThemeProvider.js +9 -2
- package/legacy/createBox.js +0 -25
- package/legacy/createStyled.js +3 -1
- package/legacy/cssVars/createCssVarsProvider.js +83 -55
- package/legacy/cssVars/cssVarsParser.js +11 -7
- package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
- package/legacy/cssVars/useCurrentColorScheme.js +20 -9
- package/legacy/index.js +1 -1
- package/legacy/spacing.js +3 -1
- package/legacy/style.js +5 -1
- package/modern/Box/Box.js +25 -0
- package/modern/ThemeProvider/ThemeProvider.js +9 -2
- package/modern/createBox.js +0 -25
- package/modern/createStyled.js +3 -1
- package/modern/cssVars/createCssVarsProvider.js +76 -55
- package/modern/cssVars/cssVarsParser.js +11 -9
- package/modern/cssVars/getInitColorSchemeScript.js +4 -3
- package/modern/cssVars/useCurrentColorScheme.js +17 -7
- package/modern/index.js +1 -1
- package/modern/spacing.js +1 -1
- package/modern/style.js +7 -1
- package/package.json +5 -5
- package/spacing.js +3 -1
- package/style.js +7 -1
- package/styleFunctionSx/styleFunctionSx.d.ts +3 -1
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -63,7 +63,8 @@ export default function useCurrentColorScheme(options) {
|
|
|
63
63
|
defaultDarkColorScheme,
|
|
64
64
|
supportedColorSchemes = [],
|
|
65
65
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
66
|
-
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY
|
|
66
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
67
|
+
storageWindow = typeof window === 'undefined' ? undefined : window
|
|
67
68
|
} = options;
|
|
68
69
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
69
70
|
const [state, setState] = React.useState(() => {
|
|
@@ -80,6 +81,10 @@ export default function useCurrentColorScheme(options) {
|
|
|
80
81
|
setState(currentState => {
|
|
81
82
|
const newMode = !mode ? defaultMode : mode;
|
|
82
83
|
|
|
84
|
+
if (mode === currentState.mode) {
|
|
85
|
+
return currentState;
|
|
86
|
+
}
|
|
87
|
+
|
|
83
88
|
if (typeof localStorage !== 'undefined') {
|
|
84
89
|
localStorage.setItem(modeStorageKey, newMode);
|
|
85
90
|
}
|
|
@@ -92,7 +97,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
92
97
|
}, [modeStorageKey, defaultMode]);
|
|
93
98
|
const setColorScheme = React.useCallback(value => {
|
|
94
99
|
if (!value || typeof value === 'string') {
|
|
95
|
-
if (value && !
|
|
100
|
+
if (value && !joinedColorSchemes.includes(value)) {
|
|
96
101
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
97
102
|
} else {
|
|
98
103
|
setState(currentState => {
|
|
@@ -119,7 +124,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
119
124
|
return newState;
|
|
120
125
|
});
|
|
121
126
|
}
|
|
122
|
-
} else if (value.light && !
|
|
127
|
+
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
123
128
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
124
129
|
} else {
|
|
125
130
|
setState(currentState => {
|
|
@@ -144,7 +149,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
144
149
|
localStorage.setItem(`${colorSchemeStorageKey}-dark`, value.dark);
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
|
-
}, [
|
|
152
|
+
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
148
153
|
const handleMediaQuery = React.useCallback(e => {
|
|
149
154
|
if (state.mode === 'system') {
|
|
150
155
|
setState(currentState => _extends({}, currentState, {
|
|
@@ -206,9 +211,14 @@ export default function useCurrentColorScheme(options) {
|
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
213
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
if (storageWindow) {
|
|
215
|
+
// For syncing color-scheme changes between iframes
|
|
216
|
+
storageWindow.addEventListener('storage', handleStorage);
|
|
217
|
+
return () => storageWindow.removeEventListener('storage', handleStorage);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return undefined;
|
|
221
|
+
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
|
212
222
|
return _extends({}, state, {
|
|
213
223
|
colorScheme,
|
|
214
224
|
setMode,
|
package/esm/spacing.js
CHANGED
|
@@ -43,7 +43,9 @@ const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTo
|
|
|
43
43
|
const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd'];
|
|
44
44
|
const spacingKeys = [...marginKeys, ...paddingKeys];
|
|
45
45
|
export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
|
|
46
|
-
|
|
46
|
+
var _getPath;
|
|
47
|
+
|
|
48
|
+
const themeSpacing = (_getPath = getPath(theme, themeKey)) != null ? _getPath : defaultValue;
|
|
47
49
|
|
|
48
50
|
if (typeof themeSpacing === 'number') {
|
|
49
51
|
return abs => {
|
package/esm/style.js
CHANGED
|
@@ -15,7 +15,13 @@ export function getPath(obj, path) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return path.split('.').reduce((acc, item) =>
|
|
18
|
+
return path.split('.').reduce((acc, item) => {
|
|
19
|
+
if (acc && acc[item] != null) {
|
|
20
|
+
return acc[item];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}, obj);
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
function getValue(themeMapping, transform, propValueFinal, userValue = propValueFinal) {
|
package/index.js
CHANGED
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/legacy/Box/Box.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
1
2
|
import createBox from '../createBox';
|
|
2
3
|
var Box = createBox();
|
|
4
|
+
process.env.NODE_ENV !== "production" ? Box.propTypes
|
|
5
|
+
/* remove-proptypes */
|
|
6
|
+
= {
|
|
7
|
+
// ----------------------------- Warning --------------------------------
|
|
8
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
9
|
+
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|
10
|
+
// ----------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
children: PropTypes.node,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The component used for the root node.
|
|
19
|
+
* Either a string to use a HTML element or a component.
|
|
20
|
+
*/
|
|
21
|
+
component: PropTypes.elementType,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
25
|
+
*/
|
|
26
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
27
|
+
} : void 0;
|
|
3
28
|
export default Box;
|
|
@@ -37,7 +37,14 @@ function ThemeProvider(props) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes
|
|
40
|
+
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes
|
|
41
|
+
/* remove-proptypes */
|
|
42
|
+
= {
|
|
43
|
+
// ----------------------------- Warning --------------------------------
|
|
44
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
45
|
+
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|
46
|
+
// ----------------------------------------------------------------------
|
|
47
|
+
|
|
41
48
|
/**
|
|
42
49
|
* Your component tree.
|
|
43
50
|
*/
|
|
@@ -46,7 +53,7 @@ process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes = {
|
|
|
46
53
|
/**
|
|
47
54
|
* A theme object. You can provide a function to extend the outer theme.
|
|
48
55
|
*/
|
|
49
|
-
theme: PropTypes.oneOfType([PropTypes.
|
|
56
|
+
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired
|
|
50
57
|
} : void 0;
|
|
51
58
|
|
|
52
59
|
if (process.env.NODE_ENV !== 'production') {
|
package/legacy/createBox.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
4
|
import clsx from 'clsx';
|
|
6
5
|
import styled from '@mui/styled-engine';
|
|
7
6
|
import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
|
|
@@ -32,29 +31,5 @@ export default function createBox() {
|
|
|
32
31
|
theme: theme
|
|
33
32
|
}, other));
|
|
34
33
|
});
|
|
35
|
-
process.env.NODE_ENV !== "production" ? Box.propTypes
|
|
36
|
-
/* remove-proptypes */
|
|
37
|
-
= {
|
|
38
|
-
// ----------------------------- Warning --------------------------------
|
|
39
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
40
|
-
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|
41
|
-
// ----------------------------------------------------------------------
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @ignore
|
|
45
|
-
*/
|
|
46
|
-
children: PropTypes.node,
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The component used for the root node.
|
|
50
|
-
* Either a string to use a HTML element or a component.
|
|
51
|
-
*/
|
|
52
|
-
component: PropTypes.elementType,
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @ignore
|
|
56
|
-
*/
|
|
57
|
-
sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func])
|
|
58
|
-
} : void 0;
|
|
59
34
|
return Box;
|
|
60
35
|
}
|
package/legacy/createStyled.js
CHANGED
|
@@ -149,7 +149,9 @@ export default function createStyled() {
|
|
|
149
149
|
slotKey = _ref3[0],
|
|
150
150
|
slotStyle = _ref3[1];
|
|
151
151
|
|
|
152
|
-
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(props
|
|
152
|
+
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
|
|
153
|
+
theme: theme
|
|
154
|
+
})) : slotStyle;
|
|
153
155
|
});
|
|
154
156
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
155
157
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
@@ -5,23 +6,19 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
5
6
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import PropTypes from 'prop-types';
|
|
8
|
-
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
10
|
-
import
|
|
11
|
-
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
10
|
+
import { GlobalStyles } from '@mui/styled-engine';
|
|
12
11
|
import cssVarsParser from './cssVarsParser';
|
|
13
12
|
import ThemeProvider from '../ThemeProvider';
|
|
14
|
-
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
|
+
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
15
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
16
15
|
import createGetCssVar from './createGetCssVar';
|
|
17
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
18
|
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
20
19
|
export default function createCssVarsProvider(options) {
|
|
21
|
-
var _baseTheme$breakpoint;
|
|
22
|
-
|
|
23
20
|
var _options$theme = options.theme,
|
|
24
|
-
|
|
21
|
+
defaultTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
25
22
|
_options$defaultMode = options.defaultMode,
|
|
26
23
|
desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
27
24
|
designSystemColorScheme = options.defaultColorScheme,
|
|
@@ -33,10 +30,8 @@ export default function createCssVarsProvider(options) {
|
|
|
33
30
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
34
31
|
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
35
32
|
resolveTheme = options.resolveTheme;
|
|
36
|
-
var systemSpacing = createSpacing(baseTheme.spacing);
|
|
37
|
-
var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
38
33
|
|
|
39
|
-
if (!
|
|
34
|
+
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
40
35
|
console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
|
|
41
36
|
}
|
|
42
37
|
|
|
@@ -55,11 +50,13 @@ export default function createCssVarsProvider(options) {
|
|
|
55
50
|
function CssVarsProvider(_ref) {
|
|
56
51
|
var children = _ref.children,
|
|
57
52
|
_ref$theme = _ref.theme,
|
|
58
|
-
themeProp = _ref$theme === void 0 ?
|
|
53
|
+
themeProp = _ref$theme === void 0 ? defaultTheme : _ref$theme,
|
|
59
54
|
_ref$prefix = _ref.prefix,
|
|
60
55
|
prefix = _ref$prefix === void 0 ? designSystemPrefix : _ref$prefix,
|
|
61
56
|
_ref$modeStorageKey = _ref.modeStorageKey,
|
|
62
57
|
modeStorageKey = _ref$modeStorageKey === void 0 ? DEFAULT_MODE_STORAGE_KEY : _ref$modeStorageKey,
|
|
58
|
+
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
59
|
+
colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
|
|
63
60
|
_ref$attribute = _ref.attribute,
|
|
64
61
|
attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
|
|
65
62
|
_ref$defaultMode = _ref.defaultMode,
|
|
@@ -69,24 +66,23 @@ export default function createCssVarsProvider(options) {
|
|
|
69
66
|
_ref$disableTransitio = _ref.disableTransitionOnChange,
|
|
70
67
|
disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
|
|
71
68
|
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
72
|
-
enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem,
|
|
70
|
+
_ref$storageWindow = _ref.storageWindow,
|
|
71
|
+
storageWindow = _ref$storageWindow === void 0 ? typeof window === 'undefined' ? undefined : window : _ref$storageWindow,
|
|
72
|
+
_ref$documentNode = _ref.documentNode,
|
|
73
|
+
documentNode = _ref$documentNode === void 0 ? typeof document === 'undefined' ? undefined : document : _ref$documentNode,
|
|
74
|
+
_ref$colorSchemeNode = _ref.colorSchemeNode,
|
|
75
|
+
colorSchemeNode = _ref$colorSchemeNode === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _ref$colorSchemeNode,
|
|
76
|
+
_ref$colorSchemeSelec = _ref.colorSchemeSelector,
|
|
77
|
+
colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec;
|
|
78
|
+
var hasMounted = React.useRef(false);
|
|
77
79
|
|
|
78
80
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
82
|
+
_themeProp$components = themeProp.components,
|
|
83
|
+
components = _themeProp$components === void 0 ? {} : _themeProp$components,
|
|
84
|
+
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components"]);
|
|
81
85
|
|
|
82
|
-
var hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
83
|
-
|
|
84
|
-
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
85
|
-
_deepmerge$components = _deepmerge.components,
|
|
86
|
-
components = _deepmerge$components === void 0 ? {} : _deepmerge$components,
|
|
87
|
-
mergedTheme = _objectWithoutProperties(_deepmerge, ["components"]);
|
|
88
|
-
|
|
89
|
-
var colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
90
86
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
91
87
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
92
88
|
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -96,7 +92,9 @@ export default function createCssVarsProvider(options) {
|
|
|
96
92
|
defaultLightColorScheme: defaultLightColorScheme,
|
|
97
93
|
defaultDarkColorScheme: defaultDarkColorScheme,
|
|
98
94
|
modeStorageKey: modeStorageKey,
|
|
99
|
-
|
|
95
|
+
colorSchemeStorageKey: colorSchemeStorageKey,
|
|
96
|
+
defaultMode: defaultMode,
|
|
97
|
+
storageWindow: storageWindow
|
|
100
98
|
}),
|
|
101
99
|
mode = _useCurrentColorSchem.mode,
|
|
102
100
|
setMode = _useCurrentColorSchem.setMode,
|
|
@@ -120,7 +118,9 @@ export default function createCssVarsProvider(options) {
|
|
|
120
118
|
return colorScheme;
|
|
121
119
|
}();
|
|
122
120
|
|
|
123
|
-
var
|
|
121
|
+
var theme = restThemeProp;
|
|
122
|
+
|
|
123
|
+
var _cssVarsParser = cssVarsParser(theme, {
|
|
124
124
|
prefix: prefix,
|
|
125
125
|
basePrefix: designSystemPrefix,
|
|
126
126
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
@@ -129,13 +129,11 @@ export default function createCssVarsProvider(options) {
|
|
|
129
129
|
rootVars = _cssVarsParser.vars,
|
|
130
130
|
parsedTheme = _cssVarsParser.parsedTheme;
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
theme = _extends({}, parsedTheme, {
|
|
133
133
|
components: components,
|
|
134
134
|
colorSchemes: colorSchemes,
|
|
135
135
|
prefix: prefix,
|
|
136
136
|
vars: rootVars,
|
|
137
|
-
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
138
|
-
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
139
137
|
getCssVar: createGetCssVar(prefix)
|
|
140
138
|
});
|
|
141
139
|
var styleSheet = {};
|
|
@@ -153,10 +151,16 @@ export default function createCssVarsProvider(options) {
|
|
|
153
151
|
vars = _cssVarsParser2.vars,
|
|
154
152
|
parsedScheme = _cssVarsParser2.parsedTheme;
|
|
155
153
|
|
|
156
|
-
|
|
154
|
+
theme.vars = deepmerge(theme.vars, vars);
|
|
157
155
|
|
|
158
156
|
if (key === resolvedColorScheme) {
|
|
159
|
-
|
|
157
|
+
theme = _extends({}, theme, parsedScheme);
|
|
158
|
+
|
|
159
|
+
if (theme.palette) {
|
|
160
|
+
// assign runtime mode & colorScheme
|
|
161
|
+
theme.palette.mode = mode;
|
|
162
|
+
theme.palette.colorScheme = resolvedColorScheme;
|
|
163
|
+
}
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
var resolvedDefaultColorScheme = function () {
|
|
@@ -172,56 +176,56 @@ export default function createCssVarsProvider(options) {
|
|
|
172
176
|
}();
|
|
173
177
|
|
|
174
178
|
if (key === resolvedDefaultColorScheme) {
|
|
175
|
-
styleSheet[
|
|
179
|
+
styleSheet[colorSchemeSelector] = css;
|
|
176
180
|
} else {
|
|
177
|
-
styleSheet["[".concat(attribute, "=\"").concat(key, "\"]")] = css;
|
|
181
|
+
styleSheet["".concat(colorSchemeSelector === ':root' ? '' : colorSchemeSelector, "[").concat(attribute, "=\"").concat(key, "\"]")] = css;
|
|
178
182
|
}
|
|
179
183
|
});
|
|
180
184
|
React.useEffect(function () {
|
|
181
|
-
if (colorScheme) {
|
|
185
|
+
if (colorScheme && colorSchemeNode) {
|
|
182
186
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
183
|
-
|
|
187
|
+
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
184
188
|
}
|
|
185
|
-
}, [colorScheme, attribute]);
|
|
189
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
186
190
|
useEnhancedEffect(function () {
|
|
187
|
-
if (!mode || !enableColorScheme) {
|
|
191
|
+
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
188
192
|
return undefined;
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
var priorColorScheme =
|
|
195
|
+
var priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
192
196
|
|
|
193
197
|
if (mode === 'system') {
|
|
194
|
-
|
|
198
|
+
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
195
199
|
} else {
|
|
196
|
-
|
|
200
|
+
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
return function () {
|
|
200
|
-
|
|
204
|
+
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
201
205
|
};
|
|
202
|
-
}, [mode, systemMode, enableColorScheme]);
|
|
206
|
+
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
203
207
|
React.useEffect(function () {
|
|
204
208
|
var timer;
|
|
205
209
|
|
|
206
|
-
if (disableTransitionOnChange && hasMounted.current) {
|
|
210
|
+
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
207
211
|
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
208
|
-
var css =
|
|
209
|
-
css.appendChild(
|
|
210
|
-
|
|
212
|
+
var css = documentNode.createElement('style');
|
|
213
|
+
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
214
|
+
documentNode.head.appendChild(css); // Force browser repaint
|
|
211
215
|
|
|
212
216
|
(function () {
|
|
213
|
-
return window.getComputedStyle(
|
|
217
|
+
return window.getComputedStyle(documentNode.body);
|
|
214
218
|
})();
|
|
215
219
|
|
|
216
220
|
timer = setTimeout(function () {
|
|
217
|
-
|
|
221
|
+
documentNode.head.removeChild(css);
|
|
218
222
|
}, 1);
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
return function () {
|
|
222
226
|
clearTimeout(timer);
|
|
223
227
|
};
|
|
224
|
-
}, [colorScheme, disableTransitionOnChange]);
|
|
228
|
+
}, [colorScheme, disableTransitionOnChange, documentNode]);
|
|
225
229
|
React.useEffect(function () {
|
|
226
230
|
hasMounted.current = true;
|
|
227
231
|
return function () {
|
|
@@ -239,13 +243,11 @@ export default function createCssVarsProvider(options) {
|
|
|
239
243
|
allColorSchemes: allColorSchemes
|
|
240
244
|
},
|
|
241
245
|
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
242
|
-
styles: {
|
|
243
|
-
':root': rootCss
|
|
244
|
-
}
|
|
246
|
+
styles: _defineProperty({}, colorSchemeSelector, rootCss)
|
|
245
247
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
246
248
|
styles: styleSheet
|
|
247
249
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
248
|
-
theme: resolveTheme ? resolveTheme(
|
|
250
|
+
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
249
251
|
children: children
|
|
250
252
|
})]
|
|
251
253
|
});
|
|
@@ -262,6 +264,21 @@ export default function createCssVarsProvider(options) {
|
|
|
262
264
|
*/
|
|
263
265
|
children: PropTypes.node,
|
|
264
266
|
|
|
267
|
+
/**
|
|
268
|
+
* The node used to attach the color-scheme attribute
|
|
269
|
+
*/
|
|
270
|
+
colorSchemeNode: PropTypes.any,
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The CSS selector for attaching the generated custom properties
|
|
274
|
+
*/
|
|
275
|
+
colorSchemeSelector: PropTypes.string,
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* localStorage key used to store `colorScheme`
|
|
279
|
+
*/
|
|
280
|
+
colorSchemeStorageKey: PropTypes.string,
|
|
281
|
+
|
|
265
282
|
/**
|
|
266
283
|
* The initial color scheme used.
|
|
267
284
|
*/
|
|
@@ -277,6 +294,11 @@ export default function createCssVarsProvider(options) {
|
|
|
277
294
|
*/
|
|
278
295
|
disableTransitionOnChange: PropTypes.bool,
|
|
279
296
|
|
|
297
|
+
/**
|
|
298
|
+
* The document to attach the attribute to
|
|
299
|
+
*/
|
|
300
|
+
documentNode: PropTypes.any,
|
|
301
|
+
|
|
280
302
|
/**
|
|
281
303
|
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
282
304
|
*/
|
|
@@ -292,6 +314,12 @@ export default function createCssVarsProvider(options) {
|
|
|
292
314
|
*/
|
|
293
315
|
prefix: PropTypes.string,
|
|
294
316
|
|
|
317
|
+
/**
|
|
318
|
+
* The window that attaches the 'storage' event listener
|
|
319
|
+
* @default window
|
|
320
|
+
*/
|
|
321
|
+
storageWindow: PropTypes.any,
|
|
322
|
+
|
|
295
323
|
/**
|
|
296
324
|
* The calculated theme object that will be passed through context.
|
|
297
325
|
*/
|
|
@@ -22,15 +22,18 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
22
22
|
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
23
23
|
*/
|
|
24
24
|
export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
|
|
25
|
+
var arrayKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
25
26
|
var temp = obj;
|
|
26
27
|
keys.forEach(function (k, index) {
|
|
27
28
|
if (index === keys.length - 1) {
|
|
28
|
-
if (
|
|
29
|
+
if (Array.isArray(temp)) {
|
|
30
|
+
temp[Number(k)] = value;
|
|
31
|
+
} else if (temp && _typeof(temp) === 'object') {
|
|
29
32
|
temp[k] = value;
|
|
30
33
|
}
|
|
31
34
|
} else if (temp && _typeof(temp) === 'object') {
|
|
32
35
|
if (!temp[k]) {
|
|
33
|
-
temp[k] = {};
|
|
36
|
+
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
temp = temp[k];
|
|
@@ -52,6 +55,7 @@ export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
|
|
|
52
55
|
export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPaths) {
|
|
53
56
|
function recurse(object) {
|
|
54
57
|
var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
58
|
+
var arrayKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
55
59
|
Object.entries(object).forEach(function (_ref) {
|
|
56
60
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
57
61
|
key = _ref2[0],
|
|
@@ -60,9 +64,9 @@ export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPat
|
|
|
60
64
|
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([].concat(_toConsumableArray(parentKeys), [key]))) {
|
|
61
65
|
if (value !== undefined && value !== null) {
|
|
62
66
|
if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
|
|
63
|
-
recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
|
|
67
|
+
recurse(value, [].concat(_toConsumableArray(parentKeys), [key]), Array.isArray(value) ? [].concat(_toConsumableArray(arrayKeys), [key]) : arrayKeys);
|
|
64
68
|
} else {
|
|
65
|
-
callback([].concat(_toConsumableArray(parentKeys), [key]), value,
|
|
69
|
+
callback([].concat(_toConsumableArray(parentKeys), [key]), value, arrayKeys);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -132,7 +136,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
132
136
|
var css = {};
|
|
133
137
|
var vars = {};
|
|
134
138
|
var parsedTheme = {};
|
|
135
|
-
walkObjectDeep(theme, function (keys, value) {
|
|
139
|
+
walkObjectDeep(theme, function (keys, value, arrayKeys) {
|
|
136
140
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
137
141
|
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
138
142
|
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
@@ -150,11 +154,11 @@ export default function cssVarsParser(theme, options) {
|
|
|
150
154
|
|
|
151
155
|
_extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
|
|
152
156
|
|
|
153
|
-
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
|
|
157
|
+
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"), arrayKeys);
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
assignNestedKeys(parsedTheme, keys, value);
|
|
161
|
+
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
158
162
|
}, function (keys) {
|
|
159
163
|
return keys[0] === 'vars';
|
|
160
164
|
} // skip 'vars/*' paths
|
|
@@ -5,7 +5,8 @@ export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export var DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
var _ref = options || {},
|
|
8
|
-
enableSystem = _ref.enableSystem,
|
|
8
|
+
_ref$enableSystem = _ref.enableSystem,
|
|
9
|
+
enableSystem = _ref$enableSystem === void 0 ? false : _ref$enableSystem,
|
|
9
10
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
10
11
|
defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
|
|
11
12
|
_ref$defaultDarkColor = _ref.defaultDarkColorScheme,
|
|
@@ -15,12 +16,14 @@ export default function getInitColorSchemeScript(options) {
|
|
|
15
16
|
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
16
17
|
colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
|
|
17
18
|
_ref$attribute = _ref.attribute,
|
|
18
|
-
attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute
|
|
19
|
+
attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
|
|
20
|
+
_ref$colorSchemeNode = _ref.colorSchemeNode,
|
|
21
|
+
colorSchemeNode = _ref$colorSchemeNode === void 0 ? 'document.documentElement' : _ref$colorSchemeNode;
|
|
19
22
|
|
|
20
23
|
return /*#__PURE__*/_jsx("script", {
|
|
21
24
|
// eslint-disable-next-line react/no-danger
|
|
22
25
|
dangerouslySetInnerHTML: {
|
|
23
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n
|
|
26
|
+
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
24
27
|
}
|
|
25
28
|
});
|
|
26
29
|
}
|