@mui/system 7.0.0-beta.2 → 7.0.0-beta.4

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 (69) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/borders/borders.d.ts +3 -2
  3. package/cssGrid/cssGrid.d.ts +15 -2
  4. package/cssVars/createCssVarsProvider.d.ts +12 -0
  5. package/cssVars/createCssVarsProvider.js +21 -4
  6. package/cssVars/index.d.ts +2 -1
  7. package/cssVars/localStorageManager.d.ts +34 -0
  8. package/cssVars/localStorageManager.js +57 -0
  9. package/cssVars/useCurrentColorScheme.d.ts +2 -0
  10. package/cssVars/useCurrentColorScheme.js +50 -69
  11. package/display/display.d.ts +2 -1
  12. package/esm/borders/borders.d.ts +3 -2
  13. package/esm/cssGrid/cssGrid.d.ts +15 -2
  14. package/esm/cssVars/createCssVarsProvider.d.ts +12 -0
  15. package/esm/cssVars/createCssVarsProvider.js +21 -4
  16. package/esm/cssVars/index.d.ts +2 -1
  17. package/esm/cssVars/localStorageManager.d.ts +34 -0
  18. package/esm/cssVars/localStorageManager.js +51 -0
  19. package/esm/cssVars/useCurrentColorScheme.d.ts +2 -0
  20. package/esm/cssVars/useCurrentColorScheme.js +49 -69
  21. package/esm/display/display.d.ts +2 -1
  22. package/esm/flexbox/flexbox.d.ts +2 -1
  23. package/esm/index.d.ts +1 -0
  24. package/esm/index.js +1 -1
  25. package/esm/palette/palette.d.ts +2 -1
  26. package/esm/positions/positions.d.ts +2 -1
  27. package/esm/shadows/shadows.d.ts +2 -1
  28. package/esm/sizing/sizing.d.ts +2 -1
  29. package/esm/spacing/spacing.d.ts +2 -1
  30. package/esm/spacing/spacing.js +9 -0
  31. package/esm/style/style.d.ts +4 -4
  32. package/esm/typography/typography.d.ts +2 -1
  33. package/esm/version/index.js +2 -2
  34. package/flexbox/flexbox.d.ts +2 -1
  35. package/index.d.ts +1 -0
  36. package/index.js +1 -1
  37. package/modern/borders/borders.d.ts +3 -2
  38. package/modern/cssGrid/cssGrid.d.ts +15 -2
  39. package/modern/cssVars/createCssVarsProvider.d.ts +12 -0
  40. package/modern/cssVars/createCssVarsProvider.js +21 -4
  41. package/modern/cssVars/index.d.ts +2 -1
  42. package/modern/cssVars/localStorageManager.d.ts +34 -0
  43. package/modern/cssVars/localStorageManager.js +51 -0
  44. package/modern/cssVars/useCurrentColorScheme.d.ts +2 -0
  45. package/modern/cssVars/useCurrentColorScheme.js +49 -69
  46. package/modern/display/display.d.ts +2 -1
  47. package/modern/flexbox/flexbox.d.ts +2 -1
  48. package/modern/index.d.ts +1 -0
  49. package/modern/index.js +1 -1
  50. package/modern/palette/palette.d.ts +2 -1
  51. package/modern/positions/positions.d.ts +2 -1
  52. package/modern/shadows/shadows.d.ts +2 -1
  53. package/modern/sizing/sizing.d.ts +2 -1
  54. package/modern/spacing/spacing.d.ts +2 -1
  55. package/modern/spacing/spacing.js +9 -0
  56. package/modern/style/style.d.ts +4 -4
  57. package/modern/typography/typography.d.ts +2 -1
  58. package/modern/version/index.js +2 -2
  59. package/package.json +5 -5
  60. package/palette/palette.d.ts +2 -1
  61. package/positions/positions.d.ts +2 -1
  62. package/shadows/shadows.d.ts +2 -1
  63. package/sizing/sizing.d.ts +2 -1
  64. package/spacing/spacing.d.ts +2 -1
  65. package/spacing/spacing.js +9 -0
  66. package/style/style.d.ts +4 -4
  67. package/tsconfig.build.tsbuildinfo +1 -1
  68. package/typography/typography.d.ts +2 -1
  69. package/version/index.js +2 -2
