@mui/system 5.11.15 → 5.12.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/CHANGELOG.md +139 -26
- package/GlobalStyles/GlobalStyles.d.ts +13 -0
- package/GlobalStyles/GlobalStyles.js +45 -0
- package/GlobalStyles/index.d.ts +2 -0
- package/GlobalStyles/index.js +26 -0
- package/GlobalStyles/package.json +6 -0
- package/ThemeProvider/ThemeProvider.d.ts +4 -0
- package/ThemeProvider/ThemeProvider.js +43 -17
- package/createBox.d.ts +1 -0
- package/createBox.js +2 -1
- package/createStyled.d.ts +1 -0
- package/createStyled.js +34 -24
- package/cssVars/createCssVarsProvider.d.ts +22 -7
- package/cssVars/createCssVarsProvider.js +7 -3
- package/esm/GlobalStyles/GlobalStyles.js +35 -0
- package/esm/GlobalStyles/index.js +2 -0
- package/esm/ThemeProvider/ThemeProvider.js +44 -18
- package/esm/createBox.js +2 -1
- package/esm/createStyled.js +34 -24
- package/esm/cssVars/createCssVarsProvider.js +7 -3
- package/esm/index.js +2 -1
- package/esm/useThemeProps/useThemeProps.js +6 -2
- package/esm/useThemeWithoutDefault.js +3 -2
- package/index.d.ts +2 -2
- package/index.js +4 -3
- package/legacy/GlobalStyles/GlobalStyles.js +35 -0
- package/legacy/GlobalStyles/index.js +2 -0
- package/legacy/ThemeProvider/ThemeProvider.js +44 -19
- package/legacy/createBox.js +3 -2
- package/legacy/createStyled.js +34 -17
- package/legacy/cssVars/createCssVarsProvider.js +18 -14
- package/legacy/index.js +3 -2
- package/legacy/useThemeProps/useThemeProps.js +5 -1
- package/legacy/useThemeWithoutDefault.js +3 -2
- package/modern/GlobalStyles/GlobalStyles.js +35 -0
- package/modern/GlobalStyles/index.js +2 -0
- package/modern/ThemeProvider/ThemeProvider.js +44 -18
- package/modern/createBox.js +2 -1
- package/modern/createStyled.js +34 -24
- package/modern/cssVars/createCssVarsProvider.js +7 -3
- package/modern/index.js +3 -2
- package/modern/useThemeProps/useThemeProps.js +6 -2
- package/modern/useThemeWithoutDefault.js +3 -2
- package/package.json +6 -6
- package/useThemeProps/useThemeProps.d.ts +6 -1
- package/useThemeProps/useThemeProps.js +6 -2
- package/useThemeWithoutDefault.js +5 -2
- package/Box/Box.spec.d.ts +0 -1
- package/createBox.spec.d.ts +0 -1
- package/cssVars/createCssVarsProvider.spec.d.ts +0 -1
- package/index.spec.d.ts +0 -1
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +0 -1
|
@@ -1,36 +1,57 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { ThemeProvider as MuiThemeProvider } from '@mui/private-theming';
|
|
5
|
+
import { ThemeProvider as MuiThemeProvider, useTheme as usePrivateTheme } from '@mui/private-theming';
|
|
5
6
|
import { exactProp } from '@mui/utils';
|
|
6
7
|
import { ThemeContext as StyledEngineThemeContext } from '@mui/styled-engine';
|
|
7
|
-
import
|
|
8
|
+
import useThemeWithoutDefault from '../useThemeWithoutDefault';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
var EMPTY_THEME = {};
|
|
10
|
-
function
|
|
11
|
-
var
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
function useThemeScoping(themeId, upperTheme, localTheme) {
|
|
12
|
+
var isPrivate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
13
|
+
return React.useMemo(function () {
|
|
14
|
+
var resolvedTheme = themeId ? upperTheme[themeId] || upperTheme : upperTheme;
|
|
15
|
+
if (typeof localTheme === 'function') {
|
|
16
|
+
var mergedTheme = localTheme(resolvedTheme);
|
|
17
|
+
var result = themeId ? _extends({}, upperTheme, _defineProperty({}, themeId, mergedTheme)) : mergedTheme;
|
|
18
|
+
// must return a function for the private theme to NOT merge with the upper theme.
|
|
19
|
+
// see the test case "use provided theme from a callback" in ThemeProvider.test.js
|
|
20
|
+
if (isPrivate) {
|
|
21
|
+
return function () {
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
return themeId ? _extends({}, upperTheme, _defineProperty({}, themeId, localTheme)) : _extends({}, upperTheme, localTheme);
|
|
28
|
+
}, [themeId, upperTheme, localTheme, isPrivate]);
|
|
16
29
|
}
|
|
17
|
-
process.env.NODE_ENV !== "production" ? InnerThemeProvider.propTypes = {
|
|
18
|
-
/**
|
|
19
|
-
* Your component tree.
|
|
20
|
-
*/
|
|
21
|
-
children: PropTypes.node
|
|
22
|
-
} : void 0;
|
|
23
30
|
|
|
24
31
|
/**
|
|
25
32
|
* This component makes the `theme` available down the React tree.
|
|
26
33
|
* It should preferably be used at **the root of your component tree**.
|
|
34
|
+
*
|
|
35
|
+
* <ThemeProvider theme={theme}> // existing use case
|
|
36
|
+
* <ThemeProvider theme={{ id: theme }}> // theme scoping
|
|
27
37
|
*/
|
|
28
38
|
function ThemeProvider(props) {
|
|
29
39
|
var children = props.children,
|
|
30
|
-
localTheme = props.theme
|
|
40
|
+
localTheme = props.theme,
|
|
41
|
+
themeId = props.themeId;
|
|
42
|
+
var upperTheme = useThemeWithoutDefault(EMPTY_THEME);
|
|
43
|
+
var upperPrivateTheme = usePrivateTheme() || EMPTY_THEME;
|
|
44
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
45
|
+
if (upperTheme === null && typeof localTheme === 'function' || themeId && upperTheme && !upperTheme[themeId] && typeof localTheme === 'function') {
|
|
46
|
+
console.error(['MUI: You are providing a theme function prop to the ThemeProvider component:', '<ThemeProvider theme={outerTheme => outerTheme} />', '', 'However, no outer theme is present.', 'Make sure a theme is already injected higher in the React tree ' + 'or provide a theme object.'].join('\n'));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var engineTheme = useThemeScoping(themeId, upperTheme, localTheme);
|
|
50
|
+
var privateTheme = useThemeScoping(themeId, upperPrivateTheme, localTheme, true);
|
|
31
51
|
return /*#__PURE__*/_jsx(MuiThemeProvider, {
|
|
32
|
-
theme:
|
|
33
|
-
children: /*#__PURE__*/_jsx(
|
|
52
|
+
theme: privateTheme,
|
|
53
|
+
children: /*#__PURE__*/_jsx(StyledEngineThemeContext.Provider, {
|
|
54
|
+
value: engineTheme,
|
|
34
55
|
children: children
|
|
35
56
|
})
|
|
36
57
|
});
|
|
@@ -47,7 +68,11 @@ process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes /* remove-propty
|
|
|
47
68
|
/**
|
|
48
69
|
* A theme object. You can provide a function to extend the outer theme.
|
|
49
70
|
*/
|
|
50
|
-
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired
|
|
71
|
+
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
|
|
72
|
+
/**
|
|
73
|
+
* The design system's unique id for getting the corresponded theme when there are multiple design systems.
|
|
74
|
+
*/
|
|
75
|
+
themeId: PropTypes.string
|
|
51
76
|
} : void 0;
|
|
52
77
|
if (process.env.NODE_ENV !== 'production') {
|
|
53
78
|
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes = exactProp(ThemeProvider.propTypes) : void 0;
|
package/legacy/createBox.js
CHANGED
|
@@ -8,7 +8,8 @@ import useTheme from './useTheme';
|
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export default function createBox() {
|
|
10
10
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
|
-
var
|
|
11
|
+
var themeId = options.themeId,
|
|
12
|
+
defaultTheme = options.defaultTheme,
|
|
12
13
|
_options$defaultClass = options.defaultClassName,
|
|
13
14
|
defaultClassName = _options$defaultClass === void 0 ? 'MuiBox-root' : _options$defaultClass,
|
|
14
15
|
generateClassName = options.generateClassName;
|
|
@@ -28,7 +29,7 @@ export default function createBox() {
|
|
|
28
29
|
as: component,
|
|
29
30
|
ref: ref,
|
|
30
31
|
className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
|
|
31
|
-
theme: theme
|
|
32
|
+
theme: themeId ? theme[themeId] || theme : theme
|
|
32
33
|
}, other));
|
|
33
34
|
});
|
|
34
35
|
return Box;
|
package/legacy/createStyled.js
CHANGED
|
@@ -68,18 +68,27 @@ export var systemDefaultTheme = createTheme();
|
|
|
68
68
|
var lowercaseFirstLetter = function lowercaseFirstLetter(string) {
|
|
69
69
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
70
70
|
};
|
|
71
|
+
function resolveTheme(_ref) {
|
|
72
|
+
var defaultTheme = _ref.defaultTheme,
|
|
73
|
+
theme = _ref.theme,
|
|
74
|
+
themeId = _ref.themeId;
|
|
75
|
+
return isEmpty(theme) ? defaultTheme : theme[themeId] || theme;
|
|
76
|
+
}
|
|
71
77
|
export default function createStyled() {
|
|
72
78
|
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
73
|
-
var
|
|
79
|
+
var themeId = input.themeId,
|
|
80
|
+
_input$defaultTheme = input.defaultTheme,
|
|
74
81
|
defaultTheme = _input$defaultTheme === void 0 ? systemDefaultTheme : _input$defaultTheme,
|
|
75
82
|
_input$rootShouldForw = input.rootShouldForwardProp,
|
|
76
83
|
rootShouldForwardProp = _input$rootShouldForw === void 0 ? shouldForwardProp : _input$rootShouldForw,
|
|
77
84
|
_input$slotShouldForw = input.slotShouldForwardProp,
|
|
78
85
|
slotShouldForwardProp = _input$slotShouldForw === void 0 ? shouldForwardProp : _input$slotShouldForw;
|
|
79
86
|
var systemSx = function systemSx(props) {
|
|
80
|
-
var theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
81
87
|
return styleFunctionSx(_extends({}, props, {
|
|
82
|
-
theme:
|
|
88
|
+
theme: resolveTheme(_extends({}, props, {
|
|
89
|
+
defaultTheme: defaultTheme,
|
|
90
|
+
themeId: themeId
|
|
91
|
+
}))
|
|
83
92
|
}));
|
|
84
93
|
};
|
|
85
94
|
systemSx.__mui_systemSx = true;
|
|
@@ -127,18 +136,22 @@ export default function createStyled() {
|
|
|
127
136
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
128
137
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
129
138
|
// which are basically components used as a selectors.
|
|
130
|
-
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? function (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? function (props) {
|
|
140
|
+
return stylesArg(_extends({}, props, {
|
|
141
|
+
theme: resolveTheme(_extends({}, props, {
|
|
142
|
+
defaultTheme: defaultTheme,
|
|
143
|
+
themeId: themeId
|
|
144
|
+
}))
|
|
145
|
+
}));
|
|
136
146
|
} : stylesArg;
|
|
137
147
|
}) : [];
|
|
138
148
|
var transformedStyleArg = styleArg;
|
|
139
149
|
if (componentName && overridesResolver) {
|
|
140
150
|
expressionsWithDefaultTheme.push(function (props) {
|
|
141
|
-
var theme =
|
|
151
|
+
var theme = resolveTheme(_extends({}, props, {
|
|
152
|
+
defaultTheme: defaultTheme,
|
|
153
|
+
themeId: themeId
|
|
154
|
+
}));
|
|
142
155
|
var styleOverrides = getStyleOverrides(componentName, theme);
|
|
143
156
|
if (styleOverrides) {
|
|
144
157
|
var resolvedStyleOverrides = {};
|
|
@@ -157,7 +170,10 @@ export default function createStyled() {
|
|
|
157
170
|
}
|
|
158
171
|
if (componentName && !skipVariantsResolver) {
|
|
159
172
|
expressionsWithDefaultTheme.push(function (props) {
|
|
160
|
-
var theme =
|
|
173
|
+
var theme = resolveTheme(_extends({}, props, {
|
|
174
|
+
defaultTheme: defaultTheme,
|
|
175
|
+
themeId: themeId
|
|
176
|
+
}));
|
|
161
177
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
162
178
|
});
|
|
163
179
|
}
|
|
@@ -176,12 +192,13 @@ export default function createStyled() {
|
|
|
176
192
|
// which are basically components used as a selectors.
|
|
177
193
|
styleArg.__emotion_real !== styleArg) {
|
|
178
194
|
// If the type is function, we need to define the default theme.
|
|
179
|
-
transformedStyleArg = function transformedStyleArg(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
195
|
+
transformedStyleArg = function transformedStyleArg(props) {
|
|
196
|
+
return styleArg(_extends({}, props, {
|
|
197
|
+
theme: resolveTheme(_extends({}, props, {
|
|
198
|
+
defaultTheme: defaultTheme,
|
|
199
|
+
themeId: themeId
|
|
200
|
+
}))
|
|
201
|
+
}));
|
|
185
202
|
};
|
|
186
203
|
}
|
|
187
204
|
var Component = defaultStyledResolver.apply(void 0, [transformedStyleArg].concat(_toConsumableArray(expressionsWithDefaultTheme)));
|
|
@@ -16,7 +16,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
16
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
17
|
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
18
18
|
export default function createCssVarsProvider(options) {
|
|
19
|
-
var
|
|
19
|
+
var themeId = options.themeId,
|
|
20
|
+
_options$theme = options.theme,
|
|
20
21
|
defaultTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
21
22
|
_options$attribute = options.attribute,
|
|
22
23
|
defaultAttribute = _options$attribute === void 0 ? DEFAULT_ATTRIBUTE : _options$attribute,
|
|
@@ -74,19 +75,21 @@ export default function createCssVarsProvider(options) {
|
|
|
74
75
|
var upperTheme = muiUseTheme();
|
|
75
76
|
var ctx = React.useContext(ColorSchemeContext);
|
|
76
77
|
var nested = !!ctx && !disableNestedContext;
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
var scopedTheme = themeProp[themeId];
|
|
79
|
+
var _ref2 = scopedTheme || themeProp,
|
|
80
|
+
_ref2$colorSchemes = _ref2.colorSchemes,
|
|
81
|
+
colorSchemes = _ref2$colorSchemes === void 0 ? {} : _ref2$colorSchemes,
|
|
82
|
+
_ref2$components = _ref2.components,
|
|
83
|
+
components = _ref2$components === void 0 ? {} : _ref2$components,
|
|
84
|
+
_ref2$generateCssVars = _ref2.generateCssVars,
|
|
85
|
+
generateCssVars = _ref2$generateCssVars === void 0 ? function () {
|
|
83
86
|
return {
|
|
84
87
|
vars: {},
|
|
85
88
|
css: {}
|
|
86
89
|
};
|
|
87
|
-
} :
|
|
88
|
-
cssVarPrefix =
|
|
89
|
-
restThemeProp = _objectWithoutProperties(
|
|
90
|
+
} : _ref2$generateCssVars,
|
|
91
|
+
cssVarPrefix = _ref2.cssVarPrefix,
|
|
92
|
+
restThemeProp = _objectWithoutProperties(_ref2, ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"]);
|
|
90
93
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
91
94
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
92
95
|
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -155,10 +158,10 @@ export default function createCssVarsProvider(options) {
|
|
|
155
158
|
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
156
159
|
var defaultColorSchemeStyleSheet = {};
|
|
157
160
|
var otherColorSchemesStyleSheet = {};
|
|
158
|
-
Object.entries(colorSchemes).forEach(function (
|
|
159
|
-
var
|
|
160
|
-
key =
|
|
161
|
-
scheme =
|
|
161
|
+
Object.entries(colorSchemes).forEach(function (_ref3) {
|
|
162
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
163
|
+
key = _ref4[0],
|
|
164
|
+
scheme = _ref4[1];
|
|
162
165
|
var _generateCssVars2 = generateCssVars(key),
|
|
163
166
|
css = _generateCssVars2.css,
|
|
164
167
|
vars = _generateCssVars2.vars;
|
|
@@ -264,6 +267,7 @@ export default function createCssVarsProvider(options) {
|
|
|
264
267
|
styles: otherColorSchemesStyleSheet
|
|
265
268
|
})]
|
|
266
269
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
270
|
+
themeId: scopedTheme ? themeId : undefined,
|
|
267
271
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
268
272
|
children: children
|
|
269
273
|
})]
|
package/legacy/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.
|
|
2
|
+
* @mui/system v5.12.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
9
|
-
export { css, keyframes,
|
|
9
|
+
export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
|
|
10
|
+
export { default as GlobalStyles } from './GlobalStyles';
|
|
10
11
|
export { default as borders } from './borders';
|
|
11
12
|
export * from './borders';
|
|
12
13
|
export { default as breakpoints } from './breakpoints';
|
|
@@ -3,8 +3,12 @@ import useTheme from '../useTheme';
|
|
|
3
3
|
export default function useThemeProps(_ref) {
|
|
4
4
|
var props = _ref.props,
|
|
5
5
|
name = _ref.name,
|
|
6
|
-
defaultTheme = _ref.defaultTheme
|
|
6
|
+
defaultTheme = _ref.defaultTheme,
|
|
7
|
+
themeId = _ref.themeId;
|
|
7
8
|
var theme = useTheme(defaultTheme);
|
|
9
|
+
if (themeId) {
|
|
10
|
+
theme = theme[themeId] || theme;
|
|
11
|
+
}
|
|
8
12
|
var mergedProps = getThemeProps({
|
|
9
13
|
theme: theme,
|
|
10
14
|
name: name,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ThemeContext } from '@mui/styled-engine';
|
|
2
3
|
function isObjectEmpty(obj) {
|
|
3
4
|
return Object.keys(obj).length === 0;
|
|
4
5
|
}
|
|
5
6
|
function useTheme() {
|
|
6
7
|
var defaultTheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
7
|
-
var contextTheme =
|
|
8
|
+
var contextTheme = React.useContext(ThemeContext);
|
|
8
9
|
return !contextTheme || isObjectEmpty(contextTheme) ? defaultTheme : contextTheme;
|
|
9
10
|
}
|
|
10
11
|
export default useTheme;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { GlobalStyles as MuiGlobalStyles } from '@mui/styled-engine';
|
|
4
|
+
import useTheme from '../useTheme';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
function GlobalStyles({
|
|
7
|
+
styles,
|
|
8
|
+
themeId,
|
|
9
|
+
defaultTheme = {}
|
|
10
|
+
}) {
|
|
11
|
+
const upperTheme = useTheme(defaultTheme);
|
|
12
|
+
const globalStyles = typeof styles === 'function' ? styles(themeId ? upperTheme[themeId] || upperTheme : upperTheme) : styles;
|
|
13
|
+
return /*#__PURE__*/_jsx(MuiGlobalStyles, {
|
|
14
|
+
styles: globalStyles
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
process.env.NODE_ENV !== "production" ? GlobalStyles.propTypes /* remove-proptypes */ = {
|
|
18
|
+
// ----------------------------- Warning --------------------------------
|
|
19
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
20
|
+
// | To update them edit TypeScript types and run "yarn proptypes" |
|
|
21
|
+
// ----------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
defaultTheme: PropTypes.object,
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
styles: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.array, PropTypes.func, PropTypes.number, PropTypes.object, PropTypes.string, PropTypes.bool]),
|
|
30
|
+
/**
|
|
31
|
+
* @ignore
|
|
32
|
+
*/
|
|
33
|
+
themeId: PropTypes.string
|
|
34
|
+
} : void 0;
|
|
35
|
+
export default GlobalStyles;
|
|
@@ -1,37 +1,59 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { ThemeProvider as MuiThemeProvider } from '@mui/private-theming';
|
|
4
|
+
import { ThemeProvider as MuiThemeProvider, useTheme as usePrivateTheme } from '@mui/private-theming';
|
|
4
5
|
import { exactProp } from '@mui/utils';
|
|
5
6
|
import { ThemeContext as StyledEngineThemeContext } from '@mui/styled-engine';
|
|
6
|
-
import
|
|
7
|
+
import useThemeWithoutDefault from '../useThemeWithoutDefault';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
const EMPTY_THEME = {};
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
|
|
11
|
+
return React.useMemo(() => {
|
|
12
|
+
const resolvedTheme = themeId ? upperTheme[themeId] || upperTheme : upperTheme;
|
|
13
|
+
if (typeof localTheme === 'function') {
|
|
14
|
+
const mergedTheme = localTheme(resolvedTheme);
|
|
15
|
+
const result = themeId ? _extends({}, upperTheme, {
|
|
16
|
+
[themeId]: mergedTheme
|
|
17
|
+
}) : mergedTheme;
|
|
18
|
+
// must return a function for the private theme to NOT merge with the upper theme.
|
|
19
|
+
// see the test case "use provided theme from a callback" in ThemeProvider.test.js
|
|
20
|
+
if (isPrivate) {
|
|
21
|
+
return () => result;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return themeId ? _extends({}, upperTheme, {
|
|
26
|
+
[themeId]: localTheme
|
|
27
|
+
}) : _extends({}, upperTheme, localTheme);
|
|
28
|
+
}, [themeId, upperTheme, localTheme, isPrivate]);
|
|
15
29
|
}
|
|
16
|
-
process.env.NODE_ENV !== "production" ? InnerThemeProvider.propTypes = {
|
|
17
|
-
/**
|
|
18
|
-
* Your component tree.
|
|
19
|
-
*/
|
|
20
|
-
children: PropTypes.node
|
|
21
|
-
} : void 0;
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
32
|
* This component makes the `theme` available down the React tree.
|
|
25
33
|
* It should preferably be used at **the root of your component tree**.
|
|
34
|
+
*
|
|
35
|
+
* <ThemeProvider theme={theme}> // existing use case
|
|
36
|
+
* <ThemeProvider theme={{ id: theme }}> // theme scoping
|
|
26
37
|
*/
|
|
27
38
|
function ThemeProvider(props) {
|
|
28
39
|
const {
|
|
29
40
|
children,
|
|
30
|
-
theme: localTheme
|
|
41
|
+
theme: localTheme,
|
|
42
|
+
themeId
|
|
31
43
|
} = props;
|
|
44
|
+
const upperTheme = useThemeWithoutDefault(EMPTY_THEME);
|
|
45
|
+
const upperPrivateTheme = usePrivateTheme() || EMPTY_THEME;
|
|
46
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
47
|
+
if (upperTheme === null && typeof localTheme === 'function' || themeId && upperTheme && !upperTheme[themeId] && typeof localTheme === 'function') {
|
|
48
|
+
console.error(['MUI: You are providing a theme function prop to the ThemeProvider component:', '<ThemeProvider theme={outerTheme => outerTheme} />', '', 'However, no outer theme is present.', 'Make sure a theme is already injected higher in the React tree ' + 'or provide a theme object.'].join('\n'));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const engineTheme = useThemeScoping(themeId, upperTheme, localTheme);
|
|
52
|
+
const privateTheme = useThemeScoping(themeId, upperPrivateTheme, localTheme, true);
|
|
32
53
|
return /*#__PURE__*/_jsx(MuiThemeProvider, {
|
|
33
|
-
theme:
|
|
34
|
-
children: /*#__PURE__*/_jsx(
|
|
54
|
+
theme: privateTheme,
|
|
55
|
+
children: /*#__PURE__*/_jsx(StyledEngineThemeContext.Provider, {
|
|
56
|
+
value: engineTheme,
|
|
35
57
|
children: children
|
|
36
58
|
})
|
|
37
59
|
});
|
|
@@ -48,7 +70,11 @@ process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes /* remove-propty
|
|
|
48
70
|
/**
|
|
49
71
|
* A theme object. You can provide a function to extend the outer theme.
|
|
50
72
|
*/
|
|
51
|
-
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired
|
|
73
|
+
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
|
|
74
|
+
/**
|
|
75
|
+
* The design system's unique id for getting the corresponded theme when there are multiple design systems.
|
|
76
|
+
*/
|
|
77
|
+
themeId: PropTypes.string
|
|
52
78
|
} : void 0;
|
|
53
79
|
if (process.env.NODE_ENV !== 'production') {
|
|
54
80
|
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes = exactProp(ThemeProvider.propTypes) : void 0;
|
package/modern/createBox.js
CHANGED
|
@@ -9,6 +9,7 @@ import useTheme from './useTheme';
|
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
export default function createBox(options = {}) {
|
|
11
11
|
const {
|
|
12
|
+
themeId,
|
|
12
13
|
defaultTheme,
|
|
13
14
|
defaultClassName = 'MuiBox-root',
|
|
14
15
|
generateClassName
|
|
@@ -28,7 +29,7 @@ export default function createBox(options = {}) {
|
|
|
28
29
|
as: component,
|
|
29
30
|
ref: ref,
|
|
30
31
|
className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
|
|
31
|
-
theme: theme
|
|
32
|
+
theme: themeId ? theme[themeId] || theme : theme
|
|
32
33
|
}, other));
|
|
33
34
|
});
|
|
34
35
|
return Box;
|
package/modern/createStyled.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"]
|
|
4
|
-
_excluded2 = ["theme"],
|
|
5
|
-
_excluded3 = ["theme"];
|
|
3
|
+
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
6
4
|
/* eslint-disable no-underscore-dangle */
|
|
7
5
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
8
6
|
import { getDisplayName } from '@mui/utils';
|
|
@@ -69,16 +67,26 @@ export const systemDefaultTheme = createTheme();
|
|
|
69
67
|
const lowercaseFirstLetter = string => {
|
|
70
68
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
71
69
|
};
|
|
70
|
+
function resolveTheme({
|
|
71
|
+
defaultTheme,
|
|
72
|
+
theme,
|
|
73
|
+
themeId
|
|
74
|
+
}) {
|
|
75
|
+
return isEmpty(theme) ? defaultTheme : theme[themeId] || theme;
|
|
76
|
+
}
|
|
72
77
|
export default function createStyled(input = {}) {
|
|
73
78
|
const {
|
|
79
|
+
themeId,
|
|
74
80
|
defaultTheme = systemDefaultTheme,
|
|
75
81
|
rootShouldForwardProp = shouldForwardProp,
|
|
76
82
|
slotShouldForwardProp = shouldForwardProp
|
|
77
83
|
} = input;
|
|
78
84
|
const systemSx = props => {
|
|
79
|
-
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
80
85
|
return styleFunctionSx(_extends({}, props, {
|
|
81
|
-
theme
|
|
86
|
+
theme: resolveTheme(_extends({}, props, {
|
|
87
|
+
defaultTheme,
|
|
88
|
+
themeId
|
|
89
|
+
}))
|
|
82
90
|
}));
|
|
83
91
|
};
|
|
84
92
|
systemSx.__mui_systemSx = true;
|
|
@@ -122,20 +130,22 @@ export default function createStyled(input = {}) {
|
|
|
122
130
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
123
131
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
124
132
|
// which are basically components used as a selectors.
|
|
125
|
-
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ?
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}, other));
|
|
133
|
+
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? props => {
|
|
134
|
+
return stylesArg(_extends({}, props, {
|
|
135
|
+
theme: resolveTheme(_extends({}, props, {
|
|
136
|
+
defaultTheme,
|
|
137
|
+
themeId
|
|
138
|
+
}))
|
|
139
|
+
}));
|
|
133
140
|
} : stylesArg;
|
|
134
141
|
}) : [];
|
|
135
142
|
let transformedStyleArg = styleArg;
|
|
136
143
|
if (componentName && overridesResolver) {
|
|
137
144
|
expressionsWithDefaultTheme.push(props => {
|
|
138
|
-
const theme =
|
|
145
|
+
const theme = resolveTheme(_extends({}, props, {
|
|
146
|
+
defaultTheme,
|
|
147
|
+
themeId
|
|
148
|
+
}));
|
|
139
149
|
const styleOverrides = getStyleOverrides(componentName, theme);
|
|
140
150
|
if (styleOverrides) {
|
|
141
151
|
const resolvedStyleOverrides = {};
|
|
@@ -151,7 +161,10 @@ export default function createStyled(input = {}) {
|
|
|
151
161
|
}
|
|
152
162
|
if (componentName && !skipVariantsResolver) {
|
|
153
163
|
expressionsWithDefaultTheme.push(props => {
|
|
154
|
-
const theme =
|
|
164
|
+
const theme = resolveTheme(_extends({}, props, {
|
|
165
|
+
defaultTheme,
|
|
166
|
+
themeId
|
|
167
|
+
}));
|
|
155
168
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
156
169
|
});
|
|
157
170
|
}
|
|
@@ -170,15 +183,12 @@ export default function createStyled(input = {}) {
|
|
|
170
183
|
// which are basically components used as a selectors.
|
|
171
184
|
styleArg.__emotion_real !== styleArg) {
|
|
172
185
|
// If the type is function, we need to define the default theme.
|
|
173
|
-
transformedStyleArg =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
180
|
-
}, other));
|
|
181
|
-
};
|
|
186
|
+
transformedStyleArg = props => styleArg(_extends({}, props, {
|
|
187
|
+
theme: resolveTheme(_extends({}, props, {
|
|
188
|
+
defaultTheme,
|
|
189
|
+
themeId
|
|
190
|
+
}))
|
|
191
|
+
}));
|
|
182
192
|
}
|
|
183
193
|
const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
|
|
184
194
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -15,6 +15,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
15
15
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
16
16
|
export default function createCssVarsProvider(options) {
|
|
17
17
|
const {
|
|
18
|
+
themeId,
|
|
18
19
|
theme: defaultTheme = {},
|
|
19
20
|
attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
|
|
20
21
|
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -56,7 +57,9 @@ export default function createCssVarsProvider(options) {
|
|
|
56
57
|
const upperTheme = muiUseTheme();
|
|
57
58
|
const ctx = React.useContext(ColorSchemeContext);
|
|
58
59
|
const nested = !!ctx && !disableNestedContext;
|
|
59
|
-
const
|
|
60
|
+
const scopedTheme = themeProp[themeId];
|
|
61
|
+
const _ref = scopedTheme || themeProp,
|
|
62
|
+
{
|
|
60
63
|
colorSchemes = {},
|
|
61
64
|
components = {},
|
|
62
65
|
generateCssVars = () => ({
|
|
@@ -64,8 +67,8 @@ export default function createCssVarsProvider(options) {
|
|
|
64
67
|
css: {}
|
|
65
68
|
}),
|
|
66
69
|
cssVarPrefix
|
|
67
|
-
} =
|
|
68
|
-
restThemeProp = _objectWithoutPropertiesLoose(
|
|
70
|
+
} = _ref,
|
|
71
|
+
restThemeProp = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
69
72
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
70
73
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
71
74
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -241,6 +244,7 @@ export default function createCssVarsProvider(options) {
|
|
|
241
244
|
styles: otherColorSchemesStyleSheet
|
|
242
245
|
})]
|
|
243
246
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
247
|
+
themeId: scopedTheme ? themeId : undefined,
|
|
244
248
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
245
249
|
children: children
|
|
246
250
|
})]
|
package/modern/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.
|
|
2
|
+
* @mui/system v5.12.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
9
|
-
export { css, keyframes,
|
|
9
|
+
export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
|
|
10
|
+
export { default as GlobalStyles } from './GlobalStyles';
|
|
10
11
|
export { default as borders } from './borders';
|
|
11
12
|
export * from './borders';
|
|
12
13
|
export { default as breakpoints } from './breakpoints';
|
|
@@ -3,9 +3,13 @@ import useTheme from '../useTheme';
|
|
|
3
3
|
export default function useThemeProps({
|
|
4
4
|
props,
|
|
5
5
|
name,
|
|
6
|
-
defaultTheme
|
|
6
|
+
defaultTheme,
|
|
7
|
+
themeId
|
|
7
8
|
}) {
|
|
8
|
-
|
|
9
|
+
let theme = useTheme(defaultTheme);
|
|
10
|
+
if (themeId) {
|
|
11
|
+
theme = theme[themeId] || theme;
|
|
12
|
+
}
|
|
9
13
|
const mergedProps = getThemeProps({
|
|
10
14
|
theme,
|
|
11
15
|
name,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ThemeContext } from '@mui/styled-engine';
|
|
2
3
|
function isObjectEmpty(obj) {
|
|
3
4
|
return Object.keys(obj).length === 0;
|
|
4
5
|
}
|
|
5
6
|
function useTheme(defaultTheme = null) {
|
|
6
|
-
const contextTheme =
|
|
7
|
+
const contextTheme = React.useContext(ThemeContext);
|
|
7
8
|
return !contextTheme || isObjectEmpty(contextTheme) ? defaultTheme : contextTheme;
|
|
8
9
|
}
|
|
9
10
|
export default useTheme;
|