@mui/system 9.0.0-alpha.4 → 9.0.0-beta.0

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 (48) hide show
  1. package/Box/Box.d.mts +1 -1
  2. package/Box/Box.d.ts +1 -1
  3. package/CHANGELOG.md +71 -4
  4. package/Stack/StackProps.d.mts +1 -2
  5. package/Stack/StackProps.d.ts +1 -2
  6. package/Stack/createStack.js +1 -3
  7. package/Stack/createStack.mjs +1 -3
  8. package/breakpoints/breakpoints.d.mts +4 -1
  9. package/breakpoints/breakpoints.d.ts +4 -1
  10. package/breakpoints/breakpoints.js +90 -49
  11. package/breakpoints/breakpoints.mjs +86 -49
  12. package/compose/compose.js +6 -6
  13. package/compose/compose.mjs +6 -6
  14. package/createBox/createBox.js +2 -2
  15. package/createBox/createBox.mjs +2 -2
  16. package/createBreakpoints/createBreakpoints.d.mts +5 -0
  17. package/createBreakpoints/createBreakpoints.d.ts +5 -0
  18. package/createBreakpoints/createBreakpoints.js +5 -0
  19. package/createBreakpoints/createBreakpoints.mjs +5 -0
  20. package/createStyled/createStyled.js +2 -8
  21. package/createStyled/createStyled.mjs +1 -7
  22. package/createTheme/createTheme.js +1 -0
  23. package/createTheme/createTheme.mjs +1 -0
  24. package/cssContainerQueries/cssContainerQueries.d.mts +1 -0
  25. package/cssContainerQueries/cssContainerQueries.d.ts +1 -0
  26. package/cssContainerQueries/cssContainerQueries.js +27 -14
  27. package/cssContainerQueries/cssContainerQueries.mjs +27 -14
  28. package/cssVars/createCssVarsTheme.js +1 -0
  29. package/cssVars/createCssVarsTheme.mjs +1 -0
  30. package/index.js +1 -1
  31. package/index.mjs +1 -1
  32. package/merge/merge.js +4 -3
  33. package/merge/merge.mjs +4 -3
  34. package/package.json +6 -6
  35. package/spacing/spacing.js +45 -45
  36. package/spacing/spacing.mjs +47 -45
  37. package/style/index.d.mts +1 -0
  38. package/style/index.d.ts +1 -0
  39. package/style/index.js +9 -1
  40. package/style/index.mjs +1 -0
  41. package/style/style.d.mts +36 -7
  42. package/style/style.d.ts +36 -7
  43. package/style/style.js +85 -34
  44. package/style/style.mjs +84 -34
  45. package/styleFunctionSx/styleFunctionSx.js +95 -100
  46. package/styleFunctionSx/styleFunctionSx.mjs +98 -102
  47. package/version/index.js +2 -2
  48. package/version/index.mjs +2 -2