@@ -50,12 +50,14 @@ export default function createCssVarsProvider(options) {
50
50
  modeStorageKey = defaultModeStorageKey,
51
51
  colorSchemeStorageKey = defaultColorSchemeStorageKey,
52
52
  disableTransitionOnChange = designSystemTransitionOnChange,
53
+ storageManager,
53
54
  storageWindow = typeof window === 'undefined' ? undefined : window,
54
55
  documentNode = typeof document === 'undefined' ? undefined : document,
55
56
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
56
57
  disableNestedContext = false,
57
58
  disableStyleSheetGeneration = false,
58
59
  defaultMode: initialMode = 'system',
60
+ forceThemeRerender = false,
59
61
  noSsr
60
62
  } = props;
61
63
  const hasMounted = React.useRef(false);
@@ -97,6 +99,7 @@ export default function createCssVarsProvider(options) {
97
99
  modeStorageKey,
98
100
  colorSchemeStorageKey,
99
101
  defaultMode,
102
+ storageManager,
100
103
  storageWindow,
101
104
  noSsr
102
105
  });
@@ -106,10 +109,15 @@ export default function createCssVarsProvider(options) {
106
109
  mode = ctx.mode;
107
110
  colorScheme = ctx.colorScheme;
108
111
  }
112
+ if (process.env.NODE_ENV !== 'production') {
113
+ if (forceThemeRerender && !restThemeProp.vars) {
114
+ console.warn(['MUI: The `forceThemeRerender` prop should only be used with CSS theme variables.', 'Note that it will slow down the app when changing between modes, so only do this when you cannot find a better solution.'].join('\n'));
115
+ }
116
+ }
117
+ const calculatedColorScheme = forceThemeRerender && restThemeProp.vars ?
118
+ // `colorScheme` is undefined on the server and hydration phase
119
+ colorScheme || restThemeProp.defaultColorScheme : restThemeProp.defaultColorScheme;
109
120
  const memoTheme = React.useMemo(() => {
110
- // `colorScheme` is undefined on the server and hydration phase
111
- const calculatedColorScheme = colorScheme || restThemeProp.defaultColorScheme;
112
-
113
121
  // 2. get the `vars` object that refers to the CSS custom properties
114
122
  const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
115
123
 
@@ -144,7 +152,7 @@ export default function createCssVarsProvider(options) {
144
152
  }
145
153
  }
146
154
  return resolveTheme ? resolveTheme(theme) : theme;
147
- }, [restThemeProp, colorScheme, components, colorSchemes, cssVarPrefix]);
155
+ }, [restThemeProp, calculatedColorScheme, components, colorSchemes, cssVarPrefix]);
148
156
 
149
157
  // 5. Declaring effects
150
158
  // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
