@mui/system 5.2.2 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +84 -0
  3. package/createBox.d.ts +3 -3
  4. package/createBox.spec.d.ts +1 -0
  5. package/createTheme/createSpacing.d.ts +10 -10
  6. package/cssVars/createCssVarsProvider.d.ts +13 -9
  7. package/cssVars/createCssVarsProvider.js +18 -4
  8. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  9. package/cssVars/cssVarsParser.d.ts +68 -68
  10. package/cssVars/cssVarsParser.js +17 -16
  11. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  12. package/cssVars/getInitColorSchemeScript.js +1 -1
  13. package/cssVars/index.d.ts +2 -2
  14. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  15. package/esm/cssVars/createCssVarsProvider.js +17 -4
  16. package/esm/cssVars/cssVarsParser.js +17 -15
  17. package/esm/cssVars/getInitColorSchemeScript.js +1 -1
  18. package/esm/useThemeProps/getThemeProps.js +2 -17
  19. package/index.js +1 -1
  20. package/index.spec.d.ts +1 -1
  21. package/legacy/cssVars/createCssVarsProvider.js +19 -5
  22. package/legacy/cssVars/cssVarsParser.js +19 -13
  23. package/legacy/cssVars/getInitColorSchemeScript.js +1 -1
  24. package/legacy/index.js +1 -1
  25. package/legacy/useThemeProps/getThemeProps.js +2 -17
  26. package/modern/cssVars/createCssVarsProvider.js +15 -4
  27. package/modern/cssVars/cssVarsParser.js +17 -15
  28. package/modern/cssVars/getInitColorSchemeScript.js +1 -1
  29. package/modern/index.js +1 -1
  30. package/modern/useThemeProps/getThemeProps.js +2 -17
  31. package/package.json +4 -4
  32. package/styleFunctionSx/styleFunctionSx.d.ts +1 -1
  33. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  34. package/useThemeProps/getThemeProps.js +2 -17
package/Box/Box.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/CHANGELOG.md CHANGED
@@ -1,5 +1,89 @@
1
1
  ### [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 5.2.3
