@mui/system 5.4.1 → 5.4.4
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 +1 -1
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +177 -0
- package/createBox.d.ts +2 -0
- package/createBox.js +3 -2
- package/createBox.spec.d.ts +1 -1
- package/createStyled.d.ts +2 -1
- package/createStyled.js +12 -6
- package/createTheme/createBreakpoints.js +21 -6
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +59 -95
- package/cssVars/createCssVarsProvider.js +32 -15
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +7 -1
- package/cssVars/cssVarsParser.d.ts +70 -68
- package/cssVars/cssVarsParser.js +21 -20
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +1 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/createBox.js +3 -2
- package/esm/createStyled.js +10 -4
- package/esm/createTheme/createBreakpoints.js +20 -4
- package/esm/cssVars/createCssVarsProvider.js +32 -16
- package/esm/cssVars/createGetCssVar.js +7 -1
- package/esm/cssVars/cssVarsParser.js +21 -20
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +1 -1
- package/esm/styleFunctionSx/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
- package/getThemeValue.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +8 -1
- package/index.spec.d.ts +1 -1
- package/legacy/createBox.js +4 -2
- package/legacy/createStyled.js +11 -4
- package/legacy/createTheme/createBreakpoints.js +23 -4
- package/legacy/cssVars/createCssVarsProvider.js +35 -18
- package/legacy/cssVars/createGetCssVar.js +7 -1
- package/legacy/cssVars/cssVarsParser.js +23 -22
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +2 -2
- package/legacy/styleFunctionSx/index.js +1 -0
- package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
- package/modern/createBox.js +3 -2
- package/modern/createStyled.js +10 -4
- package/modern/createTheme/createBreakpoints.js +20 -4
- package/modern/cssVars/createCssVarsProvider.js +32 -16
- package/modern/cssVars/createGetCssVar.js +7 -1
- package/modern/cssVars/cssVarsParser.js +21 -20
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +2 -2
- package/modern/styleFunctionSx/index.js +1 -0
- package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
- package/package.json +6 -6
- package/style.d.ts +1 -1
- package/styleFunctionSx/index.js +12 -2
- package/styleFunctionSx/styleFunctionSx.d.ts +25 -3
- package/styleFunctionSx/styleFunctionSx.js +79 -54
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -26,12 +26,13 @@ export default function createCssVarsProvider(options) {
|
|
|
26
26
|
desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
27
27
|
designSystemColorScheme = options.defaultColorScheme,
|
|
28
28
|
_options$disableTrans = options.disableTransitionOnChange,
|
|
29
|
-
|
|
29
|
+
designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
30
30
|
_options$enableColorS = options.enableColorScheme,
|
|
31
|
-
|
|
31
|
+
designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
|
|
32
32
|
_options$prefix = options.prefix,
|
|
33
33
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
34
|
-
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar
|
|
34
|
+
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
35
|
+
resolveTheme = options.resolveTheme;
|
|
35
36
|
var systemSpacing = createSpacing(baseTheme.spacing);
|
|
36
37
|
var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
37
38
|
|
|
@@ -64,16 +65,15 @@ export default function createCssVarsProvider(options) {
|
|
|
64
65
|
_ref$defaultMode = _ref.defaultMode,
|
|
65
66
|
defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
|
|
66
67
|
_ref$defaultColorSche = _ref.defaultColorScheme,
|
|
67
|
-
defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}, []);
|
|
68
|
+
defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche,
|
|
69
|
+
_ref$disableTransitio = _ref.disableTransitionOnChange,
|
|
70
|
+
disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
|
|
71
|
+
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
72
|
+
enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem;
|
|
73
73
|
|
|
74
|
-
var
|
|
75
|
-
baseColorSchemes =
|
|
76
|
-
restBaseTheme = _objectWithoutProperties(
|
|
74
|
+
var _baseTheme$colorSchem = baseTheme.colorSchemes,
|
|
75
|
+
baseColorSchemes = _baseTheme$colorSchem === void 0 ? {} : _baseTheme$colorSchem,
|
|
76
|
+
restBaseTheme = _objectWithoutProperties(baseTheme, ["colorSchemes"]);
|
|
77
77
|
|
|
78
78
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
79
79
|
colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
@@ -126,11 +126,13 @@ export default function createCssVarsProvider(options) {
|
|
|
126
126
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
127
127
|
}),
|
|
128
128
|
rootCss = _cssVarsParser.css,
|
|
129
|
-
rootVars = _cssVarsParser.vars
|
|
129
|
+
rootVars = _cssVarsParser.vars,
|
|
130
|
+
parsedTheme = _cssVarsParser.parsedTheme;
|
|
130
131
|
|
|
131
|
-
mergedTheme = _extends({},
|
|
132
|
+
mergedTheme = _extends({}, parsedTheme, {
|
|
132
133
|
components: components,
|
|
133
134
|
colorSchemes: colorSchemes,
|
|
135
|
+
prefix: prefix,
|
|
134
136
|
vars: rootVars,
|
|
135
137
|
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
136
138
|
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
@@ -148,10 +150,15 @@ export default function createCssVarsProvider(options) {
|
|
|
148
150
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
149
151
|
}),
|
|
150
152
|
css = _cssVarsParser2.css,
|
|
151
|
-
vars = _cssVarsParser2.vars
|
|
153
|
+
vars = _cssVarsParser2.vars,
|
|
154
|
+
parsedScheme = _cssVarsParser2.parsedTheme;
|
|
152
155
|
|
|
153
156
|
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
154
157
|
|
|
158
|
+
if (key === resolvedColorScheme) {
|
|
159
|
+
mergedTheme = _extends({}, mergedTheme, parsedScheme);
|
|
160
|
+
}
|
|
161
|
+
|
|
155
162
|
var resolvedDefaultColorScheme = function () {
|
|
156
163
|
if (typeof defaultColorScheme === 'string') {
|
|
157
164
|
return defaultColorScheme;
|
|
@@ -192,7 +199,7 @@ export default function createCssVarsProvider(options) {
|
|
|
192
199
|
return function () {
|
|
193
200
|
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
194
201
|
};
|
|
195
|
-
}, [mode, systemMode]);
|
|
202
|
+
}, [mode, systemMode, enableColorScheme]);
|
|
196
203
|
React.useEffect(function () {
|
|
197
204
|
var timer;
|
|
198
205
|
|
|
@@ -214,7 +221,7 @@ export default function createCssVarsProvider(options) {
|
|
|
214
221
|
return function () {
|
|
215
222
|
clearTimeout(timer);
|
|
216
223
|
};
|
|
217
|
-
}, [colorScheme]);
|
|
224
|
+
}, [colorScheme, disableTransitionOnChange]);
|
|
218
225
|
React.useEffect(function () {
|
|
219
226
|
hasMounted.current = true;
|
|
220
227
|
return function () {
|
|
@@ -238,7 +245,7 @@ export default function createCssVarsProvider(options) {
|
|
|
238
245
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
239
246
|
styles: styleSheet
|
|
240
247
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
241
|
-
theme: mergedTheme,
|
|
248
|
+
theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
|
|
242
249
|
children: children
|
|
243
250
|
})]
|
|
244
251
|
});
|
|
@@ -265,6 +272,16 @@ export default function createCssVarsProvider(options) {
|
|
|
265
272
|
*/
|
|
266
273
|
defaultMode: PropTypes.string,
|
|
267
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Disable CSS transitions when switching between modes or color schemes
|
|
277
|
+
*/
|
|
278
|
+
disableTransitionOnChange: PropTypes.bool,
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
282
|
+
*/
|
|
283
|
+
enableColorScheme: PropTypes.bool,
|
|
284
|
+
|
|
268
285
|
/**
|
|
269
286
|
* The key in the local storage used to store current color scheme.
|
|
270
287
|
*/
|
|
@@ -16,7 +16,13 @@ export default function createGetCssVar() {
|
|
|
16
16
|
return '';
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
var value = vars[0];
|
|
20
|
+
|
|
21
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
22
|
+
return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(value).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return ", ".concat(value);
|
|
20
26
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
21
27
|
|
|
22
28
|
|
|
@@ -98,19 +98,20 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
98
98
|
* `basePrefix`: defined by design system.
|
|
99
99
|
* `prefix`: defined by application
|
|
100
100
|
*
|
|
101
|
-
*
|
|
101
|
+
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
102
102
|
*
|
|
103
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
103
|
+
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
104
104
|
*
|
|
105
105
|
* @example
|
|
106
|
-
* const { css, vars } = parser({
|
|
106
|
+
* const { css, vars, parsedTheme } = parser({
|
|
107
107
|
* fontSize: 12,
|
|
108
108
|
* lineHeight: 1.2,
|
|
109
|
-
* palette: { primary: { 500: '
|
|
110
|
-
* })
|
|
109
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
110
|
+
* }, { prefix: 'foo' })
|
|
111
111
|
*
|
|
112
|
-
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '
|
|
113
|
-
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
112
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
113
|
+
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
114
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
114
115
|
*/
|
|
115
116
|
|
|
116
117
|
|
|
@@ -123,37 +124,37 @@ export default function cssVarsParser(theme, options) {
|
|
|
123
124
|
|
|
124
125
|
var css = {};
|
|
125
126
|
var vars = {};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
127
|
+
var parsedTheme = {};
|
|
128
|
+
walkObjectDeep(theme, function (keys, value) {
|
|
129
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
130
|
+
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
131
|
+
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
132
132
|
if (!basePrefix && prefix) {
|
|
133
|
-
|
|
133
|
+
value = value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
|
|
134
134
|
} else {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
scope[keys.slice(-1)[0]] = _value;
|
|
135
|
+
value = prefix ? value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
|
|
136
|
+
: value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
|
|
137
|
+
}
|
|
140
138
|
}
|
|
141
139
|
|
|
142
|
-
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys,
|
|
140
|
+
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
143
141
|
// only create css & var if `shouldSkipGeneratingVar` return false
|
|
144
142
|
var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
|
|
145
143
|
|
|
146
|
-
_extends(css, _defineProperty({}, cssVar, getCssValue(keys,
|
|
144
|
+
_extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
|
|
147
145
|
|
|
148
146
|
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
|
|
149
147
|
}
|
|
150
148
|
}
|
|
149
|
+
|
|
150
|
+
assignNestedKeys(parsedTheme, keys, value);
|
|
151
151
|
}, function (keys) {
|
|
152
152
|
return keys[0] === 'vars';
|
|
153
153
|
} // skip 'vars/*' paths
|
|
154
154
|
);
|
|
155
155
|
return {
|
|
156
156
|
css: css,
|
|
157
|
-
vars: vars
|
|
157
|
+
vars: vars,
|
|
158
|
+
parsedTheme: parsedTheme
|
|
158
159
|
};
|
|
159
160
|
}
|
package/legacy/getThemeValue.js
CHANGED
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.4.
|
|
1
|
+
/** @license MUI v5.4.4
|
|
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.
|
|
@@ -26,7 +26,7 @@ export * from './spacing';
|
|
|
26
26
|
export { default as style, getPath } from './style';
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
|
-
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
29
|
+
export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
30
|
export { default as experimental_sx } from './sx';
|
|
31
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
32
32
|
export { default as Box } from './Box';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
3
|
import merge from '../merge';
|
|
4
|
-
import
|
|
4
|
+
import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
|
|
5
5
|
import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
|
|
6
6
|
|
|
7
7
|
function objectsHaveSameKeys() {
|
|
@@ -20,70 +20,95 @@ function objectsHaveSameKeys() {
|
|
|
20
20
|
|
|
21
21
|
function callIfFn(maybeFn, arg) {
|
|
22
22
|
return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
|
|
23
|
-
}
|
|
23
|
+
} // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
24
24
|
|
|
25
|
-
function styleFunctionSx(props) {
|
|
26
|
-
var _ref = props || {},
|
|
27
|
-
sx = _ref.sx,
|
|
28
|
-
_ref$theme = _ref.theme,
|
|
29
|
-
theme = _ref$theme === void 0 ? {} : _ref$theme;
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
export function unstable_createStyleFunctionSx() {
|
|
27
|
+
var styleFunctionMapping = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultStyleFunctionMapping;
|
|
28
|
+
var propToStyleFunction = Object.keys(styleFunctionMapping).reduce(function (acc, styleFnName) {
|
|
29
|
+
styleFunctionMapping[styleFnName].filterProps.forEach(function (propName) {
|
|
30
|
+
acc[propName] = styleFunctionMapping[styleFnName];
|
|
31
|
+
});
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
|
|
35
|
+
function getThemeValue(prop, value, theme) {
|
|
36
|
+
var _inputProps;
|
|
39
37
|
|
|
38
|
+
var inputProps = (_inputProps = {}, _defineProperty(_inputProps, prop, value), _defineProperty(_inputProps, "theme", theme), _inputProps);
|
|
39
|
+
var styleFunction = propToStyleFunction[prop];
|
|
40
|
+
return styleFunction ? styleFunction(inputProps) : _defineProperty({}, prop, value);
|
|
41
|
+
}
|
|
40
42
|
|
|
41
|
-
function
|
|
42
|
-
var
|
|
43
|
+
function styleFunctionSx(props) {
|
|
44
|
+
var _ref2 = props || {},
|
|
45
|
+
sx = _ref2.sx,
|
|
46
|
+
_ref2$theme = _ref2.theme,
|
|
47
|
+
theme = _ref2$theme === void 0 ? {} : _ref2$theme;
|
|
43
48
|
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
} else if (_typeof(sxInput) !== 'object') {
|
|
47
|
-
// value
|
|
48
|
-
return sxInput;
|
|
49
|
+
if (!sx) {
|
|
50
|
+
return null; // emotion & styled-components will neglect null
|
|
49
51
|
}
|
|
52
|
+
/*
|
|
53
|
+
* Receive `sxInput` as object or callback
|
|
54
|
+
* and then recursively check keys & values to create media query object styles.
|
|
55
|
+
* (the result will be used in `styled`)
|
|
56
|
+
*/
|
|
50
57
|
|
|
51
|
-
var emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
52
|
-
var breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
53
|
-
var css = emptyBreakpoints;
|
|
54
|
-
Object.keys(sxObject).forEach(function (styleKey) {
|
|
55
|
-
var value = callIfFn(sxObject[styleKey], theme);
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
function traverse(sxInput) {
|
|
60
|
+
var sxObject = sxInput;
|
|
61
|
+
|
|
62
|
+
if (typeof sxInput === 'function') {
|
|
63
|
+
sxObject = sxInput(theme);
|
|
64
|
+
} else if (_typeof(sxInput) !== 'object') {
|
|
65
|
+
// value
|
|
66
|
+
return sxInput;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!sxObject) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
74
|
+
var breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
75
|
+
var css = emptyBreakpoints;
|
|
76
|
+
Object.keys(sxObject).forEach(function (styleKey) {
|
|
77
|
+
var value = callIfFn(sxObject[styleKey], theme);
|
|
78
|
+
|
|
79
|
+
if (value !== null && value !== undefined) {
|
|
80
|
+
if (_typeof(value) === 'object') {
|
|
81
|
+
if (propToStyleFunction[styleKey]) {
|
|
82
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
83
|
+
} else {
|
|
84
|
+
var breakpointsValues = handleBreakpoints({
|
|
71
85
|
theme: theme
|
|
86
|
+
}, value, function (x) {
|
|
87
|
+
return _defineProperty({}, styleKey, x);
|
|
72
88
|
});
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
|
|
90
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
91
|
+
css[styleKey] = styleFunctionSx({
|
|
92
|
+
sx: value,
|
|
93
|
+
theme: theme
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
css = merge(css, breakpointsValues);
|
|
97
|
+
}
|
|
75
98
|
}
|
|
99
|
+
} else {
|
|
100
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
76
101
|
}
|
|
77
|
-
} else {
|
|
78
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
79
102
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
103
|
+
});
|
|
104
|
+
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
83
108
|
}
|
|
84
109
|
|
|
85
|
-
return
|
|
110
|
+
return styleFunctionSx;
|
|
86
111
|
}
|
|
87
|
-
|
|
112
|
+
var styleFunctionSx = unstable_createStyleFunctionSx();
|
|
88
113
|
styleFunctionSx.filterProps = ['sx'];
|
|
89
114
|
export default styleFunctionSx;
|
package/modern/createBox.js
CHANGED
|
@@ -5,14 +5,15 @@ import * as React from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import styled from '@mui/styled-engine';
|
|
8
|
-
import
|
|
8
|
+
import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
|
|
9
9
|
import useTheme from './useTheme';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
export default function createBox(options = {}) {
|
|
12
12
|
const {
|
|
13
13
|
defaultTheme,
|
|
14
14
|
defaultClassName = 'MuiBox-root',
|
|
15
|
-
generateClassName
|
|
15
|
+
generateClassName,
|
|
16
|
+
styleFunctionSx = defaultStyleFunctionSx
|
|
16
17
|
} = options;
|
|
17
18
|
const BoxRoot = styled('div')(styleFunctionSx);
|
|
18
19
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
package/modern/createStyled.js
CHANGED
|
@@ -6,8 +6,8 @@ const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesR
|
|
|
6
6
|
import styledEngineStyled from '@mui/styled-engine';
|
|
7
7
|
import { getDisplayName } from '@mui/utils';
|
|
8
8
|
import createTheme from './createTheme';
|
|
9
|
-
import styleFunctionSx from './styleFunctionSx';
|
|
10
9
|
import propsToClassKey from './propsToClassKey';
|
|
10
|
+
import defaultStyleFunctionSx from './styleFunctionSx';
|
|
11
11
|
|
|
12
12
|
function isEmpty(obj) {
|
|
13
13
|
return Object.keys(obj).length === 0;
|
|
@@ -59,7 +59,8 @@ const variantsResolver = (props, styles, theme, name) => {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return variantsStyles;
|
|
62
|
-
};
|
|
62
|
+
}; // Update /system/styled/#api in case if this changes
|
|
63
|
+
|
|
63
64
|
|
|
64
65
|
export function shouldForwardProp(prop) {
|
|
65
66
|
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
@@ -74,7 +75,8 @@ export default function createStyled(input = {}) {
|
|
|
74
75
|
const {
|
|
75
76
|
defaultTheme = systemDefaultTheme,
|
|
76
77
|
rootShouldForwardProp = shouldForwardProp,
|
|
77
|
-
slotShouldForwardProp = shouldForwardProp
|
|
78
|
+
slotShouldForwardProp = shouldForwardProp,
|
|
79
|
+
styleFunctionSx = defaultStyleFunctionSx
|
|
78
80
|
} = input;
|
|
79
81
|
return (tag, inputOptions = {}) => {
|
|
80
82
|
const {
|
|
@@ -170,7 +172,11 @@ export default function createStyled(input = {}) {
|
|
|
170
172
|
|
|
171
173
|
transformedStyleArg = [...styleArg, ...placeholders];
|
|
172
174
|
transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
|
|
173
|
-
} else if (typeof styleArg === 'function'
|
|
175
|
+
} else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
|
|
176
|
+
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
177
|
+
// which are basically components used as a selectors.
|
|
178
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
179
|
+
styleArg.__emotion_real !== styleArg) {
|
|
174
180
|
// If the type is function, we need to define the default theme.
|
|
175
181
|
transformedStyleArg = _ref2 => {
|
|
176
182
|
let {
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
const _excluded = ["values", "unit", "step"];
|
|
4
4
|
// Sorted ASC by size. That's important.
|
|
5
5
|
// It can't be configured as it's used statically for propTypes.
|
|
6
|
-
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
6
|
+
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
7
|
+
|
|
8
|
+
const sortBreakpointsValues = values => {
|
|
9
|
+
const breakpointsAsArray = Object.keys(values).map(key => ({
|
|
10
|
+
key,
|
|
11
|
+
val: values[key]
|
|
12
|
+
})) || []; // Sort in ascending order
|
|
13
|
+
|
|
14
|
+
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
15
|
+
return breakpointsAsArray.reduce((acc, obj) => {
|
|
16
|
+
return _extends({}, acc, {
|
|
17
|
+
[obj.key]: obj.val
|
|
18
|
+
});
|
|
19
|
+
}, {});
|
|
20
|
+
}; // Keep in mind that @media is inclusive by the CSS specification.
|
|
21
|
+
|
|
7
22
|
|
|
8
23
|
export default function createBreakpoints(breakpoints) {
|
|
9
24
|
const {
|
|
@@ -26,7 +41,8 @@ export default function createBreakpoints(breakpoints) {
|
|
|
26
41
|
} = breakpoints,
|
|
27
42
|
other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
|
|
28
43
|
|
|
29
|
-
const
|
|
44
|
+
const sortedValues = sortBreakpointsValues(values);
|
|
45
|
+
const keys = Object.keys(sortedValues);
|
|
30
46
|
|
|
31
47
|
function up(key) {
|
|
32
48
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
@@ -68,7 +84,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
68
84
|
|
|
69
85
|
return _extends({
|
|
70
86
|
keys,
|
|
71
|
-
values,
|
|
87
|
+
values: sortedValues,
|
|
72
88
|
up,
|
|
73
89
|
down,
|
|
74
90
|
between,
|
|
@@ -23,10 +23,11 @@ export default function createCssVarsProvider(options) {
|
|
|
23
23
|
theme: baseTheme = {},
|
|
24
24
|
defaultMode: desisgnSystemMode = 'light',
|
|
25
25
|
defaultColorScheme: designSystemColorScheme,
|
|
26
|
-
disableTransitionOnChange = false,
|
|
27
|
-
enableColorScheme = true,
|
|
26
|
+
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
27
|
+
enableColorScheme: designSystemEnableColorScheme = true,
|
|
28
28
|
prefix: designSystemPrefix = '',
|
|
29
|
-
shouldSkipGeneratingVar
|
|
29
|
+
shouldSkipGeneratingVar,
|
|
30
|
+
resolveTheme
|
|
30
31
|
} = options;
|
|
31
32
|
const systemSpacing = createSpacing(baseTheme.spacing);
|
|
32
33
|
const systemBreakpoints = createBreakpoints(baseTheme.breakpoints ?? {});
|
|
@@ -54,16 +55,14 @@ export default function createCssVarsProvider(options) {
|
|
|
54
55
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
55
56
|
attribute = DEFAULT_ATTRIBUTE,
|
|
56
57
|
defaultMode = desisgnSystemMode,
|
|
57
|
-
defaultColorScheme = designSystemColorScheme
|
|
58
|
+
defaultColorScheme = designSystemColorScheme,
|
|
59
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
60
|
+
enableColorScheme = designSystemEnableColorScheme
|
|
58
61
|
}) {
|
|
59
|
-
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
60
|
-
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
61
|
-
const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
|
|
62
|
-
|
|
63
62
|
const {
|
|
64
63
|
colorSchemes: baseColorSchemes = {}
|
|
65
|
-
} =
|
|
66
|
-
restBaseTheme = _objectWithoutPropertiesLoose(
|
|
64
|
+
} = baseTheme,
|
|
65
|
+
restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
|
|
67
66
|
|
|
68
67
|
const {
|
|
69
68
|
colorSchemes: colorSchemesProp = {}
|
|
@@ -114,15 +113,17 @@ export default function createCssVarsProvider(options) {
|
|
|
114
113
|
|
|
115
114
|
const {
|
|
116
115
|
css: rootCss,
|
|
117
|
-
vars: rootVars
|
|
116
|
+
vars: rootVars,
|
|
117
|
+
parsedTheme
|
|
118
118
|
} = cssVarsParser(mergedTheme, {
|
|
119
119
|
prefix,
|
|
120
120
|
basePrefix: designSystemPrefix,
|
|
121
121
|
shouldSkipGeneratingVar
|
|
122
122
|
});
|
|
123
|
-
mergedTheme = _extends({},
|
|
123
|
+
mergedTheme = _extends({}, parsedTheme, {
|
|
124
124
|
components,
|
|
125
125
|
colorSchemes,
|
|
126
|
+
prefix,
|
|
126
127
|
vars: rootVars,
|
|
127
128
|
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
128
129
|
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
@@ -132,7 +133,8 @@ export default function createCssVarsProvider(options) {
|
|
|
132
133
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
133
134
|
const {
|
|
134
135
|
css,
|
|
135
|
-
vars
|
|
136
|
+
vars,
|
|
137
|
+
parsedTheme: parsedScheme
|
|
136
138
|
} = cssVarsParser(scheme, {
|
|
137
139
|
prefix,
|
|
138
140
|
basePrefix: designSystemPrefix,
|
|
@@ -140,6 +142,10 @@ export default function createCssVarsProvider(options) {
|
|
|
140
142
|
});
|
|
141
143
|
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
142
144
|
|
|
145
|
+
if (key === resolvedColorScheme) {
|
|
146
|
+
mergedTheme = _extends({}, mergedTheme, parsedScheme);
|
|
147
|
+
}
|
|
148
|
+
|
|
143
149
|
const resolvedDefaultColorScheme = (() => {
|
|
144
150
|
if (typeof defaultColorScheme === 'string') {
|
|
145
151
|
return defaultColorScheme;
|
|
@@ -180,7 +186,7 @@ export default function createCssVarsProvider(options) {
|
|
|
180
186
|
return () => {
|
|
181
187
|
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
182
188
|
};
|
|
183
|
-
}, [mode, systemMode]);
|
|
189
|
+
}, [mode, systemMode, enableColorScheme]);
|
|
184
190
|
React.useEffect(() => {
|
|
185
191
|
let timer;
|
|
186
192
|
|
|
@@ -200,7 +206,7 @@ export default function createCssVarsProvider(options) {
|
|
|
200
206
|
return () => {
|
|
201
207
|
clearTimeout(timer);
|
|
202
208
|
};
|
|
203
|
-
}, [colorScheme]);
|
|
209
|
+
}, [colorScheme, disableTransitionOnChange]);
|
|
204
210
|
React.useEffect(() => {
|
|
205
211
|
hasMounted.current = true;
|
|
206
212
|
return () => {
|
|
@@ -224,7 +230,7 @@ export default function createCssVarsProvider(options) {
|
|
|
224
230
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
225
231
|
styles: styleSheet
|
|
226
232
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
227
|
-
theme: mergedTheme,
|
|
233
|
+
theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
|
|
228
234
|
children: children
|
|
229
235
|
})]
|
|
230
236
|
});
|
|
@@ -251,6 +257,16 @@ export default function createCssVarsProvider(options) {
|
|
|
251
257
|
*/
|
|
252
258
|
defaultMode: PropTypes.string,
|
|
253
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Disable CSS transitions when switching between modes or color schemes
|
|
262
|
+
*/
|
|
263
|
+
disableTransitionOnChange: PropTypes.bool,
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
267
|
+
*/
|
|
268
|
+
enableColorScheme: PropTypes.bool,
|
|
269
|
+
|
|
254
270
|
/**
|
|
255
271
|
* The key in the local storage used to store current color scheme.
|
|
256
272
|
*/
|
|
@@ -8,7 +8,13 @@ export default function createGetCssVar(prefix = '') {
|
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const value = vars[0];
|
|
12
|
+
|
|
13
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
14
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return `, ${value}`;
|
|
12
18
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
13
19
|
|
|
14
20
|
|