@@ -282,6 +290,10 @@ export default function createCssVarsProvider(options) {
282
290
  * The document to attach the attribute to.
283
291
  */
284
292
  documentNode: PropTypes.any,
293
+ /**
294
+ * If `true`, theme values are recalculated when the mode changes.
295
+ */
296
+ forceThemeRerender: PropTypes.bool,
285
297
  /**
286
298
  * The key in the local storage used to store current color scheme.
287
299
  */
@@ -291,6 +303,11 @@ export default function createCssVarsProvider(options) {
291
303
  * You should use this option in conjuction with `InitColorSchemeScript` component.
292
304
  */
293
305
  noSsr: PropTypes.bool,
306
+ /**
307
+ * The storage manager to be used for storing the mode and color scheme
308
+ * @default using `window.localStorage`
309
+ */
310
+ storageManager: PropTypes.func,
294
311
  /**
295
312
  * The window that attaches the 'storage' event listener.
296
313
  * @default window
@@ -4,4 +4,5 @@ export { default as prepareCssVars } from "./prepareCssVars.js";
4
4
  export { default as prepareTypographyVars } from "./prepareTypographyVars.js";
5
5
  export type { ExtractTypographyTokens } from "./prepareTypographyVars.js";
6
6
  export { default as createCssVarsTheme } from "./createCssVarsTheme.js";
7
- export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
7
+ export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
8
+ export type { StorageManager } from "./localStorageManager.js";
@@ -0,0 +1,34 @@
1
+ export interface StorageManager {
2
+ (options: {
3
+ key: string;
4
+ storageWindow?: Window | null;
5
+ }): {
6
+ /**
7
+ * Function to get the value from the storage
8
+ * @param defaultValue The default value to be returned if the key is not found
9
+ * @returns The value from the storage or the default value
10
+ */
11
+ get(defaultValue: any): any;
12
+ /**
13
+ * Function to set the value in the storage
14
+ * @param value The value to be set
15
+ * @returns void
16
+ */
17
+ set(value: any): void;
18
+ /**
19
+ * Function to subscribe to the value of the specified key triggered by external events
20
+ * @param handler The function to be called when the value changes
21
+ * @returns A function to unsubscribe the handler
22
+ * @example
23
+ * React.useEffect(() => {
24
+ * const unsubscribe = storageManager.subscribe((value) => {
25
+ * console.log(value);
26
+ * });
27
+ * return unsubscribe;
28
+ * }, []);
29
+ */
30
+ subscribe(handler: (value: any) => void): () => void;
31
+ };
32
+ }
33
+ declare const localStorageManager: StorageManager;
34
+ export default localStorageManager;
@@ -0,0 +1,51 @@
1
+ function noop() {}
2
+ const localStorageManager = ({
3
+ key,
4
+ storageWindow
5
+ }) => {
6
+ if (!storageWindow && typeof window !== 'undefined') {
7
+ storageWindow = window;
8
+ }
9
+ return {
10
+ get(defaultValue) {
11
+ if (typeof window === 'undefined') {
12
+ return undefined;
13
+ }
14
+ if (!storageWindow) {
15
+ return defaultValue;
16
+ }
17
+ let value;
18
+ try {
19
+ value = storageWindow.localStorage.getItem(key);
20
+ } catch {
21
+ // Unsupported
22
+ }
23
+ return value || defaultValue;
24
+ },
25
+ set: value => {
26
+ if (storageWindow) {
27
+ try {
28
+ storageWindow.localStorage.setItem(key, value);
29
+ } catch {
30
+ // Unsupported
31
+ }
32
+ }
33
+ },
34
+ subscribe: handler => {
35
+ if (!storageWindow) {
36
+ return noop;
37
+ }
38
+ const listener = event => {
39
+ const value = event.newValue;
40
+ if (event.key === key) {
41
+ handler(value);
42
+ }
43
+ };
44
+ storageWindow.addEventListener('storage', listener);
45
+ return () => {
46
+ storageWindow.removeEventListener('storage', listener);
47
+ };
48
+ }
49
+ };
50
+ };
51
+ export default localStorageManager;
@@ -1,3 +1,4 @@
1
+ import type { StorageManager } from "./localStorageManager.js";
1
2
  export type Mode = 'light' | 'dark' | 'system';
2
3
  export type SystemMode = Exclude<Mode, 'system'>;
3
4
  export interface State<SupportedColorScheme extends string> {
@@ -48,6 +49,7 @@ interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
48
49
  modeStorageKey?: string;
49
50
  colorSchemeStorageKey?: string;
50
51
  storageWindow?: Window | null;
52
+ storageManager?: StorageManager | null;
51
53
  noSsr?: boolean;
52
54
  }
53
55
  export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
@@ -2,6 +2,8 @@
2
2
 
3
3
  import * as React from 'react';
