@mui/system 5.11.16 → 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.
Files changed (52) hide show
  1. package/CHANGELOG.md +73 -22
  2. package/GlobalStyles/GlobalStyles.d.ts +13 -0
  3. package/GlobalStyles/GlobalStyles.js +45 -0
  4. package/GlobalStyles/index.d.ts +2 -0
  5. package/GlobalStyles/index.js +26 -0
  6. package/GlobalStyles/package.json +6 -0
  7. package/ThemeProvider/ThemeProvider.d.ts +4 -0
  8. package/ThemeProvider/ThemeProvider.js +43 -17
  9. package/createBox.d.ts +1 -0
  10. package/createBox.js +2 -1
  11. package/createStyled.d.ts +1 -0
  12. package/createStyled.js +34 -24
  13. package/cssVars/createCssVarsProvider.d.ts +22 -7
  14. package/cssVars/createCssVarsProvider.js +7 -3
  15. package/esm/GlobalStyles/GlobalStyles.js +35 -0
  16. package/esm/GlobalStyles/index.js +2 -0
  17. package/esm/ThemeProvider/ThemeProvider.js +44 -18
  18. package/esm/createBox.js +2 -1
  19. package/esm/createStyled.js +34 -24
  20. package/esm/cssVars/createCssVarsProvider.js +7 -3
  21. package/esm/index.js +2 -1
  22. package/esm/useThemeProps/useThemeProps.js +6 -2
  23. package/esm/useThemeWithoutDefault.js +3 -2
  24. package/index.d.ts +2 -2
  25. package/index.js +4 -3
  26. package/legacy/GlobalStyles/GlobalStyles.js +35 -0
  27. package/legacy/GlobalStyles/index.js +2 -0
  28. package/legacy/ThemeProvider/ThemeProvider.js +44 -19
  29. package/legacy/createBox.js +3 -2
  30. package/legacy/createStyled.js +34 -17
  31. package/legacy/cssVars/createCssVarsProvider.js +18 -14
  32. package/legacy/index.js +3 -2
  33. package/legacy/useThemeProps/useThemeProps.js +5 -1
  34. package/legacy/useThemeWithoutDefault.js +3 -2
  35. package/modern/GlobalStyles/GlobalStyles.js +35 -0
  36. package/modern/GlobalStyles/index.js +2 -0
  37. package/modern/ThemeProvider/ThemeProvider.js +44 -18
  38. package/modern/createBox.js +2 -1
  39. package/modern/createStyled.js +34 -24
  40. package/modern/cssVars/createCssVarsProvider.js +7 -3
  41. package/modern/index.js +3 -2
  42. package/modern/useThemeProps/useThemeProps.js +6 -2
  43. package/modern/useThemeWithoutDefault.js +3 -2
  44. package/package.json +5 -5
  45. package/useThemeProps/useThemeProps.d.ts +6 -1
  46. package/useThemeProps/useThemeProps.js +6 -2
  47. package/useThemeWithoutDefault.js +5 -2
  48. package/Box/Box.spec.d.ts +0 -1
  49. package/createBox.spec.d.ts +0 -1
  50. package/cssVars/createCssVarsProvider.spec.d.ts +0 -1
  51. package/index.spec.d.ts +0 -1
  52. package/styleFunctionSx/styleFunctionSx.spec.d.ts +0 -1
@@ -41,14 +41,22 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
41
41
  disableTransitionOnChange?: boolean;
42
42
  }
43
43
 
