@mui/system 5.6.4 → 5.8.1

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 (67) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +241 -0
  3. package/Container/Container.d.ts +13 -0
  4. package/Container/Container.js +81 -0
  5. package/Container/ContainerProps.d.ts +40 -0
  6. package/Container/ContainerProps.js +5 -0
  7. package/Container/containerClasses.d.ts +22 -0
  8. package/Container/containerClasses.js +17 -0
  9. package/Container/createContainer.d.ts +18 -0
  10. package/Container/createContainer.js +172 -0
  11. package/Container/index.d.ts +5 -0
  12. package/Container/index.js +42 -0
  13. package/Container/package.json +6 -0
  14. package/ThemeProvider/ThemeProvider.d.ts +1 -1
  15. package/createBox.spec.d.ts +1 -1
  16. package/createTheme/createBreakpoints.d.ts +5 -0
  17. package/createTheme/createSpacing.d.ts +10 -10
  18. package/cssVars/createCssVarsProvider.d.ts +25 -0
  19. package/cssVars/createCssVarsProvider.js +59 -23
  20. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  21. package/cssVars/createGetCssVar.d.ts +5 -5
  22. package/cssVars/cssVarsParser.d.ts +70 -70
  23. package/cssVars/getInitColorSchemeScript.d.ts +40 -12
  24. package/cssVars/getInitColorSchemeScript.js +4 -3
  25. package/cssVars/index.d.ts +2 -2
  26. package/cssVars/useCurrentColorScheme.d.ts +53 -50
  27. package/cssVars/useCurrentColorScheme.js +17 -7
  28. package/esm/Container/Container.js +70 -0
  29. package/esm/Container/ContainerProps.js +1 -0
  30. package/esm/Container/containerClasses.js +6 -0
  31. package/esm/Container/createContainer.js +151 -0
  32. package/esm/Container/index.js +3 -0
  33. package/esm/cssVars/createCssVarsProvider.js +60 -24
  34. package/esm/cssVars/getInitColorSchemeScript.js +4 -3
  35. package/esm/cssVars/useCurrentColorScheme.js +17 -7
  36. package/esm/index.js +4 -1
  37. package/esm/spacing.js +1 -1
  38. package/esm/style.js +2 -2
  39. package/index.d.ts +6 -0
  40. package/index.js +32 -2
  41. package/index.spec.d.ts +1 -1
  42. package/legacy/Container/Container.js +70 -0
  43. package/legacy/Container/ContainerProps.js +1 -0
  44. package/legacy/Container/containerClasses.js +6 -0
  45. package/legacy/Container/createContainer.js +148 -0
  46. package/legacy/Container/index.js +3 -0
  47. package/legacy/cssVars/createCssVarsProvider.js +66 -26
  48. package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
  49. package/legacy/cssVars/useCurrentColorScheme.js +20 -9
  50. package/legacy/index.js +5 -2
  51. package/legacy/spacing.js +1 -1
  52. package/legacy/style.js +3 -1
  53. package/modern/Container/Container.js +70 -0
  54. package/modern/Container/ContainerProps.js +1 -0
  55. package/modern/Container/containerClasses.js +6 -0
  56. package/modern/Container/createContainer.js +151 -0
  57. package/modern/Container/index.js +3 -0
  58. package/modern/cssVars/createCssVarsProvider.js +60 -24
  59. package/modern/cssVars/getInitColorSchemeScript.js +4 -3
  60. package/modern/cssVars/useCurrentColorScheme.js +17 -7
  61. package/modern/index.js +5 -2
  62. package/modern/spacing.js +1 -1
  63. package/modern/style.js +2 -2
  64. package/package.json +5 -5
  65. package/spacing.js +1 -1
  66. package/style.js +2 -2
  67. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -0,0 +1,70 @@