4
4
  import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from "../InitColorSchemeScript/InitColorSchemeScript.js";
5
+ import localStorageManager from "./localStorageManager.js";
6
+ function noop() {}
5
7
  export function getSystemMode(mode) {
6
8
  if (typeof window !== 'undefined' && typeof window.matchMedia === 'function' && mode === 'system') {
7
9
  const mql = window.matchMedia('(prefers-color-scheme: dark)');
@@ -32,22 +34,6 @@ export function getColorScheme(state) {
32
34
  return undefined;
33
35
  });
34
36
  }
35
- function initializeValue(key, defaultValue) {
36
- if (typeof window === 'undefined') {
37
- return undefined;
38
- }
39
- let value;
40
- try {
41
- value = localStorage.getItem(key) || undefined;
42
- if (!value) {
43
- // the first time that user enters the site.
44
- localStorage.setItem(key, defaultValue);
45
- }
46
- } catch {
47
- // Unsupported
48
- }
49
- return value || defaultValue;
50
- }
51
37
  export default function useCurrentColorScheme(options) {
52
38
  const {
53
39
  defaultMode = 'light',
@@ -57,14 +43,27 @@ export default function useCurrentColorScheme(options) {
57
43
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
58
44
  colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
59
45
  storageWindow = typeof window === 'undefined' ? undefined : window,
46
+ storageManager = localStorageManager,
60
47
  noSsr = false
61
48
  } = options;
62
49
  const joinedColorSchemes = supportedColorSchemes.join(',');
63
50
  const isMultiSchemes = supportedColorSchemes.length > 1;
51
+ const modeStorage = React.useMemo(() => storageManager?.({
52
+ key: modeStorageKey,
53
+ storageWindow
54
+ }), [storageManager, modeStorageKey, storageWindow]);
55
+ const lightStorage = React.useMemo(() => storageManager?.({
56
+ key: `${colorSchemeStorageKey}-light`,
57
+ storageWindow
58
+ }), [storageManager, colorSchemeStorageKey, storageWindow]);
59
+ const darkStorage = React.useMemo(() => storageManager?.({
60
+ key: `${colorSchemeStorageKey}-dark`,
61
+ storageWindow
62
+ }), [storageManager, colorSchemeStorageKey, storageWindow]);
64
63
  const [state, setState] = React.useState(() => {
65
- const initialMode = initializeValue(modeStorageKey, defaultMode);
66
- const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
67
- const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
64
+ const initialMode = modeStorage?.get(defaultMode) || defaultMode;
65
+ const lightColorScheme = lightStorage?.get(defaultLightColorScheme) || defaultLightColorScheme;
66
+ const darkColorScheme = darkStorage?.get(defaultDarkColorScheme) || defaultDarkColorScheme;
68
67
  return {
69
68
  mode: initialMode,
70
69
  systemMode: getSystemMode(initialMode),
@@ -84,27 +83,19 @@ export default function useCurrentColorScheme(options) {
84
83
  return currentState;
85
84
  }
86
85
  const newMode = mode ?? defaultMode;
87
- try {
88
- localStorage.setItem(modeStorageKey, newMode);
89
- } catch {
90
- // Unsupported
91
- }
86
+ modeStorage?.set(newMode);
92
87
  return {
93
88
  ...currentState,
94
89
  mode: newMode,
95
90
  systemMode: getSystemMode(newMode)
96
91
  };
97
92
  });
98
- }, [modeStorageKey, defaultMode]);
93
+ }, [modeStorage, defaultMode]);
99
94
  const setColorScheme = React.useCallback(value => {
100
95
  if (!value) {
101
96
  setState(currentState => {
102
- try {
103
- localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
104
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
105
- } catch {
106
- // Unsupported
107
- }
97
+ lightStorage?.set(defaultLightColorScheme);
98
+ darkStorage?.set(defaultDarkColorScheme);
108
99
  return {
109
100
  ...currentState,
110
101
  lightColorScheme: defaultLightColorScheme,
@@ -120,15 +111,12 @@ export default function useCurrentColorScheme(options) {
120
111
  ...currentState
121
112
  };
122
113
  processState(currentState, mode => {
123
- try {
124
- localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
125
- } catch {
126
- // Unsupported
127
- }
128
114
  if (mode === 'light') {
115
+ lightStorage?.set(value);
129
116
  newState.lightColorScheme = value;
130
117
  }
131
118
  if (mode === 'dark') {
119
+ darkStorage?.set(value);
132
120
  newState.darkColorScheme = value;
133
121
  }
134
122
  });
@@ -147,11 +135,7 @@ export default function useCurrentColorScheme(options) {
147
135
  console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
148
136
  } else {
149
137
  newState.lightColorScheme = newLightColorScheme;
150
- try {
151
- localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
152
- } catch (error) {
153
- // Unsupported
154
- }
138
+ lightStorage?.set(newLightColorScheme);
155
139
  }
156
140
  }
157
141
  if (newDarkColorScheme) {
@@ -159,17 +143,13 @@ export default function useCurrentColorScheme(options) {
159
143
  console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
160
144
  } else {
161
145
  newState.darkColorScheme = newDarkColorScheme;
162
- try {
163
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
164
- } catch (error) {
165
- // Unsupported
166
- }
146
+ darkStorage?.set(newDarkColorScheme);
167
147
  }
168
148
  }
169
149
  return newState;
170
150
  });
171
151
  }
172
- }, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
152
+ }, [joinedColorSchemes, lightStorage, darkStorage, defaultLightColorScheme, defaultDarkColorScheme]);
173
153
  const handleMediaQuery = React.useCallback(event => {
174
154
  if (state.mode === 'system') {
175
155
  setState(currentState => {
@@ -209,34 +189,34 @@ export default function useCurrentColorScheme(options) {
209
189
 
210
190
  // Handle when localStorage has changed
211
191
  React.useEffect(() => {
212
- if (storageWindow && isMultiSchemes) {
213
- const handleStorage = event => {
214
- const value = event.newValue;
215
- if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
216
- // If the key is deleted, value will be null then reset color scheme to the default one.
217
- if (event.key.endsWith('light')) {
218
- setColorScheme({
219
- light: value
220
- });
221
- }
222
- if (event.key.endsWith('dark')) {
223
- setColorScheme({
224
- dark: value
225
- });
226
- }
227
- }
228
- if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
192
+ if (isMultiSchemes) {
193
+ const unsubscribeMode = modeStorage?.subscribe(value => {
194
+ if (!value || ['light', 'dark', 'system'].includes(value)) {
229
195
  setMode(value || defaultMode);
230
196
  }
231
- };
232
- // For syncing color-scheme changes between iframes
233
- storageWindow.addEventListener('storage', handleStorage);
197
+ }) || noop;
198
+ const unsubscribeLight = lightStorage?.subscribe(value => {
199
+ if (!value || joinedColorSchemes.match(value)) {
200
+ setColorScheme({
201
+ light: value
202
+ });
203
+ }
204
+ }) || noop;
205
+ const unsubscribeDark = darkStorage?.subscribe(value => {
206
+ if (!value || joinedColorSchemes.match(value)) {
207
+ setColorScheme({
208
+ dark: value
209
+ });
210
+ }
211
+ }) || noop;
234
212
  return () => {
235
- storageWindow.removeEventListener('storage', handleStorage);
213
+ unsubscribeMode();
214
+ unsubscribeLight();
215
+ unsubscribeDark();
236
216
  };
237
217
  }
238
218
  return undefined;
239
- }, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes]);
219
+ }, [setColorScheme, setMode, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes, modeStorage, lightStorage, darkStorage]);
240
220
  return {
241
221
  ...state,
242
222
  mode: isClient ? state.mode : undefined,
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, display } from "../Box/index.js";
2
- export type DisplayProps = PropsFor<typeof display>;
2
+ export type DisplayProps = PropsFor<typeof display>;
3
+ export default display;
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, flexbox } from "../Box/index.js";
2
- export type FlexboxProps = PropsFor<typeof flexbox>;
2
+ export type FlexboxProps = PropsFor<typeof flexbox>;
3
+ export default flexbox;
package/modern/index.d.ts CHANGED
@@ -27,6 +27,7 @@ export { css, keyframes, StyledEngineProvider, Interpolation, CSSInterpolation,
27
27
  export { default as GlobalStyles } from "./GlobalStyles/index.js";
28
28
  export type { GlobalStylesProps } from "./GlobalStyles/index.js";
29
29
  export * from "./style/index.js";
30
+ export { default as style } from "./style/index.js";
30
31
  export * from "./spacing/index.js";
31
32
  export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp, unstable_defaultSxConfig } from "./styleFunctionSx/index.js";
32
33
  export * from "./styleFunctionSx/index.js";
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/system v7.0.0-beta.2
2
+ * @mui/system v7.0.0-beta.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,4 +1,5 @@
1
1
  import { PropsFor, SimpleStyleFunction, palette } from "../Box/index.js";
2
2
  export const color: SimpleStyleFunction<'color'>;
3
3
  export const bgcolor: SimpleStyleFunction<'bgcolor'>;
4
- export type PaletteProps = PropsFor<typeof palette>;
4
+ export type PaletteProps = PropsFor<typeof palette>;
5
+ export default palette;
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, positions } from "../Box/index.js";
2
- export type PositionsProps = PropsFor<typeof positions>;
2
+ export type PositionsProps = PropsFor<typeof positions>;
3
+ export default positions;
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, shadows } from "../Box/index.js";
2
- export type ShadowsProps = PropsFor<typeof shadows>;
2
+ export type ShadowsProps = PropsFor<typeof shadows>;
3
+ export default shadows;
@@ -8,4 +8,5 @@ export const minHeight: SimpleStyleFunction<'minHeight'>;
8
8
  export const sizeWidth: SimpleStyleFunction<'sizeWidth'>;