44
- export interface CreateCssVarsProviderResult<ColorScheme extends string> {
44
+ type Identify<I extends string | undefined, T> = I extends string ? T | { [k in I]: T } : T;
45
+
46
+ export interface CreateCssVarsProviderResult<
47
+ ColorScheme extends string,
48
+ Identifier extends string | undefined = undefined,
49
+ > {
45
50
  CssVarsProvider: (
46
51
  props: React.PropsWithChildren<
47
52
  Partial<CssVarsProviderConfig<ColorScheme>> & {
48
- theme?: {
49
- cssVarPrefix?: string;
50
- colorSchemes: Record<ColorScheme, Record<string, any>>;
51
- };
53
+ theme?: Identify<
54
+ Identifier,
55
+ {
56
+ cssVarPrefix?: string;
57
+ colorSchemes: Record<ColorScheme, Record<string, any>>;
58
+ }
59
+ >;
52
60
  /**
53
61
  * The document used to perform `disableTransitionOnChange` feature
54
62
  * @default document
@@ -87,8 +95,15 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string> {
87
95
  getInitColorSchemeScript: typeof getInitColorSchemeScript;
88
96
  }
89
97
 
90
- export default function createCssVarsProvider<ColorScheme extends string>(
98
+ export default function createCssVarsProvider<
99
+ ColorScheme extends string,
100
+ Identifier extends string | undefined = undefined,
101
+ >(
91
102
  options: CssVarsProviderConfig<ColorScheme> & {
103
+ /**
104
+ * The design system's unique id for getting the corresponded theme when there are multiple design systems.
105
+ */
106
+ themeId?: Identifier;
92
107
  /**
93
108
  * Design system default theme
94
109
  *
@@ -136,7 +151,7 @@ export default function createCssVarsProvider<ColorScheme extends string>(
136
151
  */
137
152
  excludeVariablesFromRoot?: (cssVarPrefix: string) => string[];
138
153
  },
139
- ): CreateCssVarsProviderResult<ColorScheme>;
154
+ ): CreateCssVarsProviderResult<ColorScheme, Identifier>;
140
155
 
141
156
  // disable automatic export
142
157
  export {};
@@ -24,6 +24,7 @@ const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transit
24
24
  exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
25
25
  function createCssVarsProvider(options) {
26
26
  const {
27
+ themeId,
27
28
  theme: defaultTheme = {},
28
29
  attribute: defaultAttribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
29
30
  modeStorageKey: defaultModeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
@@ -65,7 +66,9 @@ function createCssVarsProvider(options) {
65
66
  const upperTheme = (0, _privateTheming.useTheme)();
66
67
  const ctx = React.useContext(ColorSchemeContext);
67
68
  const nested = !!ctx && !disableNestedContext;
68
- const {
69
+ const scopedTheme = themeProp[themeId];
70
+ const _ref = scopedTheme || themeProp,
71
+ {
69
72
  colorSchemes = {},
70
73
  components = {},
71
74
  generateCssVars = () => ({
@@ -73,8 +76,8 @@ function createCssVarsProvider(options) {
73
76
  css: {}
74
77
  }),
75
78
  cssVarPrefix
76
- } = themeProp,
77
- restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
79
+ } = _ref,
80
+ restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
78
81
  const allColorSchemes = Object.keys(colorSchemes);
79
82
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
80
83
  const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
@@ -250,6 +253,7 @@ function createCssVarsProvider(options) {
250
253
  styles: otherColorSchemesStyleSheet
251
254
  })]
252
255
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
256
+ themeId: scopedTheme ? themeId : undefined,
253
257
  theme: resolveTheme ? resolveTheme(theme) : theme,
254
258
  children: children
255
259
  })]
@@ -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;
@@ -0,0 +1,2 @@
1
+ export { default } from './GlobalStyles';
2
+ export * from './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 useTheme from '../useTheme';
7
+ import useThemeWithoutDefault from '../useThemeWithoutDefault';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
9
  const EMPTY_THEME = {};
