@mui/system 5.1.1 → 5.2.3
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 +265 -3
- package/breakpoints.js +1 -1
- package/createBox.d.ts +3 -3
- package/createBox.js +1 -1
- package/createBox.spec.d.ts +1 -0
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +24 -10
- package/cssVars/createCssVarsProvider.js +80 -12
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/cssVarsParser.d.ts +68 -68
- package/cssVars/cssVarsParser.js +18 -17
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/getInitColorSchemeScript.js +7 -7
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/breakpoints.js +1 -1
- package/esm/createBox.js +1 -1
- package/esm/cssVars/createCssVarsProvider.js +76 -12
- package/esm/cssVars/cssVarsParser.js +18 -16
- package/esm/cssVars/getInitColorSchemeScript.js +7 -7
- package/esm/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +20 -18
- package/esm/sx/index.js +1 -0
- package/esm/sx/sx.js +12 -0
- package/esm/useThemeProps/getThemeProps.js +2 -17
- package/index.d.ts +2 -0
- package/index.js +10 -1
- package/index.spec.d.ts +1 -1
- package/legacy/breakpoints.js +1 -1
- package/legacy/createBox.js +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +79 -11
- package/legacy/cssVars/cssVarsParser.js +20 -14
- package/legacy/cssVars/getInitColorSchemeScript.js +2 -3
- package/legacy/index.js +2 -1
- package/legacy/styleFunctionSx/styleFunctionSx.js +19 -17
- package/legacy/sx/index.js +1 -0
- package/legacy/sx/sx.js +13 -0
- package/legacy/useThemeProps/getThemeProps.js +2 -17
- package/modern/breakpoints.js +1 -1
- package/modern/createBox.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +74 -12
- package/modern/cssVars/cssVarsParser.js +18 -16
- package/modern/cssVars/getInitColorSchemeScript.js +7 -7
- package/modern/index.js +2 -1
- package/modern/styleFunctionSx/styleFunctionSx.js +20 -18
- package/modern/sx/index.js +1 -0
- package/modern/sx/sx.js +12 -0
- package/modern/useThemeProps/getThemeProps.js +2 -17
- package/package.json +6 -6
- package/styleFunctionSx/styleFunctionSx.d.ts +1 -1
- package/styleFunctionSx/styleFunctionSx.js +20 -18
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
- package/sx/index.d.ts +1 -0
- package/sx/index.js +15 -0
- package/sx/package.json +6 -0
- package/sx/sx.d.ts +4 -0
- package/sx/sx.js +22 -0
- package/useThemeProps/getThemeProps.js +2 -17
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* This function create an object from keys, value and then assign to target
|
|
5
3
|
*
|
|
@@ -45,14 +43,16 @@ export const assignNestedKeys = (obj, keys, value) => {
|
|
|
45
43
|
* // ['palette', 'primary', 'main'] '#000000'
|
|
46
44
|
*/
|
|
47
45
|
|
|
48
|
-
export const walkObjectDeep = (obj, callback) => {
|
|
46
|
+
export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
49
47
|
function recurse(object, parentKeys = []) {
|
|
50
48
|
Object.entries(object).forEach(([key, value]) => {
|
|
51
|
-
if (
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
|
|
50
|
+
if (value !== undefined && value !== null) {
|
|
51
|
+
if (typeof value === 'object' && Object.keys(value).length > 0) {
|
|
52
|
+
recurse(value, [...parentKeys, key]);
|
|
53
|
+
} else {
|
|
54
|
+
callback([...parentKeys, key], value, object);
|
|
55
|
+
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -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
|
|
|
@@ -102,10 +102,6 @@ const getCssValue = (keys, value) => {
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
export default function cssVarsParser(theme, options) {
|
|
105
|
-
const clonedTheme = _extends({}, theme);
|
|
106
|
-
|
|
107
|
-
delete clonedTheme.vars; // remove 'vars' from the structure
|
|
108
|
-
|
|
109
105
|
const {
|
|
110
106
|
prefix,
|
|
111
107
|
basePrefix = '',
|
|
@@ -113,13 +109,18 @@ export default function cssVarsParser(theme, options) {
|
|
|
113
109
|
} = options || {};
|
|
114
110
|
const css = {};
|
|
115
111
|
const vars = {};
|
|
116
|
-
walkObjectDeep(
|
|
112
|
+
walkObjectDeep(theme, (keys, val, scope) => {
|
|
117
113
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
118
114
|
let value = val;
|
|
119
115
|
|
|
120
116
|
if (typeof value === 'string' && value.startsWith('var')) {
|
|
121
117
|
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
122
|
-
|
|
118
|
+
if (!basePrefix && prefix) {
|
|
119
|
+
value = value.replace(/var\(--/g, `var(--${prefix}-`);
|
|
120
|
+
} else {
|
|
121
|
+
value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
|
|
122
|
+
} // scope is the deepest object in the tree, keys is the theme path keys
|
|
123
|
+
|
|
123
124
|
|
|
124
125
|
scope[keys.slice(-1)[0]] = value;
|
|
125
126
|
}
|
|
@@ -133,7 +134,8 @@ export default function cssVarsParser(theme, options) {
|
|
|
133
134
|
assignNestedKeys(vars, keys, `var(${cssVar})`);
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
}
|
|
137
|
+
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
138
|
+
);
|
|
137
139
|
return {
|
|
138
140
|
css,
|
|
139
141
|
vars
|
|
@@ -5,7 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
|
|
8
|
+
enableSystem,
|
|
9
9
|
defaultLightColorScheme = 'light',
|
|
10
10
|
defaultDarkColorScheme = 'dark',
|
|
11
11
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -18,23 +18,23 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
18
|
__html: `(function() { try {
|
|
19
19
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
20
20
|
var colorScheme = '';
|
|
21
|
-
if (mode === 'system' || (!mode &&
|
|
21
|
+
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
22
22
|
// handle system mode
|
|
23
23
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
24
24
|
if (mql.matches) {
|
|
25
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${
|
|
25
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
26
26
|
} else {
|
|
27
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${
|
|
27
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (mode === 'light') {
|
|
31
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultLightColorScheme};
|
|
31
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
32
32
|
}
|
|
33
33
|
if (mode === 'dark') {
|
|
34
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultDarkColorScheme};
|
|
34
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
35
|
}
|
|
36
36
|
if (colorScheme) {
|
|
37
|
-
document.
|
|
37
|
+
document.documentElement.setAttribute('${attribute}', colorScheme);
|
|
38
38
|
}
|
|
39
39
|
} catch (e) {} })();`
|
|
40
40
|
}
|
package/esm/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { default as style, getPath } from './style';
|
|
|
22
22
|
export { default as typography } from './typography';
|
|
23
23
|
export * from './typography';
|
|
24
24
|
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
25
|
+
export { default as experimental_sx } from './sx';
|
|
25
26
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
26
27
|
export { default as Box } from './Box';
|
|
27
28
|
export { default as createBox } from './createBox';
|
|
@@ -44,27 +44,29 @@ function styleFunctionSx(props) {
|
|
|
44
44
|
Object.keys(sxObject).forEach(styleKey => {
|
|
45
45
|
const value = callIfFn(sxObject[styleKey], theme);
|
|
46
46
|
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const breakpointsValues = handleBreakpoints({
|
|
52
|
-
theme
|
|
53
|
-
}, value, x => ({
|
|
54
|
-
[styleKey]: x
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
58
|
-
css[styleKey] = styleFunctionSx({
|
|
59
|
-
sx: value,
|
|
60
|
-
theme
|
|
61
|
-
});
|
|
47
|
+
if (value !== null && value !== undefined) {
|
|
48
|
+
if (typeof value === 'object') {
|
|
49
|
+
if (propToStyleFunction[styleKey]) {
|
|
50
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
62
51
|
} else {
|
|
63
|
-
|
|
52
|
+
const breakpointsValues = handleBreakpoints({
|
|
53
|
+
theme
|
|
54
|
+
}, value, x => ({
|
|
55
|
+
[styleKey]: x
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
59
|
+
css[styleKey] = styleFunctionSx({
|
|
60
|
+
sx: value,
|
|
61
|
+
theme
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
css = merge(css, breakpointsValues);
|
|
65
|
+
}
|
|
64
66
|
}
|
|
67
|
+
} else {
|
|
68
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
65
69
|
}
|
|
66
|
-
} else {
|
|
67
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
return removeUnusedBreakpoints(breakpointsKeys, css);
|
package/esm/sx/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/esm/sx/sx.js
ADDED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-restricted-syntax */
|
|
1
|
+
import { internal_resolveProps as resolveProps } from '@mui/utils';
|
|
4
2
|
export default function getThemeProps(params) {
|
|
5
3
|
const {
|
|
6
4
|
theme,
|
|
@@ -12,18 +10,5 @@ export default function getThemeProps(params) {
|
|
|
12
10
|
return props;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
// https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const defaultProps = theme.components[name].defaultProps;
|
|
20
|
-
let propName;
|
|
21
|
-
|
|
22
|
-
for (propName in defaultProps) {
|
|
23
|
-
if (output[propName] === undefined) {
|
|
24
|
-
output[propName] = defaultProps[propName];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return output;
|
|
13
|
+
return resolveProps(theme.components[name].defaultProps, props);
|
|
29
14
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.2.3
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -34,6 +34,7 @@ var _exportNames = {
|
|
|
34
34
|
typography: true,
|
|
35
35
|
unstable_styleFunctionSx: true,
|
|
36
36
|
unstable_extendSxProp: true,
|
|
37
|
+
experimental_sx: true,
|
|
37
38
|
unstable_getThemeValue: true,
|
|
38
39
|
Box: true,
|
|
39
40
|
createBox: true,
|
|
@@ -134,6 +135,12 @@ Object.defineProperty(exports, "display", {
|
|
|
134
135
|
return _display.default;
|
|
135
136
|
}
|
|
136
137
|
});
|
|
138
|
+
Object.defineProperty(exports, "experimental_sx", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function () {
|
|
141
|
+
return _sx.default;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
137
144
|
Object.defineProperty(exports, "flexbox", {
|
|
138
145
|
enumerable: true,
|
|
139
146
|
get: function () {
|
|
@@ -405,6 +412,8 @@ Object.keys(_typography).forEach(function (key) {
|
|
|
405
412
|
|
|
406
413
|
var _styleFunctionSx = _interopRequireWildcard(require("./styleFunctionSx"));
|
|
407
414
|
|
|
415
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
|
416
|
+
|
|
408
417
|
var _getThemeValue = _interopRequireDefault(require("./getThemeValue"));
|
|
409
418
|
|
|
410
419
|
var _Box = _interopRequireDefault(require("./Box"));
|
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/legacy/breakpoints.js
CHANGED
|
@@ -102,7 +102,7 @@ export function createEmptyBreakpointObject() {
|
|
|
102
102
|
export function removeUnusedBreakpoints(breakpointKeys, style) {
|
|
103
103
|
return breakpointKeys.reduce(function (acc, key) {
|
|
104
104
|
var breakpointOutput = acc[key];
|
|
105
|
-
var isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
|
|
105
|
+
var isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
|
|
106
106
|
|
|
107
107
|
if (isBreakpointUnused) {
|
|
108
108
|
delete acc[key];
|
package/legacy/createBox.js
CHANGED
|
@@ -7,21 +7,32 @@ import * as React from 'react';
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import { deepmerge } from '@mui/utils';
|
|
10
|
+
import createSpacing from '../createTheme/createSpacing';
|
|
11
|
+
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
10
12
|
import cssVarsParser from './cssVarsParser';
|
|
11
13
|
import ThemeProvider from '../ThemeProvider';
|
|
12
14
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
15
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
14
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
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}';
|
|
16
19
|
export default function createCssVarsProvider(options) {
|
|
20
|
+
var _baseTheme$breakpoint;
|
|
21
|
+
|
|
17
22
|
var _options$theme = options.theme,
|
|
18
23
|
baseTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
19
24
|
_options$defaultMode = options.defaultMode,
|
|
20
25
|
desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
21
26
|
designSystemColorScheme = options.defaultColorScheme,
|
|
27
|
+
_options$disableTrans = options.disableTransitionOnChange,
|
|
28
|
+
disableTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
29
|
+
_options$enableColorS = options.enableColorScheme,
|
|
30
|
+
enableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
|
|
22
31
|
_options$prefix = options.prefix,
|
|
23
32
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
24
33
|
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
|
|
34
|
+
var systemSpacing = createSpacing(baseTheme.spacing);
|
|
35
|
+
var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
25
36
|
|
|
26
37
|
if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
27
38
|
console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
|
|
@@ -53,16 +64,27 @@ export default function createCssVarsProvider(options) {
|
|
|
53
64
|
defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
|
|
54
65
|
_ref$defaultColorSche = _ref.defaultColorScheme,
|
|
55
66
|
defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche;
|
|
67
|
+
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
68
|
+
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
69
|
+
var clonedBaseTheme = React.useMemo(function () {
|
|
70
|
+
return JSON.parse(JSON.stringify(baseTheme));
|
|
71
|
+
}, []);
|
|
56
72
|
|
|
57
|
-
var
|
|
58
|
-
baseColorSchemes =
|
|
59
|
-
restBaseTheme = _objectWithoutProperties(
|
|
73
|
+
var _clonedBaseTheme$colo = clonedBaseTheme.colorSchemes,
|
|
74
|
+
baseColorSchemes = _clonedBaseTheme$colo === void 0 ? {} : _clonedBaseTheme$colo,
|
|
75
|
+
restBaseTheme = _objectWithoutProperties(clonedBaseTheme, ["colorSchemes"]);
|
|
60
76
|
|
|
61
77
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
62
78
|
colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
63
79
|
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes"]);
|
|
64
80
|
|
|
65
|
-
var
|
|
81
|
+
var hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
|
|
82
|
+
|
|
83
|
+
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
84
|
+
_deepmerge$components = _deepmerge.components,
|
|
85
|
+
components = _deepmerge$components === void 0 ? {} : _deepmerge$components,
|
|
86
|
+
mergedTheme = _objectWithoutProperties(_deepmerge, ["components"]);
|
|
87
|
+
|
|
66
88
|
var colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
67
89
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
68
90
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -77,6 +99,7 @@ export default function createCssVarsProvider(options) {
|
|
|
77
99
|
}),
|
|
78
100
|
mode = _useCurrentColorSchem.mode,
|
|
79
101
|
setMode = _useCurrentColorSchem.setMode,
|
|
102
|
+
systemMode = _useCurrentColorSchem.systemMode,
|
|
80
103
|
lightColorScheme = _useCurrentColorSchem.lightColorScheme,
|
|
81
104
|
darkColorScheme = _useCurrentColorSchem.darkColorScheme,
|
|
82
105
|
colorScheme = _useCurrentColorSchem.colorScheme,
|
|
@@ -105,7 +128,11 @@ export default function createCssVarsProvider(options) {
|
|
|
105
128
|
rootVars = _cssVarsParser.vars;
|
|
106
129
|
|
|
107
130
|
mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
108
|
-
|
|
131
|
+
components: components,
|
|
132
|
+
colorSchemes: colorSchemes,
|
|
133
|
+
vars: rootVars,
|
|
134
|
+
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
135
|
+
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
|
|
109
136
|
});
|
|
110
137
|
var styleSheet = {};
|
|
111
138
|
Object.entries(colorSchemes).forEach(function (_ref2) {
|
|
@@ -121,9 +148,7 @@ export default function createCssVarsProvider(options) {
|
|
|
121
148
|
css = _cssVarsParser2.css,
|
|
122
149
|
vars = _cssVarsParser2.vars;
|
|
123
150
|
|
|
124
|
-
|
|
125
|
-
mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
|
|
126
|
-
}
|
|
151
|
+
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
127
152
|
|
|
128
153
|
var resolvedDefaultColorScheme = function () {
|
|
129
154
|
if (typeof defaultColorScheme === 'string') {
|
|
@@ -145,9 +170,52 @@ export default function createCssVarsProvider(options) {
|
|
|
145
170
|
});
|
|
146
171
|
React.useEffect(function () {
|
|
147
172
|
if (colorScheme) {
|
|
148
|
-
|
|
173
|
+
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
174
|
+
document.documentElement.setAttribute(attribute, colorScheme);
|
|
149
175
|
}
|
|
150
176
|
}, [colorScheme, attribute]);
|
|
177
|
+
React.useEffect(function () {
|
|
178
|
+
if (!mode || !enableColorScheme) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
var priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
183
|
+
|
|
184
|
+
if (mode === 'system') {
|
|
185
|
+
document.documentElement.style.setProperty('color-scheme', systemMode);
|
|
186
|
+
} else {
|
|
187
|
+
document.documentElement.style.setProperty('color-scheme', mode);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return function () {
|
|
191
|
+
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
192
|
+
};
|
|
193
|
+
}, [mode, systemMode]);
|
|
194
|
+
React.useEffect(function () {
|
|
195
|
+
var timer;
|
|
196
|
+
|
|
197
|
+
if (disableTransitionOnChange && hasMounted.current) {
|
|
198
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
199
|
+
var css = document.createElement('style');
|
|
200
|
+
css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
|
|
201
|
+
document.head.appendChild(css); // Force browser repaint
|
|
202
|
+
|
|
203
|
+
(function () {
|
|
204
|
+
return window.getComputedStyle(document.body);
|
|
205
|
+
})();
|
|
206
|
+
|
|
207
|
+
timer = setTimeout(function () {
|
|
208
|
+
document.head.removeChild(css);
|
|
209
|
+
}, 1);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return function () {
|
|
213
|
+
clearTimeout(timer);
|
|
214
|
+
};
|
|
215
|
+
}, [colorScheme]);
|
|
216
|
+
React.useEffect(function () {
|
|
217
|
+
hasMounted.current = true;
|
|
218
|
+
}, []);
|
|
151
219
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
152
220
|
value: {
|
|
153
221
|
mode: mode,
|
|
@@ -178,7 +246,7 @@ export default function createCssVarsProvider(options) {
|
|
|
178
246
|
attribute: PropTypes.string,
|
|
179
247
|
|
|
180
248
|
/**
|
|
181
|
-
*
|
|
249
|
+
* The component tree.
|
|
182
250
|
*/
|
|
183
251
|
children: PropTypes.node,
|
|
184
252
|
|
|
@@ -198,7 +266,7 @@ export default function createCssVarsProvider(options) {
|
|
|
198
266
|
modeStorageKey: PropTypes.string,
|
|
199
267
|
|
|
200
268
|
/**
|
|
201
|
-
*
|
|
269
|
+
* CSS variable prefix.
|
|
202
270
|
*/
|
|
203
271
|
prefix: PropTypes.string,
|
|
204
272
|
|
|
@@ -49,7 +49,7 @@ export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
|
|
|
49
49
|
* // ['palette', 'primary', 'main'] '#000000'
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
export var walkObjectDeep = function walkObjectDeep(obj, callback) {
|
|
52
|
+
export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPaths) {
|
|
53
53
|
function recurse(object) {
|
|
54
54
|
var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
55
55
|
Object.entries(object).forEach(function (_ref) {
|
|
@@ -57,11 +57,13 @@ export var walkObjectDeep = function walkObjectDeep(obj, callback) {
|
|
|
57
57
|
key = _ref2[0],
|
|
58
58
|
value = _ref2[1];
|
|
59
59
|
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([].concat(_toConsumableArray(parentKeys), [key]))) {
|
|
61
|
+
if (value !== undefined && value !== null) {
|
|
62
|
+
if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
|
|
63
|
+
recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
|
|
64
|
+
} else {
|
|
65
|
+
callback([].concat(_toConsumableArray(parentKeys), [key]), value, object);
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
});
|
|
@@ -75,7 +77,7 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
75
77
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(function (prop) {
|
|
76
78
|
return keys.includes(prop);
|
|
77
79
|
})) {
|
|
78
|
-
//
|
|
80
|
+
// CSS property that are unitless
|
|
79
81
|
return value;
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -113,10 +115,6 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
113
115
|
|
|
114
116
|
|
|
115
117
|
export default function cssVarsParser(theme, options) {
|
|
116
|
-
var clonedTheme = _extends({}, theme);
|
|
117
|
-
|
|
118
|
-
delete clonedTheme.vars; // remove 'vars' from the structure
|
|
119
|
-
|
|
120
118
|
var _ref3 = options || {},
|
|
121
119
|
prefix = _ref3.prefix,
|
|
122
120
|
_ref3$basePrefix = _ref3.basePrefix,
|
|
@@ -125,13 +123,18 @@ export default function cssVarsParser(theme, options) {
|
|
|
125
123
|
|
|
126
124
|
var css = {};
|
|
127
125
|
var vars = {};
|
|
128
|
-
walkObjectDeep(
|
|
126
|
+
walkObjectDeep(theme, function (keys, val, scope) {
|
|
129
127
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
130
128
|
var _value = val;
|
|
131
129
|
|
|
132
130
|
if (typeof _value === 'string' && _value.startsWith('var')) {
|
|
133
131
|
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
134
|
-
|
|
132
|
+
if (!basePrefix && prefix) {
|
|
133
|
+
_value = _value.replace(/var\(--/g, "var(--".concat(prefix, "-"));
|
|
134
|
+
} else {
|
|
135
|
+
_value = prefix ? _value.replace(new RegExp(basePrefix, 'g'), prefix) : _value.replace(new RegExp("".concat(basePrefix, "-"), 'g'), '');
|
|
136
|
+
} // scope is the deepest object in the tree, keys is the theme path keys
|
|
137
|
+
|
|
135
138
|
|
|
136
139
|
scope[keys.slice(-1)[0]] = _value;
|
|
137
140
|
}
|
|
@@ -145,7 +148,10 @@ export default function cssVarsParser(theme, options) {
|
|
|
145
148
|
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
|
-
})
|
|
151
|
+
}, function (keys) {
|
|
152
|
+
return keys[0] === 'vars';
|
|
153
|
+
} // skip 'vars/*' paths
|
|
154
|
+
);
|
|
149
155
|
return {
|
|
150
156
|
css: css,
|
|
151
157
|
vars: vars
|
|
@@ -5,8 +5,7 @@ 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
|
-
|
|
9
|
-
defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
|
|
8
|
+
enableSystem = _ref.enableSystem,
|
|
10
9
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
11
10
|
defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
|
|
12
11
|
_ref$defaultDarkColor = _ref.defaultDarkColorScheme,
|
|
@@ -21,7 +20,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
21
20
|
return /*#__PURE__*/_jsx("script", {
|
|
22
21
|
// eslint-disable-next-line react/no-danger
|
|
23
22
|
dangerouslySetInnerHTML: {
|
|
24
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && ").concat(
|
|
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 document.documentElement.setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
}
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.2.3
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -27,6 +27,7 @@ export { default as style, getPath } from './style';
|
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
29
|
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
|
+
export { default as experimental_sx } from './sx';
|
|
30
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
31
32
|
export { default as Box } from './Box';
|
|
32
33
|
export { default as createBox } from './createBox';
|
|
@@ -54,27 +54,29 @@ function styleFunctionSx(props) {
|
|
|
54
54
|
Object.keys(sxObject).forEach(function (styleKey) {
|
|
55
55
|
var value = callIfFn(sxObject[styleKey], theme);
|
|
56
56
|
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}, value, function (x) {
|
|
64
|
-
return _defineProperty({}, styleKey, x);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
68
|
-
css[styleKey] = styleFunctionSx({
|
|
69
|
-
sx: value,
|
|
57
|
+
if (value !== null && value !== undefined) {
|
|
58
|
+
if (_typeof(value) === 'object') {
|
|
59
|
+
if (propToStyleFunction[styleKey]) {
|
|
60
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
61
|
+
} else {
|
|
62
|
+
var breakpointsValues = handleBreakpoints({
|
|
70
63
|
theme: theme
|
|
64
|
+
}, value, function (x) {
|
|
65
|
+
return _defineProperty({}, styleKey, x);
|
|
71
66
|
});
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
|
|
68
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
69
|
+
css[styleKey] = styleFunctionSx({
|
|
70
|
+
sx: value,
|
|
71
|
+
theme: theme
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
css = merge(css, breakpointsValues);
|
|
75
|
+
}
|
|
74
76
|
}
|
|
77
|
+
} else {
|
|
78
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
75
79
|
}
|
|
76
|
-
} else {
|
|
77
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
78
80
|
}
|
|
79
81
|
});
|
|
80
82
|
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/legacy/sx/sx.js
ADDED