9
9
  export const sizeHeight: SimpleStyleFunction<'sizeHeight'>;
10
10
  export const boxSizing: SimpleStyleFunction<'boxSizing'>;
11
- export type SizingProps = PropsFor<typeof sizing>;
11
+ export type SizingProps = PropsFor<typeof sizing>;
12
+ export default sizing;
@@ -15,4 +15,5 @@ export const margin: SimpleStyleFunction<'m' | 'mt' | 'mr' | 'mb' | 'ml' | 'mx'
15
15
  export type MarginProps = PropsFor<typeof margin>;
16
16
  export const padding: SimpleStyleFunction<'p' | 'pt' | 'pr' | 'pb' | 'pl' | 'px' | 'py' | 'padding' | 'paddingTop' | 'paddingRight' | 'paddingBottom' | 'paddingLeft' | 'paddingX' | 'paddingY' | 'paddingInline' | 'paddingInlineStart' | 'paddingInlineEnd' | 'paddingBlock' | 'paddingBlockStart' | 'paddingBlockEnd'>;
17
17
  export function getValue(transformer: (prop: SpacingValueType) => SpacingValueType, propValue: SpacingValueType): SpacingValueType;
18
- export type PaddingProps = PropsFor<typeof padding>;
18
+ export type PaddingProps = PropsFor<typeof padding>;
19
+ export default spacing;
@@ -55,6 +55,12 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
55
55
  }