4
+
5
+ <!-- generated comparing v5.2.2..master -->
6
+
7
+ _Dec 6, 2021_
8
+
9
+ A big thanks to the 25 contributors who made this release possible. Here are some highlights ✨:
10
+
11
+ - ✨ We have introduced a new unstyled component in `@mui/base`: `TablePagination` (#29759) @mnajdova
12
+
13
+ <a href="https://mui.com/components/tables/#unstyled-table"><img width="800" alt="unstyled table" src="https://user-images.githubusercontent.com/4512430/144862194-584356ef-7d9d-462c-a631-186a7e716193.png"></a>
14
+
15
+ You can follow our progress with unstyled components at https://github.com/mui-org/material-ui/issues/27170.
16
+
17
+ - 🎉 We have added an example of how to use MUI with [Remix](https://remix.run/) (#29952) @mnajdova
18
+
19
+ - And many more 🐛 bug fixes and 📚 improvements.
20
+
21
+ ### `@mui/material@5.2.3`
22
+
23
+ - &#8203;<!-- 33 -->[Accordion] Add a test for handling `square` prop (#29972) @daniel-sachs
24
+ - &#8203;<!-- 32 -->[Alert] Fix `square` Paper prop (#30027) @ZeeshanTamboli
25
+ - &#8203;<!-- 31 -->[AvatarGroup] Allow specifying total number of avatars (#29898) @eduardomcv
26
+ - &#8203;<!-- 29 -->[Button] Fix regression from context API (#29982) @siriwatknp
27
+ - &#8203;<!-- 13 -->[Grid] Fix generated classes for `spacing` prop when the value is object (#29880) @jayeclark
28
+ - &#8203;<!-- 10 -->[Select] Should not crash when an empty array is passed with `multiple` enabled (#29957) @Domino987
29
+
30
+ ### `@mui/system@5.2.3`
31
+
32
+ - &#8203;<!-- 06 -->[system] Fix return type of `createBox` (#29989) @mnajdova
33
+ - &#8203;<!-- 05 -->[system] Support boolean values in typescript for the `sx` prop when used as array (#29911) @tasugi
34
+
35
+ ### `@mui/utils@5.2.3`
36
+
37
+ - &#8203;<!-- 03 -->[utils] Add typings for `@mui-material/styles/cssUtils` (#29621) @Semigradsky
38
+
39
+ ### `@mui/icons-material@5.2.1`
40
+
41
+ - &#8203;<!-- 12 -->[icons] Consolidate ignored icons into one list (#29843) @chao813
42
+
43
+ ### `@mui/base@5.0.0-alpha.59`
44
+
45
+ - &#8203;<!-- 30 -->[base] Fix missing ClickAwayListener barrel index export (#30000) @oliviertassinari
46
+ - &#8203;<!-- 04 -->[TablePaginationUnstyled] Introduce new component (#29759) @mnajdova
47
+
48
+ ### `@mui/lab@5.0.0-alpha.59`
49
+
50
+ - &#8203;<!-- 27 -->[DateRangePicker] Fix `DateRangePickerDayProps` interface (#29067) @jonathanrtuck
51
+ - &#8203;<!-- 10 -->[Pickers] Remove propagation of custom props to the `MonthPicker` component's DOM element (#30021) @ZeeshanTamboli
52
+ - &#8203;<!-- 08 -->[StaticDatePicker] Add className and slot to PickerStaticWrapper (#29619) @kkorach
53
+
54
+ ### `@mui/joy@5.0.0-alpha.5`
55
+
56
+ - &#8203;<!-- 11 -->[Joy] Theme setup (#29846) @siriwatknp
57
+
58
+ ### Docs
59
+
60
+ - &#8203;<!-- 34 -->[docs] Fix link in TypeScript doc page (#30044) @genzyy
61
+ - &#8203;<!-- 26 -->[docs] Remove the 'WIP' icon from the 'Group & Pivot' page title (#30077) @flaviendelangle
62
+ - &#8203;<!-- 25 -->[docs] Add warning that `@mui/styled-engine-sc` does not work in SSR (#30026) @mnajdova
63
+ - &#8203;<!-- 24 -->[docs] Add section for CSS specificity in the migration guide (#30008) @hbjORbj
64
+ - &#8203;<!-- 28 -->[docs] Clarify comment in migration doc (#30076) @hbjORbj
65
+ - &#8203;<!-- 23 -->[docs] Sync translations with Crowdin (#30041) @l10nbot
66
+ - &#8203;<!-- 22 -->[docs] Explain how Paper changes shade in dark mode (#30003) @michaldudak
67
+ - &#8203;<!-- 21 -->[docs] Update nextjs-typescript-example (#29974) @huydhoang
68
+ - &#8203;<!-- 20 -->[docs] Add missing global state classes to API docs generator (#29945) @michaldudak
69
+ - &#8203;<!-- 19 -->[docs] Fix benchmarks folder link (#29981) @fourjr
70
+ - &#8203;<!-- 18 -->[docs] Improve wording in StackOverflow section of support page (#29956) @ronwarner
71
+ - &#8203;<!-- 17 -->[docs] Remove Black Friday sale notification (#29936) @mbrookes
72
+ - &#8203;<!-- 16 -->[examples] Fix typos in the Remix example (#30071) @MichaelDeBoey
73
+ - &#8203;<!-- 15 -->[examples] Add Remix example (#29952) @mnajdova
74
+ - &#8203;<!-- 14 -->[examples] Fix lint issue for displayName missing in the Next.js examples (#29985) @ZeeshanTamboli
75
+ - &#8203;<!-- 09 -->[Stack] Document system props in Stack API (#30069) @ThewBear
76
+ - &#8203;<!-- 07 -->[survey] Add a banner and card for promoting the 2021 survey (#29950) @danilo-leal
77
+ - &#8203;<!-- 02 -->[website] Correct the Careers page description (#30073) @michaldudak
78
+ - &#8203;<!-- 01 -->[website] Fix 301 links (#30040) @oliviertassinari
79
+
80
+ ### Core
81
+
82
+ - &#8203;<!-- 31 -->[core] Batch small changes (#30042) @oliviertassinari
83
+ - &#8203;<!-- 28 -->[core] Transition to a new StackOverflow tag (#29967) @oliviertassinari
84
+
85
+ All contributors of this release in alphabetical order: @chao813, @daniel-sachs, @danilo-leal, @Domino987, @eduardomcv, @flaviendelangle, @fourjr, @genzyy, @hbjORbj, @huydhoang, @jayeclark, @jonathanrtuck, @kkorach, @l10nbot, @mbrookes, @MichaelDeBoey, @michaldudak, @mnajdova, @oliviertassinari, @ronwarner, @Semigradsky, @siriwatknp, @tasugi, @ThewBear, @ZeeshanTamboli
86
+
3
87
  ## 5.2.2
4
88
 
5
89
  <!-- generated comparing v5.2.1..master -->
package/createBox.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
1
+ import Box from './Box';
2
2
 
3
3
  export default function createBox(options?: {
4
4
  defaultTheme: object;
5
5
  defaultClassName?: string;
6
- generateClassName?: () => string;
7
- }): React.ElementType;
6
+ generateClassName?: (componentName: string) => string;
7
+ }): typeof Box;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,10 @@
1
- export declare type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
- export declare type SpacingArgument = number | string;
3
- export interface Spacing {
4
- (): string;
5
- (value: number): string;
6
- (topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
7
- (top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
8
- (top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
9
- }
10
- export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
1
+ export declare type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
+ export declare type SpacingArgument = number | string;
3
+ export interface Spacing {
4
+ (): string;
5
+ (value: number): string;
6
+ (topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
7
+ (top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
8
+ (top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
9
+ }
10
+ export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
@@ -1,10 +1,7 @@
1
1
  import * as React from 'react';
2
+ import getInitColorSchemeScript from './getInitColorSchemeScript';
2
3
  import { Mode, Result } from './useCurrentColorScheme';
3
4
 
4
- type RequiredDeep<T> = {
5
- [K in keyof T]-?: RequiredDeep<T[K]>;
6
- };
7
-
8
5
  export type BuildCssVarsTheme<ThemeInput> = ThemeInput extends {
9
6
  colorSchemes: Record<string, infer ColorSystems>;
10
7
  }
@@ -25,7 +22,16 @@ type DecideTheme<
25
22
  ApplicationTheme extends { colorSchemes: Record<ApplicationColorScheme, any> },
26
23
  ApplicationColorScheme extends string | never,
27
24
  > = [ApplicationColorScheme] extends [never]
28
- ? { theme?: DesignSystemTheme }
25
+ ? {
26
+ theme?: Omit<DesignSystemTheme, 'colorSchemes'> & {
27
+ colorSchemes?: Partial<
28
+ Record<
29
+ DesignSystemColorScheme,
30
+ DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
31
+ >
32
+ >;
33
+ };
34
+ }
29
35
  : {
30
36
  theme: Omit<ApplicationTheme, 'colorSchemes'> & {
31
37
  colorSchemes: Partial<
@@ -34,9 +40,7 @@ type DecideTheme<
34
40
  DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
35
41
  >
36
42
  > &
37
- RequiredDeep<
38
- Record<ApplicationColorScheme, ApplicationTheme['colorSchemes'][ApplicationColorScheme]>
39
- >;
43
+ Record<ApplicationColorScheme, ApplicationTheme['colorSchemes'][ApplicationColorScheme]>;
40
44
  };
41
45
  };
42
46
 
@@ -134,7 +138,7 @@ export default function createCssVarsProvider<
134
138
  >,
135
139
  ) => React.ReactElement;
136
140
  useColorScheme: () => ColorSchemeContextValue<DesignSystemColorScheme | ApplicationColorScheme>;
137
- getInitColorSchemeScript: () => React.ReactElement;
141
+ getInitColorSchemeScript: typeof getInitColorSchemeScript;
138
142
  };
139
143
 
140
144
  // disable automatic export
@@ -20,6 +20,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
20
20
 
21
21
  var _styledEngine = require("@mui/styled-engine");
22
22
 
23
+ var _createSpacing = _interopRequireDefault(require("../createTheme/createSpacing"));
24
+
25
+ var _createBreakpoints = _interopRequireDefault(require("../createTheme/createBreakpoints"));
26
+
23
27
  var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
24
28
 
25
29
  var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
@@ -42,6 +46,8 @@ const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transit
42
46
  exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
43
47
 
44
48
  function createCssVarsProvider(options) {
49
+ var _baseTheme$breakpoint;
50
+
45
51
  const {
46
52
  theme: baseTheme = {},
47
53
  defaultMode: desisgnSystemMode = 'light',
@@ -51,6 +57,8 @@ function createCssVarsProvider(options) {
51
57
  prefix: designSystemPrefix = '',
52
58
  shouldSkipGeneratingVar
53
59
  } = options;
60
+ const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
61
+ const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
54
62
 
55
63
  if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
56
64
  console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
@@ -77,10 +85,13 @@ function createCssVarsProvider(options) {
77
85
  defaultMode = desisgnSystemMode,
78
86
  defaultColorScheme = designSystemColorScheme
79
87
  }) {
88
+ // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
89
+ // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
90
+ const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
80
91
  const {
81
92
  colorSchemes: baseColorSchemes = {}
82
- } = baseTheme,
83
- restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
93
+ } = clonedBaseTheme,
94
+ restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(clonedBaseTheme, _excluded);
84
95
  const {
85
96
  colorSchemes: colorSchemesProp = {}
86
97
  } = themeProp,
@@ -138,7 +149,9 @@ function createCssVarsProvider(options) {
138
149
  mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
139
150
  components,
140
151
  colorSchemes,
141
- vars: rootVars
152
+ vars: rootVars,
153
+ spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
154
+ breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints
142
155
  });
143
156
  const styleSheet = {};
144
157
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -172,7 +185,8 @@ function createCssVarsProvider(options) {
172
185
  });
173
186
  React.useEffect(() => {
174
187
  if (colorScheme) {
175
- document.body.setAttribute(attribute, colorScheme);
188
+ // attaches attribute to <html> because the css variables are attached to :root (html)
189
+ document.documentElement.setAttribute(attribute, colorScheme);
176
190
  }
177
191
  }, [colorScheme, attribute]);
178
192
  React.useEffect(() => {
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,68 +1,68 @@
1
- declare type NestedRecord<V = any> = {
2
- [k: string | number]: NestedRecord<V> | V;
3
- };
4
- /**
5
- * This function create an object from keys, value and then assign to target
6
- *
7
- * @param {Object} obj : the target object to be assigned
8
- * @param {string[]} keys
9
- * @param {string | number} value
10
- *
11
- * @example
12
- * const source = {}
13
- * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
14
- * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
15
- *
16
- * @example
17
- * const source = { palette: { primary: 'var(--palette-primary)' } }
18
- * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
19
- * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
20
- */
21
- export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
22
- /**
23
- *
24
- * @param {Object} obj : source object
25
- * @param {Function} callback : a function that will be called when
26
- * - the deepest key in source object is reached
27
- * - the value of the deepest key is NOT `undefined` | `null`
28
- *
29
- * @example
30
- * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
- * // ['palette', 'primary', 'main'] '#000000'
32
- */
33
- export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void) => void;
34
- /**
35
- * a function that parse theme and return { css, vars }
36
- *
37
- * @param {Object} theme
38
- * @param {{
39
- * prefix?: string,
40
- * basePrefix?: string,
41
- * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
42
- * }} options.
43
- * `basePrefix`: defined by design system.
44
- * `prefix`: defined by application
45
- *
46
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
47
- *
48
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
49
- *
50
- * @example
51
- * const { css, vars } = parser({
52
- * fontSize: 12,
53
- * lineHeight: 1.2,
54
- * palette: { primary: { 500: '#000000' } }
55
- * })
56
- *
57
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
58
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
59
- */
60
- export default function cssVarsParser(theme: Record<string, any>, options?: {
61
- prefix?: string;
62
- basePrefix?: string;
63
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
64
- }): {
65
- css: NestedRecord<string>;
66
- vars: NestedRecord<string>;
67
- };
68
- export {};
1
+ declare type NestedRecord<V = any> = {
2
+ [k: string | number]: NestedRecord<V> | V;
3
+ };
4
+ /**
5
+ * This function create an object from keys, value and then assign to target
6
+ *
7
+ * @param {Object} obj : the target object to be assigned
8
+ * @param {string[]} keys
9
+ * @param {string | number} value
10
+ *
11
+ * @example
12
+ * const source = {}
13
+ * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
14
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
15
+ *
16
+ * @example
17
+ * const source = { palette: { primary: 'var(--palette-primary)' } }
18
+ * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
19
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
20
+ */
21
+ export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
22
+ /**
23
+ *
24
+ * @param {Object} obj : source object
25
+ * @param {Function} callback : a function that will be called when
26
+ * - the deepest key in source object is reached
27
+ * - the value of the deepest key is NOT `undefined` | `null`
28
+ *
29
+ * @example
30
+ * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
+ * // ['palette', 'primary', 'main'] '#000000'
32
+ */
33
+ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
34
+ /**
35
+ * a function that parse theme and return { css, vars }
36
+ *
37
+ * @param {Object} theme
38
+ * @param {{
39
+ * prefix?: string,
40
+ * basePrefix?: string,
41
+ * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
42
+ * }} options.
43
+ * `basePrefix`: defined by design system.
44
+ * `prefix`: defined by application
45
+ *
46
+ * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
47
+ *
48
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
49
+ *
50
+ * @example
51
+ * const { css, vars } = parser({
52
+ * fontSize: 12,
53
+ * lineHeight: 1.2,
54
+ * palette: { primary: { 500: '#000000' } }
55
+ * })
56
+ *
57
+ * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
58
+ * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
59
+ */
60
+ export default function cssVarsParser(theme: Record<string, any>, options?: {
61
+ prefix?: string;
62
+ basePrefix?: string;
63
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
64
+ }): {
65
+ css: NestedRecord<string>;
66
+ vars: NestedRecord<string>;
67
+ };
68
+ export {};
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -9,8 +7,6 @@ exports.assignNestedKeys = void 0;
9
7
  exports.default = cssVarsParser;
10
8
  exports.walkObjectDeep = void 0;
11
9
 
12
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
10
  /**
15
11
  * This function create an object from keys, value and then assign to target
16
12
  *
@@ -59,14 +55,16 @@ const assignNestedKeys = (obj, keys, value) => {
59
55
 
60
56
  exports.assignNestedKeys = assignNestedKeys;
61
57
 
62
- const walkObjectDeep = (obj, callback) => {
58
+ const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
63
59
  function recurse(object, parentKeys = []) {
64
60
  Object.entries(object).forEach(([key, value]) => {
65
- if (value !== undefined && value !== null) {
66
- if (typeof value === 'object' && Object.keys(value).length > 0) {
67
- recurse(value, [...parentKeys, key]);
68
- } else {
69
- callback([...parentKeys, key], value, object);
61
+ if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
62
+ if (value !== undefined && value !== null) {
63
+ if (typeof value === 'object' && Object.keys(value).length > 0) {
64
+ recurse(value, [...parentKeys, key]);
65
+ } else {
66
+ callback([...parentKeys, key], value, object);
67
+ }
70
68
  }
71
69
  }
72
70
  });
@@ -118,9 +116,6 @@ const getCssValue = (keys, value) => {
118
116
 
119
117
 
120
118
  function cssVarsParser(theme, options) {
121
- const clonedTheme = (0, _extends2.default)({}, theme);
122
- delete clonedTheme.vars; // remove 'vars' from the structure
123
-
124
119
  const {
125
120
  prefix,
126
121
  basePrefix = '',
@@ -128,13 +123,18 @@ function cssVarsParser(theme, options) {
128
123
  } = options || {};
129
124
  const css = {};
130
125
  const vars = {};
131
- walkObjectDeep(clonedTheme, (keys, val, scope) => {
126
+ walkObjectDeep(theme, (keys, val, scope) => {
132
127
  if (typeof val === 'string' || typeof val === 'number') {
133
128
  let value = val;
134
129
 
135
130
  if (typeof value === 'string' && value.startsWith('var')) {
136
131
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
137
- value = prefix ? value.replace(basePrefix, prefix) : value.replace(`${basePrefix}-`, ''); // scope is the deepest object in the tree, keys is the theme path keys
132
+ if (!basePrefix && prefix) {
133
+ value = value.replace(/var\(--/g, `var(--${prefix}-`);
134
+ } else {
135
+ value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
136
+ } // scope is the deepest object in the tree, keys is the theme path keys
137
+
138
138
 
139
139
  scope[keys.slice(-1)[0]] = value;
140
140
  }
@@ -148,7 +148,8 @@ function cssVarsParser(theme, options) {
148
148
  assignNestedKeys(vars, keys, `var(${cssVar})`);
149
149
  }
150
150
  }
151
- });
151
+ }, keys => keys[0] === 'vars' // skip 'vars/*' paths
152
+ );
152
153
  return {
153
154
  css,
154
155
  vars
@@ -1,12 +1,12 @@
1
- /// <reference types="react" />
2
- export declare const DEFAULT_MODE_STORAGE_KEY = "mui-mode";
3
- export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "mui-color-scheme";
4
- export declare const DEFAULT_ATTRIBUTE = "data-mui-color-scheme";
5
- export default function getInitColorSchemeScript(options?: {
6
- enableSystem?: boolean;
7
- defaultLightColorScheme?: string;
8
- defaultDarkColorScheme?: string;
9
- modeStorageKey?: string;
10
- colorSchemeStorageKey?: string;
11
- attribute?: string;
12
- }): JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const DEFAULT_MODE_STORAGE_KEY = "mui-mode";
3
+ export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "mui-color-scheme";
4
+ export declare const DEFAULT_ATTRIBUTE = "data-mui-color-scheme";
5
+ export default function getInitColorSchemeScript(options?: {
6
+ enableSystem?: boolean;
7
+ defaultLightColorScheme?: string;
8
+ defaultDarkColorScheme?: string;
9
+ modeStorageKey?: string;
10
+ colorSchemeStorageKey?: string;
11
+ attribute?: string;
12
+ }): JSX.Element;
@@ -52,7 +52,7 @@ function getInitColorSchemeScript(options) {
52
52
  colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
53
53
  }
54
54
  if (colorScheme) {
55
- document.body.setAttribute('${attribute}', colorScheme);
55
+ document.documentElement.setAttribute('${attribute}', colorScheme);
56
56
  }
57
57
  } catch (e) {} })();`
58
58
  }
@@ -1,2 +1,2 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { BuildCssVarsTheme } from './createCssVarsProvider';
1
+ export { default } from './createCssVarsProvider';
2
+ export type { BuildCssVarsTheme } from './createCssVarsProvider';
@@ -1,50 +1,50 @@
1
- export declare type Mode = 'light' | 'dark' | 'system';
2
- export declare type SystemMode = Exclude<Mode, 'system'>;
3
- export interface State<SupportedColorScheme extends string> {
4
- /**
5
- * User selected mode.
6
- * Note: on the server, mode is always undefined
7
- */
8
- mode: Mode | undefined;
9
- /**
10
- * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
- */
12
- systemMode: SystemMode | undefined;
13
- /**
14
- * The color scheme for the light mode.
15
- */
16
- lightColorScheme: SupportedColorScheme;
17
- /**
18
- * The color scheme for the dark mode.
19
- */
20
- darkColorScheme: SupportedColorScheme;
21
- }
22
- export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
- /**
24
- * The current application color scheme. It is always `undefined` on the server.
25
- */
26
- colorScheme: SupportedColorScheme | undefined;
27
- /**
28
- * `mode` is saved to internal state and localStorage
29
- * If `mode` is null, it will be reset to the defaultMode
30
- */
31
- setMode: (mode: Mode | null) => void;
32
- /**
33
- * `colorScheme` is saved to internal state and localStorage
34
- * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
- */
36
- setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
- light: SupportedColorScheme | null;
38
- dark: SupportedColorScheme | null;
39
- }> | null) => void;
40
- };
41
- export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
- export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
- export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
44
- defaultLightColorScheme: SupportedColorScheme;
45
- defaultDarkColorScheme: SupportedColorScheme;
46
- supportedColorSchemes: Array<SupportedColorScheme>;
47
- defaultMode?: Mode;
48
- modeStorageKey?: string;
49
- colorSchemeStorageKey?: string;
50
- }): Result<SupportedColorScheme>;
1
+ export declare type Mode = 'light' | 'dark' | 'system';
2
+ export declare type SystemMode = Exclude<Mode, 'system'>;
3
+ export interface State<SupportedColorScheme extends string> {
4
+ /**
5
+ * User selected mode.
6
+ * Note: on the server, mode is always undefined
7
+ */
8
+ mode: Mode | undefined;
9
+ /**
10
+ * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
+ */
12
+ systemMode: SystemMode | undefined;
13
+ /**
14
+ * The color scheme for the light mode.
15
+ */
16
+ lightColorScheme: SupportedColorScheme;
17
+ /**
18
+ * The color scheme for the dark mode.
19
+ */
20
+ darkColorScheme: SupportedColorScheme;
21
+ }
22
+ export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
+ /**
24
+ * The current application color scheme. It is always `undefined` on the server.
25
+ */
26
+ colorScheme: SupportedColorScheme | undefined;
27
+ /**
28
+ * `mode` is saved to internal state and localStorage
29
+ * If `mode` is null, it will be reset to the defaultMode
30
+ */
31
+ setMode: (mode: Mode | null) => void;
32
+ /**
33
+ * `colorScheme` is saved to internal state and localStorage
34
+ * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
+ */
36
+ setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
+ light: SupportedColorScheme | null;
38
+ dark: SupportedColorScheme | null;
39
+ }> | null) => void;
40
+ };
41
+ export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
+ export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
+ export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
44
+ defaultLightColorScheme: SupportedColorScheme;
45
+ defaultDarkColorScheme: SupportedColorScheme;
46
+ supportedColorSchemes: Array<SupportedColorScheme>;
47
+ defaultMode?: Mode;
48
+ modeStorageKey?: string;
49
+ colorSchemeStorageKey?: string;
50
+ }): Result<SupportedColorScheme>;
@@ -8,6 +8,8 @@ import * as React from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { GlobalStyles } from '@mui/styled-engine';
10
10
  import { deepmerge } from '@mui/utils';