package/Box/Box.d.mts CHANGED
@@ -21,7 +21,7 @@ export type SimpleSystemKeys = keyof PropsFor<ComposedStyleFunction<[typeof bord
21
21
  // This is needed as these are used as keys inside AllSystemCSSProperties
22
22
  type StandardSystemKeys = Extract<SimpleSystemKeys, keyof AllSystemCSSProperties>;
23
23
  export type SystemProps<Theme extends object = {}> = { [K in StandardSystemKeys]?: ResponsiveStyleValue<AllSystemCSSProperties[K]> | ((theme: Theme) => ResponsiveStyleValue<AllSystemCSSProperties[K]>) };
24
- export interface BoxOwnProps<Theme extends object = SystemTheme> extends SystemProps<Theme> {
24
+ export interface BoxOwnProps<Theme extends object = SystemTheme> {
25
25
  children?: React.ReactNode;
26
26
  ref?: React.Ref<unknown> | undefined;
27
27
  /**
package/Box/Box.d.ts CHANGED
@@ -21,7 +21,7 @@ export type SimpleSystemKeys = keyof PropsFor<ComposedStyleFunction<[typeof bord
21
21
  // This is needed as these are used as keys inside AllSystemCSSProperties
22
22
  type StandardSystemKeys = Extract<SimpleSystemKeys, keyof AllSystemCSSProperties>;
23
23
  export type SystemProps<Theme extends object = {}> = { [K in StandardSystemKeys]?: ResponsiveStyleValue<AllSystemCSSProperties[K]> | ((theme: Theme) => ResponsiveStyleValue<AllSystemCSSProperties[K]>) };
24
- export interface BoxOwnProps<Theme extends object = SystemTheme> extends SystemProps<Theme> {
24
+ export interface BoxOwnProps<Theme extends object = SystemTheme> {
25
25
  children?: React.ReactNode;
26
26
  ref?: React.Ref<unknown> | undefined;
27
27
  /**
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 9.0.0-beta.0
4
+
5
+ <!-- generated comparing v9.0.0-alpha.4..master -->
6
+
7
+ _Mar 25, 2026_
8
+
9
+ A big thanks to the 8 contributors who made this release possible.
10
+
11
+ ### `@mui/material@9.0.0-beta.0`
12
+
13
+ #### Breaking Changes
14
+
15
+ - [linear-progress] Remove deprecated CSS classes (#48068) @mj12albert
16
+ - [list-item, list-item-text] Remove deprecated props (#48042) @siriwatknp
17
+ - [button-group] Remove deprecated classes (#48043) @siriwatknp
18
+ - [card] Remove deprecated CardHeader props (#47995) @silviuaavram
19
+ - [checkbox][radio][switch] Remove deprecated inputProps and inputRef (#48059) @siriwatknp
20
+ - [chip] Remove deprecated classes (#48046) @silviuaavram
21
+ - [dialog][modal][drawer][swipeabledrawer] Remove deprecated props and classes (#48039) @silviuaavram
22
+ - [divider] Remove deprecated CSS classes (#48075) @siriwatknp
23
+ - [drawer] Remove deprecated CSS classes (#48077) @siriwatknp
24
+ - [image-list-item-bar] Remove deprecated CSS classes (#48064) @siriwatknp
25
+ - [inputs] Remove deprecated props & classes (#48071) @mj12albert
26
+ - [material-ui] Remove unnecessary overridesResolvers from styled components (#48082) @ZeeshanTamboli
27
+ - [material-ui][system] Remove deprecated system props from Box, Stack, Typography (#48072) @siriwatknp
28
+ - [pagination-item] Remove deprecated CSS classes (#48076) @siriwatknp
29
+ - [pagination-item] Remove deprecated props (#48038) @siriwatknp
30
+ - [rating] Remove deprecated IconContainerComponent (#48019) @siriwatknp
31
+ - [select] Remove deprecated CSS classes (#48065) @mj12albert
32
+ - [slider] Remove deprecated CSS classes (#48074) @siriwatknp
33
+ - [step-connector][step-content][step-label] Remove deprecated props and classes (#48058) @siriwatknp
34
+ - [tabs][tab] Remove deprecated CSS classes (#48078) @siriwatknp
35
+ - [table-pagination][table-sort-label] Remove deprecated props and classes (#48060) @siriwatknp
36
+ - [toggle-button-group] Remove deprecated classes (#48061) @siriwatknp
37
+
38
+ #### Changes
39
+
40
+ - [system] Improve performance when using sx prop (#44254) @romgrk
41
+
42
+ ### `@mui/codemod@9.0.0-beta.0`
43
+
44
+ - [codemod] Add missing codemod links in upgrade guide (#48069) @silviuaavram
45
+
46
+ ### Docs
47
+
48
+ - Mention all breaking changes in changelog (#48091) @silviuaavram
49
+ - Fix link to upgrade-to-v9 docs in release CHANGELOG (#48081) @ZeeshanTamboli
50
+
51
+ ### Core
52
+
53
+ - Update browserslistrc (#48085) @silviuaavram
54
+ - [code-infra] Prevent major version updates of bundler/framework packages in bundling fixtures (#48062) @Copilot
55
+ - [code-infra][icons-material] Avoid material utils barrel in createSvgIcon (#48029) @anchmelev
56
+ - [docs-infra] Migrate more leaf components to mui-docs (#48018) @brijeshb42
57
+
58
+ All contributors of this release in alphabetical order: @anchmelev, @brijeshb42, @Copilot, @mj12albert, @romgrk, @silviuaavram, @siriwatknp, @ZeeshanTamboli
59
+
3
60
  ## 9.0.0-alpha.4
4
61
 
5
62
  <!-- generated comparing v9.0.0-alpha.3..master -->
@@ -118,7 +175,7 @@ A big thanks to the 11 contributors who made this release possible.
118
175
  - [tablepagination] Format pagination numbers according to locale (#47803) @siriwatknp
119
176
  - [textfield] Use non-native label for `<TextField select/>` (#47958) @mj12albert
120
177
 
121
- Check out the [v9 upgrade guide](https://mui.com/material-ui/migration/upgrade-to-v9/).
178
+ Check out the [v9 upgrade guide](https://next.mui.com/material-ui/migration/upgrade-to-v9/).
122
179
 
123
180
  #### Changes
124
181
 
@@ -167,11 +224,16 @@ A big thanks to the 10 contributors who made this release possible. Here are som
167
224
 
168
225
  ### `@mui/material@9.0.0-alpha.3`
169
226
 
227
+ #### Breaking Changes
228
+
229
+ - [stepper][menulist][tabs] Improve accessibility (#47687) @silviuaavram
230
+
231
+ #### Changes
232
+
170
233
  - [autocomplete] Add `root` slot (#47852) @GerardasB
171
234
  - [autocomplete] Fix popup reopening on window focus regain with openOnFocus (#47790) @aman44444
172
235
  - [autocomplete] Support full slots for clearIndicator and popupIndicator (#47891) @silviuaavram
173
236
  - [material-ui] Partially revert "[material-ui] Clean up duplicated CSS rules (#47838)" (#47927) @sai6855
174
- - [stepper][menulist][tabs] Improve accessibility (#47687) @silviuaavram
175
237
 
176
238
  ### Docs
177
239
 
@@ -229,16 +291,21 @@ A big thanks to the 13 contributors who made this release possible. Here are som
229
291
 
230
292
  ### @mui/material@9.0.0-alpha.1
231
293
 
294
+ #### Breaking Changes
295
+
232
296
  - [Autocomplete] Prevents Autocomplete menu from opening on right click (#47797) @silviuaavram
233
297
  - [Backdrop] Remove aria-hidden by default (#47798) @silviuaavram
234
298
  - [ButtonBase] Ensure that onClick propagates when non-native button is clicked (#47800) @silviuaavram
235
299
  - [Dialog][Modal] Remove `disableEscapeKeyDown` prop (#47695) @silviuaavram
236
300
  - [Grid] Remove system props support (#47846) @siriwatknp
237
- - [TableCell][theme] Apply `alpha` before color mixing to border bottom color when nativeColor + cssVariables is used (#47762) @ZeeshanTamboli
238
301
  - [theme] Remove MuiTouchRipple from theme component types (#47849) @siriwatknp
239
- - [Tooltip] Fix error is thrown when wrapping an input which is disabled while focused (#47684) @ZeeshanTamboli
240
302
  - [useAutocomplete] Improve isOptionEqualToValue value argument type (#47801) @silviuaavram
241
303
 
304
+ #### Changes
305
+
306
+ - [TableCell][theme] Apply `alpha` before color mixing to border bottom color when nativeColor + cssVariables is used (#47762) @ZeeshanTamboli
307
+ - [Tooltip] Fix error is thrown when wrapping an input which is disabled while focused (#47684) @ZeeshanTamboli
308
+
242
309
  ### Docs
243
310
 
244
311
  - [docs] Add updated community theme resource (#47847) @PeterTYLiu
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { OverrideProps } from '@mui/types';
3
3
  import { ResponsiveStyleValue, SxProps } from "../styleFunctionSx/index.mjs";
4
- import { SystemProps } from "../Box/index.mjs";
5
4
  import { Theme } from "../createTheme/index.mjs";
6
5
  export interface StackBaseProps {
7
6
  /**
@@ -40,7 +39,7 @@ export interface StackTypeMap<AdditionalProps = {}, DefaultComponent extends Rea
40
39
  * The system prop, which allows defining system overrides as well as additional CSS styles.
41
40
  */
42
41
  sx?: SxProps<Theme> | undefined;
43
- } & SystemProps<Theme>;
42
+ };
44
43
  defaultComponent: DefaultComponent;
45
44
  }