1
+ import PropTypes from 'prop-types';
2
+ import createContainer from './createContainer';
3
+ /**
4
+ *
5
+ * Demos:
6
+ *
7
+ * - [Container (Material UI)](https://mui.com/material-ui/react-container/)
8
+ * - [Container (MUI System)](https://mui.com/system/react-container/)
9
+ *
10
+ * API:
11
+ *
12
+ * - [Container API](https://mui.com/system/api/container/)
13
+ */
14
+
15
+ const Container = createContainer();
16
+ process.env.NODE_ENV !== "production" ? Container.propTypes
17
+ /* remove-proptypes */
18
+ = {
19
+ // ----------------------------- Warning --------------------------------
20
+ // | These PropTypes are generated from the TypeScript type definitions |
21
+ // | To update them edit TypeScript types and run "yarn proptypes" |
22
+ // ----------------------------------------------------------------------
23
+
24
+ /**
25
+ * @ignore
26
+ */
27
+ children: PropTypes.node,
28
+
29
+ /**
30
+ * Override or extend the styles applied to the component.
31
+ */
32
+ classes: PropTypes.object,
33
+
34
+ /**
35
+ * The component used for the root node.
36
+ * Either a string to use a HTML element or a component.
37
+ */
38
+ component: PropTypes.elementType,
39
+
40
+ /**
41
+ * If `true`, the left and right padding is removed.
42
+ * @default false
43
+ */
44
+ disableGutters: PropTypes.bool,
45
+
46
+ /**
47
+ * Set the max-width to match the min-width of the current breakpoint.
48
+ * This is useful if you'd prefer to design for a fixed set of sizes
49
+ * instead of trying to accommodate a fully fluid viewport.
50
+ * It's fluid by default.
51
+ * @default false
52
+ */
53
+ fixed: PropTypes.bool,
54
+
55
+ /**
56
+ * Determine the max-width of the container.
57
+ * The container width grows with the size of the screen.
58
+ * Set to `false` to disable `maxWidth`.
59
+ * @default 'lg'
60
+ */
61
+ maxWidth: PropTypes
62
+ /* @typescript-to-proptypes-ignore */
63
+ .oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', false]), PropTypes.string]),
64
+
65
+ /**
66
+ * The system prop that allows defining system overrides as well as additional CSS styles.
67
+ */
68
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
69
+ } : void 0;
70
+ export default Container;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
2
+ export function getContainerUtilityClass(slot) {
3
+ return generateUtilityClass('MuiContainer', slot);
4
+ }
5
+ const containerClasses = generateUtilityClasses('MuiContainer', ['root', 'disableGutters', 'fixed', 'maxWidthXs', 'maxWidthSm', 'maxWidthMd', 'maxWidthLg', 'maxWidthXl']);
6
+ export default containerClasses;
@@ -0,0 +1,151 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["className", "component", "disableGutters", "fixed", "maxWidth", "classes"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import clsx from 'clsx';
7
+ import { unstable_capitalize as capitalize, unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass } from '@mui/utils';
8
+ import useThemePropsSystem from '../useThemeProps';
9
+ import systemStyled from '../styled';
10
+ import createTheme from '../createTheme';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ const defaultTheme = createTheme();
13
+ const defaultCreateStyledComponent = systemStyled('div', {
14
+ name: 'MuiContainer',
15
+ slot: 'Root',
16
+ overridesResolver: (props, styles) => {
17
+ const {
18
+ ownerState
19
+ } = props;
20
+ return [styles.root, styles[`maxWidth${capitalize(String(ownerState.maxWidth))}`], ownerState.fixed && styles.fixed, ownerState.disableGutters && styles.disableGutters];
21
+ }
22
+ });
23
+
24
+ const useThemePropsDefault = inProps => useThemePropsSystem({
25
+ props: inProps,
26
+ name: 'MuiContainer',
27
+ defaultTheme
28
+ });
29
+
30
+ const useUtilityClasses = (ownerState, componentName) => {
31
+ const getContainerUtilityClass = slot => {
32
+ return generateUtilityClass(componentName, slot);
33
+ };
34
+
35
+ const {
36
+ classes,
37
+ fixed,
38
+ disableGutters,
39
+ maxWidth
40
+ } = ownerState;
41
+ const slots = {
42
+ root: ['root', maxWidth && `maxWidth${capitalize(String(maxWidth))}`, fixed && 'fixed', disableGutters && 'disableGutters']
43
+ };
44
+ return composeClasses(slots, getContainerUtilityClass, classes);
45
+ };
46
+
47
+ export default function createContainer(options = {}) {
48
+ const {
49
+ // This will allow adding custom styled fn (for example for custom sx style function)
50
+ createStyledComponent = defaultCreateStyledComponent,
51
+ useThemeProps = useThemePropsDefault,
52
+ componentName = 'MuiContainer'
53
+ } = options;
54
+ const ContainerRoot = createStyledComponent(({
55
+ theme,
56
+ ownerState
57
+ }) => _extends({
58
+ width: '100%',
59
+ marginLeft: 'auto',
60
+ boxSizing: 'border-box',
61
+ marginRight: 'auto',
62
+ display: 'block'
63
+ }, !ownerState.disableGutters && {
64
+ paddingLeft: theme.spacing(2),
65
+ paddingRight: theme.spacing(2),
66
+ // @ts-ignore module augmentation fails if custom breakpoints are used
67
+ [theme.breakpoints.up('sm')]: {
68
+ paddingLeft: theme.spacing(3),
69
+ paddingRight: theme.spacing(3)
70
+ }
71
+ }), ({
72
+ theme,
73
+ ownerState
74
+ }) => ownerState.fixed && Object.keys(theme.breakpoints.values).reduce((acc, breakpointValueKey) => {
75
+ const breakpoint = breakpointValueKey;
76
+ const value = theme.breakpoints.values[breakpoint];
77
+
78
+ if (value !== 0) {
79
+ // @ts-ignore
80
+ acc[theme.breakpoints.up(breakpoint)] = {
81
+ maxWidth: `${value}${theme.breakpoints.unit}`
82
+ };
83
+ }
84
+
85
+ return acc;
86
+ }, {}), ({
87
+ theme,
88
+ ownerState
89
+ }) => _extends({}, ownerState.maxWidth === 'xs' && {
90
+ // @ts-ignore module augmentation fails if custom breakpoints are used
91
+ [theme.breakpoints.up('xs')]: {
92
+ // @ts-ignore module augmentation fails if custom breakpoints are used
93
+ maxWidth: Math.max(theme.breakpoints.values.xs, 444)
94
+ }
95
+ }, ownerState.maxWidth && // @ts-ignore module augmentation fails if custom breakpoints are used
96
+ ownerState.maxWidth !== 'xs' && {
97
+ // @ts-ignore module augmentation fails if custom breakpoints are used
98
+ [theme.breakpoints.up(ownerState.maxWidth)]: {
99
+ // @ts-ignore module augmentation fails if custom breakpoints are used
100
+ maxWidth: `${theme.breakpoints.values[ownerState.maxWidth]}${theme.breakpoints.unit}`
101
+ }
102
+ }));
103
+ const Container = /*#__PURE__*/React.forwardRef(function Container(inProps, ref) {
104
+ const props = useThemeProps(inProps);
105
+
106
+ const {
107
+ className,
108
+ component = 'div',
109
+ disableGutters = false,
110
+ fixed = false,
111
+ maxWidth = 'lg'
112
+ } = props,
113
+ other = _objectWithoutPropertiesLoose(props, _excluded);
114
+
115
+ const ownerState = _extends({}, props, {
116
+ component,
117
+ disableGutters,
118
+ fixed,
119
+ maxWidth
120
+ }); // @ts-ignore module augmentation fails if custom breakpoints are used
121
+
122
+
123
+ const classes = useUtilityClasses(ownerState, componentName);
124
+ return (
125
+ /*#__PURE__*/
126
+ // @ts-ignore theme is injected by the styled util
127
+ _jsx(ContainerRoot, _extends({
128
+ as: component // @ts-ignore module augmentation fails if custom breakpoints are used
129
+ ,
130
+ ownerState: ownerState,
131
+ className: clsx(classes.root, className),
132
+ ref: ref
133
+ }, other))
134
+ );
135
+ });
136
+ process.env.NODE_ENV !== "production" ? Container.propTypes
137
+ /* remove-proptypes */
138
+ = {
139
+ children: PropTypes.node,
140
+ classes: PropTypes.object,
141
+ className: PropTypes.string,
142
+ component: PropTypes.elementType,
143
+ disableGutters: PropTypes.bool,
144
+ fixed: PropTypes.bool,
145
+ maxWidth: PropTypes
146
+ /* @typescript-to-proptypes-ignore */
147
+ .oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', false]), PropTypes.string]),
148
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
149
+ } : void 0;
150
+ return Container;
151
+ }
@@ -0,0 +1,3 @@
1
+ export { default } from './Container';
2
+ export { default as containerClasses } from './containerClasses';
3
+ export * from './containerClasses';
@@ -8,7 +8,7 @@ import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui
8
8
  import { GlobalStyles } from '@mui/styled-engine';
9
9
  import cssVarsParser from './cssVarsParser';
10
10
  import ThemeProvider from '../ThemeProvider';
11
- import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
11
+ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
12
12
  import useCurrentColorScheme from './useCurrentColorScheme';
13
13
  import createGetCssVar from './createGetCssVar';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -47,11 +47,16 @@ export default function createCssVarsProvider(options) {
47
47
  theme: themeProp = defaultTheme,
48
48
  prefix = designSystemPrefix,
49
49
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
50
+ colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
50
51
  attribute = DEFAULT_ATTRIBUTE,
51
52
  defaultMode = desisgnSystemMode,
52
53
  defaultColorScheme = designSystemColorScheme,
53
54
  disableTransitionOnChange = designSystemTransitionOnChange,
54
- enableColorScheme = designSystemEnableColorScheme
55
+ enableColorScheme = designSystemEnableColorScheme,
56
+ storageWindow = typeof window === 'undefined' ? undefined : window,
57
+ documentNode = typeof document === 'undefined' ? undefined : document,
58
+ colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
59
+ colorSchemeSelector = ':root'
55
60
  }) {
56
61
  const hasMounted = React.useRef(false);
57
62
 
@@ -77,7 +82,9 @@ export default function createCssVarsProvider(options) {
77
82
  defaultLightColorScheme,
78
83
  defaultDarkColorScheme,
79
84
  modeStorageKey,
80
- defaultMode
85
+ colorSchemeStorageKey,
86
+ defaultMode,
87
+ storageWindow
81
88
  });
