@mui/system 6.0.0-alpha.0 → 6.0.0-alpha.3

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 (141) hide show
  1. package/CHANGELOG.md +243 -4
  2. package/Container/Container.d.ts +1 -1
  3. package/Stack/Stack.d.ts +1 -1
  4. package/Stack/createStack.d.ts +1 -1
  5. package/Unstable_Grid/Grid.d.ts +1 -1
  6. package/Unstable_Grid/createGrid.d.ts +1 -1
  7. package/breakpoints/breakpoints.js +19 -1
  8. package/createTheme/createSpacing.d.ts +2 -2
  9. package/createTheme/createSpacing.js +7 -8
  10. package/createTheme/createTheme.d.ts +2 -1
  11. package/createTheme/createTheme.js +2 -0
  12. package/cssContainerQueries/cssContainerQueries.d.ts +24 -0
  13. package/cssContainerQueries/cssContainerQueries.js +68 -0
  14. package/cssContainerQueries/index.d.ts +3 -0
  15. package/cssContainerQueries/index.js +2 -0
  16. package/cssContainerQueries/package.json +6 -0
  17. package/cssVars/createCssVarsProvider.js +3 -0
  18. package/cssVars/cssVarsParser.d.ts +1 -1
  19. package/cssVars/cssVarsParser.js +3 -2
  20. package/index.d.ts +2 -0
  21. package/index.js +2 -1
  22. package/modern/breakpoints/breakpoints.js +19 -1
  23. package/modern/createTheme/createSpacing.js +7 -8
  24. package/modern/createTheme/createTheme.js +2 -0
  25. package/modern/cssContainerQueries/cssContainerQueries.js +68 -0
  26. package/modern/cssContainerQueries/index.js +2 -0
  27. package/modern/cssVars/createCssVarsProvider.js +3 -0
  28. package/modern/cssVars/cssVarsParser.js +3 -2
  29. package/modern/index.js +2 -1
  30. package/modern/spacing/spacing.js +24 -21
  31. package/modern/styleFunctionSx/styleFunctionSx.js +2 -1
  32. package/node/breakpoints/breakpoints.js +19 -1
  33. package/node/createTheme/createSpacing.js +7 -8
  34. package/node/createTheme/createTheme.js +2 -0
  35. package/node/cssContainerQueries/cssContainerQueries.js +79 -0
  36. package/node/cssContainerQueries/index.js +32 -0
  37. package/node/cssVars/createCssVarsProvider.js +3 -0
  38. package/node/cssVars/cssVarsParser.js +3 -2
  39. package/node/index.js +9 -1
  40. package/node/spacing/spacing.js +24 -21
  41. package/node/styleFunctionSx/styleFunctionSx.js +2 -1
  42. package/package.json +5 -5
  43. package/spacing/spacing.js +24 -21
  44. package/styleFunctionSx/styleFunctionSx.js +2 -1
  45. package/legacy/Box/Box.js +0 -30
  46. package/legacy/Box/boxClasses.js +0 -3
  47. package/legacy/Box/index.js +0 -5
  48. package/legacy/Container/Container.js +0 -61
  49. package/legacy/Container/ContainerProps.js +0 -1
  50. package/legacy/Container/containerClasses.js +0 -7
  51. package/legacy/Container/createContainer.js +0 -140
  52. package/legacy/Container/index.js +0 -5
  53. package/legacy/GlobalStyles/GlobalStyles.js +0 -37
  54. package/legacy/GlobalStyles/index.js +0 -4
  55. package/legacy/RtlProvider/index.js +0 -22
  56. package/legacy/Stack/Stack.js +0 -62
  57. package/legacy/Stack/StackProps.js +0 -1
  58. package/legacy/Stack/createStack.js +0 -180
  59. package/legacy/Stack/index.js +0 -7
  60. package/legacy/Stack/stackClasses.js +0 -7
  61. package/legacy/ThemeProvider/ThemeProvider.js +0 -87
  62. package/legacy/ThemeProvider/index.js +0 -3
  63. package/legacy/Unstable_Grid/Grid.js +0 -177
  64. package/legacy/Unstable_Grid/GridProps.js +0 -1
  65. package/legacy/Unstable_Grid/createGrid.js +0 -184
  66. package/legacy/Unstable_Grid/gridClasses.js +0 -28
  67. package/legacy/Unstable_Grid/gridGenerator.js +0 -216
  68. package/legacy/Unstable_Grid/index.js +0 -8
  69. package/legacy/Unstable_Grid/traverseBreakpoints.js +0 -48
  70. package/legacy/borders/borders.js +0 -51
  71. package/legacy/borders/index.js +0 -4
  72. package/legacy/breakpoints/breakpoints.js +0 -162
  73. package/legacy/breakpoints/index.js +0 -4
  74. package/legacy/colorManipulator/colorManipulator.js +0 -356
  75. package/legacy/colorManipulator/index.js +0 -3
  76. package/legacy/compose/compose.js +0 -32
  77. package/legacy/compose/index.js +0 -3
  78. package/legacy/createBox/createBox.js +0 -38
  79. package/legacy/createBox/index.js +0 -3
  80. package/legacy/createStyled/createStyled.js +0 -250
  81. package/legacy/createStyled/index.js +0 -4
  82. package/legacy/createTheme/applyStyles.js +0 -73
  83. package/legacy/createTheme/createBreakpoints.js +0 -83
  84. package/legacy/createTheme/createSpacing.js +0 -36
  85. package/legacy/createTheme/createTheme.js +0 -49
  86. package/legacy/createTheme/index.js +0 -3
  87. package/legacy/createTheme/shape.js +0 -4
  88. package/legacy/cssGrid/cssGrid.js +0 -91
  89. package/legacy/cssGrid/index.js +0 -4
  90. package/legacy/cssVars/createCssVarsProvider.js +0 -335
  91. package/legacy/cssVars/createCssVarsTheme.js +0 -13
  92. package/legacy/cssVars/createGetCssVar.js +0 -30
  93. package/legacy/cssVars/cssVarsParser.js +0 -140
  94. package/legacy/cssVars/getInitColorSchemeScript.js +0 -28
  95. package/legacy/cssVars/index.js +0 -6
  96. package/legacy/cssVars/prepareCssVars.js +0 -92
  97. package/legacy/cssVars/useCurrentColorScheme.js +0 -237
  98. package/legacy/display/display.js +0 -29
  99. package/legacy/display/index.js +0 -4
  100. package/legacy/flexbox/flexbox.js +0 -43
  101. package/legacy/flexbox/index.js +0 -4
  102. package/legacy/getThemeValue/getThemeValue.js +0 -47
  103. package/legacy/getThemeValue/index.js +0 -4
  104. package/legacy/index.js +0 -72
  105. package/legacy/memoize/index.js +0 -3
  106. package/legacy/memoize/memoize.js +0 -9
  107. package/legacy/merge/index.js +0 -3
  108. package/legacy/merge/merge.js +0 -10
  109. package/legacy/palette/index.js +0 -4
  110. package/legacy/palette/palette.js +0 -26
  111. package/legacy/positions/index.js +0 -4
  112. package/legacy/positions/positions.js +0 -22
  113. package/legacy/propsToClassKey/index.js +0 -3
  114. package/legacy/propsToClassKey/propsToClassKey.js +0 -24
  115. package/legacy/responsivePropType/index.js +0 -3
  116. package/legacy/responsivePropType/responsivePropType.js +0 -3
  117. package/legacy/shadows/index.js +0 -3
  118. package/legacy/shadows/shadows.js +0 -6
  119. package/legacy/sizing/index.js +0 -4
  120. package/legacy/sizing/sizing.js +0 -65
  121. package/legacy/spacing/index.js +0 -4
  122. package/legacy/spacing/spacing.js +0 -158
  123. package/legacy/style/index.js +0 -4
  124. package/legacy/style/style.js +0 -73
  125. package/legacy/styleFunctionSx/defaultSxConfig.js +0 -293
  126. package/legacy/styleFunctionSx/extendSxProp.js +0 -45
  127. package/legacy/styleFunctionSx/index.js +0 -4
  128. package/legacy/styleFunctionSx/styleFunctionSx.js +0 -126
  129. package/legacy/styled/index.js +0 -3
  130. package/legacy/styled/styled.js +0 -3
  131. package/legacy/typography/index.js +0 -4
  132. package/legacy/typography/typography.js +0 -37
  133. package/legacy/useMediaQuery/index.js +0 -2
  134. package/legacy/useMediaQuery/useMediaQuery.js +0 -145
  135. package/legacy/useTheme/index.js +0 -4
  136. package/legacy/useTheme/useTheme.js +0 -10
  137. package/legacy/useThemeProps/getThemeProps.js +0 -10
  138. package/legacy/useThemeProps/index.js +0 -4
  139. package/legacy/useThemeProps/useThemeProps.js +0 -20
  140. package/legacy/useThemeWithoutDefault/index.js +0 -3
  141. package/legacy/useThemeWithoutDefault/useThemeWithoutDefault.js +0 -13
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import PropTypes from 'prop-types';
3
3
  import deepmerge from '@mui/utils/deepmerge';