9
- function InnerThemeProvider(props) {
10
- const theme = useTheme();
11
- return /*#__PURE__*/_jsx(StyledEngineThemeContext.Provider, {
12
- value: typeof theme === 'object' ? theme : EMPTY_THEME,
13
- children: props.children
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: localTheme,
34
- children: /*#__PURE__*/_jsx(InnerThemeProvider, {
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/esm/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;
@@ -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';
@@ -70,16 +68,26 @@ export const systemDefaultTheme = createTheme();
70
68
  const lowercaseFirstLetter = string => {
71
69
  return string.charAt(0).toLowerCase() + string.slice(1);
72
70
  };
71
+ function resolveTheme({
72
+ defaultTheme,
73
+ theme,
74
+ themeId
75
+ }) {
76
+ return isEmpty(theme) ? defaultTheme : theme[themeId] || theme;
77
+ }
73
78
  export default function createStyled(input = {}) {
74
79
  const {
80
+ themeId,
75
81
  defaultTheme = systemDefaultTheme,
76
82
  rootShouldForwardProp = shouldForwardProp,
77
83
  slotShouldForwardProp = shouldForwardProp
78
84
  } = input;
79
85
  const systemSx = props => {
80
- const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
81
86
  return styleFunctionSx(_extends({}, props, {
82
- theme
87
+ theme: resolveTheme(_extends({}, props, {
88
+ defaultTheme,
89
+ themeId
90
+ }))
83
91
  }));
84
92
  };
85
93
  systemSx.__mui_systemSx = true;
@@ -123,20 +131,22 @@ export default function createStyled(input = {}) {
123
131
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
124
132
  // component stays as a function. This condition makes sure that we do not interpolate functions
125
133
  // which are basically components used as a selectors.
126
- return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
127
- let {
128
- theme: themeInput
129
- } = _ref,
130
- other = _objectWithoutPropertiesLoose(_ref, _excluded2);
131
- return stylesArg(_extends({
132
- theme: isEmpty(themeInput) ? defaultTheme : themeInput
133
- }, other));
134
+ return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? props => {
135
+ return stylesArg(_extends({}, props, {
136
+ theme: resolveTheme(_extends({}, props, {
137
+ defaultTheme,
138
+ themeId
139
+ }))
140
+ }));
134
141
  } : stylesArg;
135
142
  }) : [];
136
143
  let transformedStyleArg = styleArg;
137
144
  if (componentName && overridesResolver) {
138
145
  expressionsWithDefaultTheme.push(props => {
139
- const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
146
+ const theme = resolveTheme(_extends({}, props, {
147
+ defaultTheme,
148
+ themeId
149
+ }));
140
150
  const styleOverrides = getStyleOverrides(componentName, theme);
141
151
  if (styleOverrides) {
142
152
  const resolvedStyleOverrides = {};
@@ -152,7 +162,10 @@ export default function createStyled(input = {}) {
152
162
  }
153
163
  if (componentName && !skipVariantsResolver) {
154
164
  expressionsWithDefaultTheme.push(props => {
155
- const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
165
+ const theme = resolveTheme(_extends({}, props, {
166
+ defaultTheme,
167
+ themeId
168
+ }));
156
169
  return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
157
170
  });
158
171
  }
@@ -171,15 +184,12 @@ export default function createStyled(input = {}) {
171
184
  // which are basically components used as a selectors.
172
185
  styleArg.__emotion_real !== styleArg) {
173
186
  // If the type is function, we need to define the default theme.
174
- transformedStyleArg = _ref2 => {
175
- let {
176
- theme: themeInput
177
- } = _ref2,
178
- other = _objectWithoutPropertiesLoose(_ref2, _excluded3);
179
- return styleArg(_extends({
180
- theme: isEmpty(themeInput) ? defaultTheme : themeInput
181
- }, other));
182
- };
187
+ transformedStyleArg = props => styleArg(_extends({}, props, {
188
+ theme: resolveTheme(_extends({}, props, {
189
+ defaultTheme,
190
+ themeId
191
+ }))
192
+ }));
183
193
  }
184
194
  const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
185
195
  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
- } = themeProp,
68
- restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
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/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
2
- export { css, keyframes, GlobalStyles, StyledEngineProvider } from '@mui/styled-engine';
2
+ export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
3
+ export { default as GlobalStyles } from './GlobalStyles';
3
4
  export { default as borders } from './borders';
4
5
  export * from './borders';
5
6
  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
- const theme = useTheme(defaultTheme);
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 { useTheme as muiUseTheme } from '@mui/private-theming';
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 = muiUseTheme();
7
+ const contextTheme = React.useContext(ThemeContext);
7
8
  return !contextTheme || isObjectEmpty(contextTheme) ? defaultTheme : contextTheme;
8
9
  }
9
10
  export default useTheme;
package/index.d.ts CHANGED
@@ -104,13 +104,13 @@ export { DefaultTheme } from '@mui/private-theming';
104
104
  export {
105
105
  css,
106
106
  keyframes,
107
- GlobalStyles,
108
- GlobalStylesProps,
109
107
  StyledEngineProvider,
110
108
  Interpolation,
111
109
  CSSInterpolation,
112
110
  CSSObject,
113
111
  } from '@mui/styled-engine';
112
+ export { default as GlobalStyles } from './GlobalStyles';
113
+ export type { GlobalStylesProps } from './GlobalStyles';
114
114
 
115
115
  export * from './style';
116
116
  export * from './spacing';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/system v5.11.16
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
@@ -15,8 +15,8 @@ var _exportNames = {
15
15
  experimental_sx: true,
16
16
  css: true,
17
17
  keyframes: true,
18
- GlobalStyles: true,
19
18
  StyledEngineProvider: true,
19
+ GlobalStyles: true,
20
20
  borders: true,
21
21
  breakpoints: true,
22
22
  handleBreakpoints: true,
@@ -79,7 +79,7 @@ Object.defineProperty(exports, "Container", {
79
79
  Object.defineProperty(exports, "GlobalStyles", {
80
80
  enumerable: true,
81
81
  get: function () {
82
- return _styledEngine.GlobalStyles;
82
+ return _GlobalStyles.default;
83
83
  }
84
84
  });
85
85
  Object.defineProperty(exports, "Stack", {
@@ -367,6 +367,7 @@ Object.defineProperty(exports, "useThemeWithoutDefault", {
367
367
  });
368
368
  var _utils = require("@mui/utils");
369
369
  var _styledEngine = require("@mui/styled-engine");
370
+ var _GlobalStyles = _interopRequireDefault(require("./GlobalStyles"));
370
371
  var _borders = _interopRequireWildcard(require("./borders"));
371
372
  Object.keys(_borders).forEach(function (key) {
372
373
  if (key === "default" || key === "__esModule") return;
@@ -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(_ref) {
7
+ var styles = _ref.styles,
8
+ themeId = _ref.themeId,
9
+ _ref$defaultTheme = _ref.defaultTheme,
10
+ defaultTheme = _ref$defaultTheme === void 0 ? {} : _ref$defaultTheme;
11
+ var upperTheme = useTheme(defaultTheme);
12
+ var 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;
@@ -0,0 +1,2 @@
1
+ export { default } from './GlobalStyles';
2
+ export * from './GlobalStyles';
@@ -1,36 +1,57 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
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 useTheme from '../useTheme';
8
+ import useThemeWithoutDefault from '../useThemeWithoutDefault';
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
10
  var EMPTY_THEME = {};
10
- function InnerThemeProvider(props) {
11
- var theme = useTheme();
12
- return /*#__PURE__*/_jsx(StyledEngineThemeContext.Provider, {
13
- value: _typeof(theme) === 'object' ? theme : EMPTY_THEME,
14
- children: props.children
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: localTheme,
33
- children: /*#__PURE__*/_jsx(InnerThemeProvider, {
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;
@@ -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 defaultTheme = options.defaultTheme,
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;