82
89
 
83
90
  const resolvedColorScheme = (() => {
@@ -111,7 +118,8 @@ export default function createCssVarsProvider(options) {
111
118
  vars: rootVars,
112
119
  getCssVar: createGetCssVar(prefix)
113
120
  });
114
- const styleSheet = {};
121
+ const defaultColorSchemeStyleSheet = {};
122
+ const otherColorSchemesStyleSheet = {};
115
123
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
116
124
  const {
117
125
  css,
@@ -147,54 +155,54 @@ export default function createCssVarsProvider(options) {
147
155
  })();
148
156
 
149
157
  if (key === resolvedDefaultColorScheme) {
150
- styleSheet[':root'] = css;
158
+ defaultColorSchemeStyleSheet[colorSchemeSelector] = css;
151
159
  } else {
152
- styleSheet[`[${attribute}="${key}"]`] = css;
160
+ otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
153
161
  }
154
162
  });
155
163
  React.useEffect(() => {
156
- if (colorScheme) {
164
+ if (colorScheme && colorSchemeNode) {
157
165
  // attaches attribute to <html> because the css variables are attached to :root (html)
158
- document.documentElement.setAttribute(attribute, colorScheme);
166
+ colorSchemeNode.setAttribute(attribute, colorScheme);
159
167
  }
160
- }, [colorScheme, attribute]);
168
+ }, [colorScheme, attribute, colorSchemeNode]);
161
169
  useEnhancedEffect(() => {
162
- if (!mode || !enableColorScheme) {
170
+ if (!mode || !enableColorScheme || !colorSchemeNode) {
163
171
  return undefined;
164
172
  }
165
173
 
166
- const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
174
+ const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
167
175
 
168
176
  if (mode === 'system') {
169
- document.documentElement.style.setProperty('color-scheme', systemMode);
177
+ colorSchemeNode.style.setProperty('color-scheme', systemMode);
170
178
  } else {
171
- document.documentElement.style.setProperty('color-scheme', mode);
179
+ colorSchemeNode.style.setProperty('color-scheme', mode);
172
180
  }
173
181
 
174
182
  return () => {
175
- document.documentElement.style.setProperty('color-scheme', priorColorScheme);
183
+ colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
176
184
  };
177
- }, [mode, systemMode, enableColorScheme]);
185
+ }, [mode, systemMode, enableColorScheme, colorSchemeNode]);
178
186
  React.useEffect(() => {
179
187
  let timer;
180
188
 
181
- if (disableTransitionOnChange && hasMounted.current) {
189
+ if (disableTransitionOnChange && hasMounted.current && documentNode) {
182
190
  // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
183
- const css = document.createElement('style');
184
- css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
185
- document.head.appendChild(css); // Force browser repaint
191
+ const css = documentNode.createElement('style');
192
+ css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
193
+ documentNode.head.appendChild(css); // Force browser repaint
186
194
 
187
- (() => window.getComputedStyle(document.body))();
195
+ (() => window.getComputedStyle(documentNode.body))();
188
196
 
189
197
  timer = setTimeout(() => {
190
- document.head.removeChild(css);
198
+ documentNode.head.removeChild(css);
191
199
  }, 1);
192
200
  }
193
201
 
194
202
  return () => {
195
203
  clearTimeout(timer);
196
204
  };
197
- }, [colorScheme, disableTransitionOnChange]);
205
+ }, [colorScheme, disableTransitionOnChange, documentNode]);
198
206
  React.useEffect(() => {
199
207
  hasMounted.current = true;
200
208
  return () => {
@@ -213,10 +221,12 @@ export default function createCssVarsProvider(options) {
213
221
  },
214
222
  children: [/*#__PURE__*/_jsx(GlobalStyles, {
215
223
  styles: {
216
- ':root': rootCss
224
+ [colorSchemeSelector]: rootCss
217
225
  }
218
226
  }), /*#__PURE__*/_jsx(GlobalStyles, {
219
- styles: styleSheet
227
+ styles: defaultColorSchemeStyleSheet
228
+ }), /*#__PURE__*/_jsx(GlobalStyles, {
229
+ styles: otherColorSchemesStyleSheet
220
230
  }), /*#__PURE__*/_jsx(ThemeProvider, {
221
231
  theme: resolveTheme ? resolveTheme(theme) : theme,
222
232
  children: children
@@ -235,6 +245,21 @@ export default function createCssVarsProvider(options) {
235
245
  */
236
246
  children: PropTypes.node,
237
247
 
248
+ /**
249
+ * The node used to attach the color-scheme attribute
250
+ */
251
+ colorSchemeNode: PropTypes.any,
252
+
253
+ /**
254
+ * The CSS selector for attaching the generated custom properties
255
+ */
256
+ colorSchemeSelector: PropTypes.string,
257
+
258
+ /**
259
+ * localStorage key used to store `colorScheme`
260
+ */
261
+ colorSchemeStorageKey: PropTypes.string,
262
+
238
263
  /**
239
264
  * The initial color scheme used.
240
265
  */
@@ -250,6 +275,11 @@ export default function createCssVarsProvider(options) {
250
275
  */
251
276
  disableTransitionOnChange: PropTypes.bool,
252
277
 
278
+ /**
279
+ * The document to attach the attribute to
280
+ */
281
+ documentNode: PropTypes.any,
282
+
253
283
  /**
254
284
  * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
255
285
  */
@@ -265,6 +295,12 @@ export default function createCssVarsProvider(options) {
265
295
  */
266
296
  prefix: PropTypes.string,
267
297
 
298
+ /**
299
+ * The window that attaches the 'storage' event listener
300
+ * @default window
301
+ */
302
+ storageWindow: PropTypes.any,
303
+
268
304
  /**
269
305
  * The calculated theme object that will be passed through context.
270
306
  */
@@ -5,12 +5,13 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
5
5
  export const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
6
6
  export default function getInitColorSchemeScript(options) {
7
7
  const {
8
- enableSystem,
8
+ enableSystem = false,
9
9
  defaultLightColorScheme = 'light',
10
10
  defaultDarkColorScheme = 'dark',
11
11
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
12
12
  colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
13
- attribute = DEFAULT_ATTRIBUTE
13
+ attribute = DEFAULT_ATTRIBUTE,
14
+ colorSchemeNode = 'document.documentElement'
14
15
  } = options || {};
15
16
  return /*#__PURE__*/_jsx("script", {
16
17
  // eslint-disable-next-line react/no-danger
@@ -34,7 +35,7 @@ export default function getInitColorSchemeScript(options) {
34
35
  colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
35
36
  }
36
37
  if (colorScheme) {
37
- document.documentElement.setAttribute('${attribute}', colorScheme);
38
+ ${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
38
39
  }
39
40
  } catch (e) {} })();`
40
41
  }
@@ -63,7 +63,8 @@ export default function useCurrentColorScheme(options) {
63
63
  defaultDarkColorScheme,
64
64
  supportedColorSchemes = [],
65
65
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
66
- colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY
66
+ colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
67
+ storageWindow = typeof window === 'undefined' ? undefined : window
67
68
  } = options;
68
69
  const joinedColorSchemes = supportedColorSchemes.join(',');
69
70
  const [state, setState] = React.useState(() => {
@@ -80,6 +81,10 @@ export default function useCurrentColorScheme(options) {
80
81
  setState(currentState => {
81
82
  const newMode = !mode ? defaultMode : mode;
82
83
 
84
+ if (mode === currentState.mode) {
85
+ return currentState;
86
+ }
87
+
83
88
  if (typeof localStorage !== 'undefined') {
84
89
  localStorage.setItem(modeStorageKey, newMode);
85
90
  }
@@ -92,7 +97,7 @@ export default function useCurrentColorScheme(options) {
92
97
  }, [modeStorageKey, defaultMode]);
93
98
  const setColorScheme = React.useCallback(value => {
94
99
  if (!value || typeof value === 'string') {
95
- if (value && !supportedColorSchemes.includes(value)) {
100
+ if (value && !joinedColorSchemes.includes(value)) {
96
101
  console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
97
102
  } else {
98
103
  setState(currentState => {
@@ -119,7 +124,7 @@ export default function useCurrentColorScheme(options) {
119
124
  return newState;
120
125
  });
121
126
  }
122
- } else if (value.light && !supportedColorSchemes.includes(value.light) || value.dark && !supportedColorSchemes.includes(value.dark)) {
127
+ } else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
123
128
  console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
124
129
  } else {
125
130
  setState(currentState => {
@@ -144,7 +149,7 @@ export default function useCurrentColorScheme(options) {
144
149
  localStorage.setItem(`${colorSchemeStorageKey}-dark`, value.dark);
145
150
  }
146
151
  }
147
- }, [colorSchemeStorageKey, supportedColorSchemes, defaultLightColorScheme, defaultDarkColorScheme]);
152
+ }, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
148
153
  const handleMediaQuery = React.useCallback(e => {
149
154
  if (state.mode === 'system') {
150
155
  setState(currentState => _extends({}, currentState, {
@@ -206,9 +211,14 @@ export default function useCurrentColorScheme(options) {
206
211
  }
207
212
  };
208
213
 
209
- window.addEventListener('storage', handleStorage);
210
- return () => window.removeEventListener('storage', handleStorage);
211
- }, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode]);
214
+ if (storageWindow) {
215
+ // For syncing color-scheme changes between iframes
216
+ storageWindow.addEventListener('storage', handleStorage);
217
+ return () => storageWindow.removeEventListener('storage', handleStorage);
218
+ }
219
+
220
+ return undefined;
221
+ }, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
212
222
  return _extends({}, state, {
213
223
  colorScheme,
214
224
  setMode,
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.6.4
1
+ /** @license MUI v5.8.1
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.
@@ -44,4 +44,7 @@ export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
44
44
  export * from './colorManipulator';
45
45
  export { default as ThemeProvider } from './ThemeProvider';
46
46
  export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
47
- export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
47
+ export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
48
+ export { default as createContainer } from './Container/createContainer';
49
+ export { default as Container } from './Container';
50
+ export * from './Container';
package/modern/spacing.js CHANGED
@@ -43,7 +43,7 @@ const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTo
43
43
  const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd'];
44
44
  const spacingKeys = [...marginKeys, ...paddingKeys];
45
45
  export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
46
- const themeSpacing = getPath(theme, themeKey) ?? defaultValue;
46
+ const themeSpacing = getPath(theme, themeKey, false) ?? defaultValue;
47
47
 
48
48
  if (typeof themeSpacing === 'number') {
49
49
  return abs => {
package/modern/style.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { unstable_capitalize as capitalize } from '@mui/utils';
2
2
  import responsivePropType from './responsivePropType';
3
3
  import { handleBreakpoints } from './breakpoints';
4
- export function getPath(obj, path) {
4
+ export function getPath(obj, path, checkVars = true) {
5
5
  if (!path || typeof path !== 'string') {
6
6
  return null;
7
7
  } // Check if CSS variables are used
8
8
 
9
9
 
10
- if (obj && obj.vars) {
10
+ if (obj && obj.vars && checkVars) {
11
11
  const val = `vars.${path}`.split('.').reduce((acc, item) => acc && acc[item] ? acc[item] : null, obj);
12
12
 
13
13
  if (val != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.6.4",
3
+ "version": "5.8.1",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "CSS utilities for rapidly laying out custom designs.",
@@ -44,13 +44,13 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.17.2",
47
- "@mui/private-theming": "^5.6.2",
48
- "@mui/styled-engine": "^5.6.1",
47
+ "@mui/private-theming": "^5.8.0",
48
+ "@mui/styled-engine": "^5.8.0",
49
49
  "@mui/types": "^7.1.3",
50
- "@mui/utils": "^5.6.1",
50
+ "@mui/utils": "^5.8.0",
51
51
  "clsx": "^1.1.1",
52
52
  "csstype": "^3.0.11",
53
- "prop-types": "^15.7.2"
53
+ "prop-types": "^15.8.1"
54
54
  },
55
55
  "sideEffects": false,
56
56
  "publishConfig": {
package/spacing.js CHANGED
@@ -66,7 +66,7 @@ const spacingKeys = [...marginKeys, ...paddingKeys];
66
66
  function createUnaryUnit(theme, themeKey, defaultValue, propName) {
67
67
  var _getPath;
68
68
 
69
- const themeSpacing = (_getPath = (0, _style.getPath)(theme, themeKey)) != null ? _getPath : defaultValue;
69
+ const themeSpacing = (_getPath = (0, _style.getPath)(theme, themeKey, false)) != null ? _getPath : defaultValue;
70
70
 
71
71
  if (typeof themeSpacing === 'number') {
72
72
  return abs => {
package/style.js CHANGED
@@ -14,13 +14,13 @@ var _responsivePropType = _interopRequireDefault(require("./responsivePropType")
14
14
 
15
15
  var _breakpoints = require("./breakpoints");
16
16
 
17
- function getPath(obj, path) {
17
+ function getPath(obj, path, checkVars = true) {
18
18
  if (!path || typeof path !== 'string') {
19
19
  return null;
20
20
  } // Check if CSS variables are used
21
21
 
22
22
 
23
- if (obj && obj.vars) {
23
+ if (obj && obj.vars && checkVars) {
24
24
  const val = `vars.${path}`.split('.').reduce((acc, item) => acc && acc[item] ? acc[item] : null, obj);
25
25
 
26
26
  if (val != null) {
@@ -1 +1 @@
1
- export {};
1
+ export {};