11
+ import createSpacing from '../createTheme/createSpacing';
12
+ import createBreakpoints from '../createTheme/createBreakpoints';
11
13
  import cssVarsParser from './cssVarsParser';
12
14
  import ThemeProvider from '../ThemeProvider';
13
15
  import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
@@ -16,6 +18,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
16
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
19
  export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
18
20
  export default function createCssVarsProvider(options) {
21
+ var _baseTheme$breakpoint;
22
+
19
23
  const {
20
24
  theme: baseTheme = {},
21
25
  defaultMode: desisgnSystemMode = 'light',
@@ -25,6 +29,8 @@ export default function createCssVarsProvider(options) {
25
29
  prefix: designSystemPrefix = '',
26
30
  shouldSkipGeneratingVar
27
31
  } = options;
32
+ const systemSpacing = createSpacing(baseTheme.spacing);
33
+ const systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
28
34
 
29
35
  if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
30
36
  console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
@@ -51,10 +57,14 @@ export default function createCssVarsProvider(options) {
51
57
  defaultMode = desisgnSystemMode,
52
58
  defaultColorScheme = designSystemColorScheme
53
59
  }) {
60
+ // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
61
+ // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
62
+ const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
63
+
54
64
  const {
55
65
  colorSchemes: baseColorSchemes = {}
56
- } = baseTheme,
57
- restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
66
+ } = clonedBaseTheme,
67
+ restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
58
68
 
59
69
  const {
60
70
  colorSchemes: colorSchemesProp = {}
@@ -114,7 +124,9 @@ export default function createCssVarsProvider(options) {
114
124
  mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
115
125
  components,
116
126
  colorSchemes,
117
- vars: rootVars
127
+ vars: rootVars,
128
+ spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
129
+ breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
118
130
  });
119
131
  const styleSheet = {};
120
132
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -148,7 +160,8 @@ export default function createCssVarsProvider(options) {
148
160
  });