56
56
  }
57
57
  if (typeof themeSpacing === 'string') {
58
+ if (themeSpacing.startsWith('var(') && val === 0) {
59
+ return 0;
60
+ }
61
+ if (themeSpacing.startsWith('var(') && val === 1) {
62
+ return themeSpacing;
63
+ }
58
64
  return `calc(${val} * ${themeSpacing})`;
59
65
  }
60
66
  return themeSpacing * val;
@@ -80,6 +86,9 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
80
86
  if (typeof transformed === 'number') {
81
87
  return -transformed;
82
88
  }
89
+ if (typeof transformed === 'string' && transformed.startsWith('var(')) {
90
+ return `calc(-1 * ${transformed})`;
91
+ }
83
92
  return `-${transformed}`;
84
93
  };
85
94
  }
@@ -10,10 +10,10 @@ export interface StyleOptions<PropKey> {
10
10
  themeKey?: string;
11
11
  transform?: TransformFunction;
12
12
  }
13
- export function style<PropKey extends string, Theme extends object>(options: StyleOptions<PropKey>): StyleFunction<{ [K in PropKey]?: unknown } & {
13
+ export function getPath<T>(obj: T, path: string | undefined, checkVars?: boolean): null | unknown;
14
+ export function getStyleValue(themeMapping: object | ((arg: any) => any), transform: TransformFunction | null, propValueFinal: unknown, userValue?: unknown): any;
15
+ export default function style<PropKey extends string, Theme extends object>(options: StyleOptions<PropKey>): StyleFunction<{ [K in PropKey]?: unknown } & {
14
16
  theme?: Theme;
15
17
  }> & {
16
18
  filterProps: string[];
17
- };
18
- export function getPath<T>(obj: T, path: string | undefined, checkVars?: boolean): null | unknown;
19
- export function getStyleValue(themeMapping: object | ((arg: any) => any), transform: TransformFunction | null, propValueFinal: unknown, userValue?: unknown): any;
19
+ };
@@ -8,4 +8,5 @@ export const letterSpacing: SimpleStyleFunction<'letterSpacing'>;
8
8
  export const lineHeight: SimpleStyleFunction<'lineHeight'>;
