@mui/system 5.2.8 → 5.4.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 (65) hide show
  1. package/Box/Box.d.ts +2 -1
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/CHANGELOG.md +373 -28
  4. package/ThemeProvider/ThemeProvider.d.ts +1 -1
  5. package/createBox.d.ts +2 -0
  6. package/createBox.js +3 -2
  7. package/createBox.spec.d.ts +1 -1
  8. package/createStyled.d.ts +2 -1
  9. package/createStyled.js +16 -6
  10. package/createTheme/createBreakpoints.js +21 -6
  11. package/createTheme/createSpacing.d.ts +10 -10
  12. package/cssVars/createCssVarsProvider.d.ts +7 -0
  13. package/cssVars/createCssVarsProvider.js +4 -2
  14. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  15. package/cssVars/createGetCssVar.d.ts +5 -5
  16. package/cssVars/createGetCssVar.js +7 -1
  17. package/cssVars/cssVarsParser.d.ts +68 -68
  18. package/cssVars/cssVarsParser.js +4 -3
  19. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  20. package/cssVars/index.d.ts +2 -2
  21. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  22. package/esm/createBox.js +3 -2
  23. package/esm/createStyled.js +14 -4
  24. package/esm/createTheme/createBreakpoints.js +20 -4
  25. package/esm/cssVars/createCssVarsProvider.js +4 -2
  26. package/esm/cssVars/createGetCssVar.js +7 -1
  27. package/esm/cssVars/cssVarsParser.js +4 -3
  28. package/esm/getThemeValue.js +1 -1
  29. package/esm/index.js +1 -1
  30. package/esm/styleFunctionSx/index.js +1 -0
  31. package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
  32. package/esm/typography.js +4 -1
  33. package/getThemeValue.js +2 -1
  34. package/index.d.ts +2 -0
  35. package/index.js +8 -1
  36. package/index.spec.d.ts +1 -1
  37. package/legacy/createBox.js +4 -2
  38. package/legacy/createStyled.js +23 -7
  39. package/legacy/createTheme/createBreakpoints.js +23 -4
  40. package/legacy/cssVars/createCssVarsProvider.js +4 -2
  41. package/legacy/cssVars/createGetCssVar.js +7 -1
  42. package/legacy/cssVars/cssVarsParser.js +4 -3
  43. package/legacy/getThemeValue.js +1 -1
  44. package/legacy/index.js +2 -2
  45. package/legacy/styleFunctionSx/index.js +1 -0
  46. package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
  47. package/legacy/typography.js +4 -1
  48. package/modern/createBox.js +3 -2
  49. package/modern/createStyled.js +14 -4
  50. package/modern/createTheme/createBreakpoints.js +20 -4
  51. package/modern/cssVars/createCssVarsProvider.js +4 -2
  52. package/modern/cssVars/createGetCssVar.js +7 -1
  53. package/modern/cssVars/cssVarsParser.js +4 -3
  54. package/modern/getThemeValue.js +1 -1
  55. package/modern/index.js +2 -2
  56. package/modern/styleFunctionSx/index.js +1 -0
  57. package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
  58. package/modern/typography.js +4 -1
  59. package/package.json +9 -9
  60. package/style.d.ts +1 -1
  61. package/styleFunctionSx/index.js +12 -2
  62. package/styleFunctionSx/styleFunctionSx.d.ts +12 -1
  63. package/styleFunctionSx/styleFunctionSx.js +79 -54
  64. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  65. package/typography.js +6 -2
package/createStyled.d.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  CreateMUIStyled as CreateMUIStyledStyledEngine,
4
4
  CSSInterpolation,
5
5
  } from '@mui/styled-engine';
6
- import { SxProps } from './styleFunctionSx';
6
+ import styleFunctionSx, { SxProps } from './styleFunctionSx';
7
7
  import { Theme as DefaultTheme } from './createTheme';
8
8
 
