@mui/system 5.1.0 → 5.2.2

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/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +257 -10
  3. package/breakpoints.js +1 -1
  4. package/createBox.js +1 -1
  5. package/createTheme/createSpacing.d.ts +10 -10
  6. package/cssVars/createCssVarsProvider.d.ts +11 -1
  7. package/cssVars/createCssVarsProvider.js +62 -8
  8. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  9. package/cssVars/cssVarsParser.d.ts +68 -68
  10. package/cssVars/cssVarsParser.js +1 -1
  11. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  12. package/cssVars/getInitColorSchemeScript.js +6 -6
  13. package/cssVars/index.d.ts +2 -2
  14. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  15. package/esm/breakpoints.js +1 -1
  16. package/esm/createBox.js +1 -1
  17. package/esm/cssVars/createCssVarsProvider.js +59 -8
  18. package/esm/cssVars/cssVarsParser.js +1 -1
  19. package/esm/cssVars/getInitColorSchemeScript.js +6 -6
  20. package/esm/index.js +1 -0
  21. package/esm/styleFunctionSx/styleFunctionSx.js +20 -18
  22. package/esm/sx/index.js +1 -0
  23. package/esm/sx/sx.js +12 -0
  24. package/index.d.ts +2 -0
  25. package/index.js +10 -1
  26. package/index.spec.d.ts +1 -1
  27. package/legacy/breakpoints.js +1 -1
  28. package/legacy/createBox.js +1 -1
  29. package/legacy/cssVars/createCssVarsProvider.js +60 -6
  30. package/legacy/cssVars/cssVarsParser.js +1 -1
  31. package/legacy/cssVars/getInitColorSchemeScript.js +2 -3
  32. package/legacy/index.js +2 -1
  33. package/legacy/styleFunctionSx/styleFunctionSx.js +19 -17
  34. package/legacy/sx/index.js +1 -0
  35. package/legacy/sx/sx.js +13 -0
  36. package/modern/breakpoints.js +1 -1
  37. package/modern/createBox.js +1 -1
  38. package/modern/cssVars/createCssVarsProvider.js +59 -8
  39. package/modern/cssVars/cssVarsParser.js +1 -1
  40. package/modern/cssVars/getInitColorSchemeScript.js +6 -6
  41. package/modern/index.js +2 -1
  42. package/modern/styleFunctionSx/styleFunctionSx.js +20 -18
  43. package/modern/sx/index.js +1 -0
  44. package/modern/sx/sx.js +12 -0
  45. package/package.json +6 -6
  46. package/styleFunctionSx/styleFunctionSx.js +20 -18
  47. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  48. package/sx/index.d.ts +1 -0
  49. package/sx/index.js +15 -0
  50. package/sx/package.json +6 -0
  51. package/sx/sx.d.ts +4 -0
  52. package/sx/sx.js +22 -0
