@mui/system 5.4.1 → 5.4.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 (60) hide show
  1. package/Box/Box.d.ts +1 -1
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/CHANGELOG.md +177 -0
  4. package/createBox.d.ts +2 -0
  5. package/createBox.js +3 -2
  6. package/createBox.spec.d.ts +1 -1
  7. package/createStyled.d.ts +2 -1
  8. package/createStyled.js +12 -6
  9. package/createTheme/createBreakpoints.js +21 -6
  10. package/createTheme/createSpacing.d.ts +10 -10
  11. package/cssVars/createCssVarsProvider.d.ts +59 -95
  12. package/cssVars/createCssVarsProvider.js +32 -15
  13. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  14. package/cssVars/createGetCssVar.d.ts +5 -5
  15. package/cssVars/createGetCssVar.js +7 -1
  16. package/cssVars/cssVarsParser.d.ts +70 -68
  17. package/cssVars/cssVarsParser.js +21 -20
  18. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  19. package/cssVars/index.d.ts +1 -2
  20. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  21. package/esm/createBox.js +3 -2
  22. package/esm/createStyled.js +10 -4
  23. package/esm/createTheme/createBreakpoints.js +20 -4
  24. package/esm/cssVars/createCssVarsProvider.js +32 -16
  25. package/esm/cssVars/createGetCssVar.js +7 -1
  26. package/esm/cssVars/cssVarsParser.js +21 -20
  27. package/esm/getThemeValue.js +1 -1
  28. package/esm/index.js +1 -1
  29. package/esm/styleFunctionSx/index.js +1 -0
  30. package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
  31. package/getThemeValue.js +2 -1
  32. package/index.d.ts +1 -0
  33. package/index.js +8 -1
  34. package/index.spec.d.ts +1 -1
  35. package/legacy/createBox.js +4 -2
  36. package/legacy/createStyled.js +11 -4
  37. package/legacy/createTheme/createBreakpoints.js +23 -4
  38. package/legacy/cssVars/createCssVarsProvider.js +35 -18
  39. package/legacy/cssVars/createGetCssVar.js +7 -1
  40. package/legacy/cssVars/cssVarsParser.js +23 -22
  41. package/legacy/getThemeValue.js +1 -1
  42. package/legacy/index.js +2 -2
  43. package/legacy/styleFunctionSx/index.js +1 -0
  44. package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
  45. package/modern/createBox.js +3 -2
  46. package/modern/createStyled.js +10 -4
  47. package/modern/createTheme/createBreakpoints.js +20 -4
  48. package/modern/cssVars/createCssVarsProvider.js +32 -16
  49. package/modern/cssVars/createGetCssVar.js +7 -1
  50. package/modern/cssVars/cssVarsParser.js +21 -20
  51. package/modern/getThemeValue.js +1 -1
  52. package/modern/index.js +2 -2
  53. package/modern/styleFunctionSx/index.js +1 -0
  54. package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
  55. package/package.json +6 -6
  56. package/style.d.ts +1 -1
  57. package/styleFunctionSx/index.js +12 -2
  58. package/styleFunctionSx/styleFunctionSx.d.ts +25 -3
  59. package/styleFunctionSx/styleFunctionSx.js +79 -54
  60. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -54,10 +54,11 @@ function createCssVarsProvider(options) {
54
54
  theme: baseTheme = {},
55
55
  defaultMode: desisgnSystemMode = 'light',
56
56
  defaultColorScheme: designSystemColorScheme,
57
- disableTransitionOnChange = false,
58
- enableColorScheme = true,
57
+ disableTransitionOnChange: designSystemTransitionOnChange = false,
58
+ enableColorScheme: designSystemEnableColorScheme = true,
59
59
  prefix: designSystemPrefix = '',
60
- shouldSkipGeneratingVar
60
+ shouldSkipGeneratingVar,
61
+ resolveTheme
61
62
  } = options;
62
63
  const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
63
64
  const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