9
9
  export function shouldForwardProp(propName: PropertyKey): boolean;
@@ -34,4 +34,5 @@ export default function createStyled<T extends object = DefaultTheme>(options?:
34
34
  defaultTheme?: T;
35
35
  rootShouldForwardProp?: (prop: PropertyKey) => boolean;
36
36
  slotShouldForwardProp?: (prop: PropertyKey) => boolean;
37
+ styleFunctionSx?: typeof styleFunctionSx;
37
38
  }): CreateMUIStyled<T>;
package/createStyled.js CHANGED
@@ -19,10 +19,10 @@ var _utils = require("@mui/utils");
19
19
 
20
20
  var _createTheme = _interopRequireDefault(require("./createTheme"));
21
21
 
22
- var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
23
-
24
22
  var _propsToClassKey = _interopRequireDefault(require("./propsToClassKey"));
25
23
 
24
+ var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
25
+
26
26
  const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"],
27
27
  _excluded2 = ["theme"],
28
28
  _excluded3 = ["theme"];
@@ -79,7 +79,8 @@ const variantsResolver = (props, styles, theme, name) => {
79
79
  }
80
80
 
81
81
  return variantsStyles;
82
- };
82
+ }; // Update /system/styled/#api in case if this changes
83
+
83
84
 
84
85
  function shouldForwardProp(prop) {
85
86
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
@@ -96,7 +97,8 @@ function createStyled(input = {}) {
96
97
  const {
97
98
  defaultTheme = systemDefaultTheme,
98
99
  rootShouldForwardProp = shouldForwardProp,
99
- slotShouldForwardProp = shouldForwardProp
100
+ slotShouldForwardProp = shouldForwardProp,
101
+ styleFunctionSx = _styleFunctionSx.default
100
102
  } = input;
101
103
  return (tag, inputOptions = {}) => {
102
104
  const {
@@ -156,7 +158,11 @@ function createStyled(input = {}) {
156
158
  const styleOverrides = getStyleOverrides(componentName, theme);
157
159
 
158
160
  if (styleOverrides) {
159
- return overridesResolver(props, styleOverrides);
161
+ const resolvedStyleOverrides = {};
162
+ Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
163
+ resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(props) : slotStyle;
164
+ });
165
+ return overridesResolver(props, resolvedStyleOverrides);
160
166
  }
161
167
 
162
168
  return null;
@@ -173,7 +179,7 @@ function createStyled(input = {}) {
173
179
  if (!skipSx) {
174
180
  expressionsWithDefaultTheme.push(props => {
175
181
  const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
176
- return (0, _styleFunctionSx.default)((0, _extends2.default)({}, props, {
182
+ return styleFunctionSx((0, _extends2.default)({}, props, {
177
183
  theme
178
184
  }));
179
185
  });
@@ -218,6 +224,10 @@ function createStyled(input = {}) {
218
224
  return Component;
219
225
  };
220
226
 
227
+ if (defaultStyledResolver.withConfig) {
228
+ muiStyledResolver.withConfig = defaultStyledResolver.withConfig;
229
+ }
230
+
221
231
  return muiStyledResolver;
222
232
  };
223
233
  }
@@ -8,17 +8,31 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.breakpointKeys = void 0;
9
9
  exports.default = createBreakpoints;
10
10
 
11
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
-
13
11
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
14
12
 
13
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
+
15
15
  const _excluded = ["values", "unit", "step"];
16
16
  // Sorted ASC by size. That's important.
17
17
  // It can't be configured as it's used statically for propTypes.
18
- const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
19
-
18
+ const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
20
19
  exports.breakpointKeys = breakpointKeys;
21
20
 
21
+ const sortBreakpointsValues = values => {
22
+ const breakpointsAsArray = Object.keys(values).map(key => ({
23
+ key,
24
+ val: values[key]
25
+ })) || []; // Sort in ascending order
26
+
27
+ breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
28
+ return breakpointsAsArray.reduce((acc, obj) => {
29
+ return (0, _extends2.default)({}, acc, {
30
+ [obj.key]: obj.val
31
+ });
32
+ }, {});
33
+ }; // Keep in mind that @media is inclusive by the CSS specification.
34
+
35
+
22
36
  function createBreakpoints(breakpoints) {
23
37
  const {
24
38
  // The breakpoint **start** at this value.
@@ -39,7 +53,8 @@ function createBreakpoints(breakpoints) {
39
53
  step = 5
40
54
  } = breakpoints,
41
55
  other = (0, _objectWithoutPropertiesLoose2.default)(breakpoints, _excluded);
42
- const keys = Object.keys(values);
56
+ const sortedValues = sortBreakpointsValues(values);
57
+ const keys = Object.keys(sortedValues);
43
58
 
44
59
  function up(key) {
45
60
  const value = typeof values[key] === 'number' ? values[key] : key;
@@ -81,7 +96,7 @@ function createBreakpoints(breakpoints) {
81
96
 
82
97
  return (0, _extends2.default)({
83
98
  keys,
84
- values,
99
+ values: sortedValues,
85
100
  up,
86
101
  down,
87
102
  between,
@@ -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;
@@ -97,6 +97,13 @@ export default function createCssVarsProvider<
97
97
  * value = 'var(--test)'
98
98
  */
99
99
  shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
100
+ /**
101
+ * A function to be called after the CSS variables are attached. The result of this function will be the final theme pass to ThemeProvider.
102
+ *
103
+ * The example usage is the variant generation in Joy. We need to combine the token from user-input and the default theme first, then generate
104
+ * variants from those tokens.
105
+ */
106
+ resolveTheme?: (theme: any) => any; // the type is any because it depends on the design system.
100
107
  }): {
101
108
  CssVarsProvider: (
102
109
  props: React.PropsWithChildren<
@@ -57,7 +57,8 @@ function createCssVarsProvider(options) {
57
57
  disableTransitionOnChange = false,
58
58
  enableColorScheme = 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 : {});
@@ -151,6 +152,7 @@ function createCssVarsProvider(options) {
151
152
  mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
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,
@@ -252,7 +254,7 @@ function createCssVarsProvider(options) {
252
254
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
253
255
  styles: styleSheet
254
256
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
255
- theme: mergedTheme,
257
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
256
258
  children: children
257
259
  })]
258
260
  });
@@ -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,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, 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
+ * 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 {};
@@ -127,12 +127,13 @@ function cssVarsParser(theme, options) {
127
127
  if (typeof val === 'string' || typeof val === 'number') {
128
128
  let value = val;
129
129
 
130
- if (typeof value === 'string' && value.startsWith('var')) {
130
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
131
131
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
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'), '');
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(--');
136
137
  } // scope is the deepest object in the tree, keys is the theme path keys
137
138
 
138
139
 
@@ -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,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>;
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 {
@@ -138,7 +140,11 @@ export default function createStyled(input = {}) {
138
140
  const styleOverrides = getStyleOverrides(componentName, theme);
139
141
 
140
142
  if (styleOverrides) {
141
- return overridesResolver(props, styleOverrides);
143
+ const resolvedStyleOverrides = {};
144
+ Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
145
+ resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(props) : slotStyle;
146
+ });
147
+ return overridesResolver(props, resolvedStyleOverrides);
142
148
  }
143
149
 
144
150
  return null;
@@ -201,6 +207,10 @@ export default function createStyled(input = {}) {
201
207
  return Component;
202
208
  };
203
209
 
210
+ if (defaultStyledResolver.withConfig) {
211
+ muiStyledResolver.withConfig = defaultStyledResolver.withConfig;
212
+ }
213
+
204
214
  return muiStyledResolver;
205
215
  };
206
216
  }
@@ -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,