9
9
  export const textAlign: SimpleStyleFunction<'textAlign'>;
10
10
  export const textTransform: SimpleStyleFunction<'textTransform'>;
11
- export type TypographyProps = PropsFor<typeof typography>;
11
+ export type TypographyProps = PropsFor<typeof typography>;
12
+ export default typography;
@@ -1,6 +1,6 @@
1
- export const version = "7.0.0-beta.2";
1
+ export const version = "7.0.0-beta.4";
2
2
  export const major = Number("7");
3
3
  export const minor = Number("0");
4
4
  export const patch = Number("0");
5
- export const prerelease = "beta.2";
5
+ export const prerelease = "beta.4";
6
6
  export default version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "7.0.0-beta.2",
3
+ "version": "7.0.0-beta.4",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "MUI System is a set of CSS utilities to help you build custom designs more efficiently. It makes it possible to rapidly lay out custom designs.",
@@ -30,10 +30,10 @@
30
30
  "clsx": "^2.1.1",
31
31
  "csstype": "^3.1.3",
32
32
  "prop-types": "^15.8.1",
33
- "@mui/types": "^7.2.22",
34
- "@mui/styled-engine": "7.0.0-beta.1",
35
- "@mui/private-theming": "7.0.0-beta.2",
36
- "@mui/utils": "7.0.0-beta.2"
33
+ "@mui/private-theming": "7.0.0-beta.4",
34
+ "@mui/types": "^7.3.0",
35
+ "@mui/styled-engine": "7.0.0-beta.4",
36
+ "@mui/utils": "7.0.0-beta.4"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@emotion/react": "^11.5.0",
@@ -1,4 +1,5 @@
1
1
  import { PropsFor, SimpleStyleFunction, palette } from "../Box/index.js";
2
2
  export const color: SimpleStyleFunction<'color'>;
3
3
  export const bgcolor: SimpleStyleFunction<'bgcolor'>;