149
161
  React.useEffect(() => {
150
162
  if (colorScheme) {
151
- document.body.setAttribute(attribute, colorScheme);
163
+ // attaches attribute to <html> because the css variables are attached to :root (html)
164
+ document.documentElement.setAttribute(attribute, colorScheme);
152
165
  }
153
166
  }, [colorScheme, attribute]);
154
167
  React.useEffect(() => {
@@ -1,5 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
-
3
1
  /**
4
2
  * This function create an object from keys, value and then assign to target
5
3
  *
@@ -45,14 +43,16 @@ export const assignNestedKeys = (obj, keys, value) => {
45
43
  * // ['palette', 'primary', 'main'] '#000000'
46
44
  */
47
45
 
48
- export const walkObjectDeep = (obj, callback) => {
46
+ export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
49
47
  function recurse(object, parentKeys = []) {
50
48
  Object.entries(object).forEach(([key, value]) => {
51
- if (value !== undefined && value !== null) {
52
- if (typeof value === 'object' && Object.keys(value).length > 0) {
53
- recurse(value, [...parentKeys, key]);
54
- } else {
55
- callback([...parentKeys, key], value, object);
49
+ if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
50
+ if (value !== undefined && value !== null) {
51
+ if (typeof value === 'object' && Object.keys(value).length > 0) {
52
+ recurse(value, [...parentKeys, key]);
53
+ } else {
54
+ callback([...parentKeys, key], value, object);
55
+ }
56
56
  }
57
57
  }
58
58
  });
@@ -102,10 +102,6 @@ const getCssValue = (keys, value) => {
102
102
 
103
103
 
104
104
  export default function cssVarsParser(theme, options) {
105
- const clonedTheme = _extends({}, theme);
106
-
107
- delete clonedTheme.vars; // remove 'vars' from the structure
108
-
109
105
  const {
110
106
  prefix,
111
107
  basePrefix = '',
@@ -113,13 +109,18 @@ export default function cssVarsParser(theme, options) {
113
109
  } = options || {};
114
110
  const css = {};
115
111
  const vars = {};
116
- walkObjectDeep(clonedTheme, (keys, val, scope) => {
112
+ walkObjectDeep(theme, (keys, val, scope) => {
117
113
  if (typeof val === 'string' || typeof val === 'number') {
118
114
  let value = val;
119
115
 
120
116
  if (typeof value === 'string' && value.startsWith('var')) {
121
117
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
122
- value = prefix ? value.replace(basePrefix, prefix) : value.replace(`${basePrefix}-`, ''); // scope is the deepest object in the tree, keys is the theme path keys
118
+ if (!basePrefix && prefix) {
119
+ value = value.replace(/var\(--/g, `var(--${prefix}-`);
120
+ } else {
121
+ value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
122
+ } // scope is the deepest object in the tree, keys is the theme path keys
123
+
123
124
 
124
125
  scope[keys.slice(-1)[0]] = value;
125
126
  }
@@ -133,7 +134,8 @@ export default function cssVarsParser(theme, options) {
133
134
  assignNestedKeys(vars, keys, `var(${cssVar})`);
134
135
  }
135
136
  }
136
- });
137
+ }, keys => keys[0] === 'vars' // skip 'vars/*' paths
138
+ );
137
139
  return {
138
140
  css,
139
141
  vars
@@ -34,7 +34,7 @@ export default function getInitColorSchemeScript(options) {
34
34
  colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
35
35
  }
36
36
  if (colorScheme) {
37
- document.body.setAttribute('${attribute}', colorScheme);
37
+ document.documentElement.setAttribute('${attribute}', colorScheme);
38
38
  }
39
39
  } catch (e) {} })();`
40
40
  }
@@ -1,6 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
-
3
- /* eslint-disable no-restricted-syntax */
1
+ import { internal_resolveProps as resolveProps } from '@mui/utils';
4
2
  export default function getThemeProps(params) {
5
3
  const {
6
4
  theme,
@@ -12,18 +10,5 @@ export default function getThemeProps(params) {
12
10
  return props;
13
11
  }
14
12
 
15
- const output = _extends({}, props); // Resolve default props, code borrow from React source.
16
- // https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
17
-
18
-
19
- const defaultProps = theme.components[name].defaultProps;
20
- let propName;
21
-
22
- for (propName in defaultProps) {
23
- if (output[propName] === undefined) {
24
- output[propName] = defaultProps[propName];
25
- }
26
- }
27
-
28
- return output;
13
+ return resolveProps(theme.components[name].defaultProps, props);
29
14
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.2.2
1
+ /** @license MUI v5.2.3
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -7,6 +7,8 @@ import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { GlobalStyles } from '@mui/styled-engine';
9
9
  import { deepmerge } from '@mui/utils';
10
+ import createSpacing from '../createTheme/createSpacing';
11
+ import createBreakpoints from '../createTheme/createBreakpoints';
10
12
  import cssVarsParser from './cssVarsParser';
11
13
  import ThemeProvider from '../ThemeProvider';
12
14
  import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
@@ -15,6 +17,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
15
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
18
  export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
17
19
  export default function createCssVarsProvider(options) {
20
+ var _baseTheme$breakpoint;
21
+
18
22
  var _options$theme = options.theme,
19
23
  baseTheme = _options$theme === void 0 ? {} : _options$theme,
20
24
  _options$defaultMode = options.defaultMode,
@@ -27,6 +31,8 @@ export default function createCssVarsProvider(options) {
27
31
  _options$prefix = options.prefix,
28
32
  designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
29
33
  shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
34
+ var systemSpacing = createSpacing(baseTheme.spacing);
35
+ var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
30
36
 
31
37
  if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
32
38
  console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
@@ -58,10 +64,15 @@ export default function createCssVarsProvider(options) {
58
64
  defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
59
65
  _ref$defaultColorSche = _ref.defaultColorScheme,
60
66
  defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche;
67
+ // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
68
+ // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
69
+ var clonedBaseTheme = React.useMemo(function () {
70
+ return JSON.parse(JSON.stringify(baseTheme));
71
+ }, []);
61
72
 
62
- var _baseTheme$colorSchem = baseTheme.colorSchemes,
63
- baseColorSchemes = _baseTheme$colorSchem === void 0 ? {} : _baseTheme$colorSchem,
64
- restBaseTheme = _objectWithoutProperties(baseTheme, ["colorSchemes"]);
73
+ var _clonedBaseTheme$colo = clonedBaseTheme.colorSchemes,
74
+ baseColorSchemes = _clonedBaseTheme$colo === void 0 ? {} : _clonedBaseTheme$colo,
75
+ restBaseTheme = _objectWithoutProperties(clonedBaseTheme, ["colorSchemes"]);
65
76
 
66
77
  var _themeProp$colorSchem = themeProp.colorSchemes,
67
78
  colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
@@ -119,7 +130,9 @@ export default function createCssVarsProvider(options) {
119
130
  mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
120
131
  components: components,
121
132
  colorSchemes: colorSchemes,
122
- vars: rootVars
133
+ vars: rootVars,
134
+ spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
135
+ breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
123
136
  });
124
137
  var styleSheet = {};
125
138
  Object.entries(colorSchemes).forEach(function (_ref2) {
@@ -157,7 +170,8 @@ export default function createCssVarsProvider(options) {
157
170
  });
158
171
  React.useEffect(function () {
159
172
  if (colorScheme) {
160
- document.body.setAttribute(attribute, colorScheme);
173
+ // attaches attribute to <html> because the css variables are attached to :root (html)
174
+ document.documentElement.setAttribute(attribute, colorScheme);
161
175
  }
162
176
  }, [colorScheme, attribute]);
163
177
  React.useEffect(function () {
@@ -49,7 +49,7 @@ export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
49
49
  * // ['palette', 'primary', 'main'] '#000000'
50
50
  */
51
51
 
52
- export var walkObjectDeep = function walkObjectDeep(obj, callback) {
52
+ export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPaths) {
53
53
  function recurse(object) {
54
54
  var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
55
55
  Object.entries(object).forEach(function (_ref) {
@@ -57,11 +57,13 @@ export var walkObjectDeep = function walkObjectDeep(obj, callback) {
57
57
  key = _ref2[0],
58
58
  value = _ref2[1];
59
59
 
60
- if (value !== undefined && value !== null) {
61
- if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
62
- recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
63
- } else {
64
- callback([].concat(_toConsumableArray(parentKeys), [key]), value, object);
60
+ if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([].concat(_toConsumableArray(parentKeys), [key]))) {
61
+ if (value !== undefined && value !== null) {
62
+ if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
63
+ recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
64
+ } else {
65
+ callback([].concat(_toConsumableArray(parentKeys), [key]), value, object);
66
+ }
65
67
  }
66
68
  }
67
69
  });
@@ -113,10 +115,6 @@ var getCssValue = function getCssValue(keys, value) {
113
115
 
114
116
 
115
117
  export default function cssVarsParser(theme, options) {
116
- var clonedTheme = _extends({}, theme);
117
-
118
- delete clonedTheme.vars; // remove 'vars' from the structure
119
-
120
118
  var _ref3 = options || {},
121
119
  prefix = _ref3.prefix,
122
120
  _ref3$basePrefix = _ref3.basePrefix,
@@ -125,13 +123,18 @@ export default function cssVarsParser(theme, options) {
125
123
 
126
124
  var css = {};
127
125
  var vars = {};
128
- walkObjectDeep(clonedTheme, function (keys, val, scope) {
126
+ walkObjectDeep(theme, function (keys, val, scope) {
129
127
  if (typeof val === 'string' || typeof val === 'number') {
130
128
  var _value = val;
131
129
 
132
130
  if (typeof _value === 'string' && _value.startsWith('var')) {
133
131
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
134
- _value = prefix ? _value.replace(basePrefix, prefix) : _value.replace("".concat(basePrefix, "-"), ''); // scope is the deepest object in the tree, keys is the theme path keys
132
+ if (!basePrefix && prefix) {
133
+ _value = _value.replace(/var\(--/g, "var(--".concat(prefix, "-"));
134
+ } else {
135
+ _value = prefix ? _value.replace(new RegExp(basePrefix, 'g'), prefix) : _value.replace(new RegExp("".concat(basePrefix, "-"), 'g'), '');
136
+ } // scope is the deepest object in the tree, keys is the theme path keys
137
+
135
138
 
136
139
  scope[keys.slice(-1)[0]] = _value;
137
140
  }
@@ -145,7 +148,10 @@ export default function cssVarsParser(theme, options) {
145
148
  assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
146
149
  }
147
150
  }
148
- });
151
+ }, function (keys) {
152
+ return keys[0] === 'vars';
153
+ } // skip 'vars/*' paths
154
+ );
149
155
  return {
150
156
  css: css,
151
157
  vars: vars
@@ -20,7 +20,7 @@ export default function getInitColorSchemeScript(options) {
20
20
  return /*#__PURE__*/_jsx("script", {
21
21
  // eslint-disable-next-line react/no-danger
22
22
  dangerouslySetInnerHTML: {
23
- __html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n document.body.setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
23
+ __html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n document.documentElement.setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
24
24
  }
25
25
  });
26
26
  }
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.2.2
1
+ /** @license MUI v5.2.3
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
-
3
- /* eslint-disable no-restricted-syntax */
1
+ import { internal_resolveProps as resolveProps } from '@mui/utils';
4
2
  export default function getThemeProps(params) {
5
3
  var theme = params.theme,
6
4
  name = params.name,
@@ -10,18 +8,5 @@ export default function getThemeProps(params) {
10
8
  return props;
11
9
  }
12
10
 
13
- var output = _extends({}, props); // Resolve default props, code borrow from React source.
14
- // https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
15
-
16
-
17
- var defaultProps = theme.components[name].defaultProps;
18
- var propName;
19
-
20
- for (propName in defaultProps) {
21
- if (output[propName] === undefined) {
22
- output[propName] = defaultProps[propName];
23
- }
24
- }
25
-
26
- return output;
11
+ return resolveProps(theme.components[name].defaultProps, props);
27
12
  }
@@ -8,6 +8,8 @@ import * as React from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { GlobalStyles } from '@mui/styled-engine';
10
10
  import { deepmerge } from '@mui/utils';
11
+ import createSpacing from '../createTheme/createSpacing';
12
+ import createBreakpoints from '../createTheme/createBreakpoints';
11
13
  import cssVarsParser from './cssVarsParser';
12
14
  import ThemeProvider from '../ThemeProvider';
13
15
  import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
@@ -25,6 +27,8 @@ export default function createCssVarsProvider(options) {
25
27
  prefix: designSystemPrefix = '',
26
28
  shouldSkipGeneratingVar
27
29
  } = options;
30
+ const systemSpacing = createSpacing(baseTheme.spacing);
31
+ const systemBreakpoints = createBreakpoints(baseTheme.breakpoints ?? {});
28
32
 
29
33
  if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme?.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme?.dark]) {
30
34
  console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
@@ -51,10 +55,14 @@ export default function createCssVarsProvider(options) {
51
55
  defaultMode = desisgnSystemMode,
52
56
  defaultColorScheme = designSystemColorScheme
53
57
  }) {
58
+ // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
59
+ // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
60
+ const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
61
+
54
62
  const {
55
63
  colorSchemes: baseColorSchemes = {}
56
- } = baseTheme,
57
- restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
64
+ } = clonedBaseTheme,
65
+ restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
58
66
 
59
67
  const {
60
68
  colorSchemes: colorSchemesProp = {}
@@ -114,7 +122,9 @@ export default function createCssVarsProvider(options) {
114
122
  mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
115
123
  components,
116
124
  colorSchemes,
117
- vars: rootVars
125
+ vars: rootVars,
126
+ spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
127
+ breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
118
128
  });
119
129
  const styleSheet = {};
120
130
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -148,7 +158,8 @@ export default function createCssVarsProvider(options) {
148
158
  });
149
159
  React.useEffect(() => {
150
160
  if (colorScheme) {
151
- document.body.setAttribute(attribute, colorScheme);
161
+ // attaches attribute to <html> because the css variables are attached to :root (html)
162
+ document.documentElement.setAttribute(attribute, colorScheme);
152
163
  }
153
164
  }, [colorScheme, attribute]);
154
165
  React.useEffect(() => {
@@ -1,5 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
-
3
1
  /**
4
2
  * This function create an object from keys, value and then assign to target
5
3
  *
@@ -45,14 +43,16 @@ export const assignNestedKeys = (obj, keys, value) => {
45
43
  * // ['palette', 'primary', 'main'] '#000000'
46
44
  */
47
45
 
48
- export const walkObjectDeep = (obj, callback) => {
46
+ export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
49
47
  function recurse(object, parentKeys = []) {
50
48
  Object.entries(object).forEach(([key, value]) => {
51
- if (value !== undefined && value !== null) {
52
- if (typeof value === 'object' && Object.keys(value).length > 0) {
53
- recurse(value, [...parentKeys, key]);
54
- } else {
55
- callback([...parentKeys, key], value, object);
49
+ if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
50
+ if (value !== undefined && value !== null) {
51
+ if (typeof value === 'object' && Object.keys(value).length > 0) {
52
+ recurse(value, [...parentKeys, key]);
53
+ } else {
54
+ callback([...parentKeys, key], value, object);
55
+ }
56
56
  }
57
57
  }
58
58
  });
@@ -102,10 +102,6 @@ const getCssValue = (keys, value) => {
102
102
 
103
103
 
104
104
  export default function cssVarsParser(theme, options) {
105
- const clonedTheme = _extends({}, theme);
106
-
107
- delete clonedTheme.vars; // remove 'vars' from the structure
108
-
109
105
  const {
110
106
  prefix,
111
107
  basePrefix = '',
@@ -113,13 +109,18 @@ export default function cssVarsParser(theme, options) {
113
109
  } = options || {};
114
110
  const css = {};
115
111
  const vars = {};
116
- walkObjectDeep(clonedTheme, (keys, val, scope) => {
112
+ walkObjectDeep(theme, (keys, val, scope) => {
117
113
  if (typeof val === 'string' || typeof val === 'number') {
118
114
  let value = val;
119
115
 
120
116
  if (typeof value === 'string' && value.startsWith('var')) {
121
117
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
122
- value = prefix ? value.replace(basePrefix, prefix) : value.replace(`${basePrefix}-`, ''); // scope is the deepest object in the tree, keys is the theme path keys
118
+ if (!basePrefix && prefix) {
119
+ value = value.replace(/var\(--/g, `var(--${prefix}-`);
120
+ } else {
121
+ value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
122
+ } // scope is the deepest object in the tree, keys is the theme path keys
123
+
123
124
 
124
125
  scope[keys.slice(-1)[0]] = value;
125
126
  }
@@ -133,7 +134,8 @@ export default function cssVarsParser(theme, options) {
133
134
  assignNestedKeys(vars, keys, `var(${cssVar})`);
134
135
  }
135
136
  }
136
- });
137
+ }, keys => keys[0] === 'vars' // skip 'vars/*' paths
138
+ );
137
139
  return {
138
140
  css,
139
141
  vars
@@ -34,7 +34,7 @@ export default function getInitColorSchemeScript(options) {
34
34
  colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
35
35
  }
36
36
  if (colorScheme) {
37
- document.body.setAttribute('${attribute}', colorScheme);
37
+ document.documentElement.setAttribute('${attribute}', colorScheme);
38
38
  }
39
39
  } catch (e) {} })();`
40
40
  }
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.2.2
1
+ /** @license MUI v5.2.3
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
-
3
- /* eslint-disable no-restricted-syntax */
1
+ import { internal_resolveProps as resolveProps } from '@mui/utils';
4
2
  export default function getThemeProps(params) {
5
3
  const {
6
4
  theme,
@@ -12,18 +10,5 @@ export default function getThemeProps(params) {
12
10
  return props;
13
11
  }
14
12
 
15
- const output = _extends({}, props); // Resolve default props, code borrow from React source.
16
- // https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
17
-
18
-
19
- const defaultProps = theme.components[name].defaultProps;
20
- let propName;
21
-
22
- for (propName in defaultProps) {
23
- if (output[propName] === undefined) {
24
- output[propName] = defaultProps[propName];
25
- }
26
- }
27
-
28
- return output;
13
+ return resolveProps(theme.components[name].defaultProps, props);
29
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.2.2",
3
+ "version": "5.2.3",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "CSS utilities for rapidly laying out custom designs.",
@@ -23,7 +23,7 @@
23
23
  "homepage": "https://mui.com/system/basics/",
24
24
  "funding": {
25
25
  "type": "opencollective",
26
- "url": "https://opencollective.com/material-ui"
26
+ "url": "https://opencollective.com/mui"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@emotion/react": "^11.5.0",
@@ -44,10 +44,10 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.16.3",
47
- "@mui/private-theming": "^5.2.2",
47
+ "@mui/private-theming": "^5.2.3",
48
48
  "@mui/styled-engine": "^5.2.0",
49
49
  "@mui/types": "^7.1.0",
50
- "@mui/utils": "^5.2.2",
50
+ "@mui/utils": "^5.2.3",
51
51
  "clsx": "^1.1.1",
52
52
  "csstype": "^3.0.10",
53
53
  "prop-types": "^15.7.2"
@@ -57,7 +57,7 @@ export type SystemStyleObject<Theme extends object = {}> =
57
57
  export type SxProps<Theme extends object = {}> =
58
58
  | SystemStyleObject<Theme>
59
59
  | ((theme: Theme) => SystemStyleObject<Theme>)
60
- | Array<SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
60
+ | Array<boolean | SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
61
61
 
62
62
  // eslint-disable-next-line @typescript-eslint/naming-convention
63
63
  export default function unstable_styleFunctionSx(props: object): object;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = getThemeProps;
9
7
 
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
+ var _utils = require("@mui/utils");
11
9
 
12
- /* eslint-disable no-restricted-syntax */
13
10
  function getThemeProps(params) {
14
11
  const {
15
12
  theme,
@@ -21,17 +18,5 @@ function getThemeProps(params) {
21
18
  return props;
22
19
  }
23
20
 
24
- const output = (0, _extends2.default)({}, props); // Resolve default props, code borrow from React source.
25
- // https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
26
-
27
- const defaultProps = theme.components[name].defaultProps;
28
- let propName;
29
-
30
- for (propName in defaultProps) {
31
- if (output[propName] === undefined) {
32
- output[propName] = defaultProps[propName];
33
- }
34
- }
35
-
36
- return output;
21
+ return (0, _utils.internal_resolveProps)(theme.components[name].defaultProps, props);
37
22
  }