@@ -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) => 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 {};
@@ -80,7 +80,7 @@ exports.walkObjectDeep = walkObjectDeep;
80
80
  const getCssValue = (keys, value) => {
81
81
  if (typeof value === 'number') {
82
82
  if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
83
- // css property that are unitless
83
+ // CSS property that are unitless
84
84
  return value;
85
85
  }
86
86
 
@@ -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
- defaultMode?: 'light' | 'dark' | 'system';
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;
@@ -23,7 +23,7 @@ exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
23
23
 
24
24
  function getInitColorSchemeScript(options) {
25
25
  const {
26
- defaultMode = 'light',
26
+ enableSystem,
27
27
  defaultLightColorScheme = 'light',
28
28
  defaultDarkColorScheme = 'dark',
29
29
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
@@ -36,20 +36,20 @@ function getInitColorSchemeScript(options) {
36
36
  __html: `(function() { try {
37
37
  var mode = localStorage.getItem('${modeStorageKey}');
38
38
  var colorScheme = '';
39
- if (mode === 'system' || (!mode && ${defaultMode} === 'system')) {
39
+ if (mode === 'system' || (!mode && !!${enableSystem})) {
40
40
  // handle system mode
41
41
  var mql = window.matchMedia('(prefers-color-scheme: dark)');
42
42
  if (mql.matches) {
43
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultLightColorScheme};
43
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
44
44
  } else {
45
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultDarkColorScheme};
45
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
46
46
  }
47
47
  }
48
48
  if (mode === 'light') {
49
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultLightColorScheme};
49
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
50
50
  }
51
51
  if (mode === 'dark') {
52
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultDarkColorScheme};
52
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
53
53
  }
54
54
  if (colorScheme) {
55
55
  document.body.setAttribute('${attribute}', colorScheme);
@@ -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>;
@@ -95,7 +95,7 @@ export function createEmptyBreakpointObject(breakpointsInput = {}) {
95
95
  export function removeUnusedBreakpoints(breakpointKeys, style) {
96
96
  return breakpointKeys.reduce((acc, key) => {
97
97
  const breakpointOutput = acc[key];
98
- const isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
98
+ const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
99
99
 
100
100
  if (isBreakpointUnused) {
101
101
  delete acc[key];
package/esm/createBox.js CHANGED
@@ -54,7 +54,7 @@ export default function createBox(options = {}) {
54
54
  /**
55
55
  * @ignore
56
56
  */
57
- sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
57
+ sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func])
58
58
  } : void 0;
59
59
  return Box;
60
60
  }
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
4
4
  const _excluded = ["colorSchemes"],
5
- _excluded2 = ["colorSchemes"];
5
+ _excluded2 = ["colorSchemes"],
6
+ _excluded3 = ["components"];
6
7
  import * as React from 'react';
7
8
  import PropTypes from 'prop-types';
8
9
  import { GlobalStyles } from '@mui/styled-engine';
@@ -13,11 +14,14 @@ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY }
13
14
  import useCurrentColorScheme from './useCurrentColorScheme';
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ 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
18
  export default function createCssVarsProvider(options) {
17
19
  const {
18
20
  theme: baseTheme = {},
19
21
  defaultMode: desisgnSystemMode = 'light',
20
22
  defaultColorScheme: designSystemColorScheme,
23
+ disableTransitionOnChange = false,
24
+ enableColorScheme = true,
21
25
  prefix: designSystemPrefix = '',
22
26
  shouldSkipGeneratingVar
23
27
  } = options;
@@ -57,7 +61,14 @@ export default function createCssVarsProvider(options) {
57
61
  } = themeProp,
58
62
  restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
59
63
 
60
- let mergedTheme = deepmerge(restBaseTheme, restThemeProp);
64
+ const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
65
+
66
+ let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
67
+ {
68
+ components = {}
69
+ } = _deepmerge,
70
+ mergedTheme = _objectWithoutPropertiesLoose(_deepmerge, _excluded3);
71
+
61
72
  const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
62
73
  const allColorSchemes = Object.keys(colorSchemes);
63
74
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
@@ -65,6 +76,7 @@ export default function createCssVarsProvider(options) {
65
76
  const {
66
77
  mode,
67
78
  setMode,
79
+ systemMode,
68
80
  lightColorScheme,
69
81
  darkColorScheme,
70
82
  colorScheme,
@@ -100,6 +112,8 @@ export default function createCssVarsProvider(options) {
100
112
  shouldSkipGeneratingVar
101
113
  });
102
114
  mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
115
+ components,
116
+ colorSchemes,
103
117
  vars: rootVars
104
118
  });
105
119
  const styleSheet = {};
@@ -112,10 +126,7 @@ export default function createCssVarsProvider(options) {
112
126
  basePrefix: designSystemPrefix,
113
127
  shouldSkipGeneratingVar
114
128
  });
115
-
116
- if (key === resolvedColorScheme) {
117
- mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
118
- }
129
+ mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
119
130
 
120
131
  const resolvedDefaultColorScheme = (() => {
121
132
  if (typeof defaultColorScheme === 'string') {
@@ -140,6 +151,46 @@ export default function createCssVarsProvider(options) {
140
151
  document.body.setAttribute(attribute, colorScheme);
141
152
  }
142
153
  }, [colorScheme, attribute]);
154
+ React.useEffect(() => {
155
+ if (!mode || !enableColorScheme) {
156
+ return undefined;
157
+ }
158
+
159
+ const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
160
+
161
+ if (mode === 'system') {
162
+ document.documentElement.style.setProperty('color-scheme', systemMode);
163
+ } else {
164
+ document.documentElement.style.setProperty('color-scheme', mode);
165
+ }
166
+
167
+ return () => {
168
+ document.documentElement.style.setProperty('color-scheme', priorColorScheme);
169
+ };
170
+ }, [mode, systemMode]);
171
+ React.useEffect(() => {
172
+ let timer;
173
+
174
+ if (disableTransitionOnChange && hasMounted.current) {
175
+ // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
176
+ const css = document.createElement('style');
177
+ css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
178
+ document.head.appendChild(css); // Force browser repaint
179
+
180
+ (() => window.getComputedStyle(document.body))();
181
+
182
+ timer = setTimeout(() => {
183
+ document.head.removeChild(css);
184
+ }, 1);
185
+ }
186
+
187
+ return () => {
188
+ clearTimeout(timer);
189
+ };
190
+ }, [colorScheme]);
191
+ React.useEffect(() => {
192
+ hasMounted.current = true;
193
+ }, []);
143
194
  return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
144
195
  value: {
145
196
  mode,
@@ -170,7 +221,7 @@ export default function createCssVarsProvider(options) {
170
221
  attribute: PropTypes.string,
171
222
 
172
223
  /**
173
- * Your component tree.
224
+ * The component tree.
174
225
  */
175
226
  children: PropTypes.node,
176
227
 
@@ -190,7 +241,7 @@ export default function createCssVarsProvider(options) {
190
241
  modeStorageKey: PropTypes.string,
191
242
 
192
243
  /**
193
- * css variable prefix
244
+ * CSS variable prefix.
194
245
  */
195
246
  prefix: PropTypes.string,
196
247
 
@@ -64,7 +64,7 @@ export const walkObjectDeep = (obj, callback) => {
64
64
  const getCssValue = (keys, value) => {
65
65
  if (typeof value === 'number') {
66
66
  if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
67
- // css property that are unitless
67
+ // CSS property that are unitless
68
68
  return value;
69
69
  }
70
70
 
@@ -5,7 +5,7 @@ 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
- defaultMode = 'light',
8
+ enableSystem,
9
9
  defaultLightColorScheme = 'light',
10
10
  defaultDarkColorScheme = 'dark',
11
11
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
@@ -18,20 +18,20 @@ export default function getInitColorSchemeScript(options) {
18
18
  __html: `(function() { try {
19
19
  var mode = localStorage.getItem('${modeStorageKey}');
20
20
  var colorScheme = '';
21
- if (mode === 'system' || (!mode && ${defaultMode} === 'system')) {
21
+ if (mode === 'system' || (!mode && !!${enableSystem})) {
22
22
  // handle system mode
23
23
  var mql = window.matchMedia('(prefers-color-scheme: dark)');
24
24
  if (mql.matches) {
25
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultLightColorScheme};
25
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
26
26
  } else {
27
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultDarkColorScheme};
27
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
28
28
  }
29
29
  }
30
30
  if (mode === 'light') {
31
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || ${defaultLightColorScheme};
31
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
32
32
  }
33
33
  if (mode === 'dark') {
34
- colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || ${defaultDarkColorScheme};
34
+ colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
35
35
  }
36
36
  if (colorScheme) {
37
37
  document.body.setAttribute('${attribute}', colorScheme);
package/esm/index.js CHANGED
@@ -22,6 +22,7 @@ export { default as style, getPath } from './style';
22
22
  export { default as typography } from './typography';
23
23
  export * from './typography';
24
24
  export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
25
+ export { default as experimental_sx } from './sx';
25
26
  export { default as unstable_getThemeValue } from './getThemeValue';
26
27
  export { default as Box } from './Box';
27
28
  export { default as createBox } from './createBox';
@@ -44,27 +44,29 @@ function styleFunctionSx(props) {
44
44
  Object.keys(sxObject).forEach(styleKey => {
45
45
  const value = callIfFn(sxObject[styleKey], theme);
46
46
 
47
- if (typeof value === 'object') {
48
- if (propToStyleFunction[styleKey]) {
49
- css = merge(css, getThemeValue(styleKey, value, theme));
50
- } else {
51
- const breakpointsValues = handleBreakpoints({
52
- theme
53
- }, value, x => ({
54
- [styleKey]: x
55
- }));
56
-
57
- if (objectsHaveSameKeys(breakpointsValues, value)) {
58
- css[styleKey] = styleFunctionSx({
59
- sx: value,
60
- theme
61
- });
47
+ if (value !== null && value !== undefined) {
48
+ if (typeof value === 'object') {
49
+ if (propToStyleFunction[styleKey]) {
50
+ css = merge(css, getThemeValue(styleKey, value, theme));
62
51
  } else {
63
- css = merge(css, breakpointsValues);
52
+ const breakpointsValues = handleBreakpoints({
53
+ theme
54
+ }, value, x => ({
55
+ [styleKey]: x
56
+ }));
57
+
58
+ if (objectsHaveSameKeys(breakpointsValues, value)) {
59
+ css[styleKey] = styleFunctionSx({
60
+ sx: value,
61
+ theme
62
+ });
63
+ } else {
64
+ css = merge(css, breakpointsValues);
65
+ }
64
66
  }
67
+ } else {
68
+ css = merge(css, getThemeValue(styleKey, value, theme));
65
69
  }
66
- } else {
67
- css = merge(css, getThemeValue(styleKey, value, theme));
68
70
  }
69
71
  });
70
72
  return removeUnusedBreakpoints(breakpointsKeys, css);
@@ -0,0 +1 @@
1
+ export { default } from './sx';
package/esm/sx/sx.js ADDED
@@ -0,0 +1,12 @@
1
+ import styleFunctionSx from '../styleFunctionSx';
2
+
3
+ function sx(styles) {
4
+ return ({
5
+ theme
6
+ }) => styleFunctionSx({
7
+ sx: styles,
8
+ theme
9
+ });
10
+ }
11
+
12
+ export default sx;
package/index.d.ts CHANGED
@@ -121,6 +121,8 @@ export {
121
121
  } from './styleFunctionSx';
122
122
  export * from './styleFunctionSx';
123
123
 
124
+ export { default as experimental_sx } from './sx';
125
+
124
126
  export { default as Box } from './Box';
125
127
  export * from './Box';
126
128
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.1.0
1
+ /** @license MUI v5.2.2
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.
@@ -34,6 +34,7 @@ var _exportNames = {
34
34
  typography: true,
35
35
  unstable_styleFunctionSx: true,
36
36
  unstable_extendSxProp: true,
37
+ experimental_sx: true,
37
38
  unstable_getThemeValue: true,
38
39
  Box: true,
39
40
  createBox: true,
@@ -134,6 +135,12 @@ Object.defineProperty(exports, "display", {
134
135
  return _display.default;
135
136
  }
136
137
  });
138
+ Object.defineProperty(exports, "experimental_sx", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _sx.default;
142
+ }
143
+ });
137
144
  Object.defineProperty(exports, "flexbox", {
138
145
  enumerable: true,
139
146
  get: function () {
@@ -405,6 +412,8 @@ Object.keys(_typography).forEach(function (key) {
405
412
 
406
413
  var _styleFunctionSx = _interopRequireWildcard(require("./styleFunctionSx"));
407
414
 
415
+ var _sx = _interopRequireDefault(require("./sx"));
416
+
408
417
  var _getThemeValue = _interopRequireDefault(require("./getThemeValue"));
409
418
 
410
419
  var _Box = _interopRequireDefault(require("./Box"));
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -102,7 +102,7 @@ export function createEmptyBreakpointObject() {
102
102
  export function removeUnusedBreakpoints(breakpointKeys, style) {
103
103
  return breakpointKeys.reduce(function (acc, key) {
104
104
  var breakpointOutput = acc[key];
105
- var isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
105
+ var isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
106
106
 
107
107
  if (isBreakpointUnused) {
108
108
  delete acc[key];