@@ -85,15 +86,14 @@ function createCssVarsProvider(options) {
85
86
  modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
86
87
  attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
87
88
  defaultMode = desisgnSystemMode,
88
- defaultColorScheme = designSystemColorScheme
89
+ defaultColorScheme = designSystemColorScheme,
90
+ disableTransitionOnChange = designSystemTransitionOnChange,
91
+ enableColorScheme = designSystemEnableColorScheme
89
92
  }) {
90
- // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
91
- // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
92
- const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
93
93
  const {
94
94
  colorSchemes: baseColorSchemes = {}
95
- } = clonedBaseTheme,
96
- restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(clonedBaseTheme, _excluded);
95
+ } = baseTheme,
96
+ restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
97
97
  const {
98
98
  colorSchemes: colorSchemesProp = {}
99
99
  } = themeProp,
@@ -142,15 +142,17 @@ function createCssVarsProvider(options) {
142
142
 
143
143
  const {
144
144
  css: rootCss,
145
- vars: rootVars
145
+ vars: rootVars,
146
+ parsedTheme
146
147
  } = (0, _cssVarsParser.default)(mergedTheme, {
147
148
  prefix,
148
149
  basePrefix: designSystemPrefix,
149
150
  shouldSkipGeneratingVar
150
151
  });
151
- mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
152
+ mergedTheme = (0, _extends2.default)({}, parsedTheme, {
152
153
  components,
153
154
  colorSchemes,
155
+ prefix,
154
156
  vars: rootVars,
155
157
  spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
156
158
  breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints,
@@ -160,7 +162,8 @@ function createCssVarsProvider(options) {
160
162
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
161
163
  const {
162
164
  css,
163
- vars
165
+ vars,
166
+ parsedTheme: parsedScheme
164
167
  } = (0, _cssVarsParser.default)(scheme, {
165
168
  prefix,
166
169
  basePrefix: designSystemPrefix,
@@ -168,6 +171,10 @@ function createCssVarsProvider(options) {
168
171
  });
169
172
  mergedTheme.vars = (0, _utils.deepmerge)(mergedTheme.vars, vars);
170
173
 
174
+ if (key === resolvedColorScheme) {
175
+ mergedTheme = (0, _extends2.default)({}, mergedTheme, parsedScheme);
176
+ }
177
+
171
178
  const resolvedDefaultColorScheme = (() => {
172
179
  if (typeof defaultColorScheme === 'string') {
173
180
  return defaultColorScheme;
@@ -208,7 +215,7 @@ function createCssVarsProvider(options) {
208
215
  return () => {
209
216
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
210
217
  };
211
- }, [mode, systemMode]);
218
+ }, [mode, systemMode, enableColorScheme]);
212
219
  React.useEffect(() => {
213
220
  let timer;
214
221
 
@@ -228,7 +235,7 @@ function createCssVarsProvider(options) {
228
235
  return () => {
229
236
  clearTimeout(timer);
230
237
  };
231
- }, [colorScheme]);
238
+ }, [colorScheme, disableTransitionOnChange]);
232
239
  React.useEffect(() => {
233
240
  hasMounted.current = true;
234
241
  return () => {
@@ -252,7 +259,7 @@ function createCssVarsProvider(options) {
252
259
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
253
260
  styles: styleSheet
254
261
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
255
- theme: mergedTheme,
262
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
256
263
  children: children
257
264
  })]
258
265
  });
@@ -279,6 +286,16 @@ function createCssVarsProvider(options) {
279
286
  */
280
287
  defaultMode: _propTypes.default.string,
281
288
 
289
+ /**
290
+ * Disable CSS transitions when switching between modes or color schemes
291
+ */
292
+ disableTransitionOnChange: _propTypes.default.bool,
293
+
294
+ /**
295
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
296
+ */
297
+ enableColorScheme: _propTypes.default.bool,
298
+
282
299
  /**
283
300
  * The key in the local storage used to store current color scheme.
284
301
  */
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,5 +1,5 @@
1
- /**
2
- * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
- * and they does not need to remember the prefix (defined once).
4
- */
5
- export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
1
+ /**
2
+ * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
+ * and they does not need to remember the prefix (defined once).
4
+ */
5
+ export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
@@ -15,7 +15,13 @@ function createGetCssVar(prefix = '') {
15
15
  return '';
16
16
  }
17
17
 
18
- return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
18
+ const value = vars[0];
19
+
20
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
21
+ return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
22
+ }
23
+
24
+ return `, ${value}`;
19
25
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
20
26
 
21
27
 
@@ -1,68 +1,70 @@
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
+ 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
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
47
+ *
48
+ * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
49
+ *
50
+ * @example
51
+ * const { css, vars, parsedTheme } = parser({
52
+ * fontSize: 12,
53
+ * lineHeight: 1.2,
54
+ * palette: { primary: { 500: 'var(--color)' } }
55
+ * }, { prefix: 'foo' })
56
+ *
57
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
58
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
59
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
60
+ */
61
+ export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
62
+ prefix?: string;
63
+ basePrefix?: string;
64
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
65
+ }): {
66
+ css: NestedRecord<string>;
67
+ vars: NestedRecord<string>;
68
+ parsedTheme: T;
69
+ };
70
+ export {};
@@ -99,19 +99,20 @@ const getCssValue = (keys, value) => {
99
99
  * `basePrefix`: defined by design system.
100
100
  * `prefix`: defined by application
101
101
  *
102
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
102
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
103
103
  *
104
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
104
+ * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
105
105
  *
106
106
  * @example
107
- * const { css, vars } = parser({
107
+ * const { css, vars, parsedTheme } = parser({
108
108
  * fontSize: 12,
109
109
  * lineHeight: 1.2,
110
- * palette: { primary: { 500: '#000000' } }
111
- * })
110
+ * palette: { primary: { 500: 'var(--color)' } }
111
+ * }, { prefix: 'foo' })
112
112
  *
113
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
114
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
113
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
114
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
115
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
115
116
  */
116
117
 
117
118
 
@@ -123,20 +124,17 @@ function cssVarsParser(theme, options) {
123
124
  } = options || {};
124
125
  const css = {};
125
126
  const vars = {};
126
- walkObjectDeep(theme, (keys, val, scope) => {
127
- if (typeof val === 'string' || typeof val === 'number') {
128
- let value = val;
129
-
130
- if (typeof value === 'string' && value.startsWith('var')) {
131
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
127
+ const parsedTheme = {};
128
+ walkObjectDeep(theme, (keys, value) => {
129
+ if (typeof value === 'string' || typeof value === 'number') {
130
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
131
+ // for CSS variable, apply prefix or remove basePrefix from the variable
132
132
  if (!basePrefix && prefix) {
133
- value = value.replace(/var\(--/g, `var(--${prefix}-`);
133
+ value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
134
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
-
139
- scope[keys.slice(-1)[0]] = value;
135
+ value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
136
+ : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
137
+ }
140
138
  }
141
139
 
142
140
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -148,10 +146,13 @@ function cssVarsParser(theme, options) {
148
146
  assignNestedKeys(vars, keys, `var(${cssVar})`);
149
147
  }
150
148
  }
149
+
150
+ assignNestedKeys(parsedTheme, keys, value);
151
151
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
152
152
  );
153
153
  return {
154
154
  css,
155
- vars
155
+ vars,
156
+ parsedTheme
156
157
  };
157
158
  }
@@ -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;
@@ -1,2 +1 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { BuildCssVarsTheme } from './createCssVarsProvider';
1
+ export { default } 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>;
package/esm/createBox.js CHANGED
@@ -5,14 +5,15 @@ import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
7
7
  import styled from '@mui/styled-engine';
8
- import styleFunctionSx, { extendSxProp } from './styleFunctionSx';
8
+ import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
9
9
  import useTheme from './useTheme';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  export default function createBox(options = {}) {
12
12
  const {
13
13
  defaultTheme,
14
14
  defaultClassName = 'MuiBox-root',
15
- generateClassName
15
+ generateClassName,
16
+ styleFunctionSx = defaultStyleFunctionSx
16
17
  } = options;
17
18
  const BoxRoot = styled('div')(styleFunctionSx);
18
19
  const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
@@ -6,8 +6,8 @@ const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesR
6
6
  import styledEngineStyled from '@mui/styled-engine';
7
7
  import { getDisplayName } from '@mui/utils';
8
8
  import createTheme from './createTheme';
9
- import styleFunctionSx from './styleFunctionSx';
10
9
  import propsToClassKey from './propsToClassKey';
10
+ import defaultStyleFunctionSx from './styleFunctionSx';
11
11
 
12
12
  function isEmpty(obj) {
13
13
  return Object.keys(obj).length === 0;
@@ -61,7 +61,8 @@ const variantsResolver = (props, styles, theme, name) => {
61
61
  }
62
62
 
63
63
  return variantsStyles;
64
- };
64
+ }; // Update /system/styled/#api in case if this changes
65
+
65
66
 
66
67
  export function shouldForwardProp(prop) {
67
68
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
@@ -76,7 +77,8 @@ export default function createStyled(input = {}) {
76
77
  const {
77
78
  defaultTheme = systemDefaultTheme,
78
79
  rootShouldForwardProp = shouldForwardProp,
79
- slotShouldForwardProp = shouldForwardProp
80
+ slotShouldForwardProp = shouldForwardProp,
81
+ styleFunctionSx = defaultStyleFunctionSx
80
82
  } = input;
81
83
  return (tag, inputOptions = {}) => {
82
84
  const {
@@ -172,7 +174,11 @@ export default function createStyled(input = {}) {
172
174
 
173
175
  transformedStyleArg = [...styleArg, ...placeholders];
174
176
  transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
175
- } else if (typeof styleArg === 'function') {
177
+ } else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
178
+ // component stays as a function. This condition makes sure that we do not interpolate functions
179
+ // which are basically components used as a selectors.
180
+ // eslint-disable-next-line no-underscore-dangle
181
+ styleArg.__emotion_real !== styleArg) {
176
182
  // If the type is function, we need to define the default theme.
177
183
  transformedStyleArg = _ref2 => {
178
184
  let {
@@ -1,9 +1,24 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["values", "unit", "step"];
4
4
  // Sorted ASC by size. That's important.
5
5
  // It can't be configured as it's used statically for propTypes.
6
- export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
6
+ export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
7
+
8
+ const sortBreakpointsValues = values => {
9
+ const breakpointsAsArray = Object.keys(values).map(key => ({
10
+ key,
11
+ val: values[key]
12
+ })) || []; // Sort in ascending order
13
+
14
+ breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
15
+ return breakpointsAsArray.reduce((acc, obj) => {
16
+ return _extends({}, acc, {
17
+ [obj.key]: obj.val
18
+ });
19
+ }, {});
20
+ }; // Keep in mind that @media is inclusive by the CSS specification.
21
+
7
22
 
8
23
  export default function createBreakpoints(breakpoints) {
9
24
  const {
@@ -26,7 +41,8 @@ export default function createBreakpoints(breakpoints) {
26
41
  } = breakpoints,
27
42
  other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
28
43
 
29
- const keys = Object.keys(values);
44
+ const sortedValues = sortBreakpointsValues(values);
45
+ const keys = Object.keys(sortedValues);
30
46
 
31
47
  function up(key) {
32
48
  const value = typeof values[key] === 'number' ? values[key] : key;
@@ -68,7 +84,7 @@ export default function createBreakpoints(breakpoints) {
68
84
 
69
85
  return _extends({
70
86
  keys,
71
- values,
87
+ values: sortedValues,
72
88
  up,
73
89
  down,
74
90
  between,