4
4
  import merge from '../merge';
5
+ import { isCqShorthand, getContainerQuery } from '../cssContainerQueries';
5
6
 
6
7
  // The breakpoint **start** at this value.
7
8
  // For instance with the first breakpoint xs: [xs, sm[.
@@ -22,6 +23,17 @@ const defaultBreakpoints = {
22
23
  keys: ['xs', 'sm', 'md', 'lg', 'xl'],
23
24
  up: key => `@media (min-width:${values[key]}px)`
24
25
  };
26
+ const defaultContainerQueries = {
27
+ containerQueries: containerName => ({
28
+ up: key => {
29
+ let result = typeof key === 'number' ? key : values[key] || key;
30
+ if (typeof result === 'number') {
31
+ result = `${result}px`;
32
+ }
33
+ return containerName ? `@container ${containerName} (min-width:${result})` : `@container (min-width:${result})`;
34
+ }
35
+ })
36
+ };
25
37
  export function handleBreakpoints(props, propValue, styleFromPropValue) {
26
38
  const theme = props.theme || {};
27
39
  if (Array.isArray(propValue)) {
@@ -34,8 +46,14 @@ export function handleBreakpoints(props, propValue, styleFromPropValue) {
34
46
  if (typeof propValue === 'object') {
35
47
  const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
36
48
  return Object.keys(propValue).reduce((acc, breakpoint) => {
49
+ if (isCqShorthand(themeBreakpoints.keys, breakpoint)) {
50
+ const containerKey = getContainerQuery(theme.containerQueries ? theme : defaultContainerQueries, breakpoint);
51
+ if (containerKey) {
52
+ acc[containerKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
53
+ }
54
+ }
37
55
  // key is breakpoint
38
- if (Object.keys(themeBreakpoints.values || values).indexOf(breakpoint) !== -1) {
56
+ else if (Object.keys(themeBreakpoints.values || values).indexOf(breakpoint) !== -1) {
39
57
  const mediaKey = themeBreakpoints.up(breakpoint);
40
58
  acc[mediaKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
41
59
  } else {
@@ -3,18 +3,17 @@ import { createUnarySpacing } from '../spacing';
3
3
  // The different signatures imply different meaning for their arguments that can't be expressed structurally.
4
4
  // We express the difference with variable names.
5
5
 
6
- export default function createSpacing(spacingInput = 8) {
6
+ export default function createSpacing(spacingInput = 8,
7
+ // Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
8
+ // Smaller components, such as icons, can align to a 4dp grid.
9
+ // https://m2.material.io/design/layout/understanding-layout.html
10
+ transform = createUnarySpacing({
11
+ spacing: spacingInput
12
+ })) {
7
13
  // Already transformed.
8
14
  if (spacingInput.mui) {
9
15
  return spacingInput;
10
16
  }
11
-
12
- // Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
13
- // Smaller components, such as icons, can align to a 4dp grid.
14
- // https://m2.material.io/design/layout/understanding-layout.html
15
- const transform = createUnarySpacing({
16
- spacing: spacingInput
17
- });
18
17
  const spacing = (...argsInput) => {
19
18
  if (process.env.NODE_ENV !== 'production') {
20
19
  if (!(argsInput.length <= 4)) {
@@ -3,6 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["breakpoints", "palette", "spacing", "shape"];
4
4
  import deepmerge from '@mui/utils/deepmerge';
5
5
  import createBreakpoints from './createBreakpoints';
6
+ import cssContainerQueries from '../cssContainerQueries';
6
7
  import shape from './shape';
7
8
  import createSpacing from './createSpacing';
8
9
  import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
@@ -29,6 +30,7 @@ function createTheme(options = {}, ...args) {
29
30
  spacing,
30
31
  shape: _extends({}, shape, shapeInput)
31
32
  }, other);
33
+ muiTheme = cssContainerQueries(muiTheme);
32
34
  muiTheme.applyStyles = applyStyles;
33
35
  muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
34
36
  muiTheme.unstable_sxConfig = _extends({}, defaultSxConfig, other?.unstable_sxConfig);
@@ -0,0 +1,68 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
3
+ /**
4
+ * For using in `sx` prop to sort the breakpoint from low to high.
5
+ * Note: this function does not work and will not support multiple units.
6
+ * e.g. input: { '@container (min-width:300px)': '1rem', '@container (min-width:40rem)': '2rem' }
7
+ * output: { '@container (min-width:40rem)': '2rem', '@container (min-width:300px)': '1rem' } // since 40 < 300 eventhough 40rem > 300px
8
+ */
9
+ export function sortContainerQueries(theme, css) {
10
+ if (!theme.containerQueries) {
11
+ return css;
12
+ }
13
+ const sorted = Object.keys(css).filter(key => key.startsWith('@container')).sort((a, b) => {
14
+ const regex = /min-width:\s*([0-9.]+)/;
15
+ return +(a.match(regex)?.[1] || 0) - +(b.match(regex)?.[1] || 0);
16
+ });
17
+ if (!sorted.length) {
18
+ return css;
19
+ }
20
+ return sorted.reduce((acc, key) => {
21
+ const value = css[key];
22
+ delete acc[key];
23
+ acc[key] = value;
24
+ return acc;
25
+ }, _extends({}, css));
26
+ }
27
+ export function isCqShorthand(breakpointKeys, value) {
28
+ return value.startsWith('@') && (breakpointKeys.some(key => value.startsWith(`@${key}`)) || !!value.match(/^@\d/));
29
+ }
30
+ export function getContainerQuery(theme, shorthand) {
31
+ const matches = shorthand.match(/^@([^/]+)\/?(.+)?$/);
32
+ if (!matches) {
33
+ if (process.env.NODE_ENV !== 'production') {
34
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
35
+ For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.` : _formatMuiErrorMessage(21, `(${shorthand})`));
36
+ }
37
+ return null;
38
+ }
39
+ const [, containerQuery, containerName] = matches;
40
+ const value = Number.isNaN(+containerQuery) ? containerQuery : +containerQuery;
41
+ return theme.containerQueries(containerName).up(value);
42
+ }
43
+ export default function cssContainerQueries(themeInput) {
44
+ const toContainerQuery = (mediaQuery, name) => mediaQuery.replace('@media', name ? `@container ${name}` : '@container');
45
+ function attachCq(node, name) {
46
+ node.up = (...args) => toContainerQuery(themeInput.breakpoints.up(...args), name);
47
+ node.down = (...args) => toContainerQuery(themeInput.breakpoints.down(...args), name);
48
+ node.between = (...args) => toContainerQuery(themeInput.breakpoints.between(...args), name);
49
+ node.only = (...args) => toContainerQuery(themeInput.breakpoints.only(...args), name);
50
+ node.not = (...args) => {
51
+ const result = toContainerQuery(themeInput.breakpoints.not(...args), name);
52
+ if (result.includes('not all and')) {
53
+ // `@container` does not work with `not all and`, so need to invert the logic
54
+ return result.replace('not all and ', '').replace('min-width:', 'width<').replace('max-width:', 'width>');
55
+ }
56
+ return result;
57
+ };
58
+ }
59
+ const node = {};
60
+ const containerQueries = name => {
61
+ attachCq(node, name);
62
+ return node;
63
+ };
64
+ attachCq(containerQueries);
65
+ return _extends({}, themeInput, {
66
+ containerQueries
67
+ });
68
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './cssContainerQueries';
2
+ export { isCqShorthand, getContainerQuery, sortContainerQueries } from './cssContainerQueries';
@@ -132,6 +132,9 @@ export default function createCssVarsProvider(options) {
132
132
  cssVarPrefix,
133
133
  vars: themeVars
134
134
  });
135
+ if (typeof theme.generateSpacing === 'function') {
136
+ theme.spacing = theme.generateSpacing();
137
+ }
135
138
 
136
139
  // 4. Resolve the color scheme and merge it to the theme
137
140
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -111,11 +111,12 @@ export default function cssVarsParser(theme, options) {
111
111
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
112
112
  // only create css & var if `shouldSkipGeneratingVar` return false
113
113
  const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
114
+ const resolvedValue = getCssValue(keys, value);
114
115
  Object.assign(css, {
115
- [cssVar]: getCssValue(keys, value)
116
+ [cssVar]: resolvedValue
116
117
  });
117
118
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
118
- assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
119
+ assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${resolvedValue})`, arrayKeys);
119
120
  }
120
121
  }
121
122
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/system v6.0.0-alpha.0
2
+ * @mui/system v6.0.0-alpha.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -11,6 +11,7 @@ export { default as GlobalStyles } from './GlobalStyles';
11
11
  export { default as borders } from './borders';
12
12
  export * from './borders';
13
13
  export { default as breakpoints } from './breakpoints';
14
+ export { default as cssContainerQueries } from './cssContainerQueries';
14
15
  export { handleBreakpoints, mergeBreakpointsInOrder, resolveBreakpointValues as unstable_resolveBreakpointValues } from './breakpoints';
15
16
  export { default as compose } from './compose';
16
17
  export { default as display } from './display';
@@ -43,25 +43,29 @@ export const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'm
43
43
  export const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd'];
44
44
  const spacingKeys = [...marginKeys, ...paddingKeys];
45
45
  export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
46
- const themeSpacing = getPath(theme, themeKey, false) ?? defaultValue;
47
- if (typeof themeSpacing === 'number') {
48
- return abs => {
49
- if (typeof abs === 'string') {
50
- return abs;
46
+ const themeSpacing = getPath(theme, themeKey, true) ?? defaultValue;
47
+ if (typeof themeSpacing === 'number' || typeof themeSpacing === 'string') {
48
+ return val => {
49
+ if (typeof val === 'string') {
50
+ return val;
51
51
  }
52
52
  if (process.env.NODE_ENV !== 'production') {
53
- if (typeof abs !== 'number') {
54
- console.error(`MUI: Expected ${propName} argument to be a number or a string, got ${abs}.`);
53
+ if (typeof val !== 'number') {
54
+ console.error(`MUI: Expected ${propName} argument to be a number or a string, got ${val}.`);
55
55
  }
56
56
  }
57
- return themeSpacing * abs;
57
+ if (typeof themeSpacing === 'string') {
58
+ return `calc(${val} * ${themeSpacing})`;
59
+ }
60
+ return themeSpacing * val;
58
61
  };
59
62
  }
60
63
  if (Array.isArray(themeSpacing)) {
61
- return abs => {
62
- if (typeof abs === 'string') {
63
- return abs;
64
+ return val => {
65
+ if (typeof val === 'string') {
66
+ return val;
64
67
  }
68
+ const abs = Math.abs(val);
65
69
  if (process.env.NODE_ENV !== 'production') {
66
70
  if (!Number.isInteger(abs)) {
67
71
  console.error([`MUI: The \`theme.${themeKey}\` array type cannot be combined with non integer values.` + `You should either use an integer value that can be used as index, or define the \`theme.${themeKey}\` as a number.`].join('\n'));
@@ -69,7 +73,14 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
69
73
  console.error([`MUI: The value provided (${abs}) overflows.`, `The supported values are: ${JSON.stringify(themeSpacing)}.`, `${abs} > ${themeSpacing.length - 1}, you need to add the missing values.`].join('\n'));
70
74
  }
71
75
  }
72
- return themeSpacing[abs];
76
+ const transformed = themeSpacing[abs];
77
+ if (val >= 0) {
78
+ return transformed;
79
+ }
80
+ if (typeof transformed === 'number') {
81
+ return -transformed;
82
+ }
83
+ return `-${transformed}`;
73
84
  };
74
85
  }
75
86
  if (typeof themeSpacing === 'function') {
@@ -87,15 +98,7 @@ export function getValue(transformer, propValue) {
87
98
  if (typeof propValue === 'string' || propValue == null) {
88
99
  return propValue;
89
100
  }
90
- const abs = Math.abs(propValue);
91
- const transformed = transformer(abs);
92
- if (propValue >= 0) {
93
- return transformed;
94
- }
95
- if (typeof transformed === 'number') {
96
- return -transformed;
97
- }
98
- return `-${transformed}`;
101
+ return transformer(propValue);
99
102
  }
100
103
  export function getStyleFromPropValue(cssProperties, transformer) {
101
104
  return propValue => cssProperties.reduce((acc, cssProperty) => {
@@ -2,6 +2,7 @@ import capitalize from '@mui/utils/capitalize';
2
2
  import merge from '../merge';
3
3
  import { getPath, getStyleValue as getValue } from '../style';
4
4
  import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
5
+ import { sortContainerQueries } from '../cssContainerQueries';
5
6
  import defaultSxConfig from './defaultSxConfig';
6
7
  function objectsHaveSameKeys(...objects) {
7
8
  const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
@@ -115,7 +116,7 @@ export function unstable_createStyleFunctionSx() {
115
116
  }
116
117
  }
117
118
  });
118
- return removeUnusedBreakpoints(breakpointsKeys, css);
119
+ return sortContainerQueries(theme, removeUnusedBreakpoints(breakpointsKeys, css));
119
120
  }
120
121
  return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
121
122
  }
@@ -16,6 +16,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
16
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
17
17
  var _deepmerge = _interopRequireDefault(require("@mui/utils/deepmerge"));
18
18
  var _merge = _interopRequireDefault(require("../merge"));
19
+ var _cssContainerQueries = require("../cssContainerQueries");
19
20
  // The breakpoint **start** at this value.
20
21
  // For instance with the first breakpoint xs: [xs, sm[.
21
22
  const values = exports.values = {
@@ -35,6 +36,17 @@ const defaultBreakpoints = {
35
36
  keys: ['xs', 'sm', 'md', 'lg', 'xl'],
36
37
  up: key => `@media (min-width:${values[key]}px)`
37
38
  };
39
+ const defaultContainerQueries = {
40
+ containerQueries: containerName => ({
41
+ up: key => {
42
+ let result = typeof key === 'number' ? key : values[key] || key;
43
+ if (typeof result === 'number') {
44
+ result = `${result}px`;
45
+ }
46
+ return containerName ? `@container ${containerName} (min-width:${result})` : `@container (min-width:${result})`;
47
+ }
48
+ })
49
+ };
38
50
  function handleBreakpoints(props, propValue, styleFromPropValue) {
39
51
  const theme = props.theme || {};
40
52
  if (Array.isArray(propValue)) {
@@ -47,8 +59,14 @@ function handleBreakpoints(props, propValue, styleFromPropValue) {
47
59
  if (typeof propValue === 'object') {
48
60
  const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
49
61
  return Object.keys(propValue).reduce((acc, breakpoint) => {
62
+ if ((0, _cssContainerQueries.isCqShorthand)(themeBreakpoints.keys, breakpoint)) {
63
+ const containerKey = (0, _cssContainerQueries.getContainerQuery)(theme.containerQueries ? theme : defaultContainerQueries, breakpoint);
64
+ if (containerKey) {
65
+ acc[containerKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
66
+ }
67
+ }
50
68
  // key is breakpoint
51
- if (Object.keys(themeBreakpoints.values || values).indexOf(breakpoint) !== -1) {
69
+ else if (Object.keys(themeBreakpoints.values || values).indexOf(breakpoint) !== -1) {
52
70
  const mediaKey = themeBreakpoints.up(breakpoint);
53
71
  acc[mediaKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
54
72
  } else {
@@ -8,18 +8,17 @@ var _spacing = require("../spacing");
8
8
  // The different signatures imply different meaning for their arguments that can't be expressed structurally.
9
9
  // We express the difference with variable names.
10
10
 
11
- function createSpacing(spacingInput = 8) {
11
+ function createSpacing(spacingInput = 8,
12
+ // Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
13
+ // Smaller components, such as icons, can align to a 4dp grid.
14
+ // https://m2.material.io/design/layout/understanding-layout.html
15
+ transform = (0, _spacing.createUnarySpacing)({
16
+ spacing: spacingInput
17
+ })) {
12
18
  // Already transformed.
13
19
  if (spacingInput.mui) {
14
20
  return spacingInput;
15
21
  }
16
-
17
- // Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
18
- // Smaller components, such as icons, can align to a 4dp grid.
19
- // https://m2.material.io/design/layout/understanding-layout.html
20
- const transform = (0, _spacing.createUnarySpacing)({
21
- spacing: spacingInput
22
- });
23
22
  const spacing = (...argsInput) => {
24
23
  if (process.env.NODE_ENV !== 'production') {
25
24
  if (!(argsInput.length <= 4)) {
@@ -9,6 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
10
  var _deepmerge = _interopRequireDefault(require("@mui/utils/deepmerge"));
11
11
  var _createBreakpoints = _interopRequireDefault(require("./createBreakpoints"));
12
+ var _cssContainerQueries = _interopRequireDefault(require("../cssContainerQueries"));
12
13
  var _shape = _interopRequireDefault(require("./shape"));
13
14
  var _createSpacing = _interopRequireDefault(require("./createSpacing"));
14
15
  var _styleFunctionSx = _interopRequireDefault(require("../styleFunctionSx/styleFunctionSx"));
@@ -36,6 +37,7 @@ function createTheme(options = {}, ...args) {
36
37
  spacing,
37
38
  shape: (0, _extends2.default)({}, _shape.default, shapeInput)
38
39
  }, other);
40
+ muiTheme = (0, _cssContainerQueries.default)(muiTheme);
39
41
  muiTheme.applyStyles = _applyStyles.default;
40
42
  muiTheme = args.reduce((acc, argument) => (0, _deepmerge.default)(acc, argument), muiTheme);
41
43
  muiTheme.unstable_sxConfig = (0, _extends2.default)({}, _defaultSxConfig.default, other == null ? void 0 : other.unstable_sxConfig);
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = cssContainerQueries;
8
+ exports.getContainerQuery = getContainerQuery;
9
+ exports.isCqShorthand = isCqShorthand;
10
+ exports.sortContainerQueries = sortContainerQueries;
11
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
+ var _formatMuiErrorMessage2 = _interopRequireDefault(require("@mui/utils/formatMuiErrorMessage"));
13
+ /**
14
+ * For using in `sx` prop to sort the breakpoint from low to high.
15
+ * Note: this function does not work and will not support multiple units.
16
+ * e.g. input: { '@container (min-width:300px)': '1rem', '@container (min-width:40rem)': '2rem' }
17
+ * output: { '@container (min-width:40rem)': '2rem', '@container (min-width:300px)': '1rem' } // since 40 < 300 eventhough 40rem > 300px
18
+ */
19
+ function sortContainerQueries(theme, css) {
20
+ if (!theme.containerQueries) {
21
+ return css;
22
+ }
23
+ const sorted = Object.keys(css).filter(key => key.startsWith('@container')).sort((a, b) => {
24
+ var _a$match, _b$match;
25
+ const regex = /min-width:\s*([0-9.]+)/;
26
+ return +(((_a$match = a.match(regex)) == null ? void 0 : _a$match[1]) || 0) - +(((_b$match = b.match(regex)) == null ? void 0 : _b$match[1]) || 0);
27
+ });
28
+ if (!sorted.length) {
29
+ return css;
30
+ }
31
+ return sorted.reduce((acc, key) => {
32
+ const value = css[key];
33
+ delete acc[key];
34
+ acc[key] = value;
35
+ return acc;
36
+ }, (0, _extends2.default)({}, css));
37
+ }
38
+ function isCqShorthand(breakpointKeys, value) {
39
+ return value.startsWith('@') && (breakpointKeys.some(key => value.startsWith(`@${key}`)) || !!value.match(/^@\d/));
40
+ }
41
+ function getContainerQuery(theme, shorthand) {
42
+ const matches = shorthand.match(/^@([^/]+)\/?(.+)?$/);
43
+ if (!matches) {
44
+ if (process.env.NODE_ENV !== 'production') {
45
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
46
+ For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.` : (0, _formatMuiErrorMessage2.default)(21, `(${shorthand})`));
47
+ }
48
+ return null;
49
+ }
50
+ const [, containerQuery, containerName] = matches;
51
+ const value = Number.isNaN(+containerQuery) ? containerQuery : +containerQuery;
52
+ return theme.containerQueries(containerName).up(value);
53
+ }
54
+ function cssContainerQueries(themeInput) {
55
+ const toContainerQuery = (mediaQuery, name) => mediaQuery.replace('@media', name ? `@container ${name}` : '@container');
56
+ function attachCq(node, name) {
57
+ node.up = (...args) => toContainerQuery(themeInput.breakpoints.up(...args), name);
58
+ node.down = (...args) => toContainerQuery(themeInput.breakpoints.down(...args), name);
59
+ node.between = (...args) => toContainerQuery(themeInput.breakpoints.between(...args), name);
60
+ node.only = (...args) => toContainerQuery(themeInput.breakpoints.only(...args), name);
61
+ node.not = (...args) => {
62
+ const result = toContainerQuery(themeInput.breakpoints.not(...args), name);
63
+ if (result.includes('not all and')) {
64
+ // `@container` does not work with `not all and`, so need to invert the logic
65
+ return result.replace('not all and ', '').replace('min-width:', 'width<').replace('max-width:', 'width>');
66
+ }
67
+ return result;
68
+ };
69
+ }
70
+ const node = {};
71
+ const containerQueries = name => {
72
+ attachCq(node, name);
73
+ return node;
74
+ };
75
+ attachCq(containerQueries);
76
+ return (0, _extends2.default)({}, themeInput, {
77
+ containerQueries
78
+ });
79
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _cssContainerQueries.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getContainerQuery", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _cssContainerQueries.getContainerQuery;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "isCqShorthand", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _cssContainerQueries.isCqShorthand;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "sortContainerQueries", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _cssContainerQueries.sortContainerQueries;
28
+ }
29
+ });
30
+ var _cssContainerQueries = _interopRequireWildcard(require("./cssContainerQueries"));
31
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
32
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -143,6 +143,9 @@ function createCssVarsProvider(options) {
143
143
  cssVarPrefix,
144
144
  vars: themeVars
145
145
  });
146
+ if (typeof theme.generateSpacing === 'function') {
147
+ theme.spacing = theme.generateSpacing();
148
+ }
146
149
 
147
150
  // 4. Resolve the color scheme and merge it to the theme
148
151
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -121,11 +121,12 @@ function cssVarsParser(theme, options) {
121
121
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
122
122
  // only create css & var if `shouldSkipGeneratingVar` return false
123
123
  const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
124
+ const resolvedValue = getCssValue(keys, value);
124
125
  Object.assign(css, {
125
- [cssVar]: getCssValue(keys, value)
126
+ [cssVar]: resolvedValue
126
127
  });
127
128
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
128
- assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
129
+ assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${resolvedValue})`, arrayKeys);
129
130
  }
130
131
  }
131
132
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/system v6.0.0-alpha.0
2
+ * @mui/system v6.0.0-alpha.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -22,6 +22,7 @@ var _exportNames = {
22
22
  handleBreakpoints: true,
23
23
  mergeBreakpointsInOrder: true,
24
24
  unstable_resolveBreakpointValues: true,
25
+ cssContainerQueries: true,
25
26
  compose: true,
26
27
  display: true,
27
28
  flexbox: true,
@@ -174,6 +175,12 @@ Object.defineProperty(exports, "css", {
174
175
  return _styledEngine.css;
175
176
  }
176
177
  });
178
+ Object.defineProperty(exports, "cssContainerQueries", {
179
+ enumerable: true,
180
+ get: function () {
181
+ return _cssContainerQueries.default;
182
+ }
183
+ });
177
184
  Object.defineProperty(exports, "display", {
178
185
  enumerable: true,
179
186
  get: function () {
@@ -395,6 +402,7 @@ Object.keys(_borders).forEach(function (key) {
395
402
  });
396
403
  });
397
404
  var _breakpoints = _interopRequireWildcard(require("./breakpoints"));
405
+ var _cssContainerQueries = _interopRequireDefault(require("./cssContainerQueries"));
398
406
  var _compose = _interopRequireDefault(require("./compose"));
399
407
  var _display = _interopRequireDefault(require("./display"));
400
408
  var _flexbox = _interopRequireWildcard(require("./flexbox"));
@@ -59,25 +59,29 @@ const paddingKeys = exports.paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'p
59
59
  const spacingKeys = [...marginKeys, ...paddingKeys];
60
60
  function createUnaryUnit(theme, themeKey, defaultValue, propName) {
61
61
  var _getPath;
62
- const themeSpacing = (_getPath = (0, _style.getPath)(theme, themeKey, false)) != null ? _getPath : defaultValue;
63
- if (typeof themeSpacing === 'number') {
64
- return abs => {
65
- if (typeof abs === 'string') {
66
- return abs;
62
+ const themeSpacing = (_getPath = (0, _style.getPath)(theme, themeKey, true)) != null ? _getPath : defaultValue;
63
+ if (typeof themeSpacing === 'number' || typeof themeSpacing === 'string') {
64
+ return val => {
65
+ if (typeof val === 'string') {
66
+ return val;
67
67
  }
68
68
  if (process.env.NODE_ENV !== 'production') {
69
- if (typeof abs !== 'number') {
70
- console.error(`MUI: Expected ${propName} argument to be a number or a string, got ${abs}.`);
69
+ if (typeof val !== 'number') {
70
+ console.error(`MUI: Expected ${propName} argument to be a number or a string, got ${val}.`);
71
71
  }
72
72
  }
73
- return themeSpacing * abs;
73
+ if (typeof themeSpacing === 'string') {
74
+ return `calc(${val} * ${themeSpacing})`;
75
+ }
76
+ return themeSpacing * val;
74
77
  };
75
78
  }
76
79
  if (Array.isArray(themeSpacing)) {
77
- return abs => {
78
- if (typeof abs === 'string') {
79
- return abs;
80
+ return val => {
81
+ if (typeof val === 'string') {
82
+ return val;
80
83
  }
84
+ const abs = Math.abs(val);
81
85
  if (process.env.NODE_ENV !== 'production') {
82
86
  if (!Number.isInteger(abs)) {
83
87
  console.error([`MUI: The \`theme.${themeKey}\` array type cannot be combined with non integer values.` + `You should either use an integer value that can be used as index, or define the \`theme.${themeKey}\` as a number.`].join('\n'));
@@ -85,7 +89,14 @@ function createUnaryUnit(theme, themeKey, defaultValue, propName) {
85
89
  console.error([`MUI: The value provided (${abs}) overflows.`, `The supported values are: ${JSON.stringify(themeSpacing)}.`, `${abs} > ${themeSpacing.length - 1}, you need to add the missing values.`].join('\n'));
86
90
  }
87
91
  }
88
- return themeSpacing[abs];
92
+ const transformed = themeSpacing[abs];
93
+ if (val >= 0) {
94
+ return transformed;
95
+ }
96
+ if (typeof transformed === 'number') {
97
+ return -transformed;
98
+ }
99
+ return `-${transformed}`;
89
100
  };
90
101
  }
91
102
  if (typeof themeSpacing === 'function') {
@@ -103,15 +114,7 @@ function getValue(transformer, propValue) {
103
114
  if (typeof propValue === 'string' || propValue == null) {
104
115
  return propValue;
105
116
  }
106
- const abs = Math.abs(propValue);
107
- const transformed = transformer(abs);
108
- if (propValue >= 0) {
109
- return transformed;
110
- }
111
- if (typeof transformed === 'number') {
112
- return -transformed;
113
- }
114
- return `-${transformed}`;
117
+ return transformer(propValue);
115
118
  }
116
119
  function getStyleFromPropValue(cssProperties, transformer) {
117
120
  return propValue => cssProperties.reduce((acc, cssProperty) => {
@@ -10,6 +10,7 @@ var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
10
10
  var _merge = _interopRequireDefault(require("../merge"));
11
11
  var _style = require("../style");
12
12
  var _breakpoints = require("../breakpoints");
13
+ var _cssContainerQueries = require("../cssContainerQueries");
13
14
  var _defaultSxConfig = _interopRequireDefault(require("./defaultSxConfig"));
14
15
  function objectsHaveSameKeys(...objects) {
15
16
  const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
@@ -124,7 +125,7 @@ function unstable_createStyleFunctionSx() {
124
125
  }
125
126
  }
126
127
  });
127
- return (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css);
128
+ return (0, _cssContainerQueries.sortContainerQueries)(theme, (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css));
128
129
  }
129
130
  return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
130
131
  }