4
- export type PaletteProps = PropsFor<typeof palette>;
4
+ export type PaletteProps = PropsFor<typeof palette>;
5
+ export default palette;
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, positions } from "../Box/index.js";
2
- export type PositionsProps = PropsFor<typeof positions>;
2
+ export type PositionsProps = PropsFor<typeof positions>;
3
+ export default positions;
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, shadows } from "../Box/index.js";
2
- export type ShadowsProps = PropsFor<typeof shadows>;
2
+ export type ShadowsProps = PropsFor<typeof shadows>;
3
+ export default shadows;
@@ -8,4 +8,5 @@ export const minHeight: SimpleStyleFunction<'minHeight'>;
8
8
  export const sizeWidth: SimpleStyleFunction<'sizeWidth'>;
9
9
  export const sizeHeight: SimpleStyleFunction<'sizeHeight'>;
10
10
  export const boxSizing: SimpleStyleFunction<'boxSizing'>;
11
- export type SizingProps = PropsFor<typeof sizing>;
11
+ export type SizingProps = PropsFor<typeof sizing>;
12
+ export default sizing;
@@ -15,4 +15,5 @@ export const margin: SimpleStyleFunction<'m' | 'mt' | 'mr' | 'mb' | 'ml' | 'mx'
15
15
  export type MarginProps = PropsFor<typeof margin>;
16
16
  export const padding: SimpleStyleFunction<'p' | 'pt' | 'pr' | 'pb' | 'pl' | 'px' | 'py' | 'padding' | 'paddingTop' | 'paddingRight' | 'paddingBottom' | 'paddingLeft' | 'paddingX' | 'paddingY' | 'paddingInline' | 'paddingInlineStart' | 'paddingInlineEnd' | 'paddingBlock' | 'paddingBlockStart' | 'paddingBlockEnd'>;
17
17
  export function getValue(transformer: (prop: SpacingValueType) => SpacingValueType, propValue: SpacingValueType): SpacingValueType;
18
- export type PaddingProps = PropsFor<typeof padding>;
18
+ export type PaddingProps = PropsFor<typeof padding>;
19
+ export default spacing;
@@ -70,6 +70,12 @@ function createUnaryUnit(theme, themeKey, defaultValue, propName) {
70
70
  }
71
71
  }
72
72
  if (typeof themeSpacing === 'string') {
73
+ if (themeSpacing.startsWith('var(') && val === 0) {
74
+ return 0;
75
+ }
76
+ if (themeSpacing.startsWith('var(') && val === 1) {
77
+ return themeSpacing;
78
+ }
73
79
  return `calc(${val} * ${themeSpacing})`;
74
80
  }
75
81
  return themeSpacing * val;
@@ -95,6 +101,9 @@ function createUnaryUnit(theme, themeKey, defaultValue, propName) {
95
101
  if (typeof transformed === 'number') {
96
102
  return -transformed;
97
103
  }
104
+ if (typeof transformed === 'string' && transformed.startsWith('var(')) {
105
+ return `calc(-1 * ${transformed})`;
106
+ }
98
107
  return `-${transformed}`;
99
108
  };
100
109
  }
package/style/style.d.ts CHANGED
@@ -10,10 +10,10 @@ export interface StyleOptions<PropKey> {
10
10
  themeKey?: string;
11
11
  transform?: TransformFunction;
12
12
  }
13
- export function style<PropKey extends string, Theme extends object>(options: StyleOptions<PropKey>): StyleFunction<{ [K in PropKey]?: unknown } & {
13
+ export function getPath<T>(obj: T, path: string | undefined, checkVars?: boolean): null | unknown;
14
+ export function getStyleValue(themeMapping: object | ((arg: any) => any), transform: TransformFunction | null, propValueFinal: unknown, userValue?: unknown): any;
15
+ export default function style<PropKey extends string, Theme extends object>(options: StyleOptions<PropKey>): StyleFunction<{ [K in PropKey]?: unknown } & {
14
16
  theme?: Theme;
15
17
  }> & {
16
18
  filterProps: string[];
17
- };
18
- export function getPath<T>(obj: T, path: string | undefined, checkVars?: boolean): null | unknown;
19
- export function getStyleValue(themeMapping: object | ((arg: any) => any), transform: TransformFunction | null, propValueFinal: unknown, userValue?: unknown): any;
19
+ };