46
45
  export type StackProps<RootComponent extends React.ElementType = StackTypeMap['defaultComponent'], AdditionalProps = {
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { OverrideProps } from '@mui/types';
3
3
  import { ResponsiveStyleValue, SxProps } from "../styleFunctionSx/index.js";
4
- import { SystemProps } from "../Box/index.js";
5
4
  import { Theme } from "../createTheme/index.js";
6
5
  export interface StackBaseProps {
7
6
  /**
@@ -40,7 +39,7 @@ export interface StackTypeMap<AdditionalProps = {}, DefaultComponent extends Rea
40
39
  * The system prop, which allows defining system overrides as well as additional CSS styles.
41
40
  */
42
41
  sx?: SxProps<Theme> | undefined;
43
- } & SystemProps<Theme>;
42
+ };
44
43
  defaultComponent: DefaultComponent;
45
44
  }
46
45
  export type StackProps<RootComponent extends React.ElementType = StackTypeMap['defaultComponent'], AdditionalProps = {
@@ -16,7 +16,6 @@ var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateU
16
16
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
17
17
  var _styled = _interopRequireDefault(require("../styled"));
18
18
  var _useThemeProps = _interopRequireDefault(require("../useThemeProps"));
19
- var _styleFunctionSx = require("../styleFunctionSx");
20
19
  var _createTheme = _interopRequireDefault(require("../createTheme"));
21
20
  var _breakpoints = require("../breakpoints");
22
21
  var _spacing = require("../spacing");
@@ -144,7 +143,6 @@ function createStack(options = {}) {
144
143
  const StackRoot = createStyledComponent(style);
145
144
  const Stack = /*#__PURE__*/React.forwardRef(function Grid(inProps, ref) {
146
145
  const themeProps = useThemeProps(inProps);
147
- const props = (0, _styleFunctionSx.extendSxProp)(themeProps); // `color` type conflicts with html color attribute.
148
146
  const {
149
147
  component = 'div',
150
148
  direction = 'column',
@@ -154,7 +152,7 @@ function createStack(options = {}) {
154
152
  className,
155
153
  useFlexGap = false,
156
154
  ...other
157
- } = props;
155
+ } = themeProps;
158
156
  const ownerState = {
159
157
  direction,
160
158
  spacing,
@@ -8,7 +8,6 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
8
8
  import composeClasses from '@mui/utils/composeClasses';
9
9
  import systemStyled from "../styled/index.mjs";
10
10
  import useThemePropsSystem from "../useThemeProps/index.mjs";
11
- import { extendSxProp } from "../styleFunctionSx/index.mjs";
12
11
  import createTheme from "../createTheme/index.mjs";
13
12
  import { handleBreakpoints, mergeBreakpointsInOrder, resolveBreakpointValues } from "../breakpoints/index.mjs";
14
13
  import { createUnarySpacing, getValue } from "../spacing/index.mjs";
@@ -135,7 +134,6 @@ export default function createStack(options = {}) {
135
134
  const StackRoot = createStyledComponent(style);
136
135
  const Stack = /*#__PURE__*/React.forwardRef(function Grid(inProps, ref) {
137
136
  const themeProps = useThemeProps(inProps);
138
- const props = extendSxProp(themeProps); // `color` type conflicts with html color attribute.
139
137
  const {
140
138
  component = 'div',
141
139
  direction = 'column',
@@ -145,7 +143,7 @@ export default function createStack(options = {}) {
145
143
  className,
146
144
  useFlexGap = false,
147
145
  ...other
148
- } = props;
146
+ } = themeProps;
149
147
  const ownerState = {
150
148
  direction,
151
149
  spacing,
@@ -1,8 +1,9 @@
1
1
  import { CSSObject } from '@mui/styled-engine';
2
2
  import { Breakpoints } from "../createBreakpoints/createBreakpoints.mjs";
3
- import type { Breakpoint } from "../createTheme/index.mjs";
3
+ import type { Breakpoint, Theme } from "../createTheme/index.mjs";
4
4
  import { ResponsiveStyleValue } from "../styleFunctionSx/index.mjs";
5
5
  import { StyleFunction } from "../style/index.mjs";
6
+ export const DEFAULT_BREAKPOINTS: Breakpoints;
6
7
  export interface ResolveBreakpointValuesOptions<T> {
7
8
  values: ResponsiveStyleValue<T>;
8
9
  breakpoints?: Breakpoints['values'] | undefined;
@@ -10,7 +11,9 @@ export interface ResolveBreakpointValuesOptions<T> {
10
11
  }
11
12
  export function resolveBreakpointValues<T>(options: ResolveBreakpointValuesOptions<T>): Record<string, T>;
12
13
  export function mergeBreakpointsInOrder(breakpoints: Breakpoints, styles: CSSObject[]): CSSObject;
14
+ export function iterateBreakpoints(target: any, theme: Theme, propValue: any, callback: (mediaKey: string | undefined, value: any, initialKey?: string) => any): any;
13
15
  export function handleBreakpoints<Props>(props: Props, propValue: any, styleFromPropValue: (value: any, breakpoint?: Breakpoint) => any): any;
16
+ export function hasBreakpoint(breakpoints: Breakpoints, value: any): boolean;
14
17
  type DefaultBreakPoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
15
18
 
16
19
  /**
@@ -1,8 +1,9 @@
1
1
  import { CSSObject } from '@mui/styled-engine';
2
2
  import { Breakpoints } from "../createBreakpoints/createBreakpoints.js";
3
- import type { Breakpoint } from "../createTheme/index.js";
3
+ import type { Breakpoint, Theme } from "../createTheme/index.js";
4
4
  import { ResponsiveStyleValue } from "../styleFunctionSx/index.js";
5
5
  import { StyleFunction } from "../style/index.js";
6
+ export const DEFAULT_BREAKPOINTS: Breakpoints;
6
7
  export interface ResolveBreakpointValuesOptions<T> {
7
8
  values: ResponsiveStyleValue<T>;
8
9
  breakpoints?: Breakpoints['values'] | undefined;
@@ -10,7 +11,9 @@ export interface ResolveBreakpointValuesOptions<T> {
10
11
  }
11
12
  export function resolveBreakpointValues<T>(options: ResolveBreakpointValuesOptions<T>): Record<string, T>;
12
13
  export function mergeBreakpointsInOrder(breakpoints: Breakpoints, styles: CSSObject[]): CSSObject;
14
+ export function iterateBreakpoints(target: any, theme: Theme, propValue: any, callback: (mediaKey: string | undefined, value: any, initialKey?: string) => any): any;
13
15
  export function handleBreakpoints<Props>(props: Props, propValue: any, styleFromPropValue: (value: any, breakpoint?: Breakpoint) => any): any;
16
+ export function hasBreakpoint(breakpoints: Breakpoints, value: any): boolean;
14
17
  type DefaultBreakPoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
15
18
 
16
19
  /**
@@ -4,18 +4,26 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.DEFAULT_BREAKPOINTS = void 0;
7
8
  exports.computeBreakpointsBase = computeBreakpointsBase;
8
9
  exports.createEmptyBreakpointObject = createEmptyBreakpointObject;
9
10
  exports.default = void 0;
10
11
  exports.handleBreakpoints = handleBreakpoints;
12
+ exports.hasBreakpoint = hasBreakpoint;
13
+ exports.iterateBreakpoints = iterateBreakpoints;
11
14
  exports.mergeBreakpointsInOrder = mergeBreakpointsInOrder;
12
15
  exports.removeUnusedBreakpoints = removeUnusedBreakpoints;
13
16
  exports.resolveBreakpointValues = resolveBreakpointValues;
14
17
  exports.values = void 0;
15
18
  var _propTypes = _interopRequireDefault(require("prop-types"));
19
+ var _isObjectEmpty = _interopRequireDefault(require("@mui/utils/isObjectEmpty"));
20
+ var _fastDeepAssign = _interopRequireDefault(require("@mui/utils/fastDeepAssign"));
16
21
  var _deepmerge = _interopRequireDefault(require("@mui/utils/deepmerge"));
17
22
  var _merge = _interopRequireDefault(require("../merge"));
18
23
  var _cssContainerQueries = require("../cssContainerQueries");
24
+ var _createBreakpoints = _interopRequireDefault(require("../createBreakpoints/createBreakpoints"));
25
+ const EMPTY_THEME = {};
26
+
19
27
  // The breakpoint **start** at this value.
20
28
  // For instance with the first breakpoint xs: [xs, sm[.
21
29
  const values = exports.values = {
@@ -29,12 +37,9 @@ const values = exports.values = {
29
37
  // desktop
30
38
  xl: 1536 // large screen
31
39
  };
32
- const defaultBreakpoints = {
33
- // Sorted ASC by size. That's important.
34
- // It can't be configured as it's used statically for propTypes.
35
- keys: ['xs', 'sm', 'md', 'lg', 'xl'],
36
- up: key => `@media (min-width:${values[key]}px)`
37
- };
40
+ const DEFAULT_BREAKPOINTS = exports.DEFAULT_BREAKPOINTS = (0, _createBreakpoints.default)({
41
+ values
42
+ });
38
43
  const defaultContainerQueries = {
39
44
  containerQueries: containerName => ({
40
45
  up: key => {
@@ -47,44 +52,59 @@ const defaultContainerQueries = {
47
52
  })
48
53
  };
49
54
  function handleBreakpoints(props, propValue, styleFromPropValue) {
50
- const theme = props.theme || {};
55
+ const result = {};
56
+ return iterateBreakpoints(result, props.theme, propValue, (mediaKey, value, initialKey) => {
57
+ const finalValue = styleFromPropValue(value, initialKey);
58
+ if (mediaKey) {
59
+ result[mediaKey] = finalValue;
60
+ } else {
61
+ (0, _fastDeepAssign.default)(result, finalValue);
62
+ }
63
+ });
64
+ }
65
+ function iterateBreakpoints(target, theme, propValue, callback) {
66
+ theme ?? (theme = EMPTY_THEME);
51
67
  if (Array.isArray(propValue)) {
52
- const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
53
- return propValue.reduce((acc, item, index) => {
54
- acc[themeBreakpoints.up(themeBreakpoints.keys[index])] = styleFromPropValue(propValue[index]);
55
- return acc;
56
- }, {});
68
+ const breakpoints = theme.breakpoints ?? DEFAULT_BREAKPOINTS;
69
+ for (let i = 0; i < propValue.length; i += 1) {
70
+ buildBreakpoint(target, breakpoints.up(breakpoints.keys[i]), propValue[i], undefined, callback);
71
+ }
72
+ return target;
57
73
  }
58
74
  if (typeof propValue === 'object') {
59
- const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
60
- return Object.keys(propValue).reduce((acc, breakpoint) => {
61
- if ((0, _cssContainerQueries.isCqShorthand)(themeBreakpoints.keys, breakpoint)) {
62
- const containerKey = (0, _cssContainerQueries.getContainerQuery)(theme.containerQueries ? theme : defaultContainerQueries, breakpoint);
75
+ const breakpoints = theme.breakpoints ?? DEFAULT_BREAKPOINTS;
76
+ const breakpointValues = breakpoints.values ?? values;
77
+ for (const key in propValue) {
78
+ if ((0, _cssContainerQueries.isCqShorthand)(breakpoints.keys, key)) {
79
+ const containerKey = (0, _cssContainerQueries.getContainerQuery)(theme.containerQueries ? theme : defaultContainerQueries, key);
63
80
  if (containerKey) {
64
- acc[containerKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
81
+ buildBreakpoint(target, containerKey, propValue[key], key, callback);
65
82
  }
66
83
  }
67
- // key is breakpoint
68
- else if (Object.keys(themeBreakpoints.values || values).includes(breakpoint)) {
69
- const mediaKey = themeBreakpoints.up(breakpoint);
70
- acc[mediaKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
84
+ // key is key
85
+ else if (key in breakpointValues) {
86
+ const mediaKey = breakpoints.up(key);
87
+ buildBreakpoint(target, mediaKey, propValue[key], key, callback);
71
88
  } else {
72
- const cssKey = breakpoint;
73
- acc[cssKey] = propValue[cssKey];
89
+ const cssKey = key;
90
+ target[cssKey] = propValue[cssKey];
74
91
  }
75
- return acc;
76
- }, {});
92
+ }
93
+ return target;
77
94
  }
78
- const output = styleFromPropValue(propValue);
79
- return output;
95
+ callback(undefined, propValue);
96
+ return target;
97
+ }
98
+ function buildBreakpoint(target, mediaKey, value, initialKey, callback) {
99
+ target[mediaKey] ?? (target[mediaKey] = {});
100
+ callback(mediaKey, value, initialKey);
80
101
  }
81
- function breakpoints(styleFunction) {
82
- // false positive
102
+ function setupBreakpoints(styleFunction) {
83
103
  // eslint-disable-next-line react/function-component-definition
84
104
  const newStyleFunction = props => {
85
105
  const theme = props.theme || {};
86
106
  const base = styleFunction(props);
87
- const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
107
+ const themeBreakpoints = theme.breakpoints || DEFAULT_BREAKPOINTS;
88
108
  const extended = themeBreakpoints.keys.reduce((acc, key) => {
89
109
  if (props[key]) {
90
110
  acc = acc || {};
@@ -108,28 +128,30 @@ function breakpoints(styleFunction) {
108
128
  newStyleFunction.filterProps = ['xs', 'sm', 'md', 'lg', 'xl', ...styleFunction.filterProps];
109
129
  return newStyleFunction;
110
130
  }
111
- function createEmptyBreakpointObject(breakpointsInput = {}) {
112
- const breakpointsInOrder = breakpointsInput.keys?.reduce((acc, key) => {
113
- const breakpointStyleKey = breakpointsInput.up(key);
114
- acc[breakpointStyleKey] = {};
115
- return acc;
116
- }, {});
117
- return breakpointsInOrder || {};
131
+ function createEmptyBreakpointObject(breakpoints = DEFAULT_BREAKPOINTS) {
132
+ const {
133
+ internal_mediaKeys: mediaKeys
134
+ } = breakpoints;
135
+ const result = {};
136
+ for (let i = 0; i < mediaKeys.length; i += 1) {
137
+ result[mediaKeys[i]] = {};
138
+ }
139
+ return result;
118
140
  }
119
- function removeUnusedBreakpoints(breakpointKeys, style) {
120
- return breakpointKeys.reduce((acc, key) => {
121
- const breakpointOutput = acc[key];
122
- const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
123
- if (isBreakpointUnused) {
124
- delete acc[key];
141
+ function removeUnusedBreakpoints(breakpoints, style) {
142
+ const breakpointKeys = breakpoints.internal_mediaKeys;
143
+ for (let i = 0; i < breakpointKeys.length; i += 1) {
144
+ const key = breakpointKeys[i];
145
+ if ((0, _isObjectEmpty.default)(style[key])) {
146
+ delete style[key];
125
147
  }
126
- return acc;
127
- }, style);
148
+ }
149
+ return style;
128
150
  }
129
- function mergeBreakpointsInOrder(breakpointsInput, ...styles) {
130
- const emptyBreakpoints = createEmptyBreakpointObject(breakpointsInput);
151
+ function mergeBreakpointsInOrder(breakpoints, ...styles) {
152
+ const emptyBreakpoints = createEmptyBreakpointObject(breakpoints);
131
153
  const mergedOutput = [emptyBreakpoints, ...styles].reduce((prev, next) => (0, _deepmerge.default)(prev, next), {});
132
- return removeUnusedBreakpoints(Object.keys(emptyBreakpoints), mergedOutput);
154
+ return removeUnusedBreakpoints(breakpoints, mergedOutput);
133
155
  }
134
156
 
135
157
  // compute base for responsive values; e.g.,
@@ -181,4 +203,23 @@ function resolveBreakpointValues({
181
203
  return acc;
182
204
  }, {});
183
205
  }
184
- var _default = exports.default = breakpoints;
206
+ function hasBreakpoint(breakpoints, value) {
207
+ if (Array.isArray(value)) {
208
+ return true;
209
+ }
210
+ if (typeof value === 'object' && value !== null) {
211
+ for (let i = 0; i < breakpoints.keys.length; i += 1) {
212
+ if (breakpoints.keys[i] in value) {
213
+ return true;
214
+ }
215
+ }
216
+ const valueKeys = Object.keys(value);
217
+ for (let i = 0; i < valueKeys.length; i += 1) {
218
+ if ((0, _cssContainerQueries.isCqShorthand)(breakpoints.keys, valueKeys[i])) {
219
+ return true;
220
+ }
221
+ }
222
+ }
223
+ return false;
224
+ }
225
+ var _default = exports.default = setupBreakpoints;
@@ -1,7 +1,11 @@
1
1
  import PropTypes from 'prop-types';
2
+ import isObjectEmpty from '@mui/utils/isObjectEmpty';
3
+ import fastDeepAssign from '@mui/utils/fastDeepAssign';
2
4
  import deepmerge from '@mui/utils/deepmerge';
3
5
  import merge from "../merge/index.mjs";
4
6
  import { isCqShorthand, getContainerQuery } from "../cssContainerQueries/index.mjs";
7
+ import createBreakpoints from "../createBreakpoints/createBreakpoints.mjs";
8
+ const EMPTY_THEME = {};
5
9
 
6
10
  // The breakpoint **start** at this value.
7
11
  // For instance with the first breakpoint xs: [xs, sm[.
@@ -16,12 +20,9 @@ export const values = {
16
20
  // desktop
17
21
  xl: 1536 // large screen
18
22
  };
19
- const defaultBreakpoints = {
20
- // Sorted ASC by size. That's important.
21
- // It can't be configured as it's used statically for propTypes.
22
- keys: ['xs', 'sm', 'md', 'lg', 'xl'],
23
- up: key => `@media (min-width:${values[key]}px)`
24
- };
23
+ export const DEFAULT_BREAKPOINTS = createBreakpoints({
24
+ values
25
+ });
25
26
  const defaultContainerQueries = {
26
27
  containerQueries: containerName => ({
27
28
  up: key => {
@@ -34,44 +35,59 @@ const defaultContainerQueries = {
34
35
  })
35
36
  };
36
37
  export function handleBreakpoints(props, propValue, styleFromPropValue) {
37
- const theme = props.theme || {};
38
+ const result = {};
39
+ return iterateBreakpoints(result, props.theme, propValue, (mediaKey, value, initialKey) => {
40
+ const finalValue = styleFromPropValue(value, initialKey);
41
+ if (mediaKey) {
42
+ result[mediaKey] = finalValue;
43
+ } else {
44
+ fastDeepAssign(result, finalValue);
45
+ }
46
+ });
47
+ }
48
+ export function iterateBreakpoints(target, theme, propValue, callback) {
49
+ theme ??= EMPTY_THEME;
38
50
  if (Array.isArray(propValue)) {
39
- const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
40
- return propValue.reduce((acc, item, index) => {
41
- acc[themeBreakpoints.up(themeBreakpoints.keys[index])] = styleFromPropValue(propValue[index]);
42
- return acc;
43
- }, {});
51
+ const breakpoints = theme.breakpoints ?? DEFAULT_BREAKPOINTS;
52
+ for (let i = 0; i < propValue.length; i += 1) {
53
+ buildBreakpoint(target, breakpoints.up(breakpoints.keys[i]), propValue[i], undefined, callback);
54
+ }
55
+ return target;
44
56
  }
45
57
  if (typeof propValue === 'object') {
46
- const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
47
- return Object.keys(propValue).reduce((acc, breakpoint) => {
48
- if (isCqShorthand(themeBreakpoints.keys, breakpoint)) {
49
- const containerKey = getContainerQuery(theme.containerQueries ? theme : defaultContainerQueries, breakpoint);
58
+ const breakpoints = theme.breakpoints ?? DEFAULT_BREAKPOINTS;
59
+ const breakpointValues = breakpoints.values ?? values;
60
+ for (const key in propValue) {
61
+ if (isCqShorthand(breakpoints.keys, key)) {
62
+ const containerKey = getContainerQuery(theme.containerQueries ? theme : defaultContainerQueries, key);
50
63
  if (containerKey) {
51
- acc[containerKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
64
+ buildBreakpoint(target, containerKey, propValue[key], key, callback);
52
65
  }
53
66
  }
54
- // key is breakpoint
55
- else if (Object.keys(themeBreakpoints.values || values).includes(breakpoint)) {
56
- const mediaKey = themeBreakpoints.up(breakpoint);
57
- acc[mediaKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
67
+ // key is key
68
+ else if (key in breakpointValues) {
69
+ const mediaKey = breakpoints.up(key);
70
+ buildBreakpoint(target, mediaKey, propValue[key], key, callback);
58
71
  } else {
59
- const cssKey = breakpoint;
60
- acc[cssKey] = propValue[cssKey];
72
+ const cssKey = key;
73
+ target[cssKey] = propValue[cssKey];
61
74
  }
62
- return acc;
63
- }, {});
75
+ }
76
+ return target;
64
77
  }
65
- const output = styleFromPropValue(propValue);
66
- return output;
78
+ callback(undefined, propValue);
79
+ return target;
80
+ }
81
+ function buildBreakpoint(target, mediaKey, value, initialKey, callback) {
82
+ target[mediaKey] ??= {};
83
+ callback(mediaKey, value, initialKey);
67
84
  }
68
- function breakpoints(styleFunction) {
69
- // false positive
85
+ function setupBreakpoints(styleFunction) {
70
86
  // eslint-disable-next-line react/function-component-definition
71
87
  const newStyleFunction = props => {
72
88
  const theme = props.theme || {};
73
89
  const base = styleFunction(props);
74
- const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
90
+ const themeBreakpoints = theme.breakpoints || DEFAULT_BREAKPOINTS;
75
91
  const extended = themeBreakpoints.keys.reduce((acc, key) => {
76
92
  if (props[key]) {
77
93
  acc = acc || {};
@@ -95,28 +111,30 @@ function breakpoints(styleFunction) {
95
111
  newStyleFunction.filterProps = ['xs', 'sm', 'md', 'lg', 'xl', ...styleFunction.filterProps];
96
112
  return newStyleFunction;
97
113
  }
98
- export function createEmptyBreakpointObject(breakpointsInput = {}) {
99
- const breakpointsInOrder = breakpointsInput.keys?.reduce((acc, key) => {
100
- const breakpointStyleKey = breakpointsInput.up(key);
101
- acc[breakpointStyleKey] = {};
102
- return acc;
103
- }, {});
104
- return breakpointsInOrder || {};
114
+ export function createEmptyBreakpointObject(breakpoints = DEFAULT_BREAKPOINTS) {
115
+ const {
116
+ internal_mediaKeys: mediaKeys
117
+ } = breakpoints;
118
+ const result = {};
119
+ for (let i = 0; i < mediaKeys.length; i += 1) {
120
+ result[mediaKeys[i]] = {};
121
+ }
122
+ return result;
105
123
  }
106
- export function removeUnusedBreakpoints(breakpointKeys, style) {
107
- return breakpointKeys.reduce((acc, key) => {
108
- const breakpointOutput = acc[key];
109
- const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
110
- if (isBreakpointUnused) {
111
- delete acc[key];
124
+ export function removeUnusedBreakpoints(breakpoints, style) {
125
+ const breakpointKeys = breakpoints.internal_mediaKeys;
126
+ for (let i = 0; i < breakpointKeys.length; i += 1) {
127
+ const key = breakpointKeys[i];
128
+ if (isObjectEmpty(style[key])) {
129
+ delete style[key];
112
130
  }
113
- return acc;
114
- }, style);
131
+ }
132
+ return style;
115
133
  }
116
- export function mergeBreakpointsInOrder(breakpointsInput, ...styles) {
117
- const emptyBreakpoints = createEmptyBreakpointObject(breakpointsInput);
134
+ export function mergeBreakpointsInOrder(breakpoints, ...styles) {
135
+ const emptyBreakpoints = createEmptyBreakpointObject(breakpoints);
118
136
  const mergedOutput = [emptyBreakpoints, ...styles].reduce((prev, next) => deepmerge(prev, next), {});
119
- return removeUnusedBreakpoints(Object.keys(emptyBreakpoints), mergedOutput);
137
+ return removeUnusedBreakpoints(breakpoints, mergedOutput);
120
138
  }
121
139
 
122
140
  // compute base for responsive values; e.g.,
@@ -168,4 +186,23 @@ export function resolveBreakpointValues({
168
186
  return acc;
169
187
  }, {});
170
188
  }
171
- export default breakpoints;
189
+ export function hasBreakpoint(breakpoints, value) {
190
+ if (Array.isArray(value)) {
191
+ return true;
192
+ }
193
+ if (typeof value === 'object' && value !== null) {
194
+ for (let i = 0; i < breakpoints.keys.length; i += 1) {
195
+ if (breakpoints.keys[i] in value) {
196
+ return true;
197
+ }
198
+ }
199
+ const valueKeys = Object.keys(value);
200
+ for (let i = 0; i < valueKeys.length; i += 1) {
201
+ if (isCqShorthand(breakpoints.keys, valueKeys[i])) {
202
+ return true;
203
+ }
204
+ }
205
+ }
206
+ return false;
207
+ }
208
+ export default setupBreakpoints;