@mui/system 6.0.0-alpha.1 → 6.0.0-alpha.11
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.
- package/CHANGELOG.md +538 -4
- package/Container/Container.d.ts +1 -1
- package/Container/createContainer.js +39 -35
- package/RtlProvider/index.js +8 -11
- package/Stack/Stack.d.ts +1 -1
- package/Stack/createStack.d.ts +1 -1
- package/Stack/createStack.js +24 -26
- package/ThemeProvider/ThemeProvider.js +9 -5
- package/Unstable_Grid/Grid.d.ts +1 -1
- package/Unstable_Grid/Grid.js +0 -4
- package/Unstable_Grid/GridProps.d.ts +0 -4
- package/Unstable_Grid/createGrid.d.ts +1 -1
- package/Unstable_Grid/createGrid.js +21 -48
- package/Unstable_Grid/gridGenerator.d.ts +1 -3
- package/Unstable_Grid/gridGenerator.js +15 -21
- package/breakpoints/breakpoints.js +26 -7
- package/createBox/createBox.js +9 -12
- package/createStyled/createStyled.js +56 -51
- package/createTheme/applyStyles.d.ts +1 -1
- package/createTheme/applyStyles.js +1 -1
- package/createTheme/createBreakpoints.js +24 -25
- package/createTheme/createTheme.d.ts +2 -1
- package/createTheme/createTheme.js +20 -14
- package/cssContainerQueries/cssContainerQueries.d.ts +24 -0
- package/cssContainerQueries/cssContainerQueries.js +70 -0
- package/cssContainerQueries/index.d.ts +3 -0
- package/cssContainerQueries/index.js +2 -0
- package/cssContainerQueries/package.json +6 -0
- package/cssVars/createCssVarsProvider.d.ts +1 -1
- package/cssVars/createCssVarsProvider.js +17 -16
- package/cssVars/createCssVarsTheme.js +3 -3
- package/cssVars/cssVarsParser.d.ts +1 -1
- package/cssVars/index.d.ts +2 -0
- package/cssVars/index.js +1 -0
- package/cssVars/prepareCssVars.js +30 -25
- package/cssVars/prepareTypographyVars.d.ts +8 -0
- package/cssVars/prepareTypographyVars.js +11 -0
- package/cssVars/useCurrentColorScheme.js +18 -11
- package/index.d.ts +2 -0
- package/index.js +2 -1
- package/modern/Container/createContainer.js +39 -35
- package/modern/RtlProvider/index.js +8 -11
- package/modern/Stack/createStack.js +24 -26
- package/modern/ThemeProvider/ThemeProvider.js +9 -5
- package/modern/Unstable_Grid/Grid.js +0 -4
- package/modern/Unstable_Grid/createGrid.js +21 -48
- package/modern/Unstable_Grid/gridGenerator.js +15 -21
- package/modern/breakpoints/breakpoints.js +26 -7
- package/modern/createBox/createBox.js +9 -12
- package/modern/createStyled/createStyled.js +56 -51
- package/modern/createTheme/applyStyles.js +1 -1
- package/modern/createTheme/createBreakpoints.js +24 -25
- package/modern/createTheme/createTheme.js +20 -14
- package/modern/cssContainerQueries/cssContainerQueries.js +70 -0
- package/modern/cssContainerQueries/index.js +2 -0
- package/modern/cssVars/createCssVarsProvider.js +17 -16
- package/modern/cssVars/createCssVarsTheme.js +3 -3
- package/modern/cssVars/index.js +1 -0
- package/modern/cssVars/prepareCssVars.js +30 -25
- package/modern/cssVars/prepareTypographyVars.js +11 -0
- package/modern/cssVars/useCurrentColorScheme.js +18 -11
- package/modern/index.js +2 -1
- package/modern/propsToClassKey/propsToClassKey.js +3 -5
- package/modern/styleFunctionSx/defaultSxConfig.js +3 -0
- package/modern/styleFunctionSx/extendSxProp.js +14 -10
- package/modern/styleFunctionSx/styleFunctionSx.js +2 -1
- package/modern/useMediaQuery/useMediaQuery.js +5 -14
- package/node/Container/createContainer.js +39 -35
- package/node/RtlProvider/index.js +8 -11
- package/node/Stack/createStack.js +24 -26
- package/node/ThemeProvider/ThemeProvider.js +9 -5
- package/node/Unstable_Grid/Grid.js +0 -4
- package/node/Unstable_Grid/createGrid.js +24 -51
- package/node/Unstable_Grid/gridGenerator.js +15 -22
- package/node/breakpoints/breakpoints.js +26 -7
- package/node/createBox/createBox.js +9 -12
- package/node/createStyled/createStyled.js +58 -52
- package/node/createTheme/applyStyles.js +1 -1
- package/node/createTheme/createBreakpoints.js +24 -26
- package/node/createTheme/createTheme.js +20 -14
- package/node/cssContainerQueries/cssContainerQueries.js +81 -0
- package/node/cssContainerQueries/index.js +32 -0
- package/node/cssVars/createCssVarsProvider.js +17 -16
- package/node/cssVars/createCssVarsTheme.js +3 -3
- package/node/cssVars/index.js +7 -0
- package/node/cssVars/prepareCssVars.js +30 -25
- package/node/cssVars/prepareTypographyVars.js +17 -0
- package/node/cssVars/useCurrentColorScheme.js +18 -12
- package/node/index.js +9 -1
- package/node/propsToClassKey/propsToClassKey.js +3 -5
- package/node/styleFunctionSx/defaultSxConfig.js +3 -0
- package/node/styleFunctionSx/extendSxProp.js +14 -10
- package/node/styleFunctionSx/styleFunctionSx.js +2 -1
- package/node/useMediaQuery/useMediaQuery.js +5 -14
- package/package.json +6 -6
- package/propsToClassKey/propsToClassKey.js +3 -5
- package/styleFunctionSx/defaultSxConfig.js +3 -0
- package/styleFunctionSx/extendSxProp.js +14 -10
- package/styleFunctionSx/styleFunctionSx.js +2 -1
- package/useMediaQuery/useMediaQuery.js +5 -14
- package/legacy/Box/Box.js +0 -30
- package/legacy/Box/boxClasses.js +0 -3
- package/legacy/Box/index.js +0 -5
- package/legacy/Container/Container.js +0 -61
- package/legacy/Container/ContainerProps.js +0 -1
- package/legacy/Container/containerClasses.js +0 -7
- package/legacy/Container/createContainer.js +0 -140
- package/legacy/Container/index.js +0 -5
- package/legacy/GlobalStyles/GlobalStyles.js +0 -37
- package/legacy/GlobalStyles/index.js +0 -4
- package/legacy/RtlProvider/index.js +0 -22
- package/legacy/Stack/Stack.js +0 -62
- package/legacy/Stack/StackProps.js +0 -1
- package/legacy/Stack/createStack.js +0 -180
- package/legacy/Stack/index.js +0 -7
- package/legacy/Stack/stackClasses.js +0 -7
- package/legacy/ThemeProvider/ThemeProvider.js +0 -87
- package/legacy/ThemeProvider/index.js +0 -3
- package/legacy/Unstable_Grid/Grid.js +0 -177
- package/legacy/Unstable_Grid/GridProps.js +0 -1
- package/legacy/Unstable_Grid/createGrid.js +0 -184
- package/legacy/Unstable_Grid/gridClasses.js +0 -28
- package/legacy/Unstable_Grid/gridGenerator.js +0 -216
- package/legacy/Unstable_Grid/index.js +0 -8
- package/legacy/Unstable_Grid/traverseBreakpoints.js +0 -48
- package/legacy/borders/borders.js +0 -51
- package/legacy/borders/index.js +0 -4
- package/legacy/breakpoints/breakpoints.js +0 -162
- package/legacy/breakpoints/index.js +0 -4
- package/legacy/colorManipulator/colorManipulator.js +0 -356
- package/legacy/colorManipulator/index.js +0 -3
- package/legacy/compose/compose.js +0 -32
- package/legacy/compose/index.js +0 -3
- package/legacy/createBox/createBox.js +0 -38
- package/legacy/createBox/index.js +0 -3
- package/legacy/createStyled/createStyled.js +0 -250
- package/legacy/createStyled/index.js +0 -4
- package/legacy/createTheme/applyStyles.js +0 -73
- package/legacy/createTheme/createBreakpoints.js +0 -83
- package/legacy/createTheme/createSpacing.js +0 -32
- package/legacy/createTheme/createTheme.js +0 -49
- package/legacy/createTheme/index.js +0 -3
- package/legacy/createTheme/shape.js +0 -4
- package/legacy/cssGrid/cssGrid.js +0 -91
- package/legacy/cssGrid/index.js +0 -4
- package/legacy/cssVars/createCssVarsProvider.js +0 -338
- package/legacy/cssVars/createCssVarsTheme.js +0 -13
- package/legacy/cssVars/createGetCssVar.js +0 -30
- package/legacy/cssVars/cssVarsParser.js +0 -141
- package/legacy/cssVars/getInitColorSchemeScript.js +0 -28
- package/legacy/cssVars/index.js +0 -6
- package/legacy/cssVars/prepareCssVars.js +0 -92
- package/legacy/cssVars/useCurrentColorScheme.js +0 -237
- package/legacy/display/display.js +0 -29
- package/legacy/display/index.js +0 -4
- package/legacy/flexbox/flexbox.js +0 -43
- package/legacy/flexbox/index.js +0 -4
- package/legacy/getThemeValue/getThemeValue.js +0 -47
- package/legacy/getThemeValue/index.js +0 -4
- package/legacy/index.js +0 -72
- package/legacy/memoize/index.js +0 -3
- package/legacy/memoize/memoize.js +0 -9
- package/legacy/merge/index.js +0 -3
- package/legacy/merge/merge.js +0 -10
- package/legacy/palette/index.js +0 -4
- package/legacy/palette/palette.js +0 -26
- package/legacy/positions/index.js +0 -4
- package/legacy/positions/positions.js +0 -22
- package/legacy/propsToClassKey/index.js +0 -3
- package/legacy/propsToClassKey/propsToClassKey.js +0 -24
- package/legacy/responsivePropType/index.js +0 -3
- package/legacy/responsivePropType/responsivePropType.js +0 -3
- package/legacy/shadows/index.js +0 -3
- package/legacy/shadows/shadows.js +0 -6
- package/legacy/sizing/index.js +0 -4
- package/legacy/sizing/sizing.js +0 -65
- package/legacy/spacing/index.js +0 -4
- package/legacy/spacing/spacing.js +0 -161
- package/legacy/style/index.js +0 -4
- package/legacy/style/style.js +0 -73
- package/legacy/styleFunctionSx/defaultSxConfig.js +0 -293
- package/legacy/styleFunctionSx/extendSxProp.js +0 -45
- package/legacy/styleFunctionSx/index.js +0 -4
- package/legacy/styleFunctionSx/styleFunctionSx.js +0 -126
- package/legacy/styled/index.js +0 -3
- package/legacy/styled/styled.js +0 -3
- package/legacy/typography/index.js +0 -4
- package/legacy/typography/typography.js +0 -37
- package/legacy/useMediaQuery/index.js +0 -2
- package/legacy/useMediaQuery/useMediaQuery.js +0 -145
- package/legacy/useTheme/index.js +0 -4
- package/legacy/useTheme/useTheme.js +0 -10
- package/legacy/useThemeProps/getThemeProps.js +0 -10
- package/legacy/useThemeProps/index.js +0 -4
- package/legacy/useThemeProps/useThemeProps.js +0 -20
- package/legacy/useThemeWithoutDefault/index.js +0 -3
- package/legacy/useThemeWithoutDefault/useThemeWithoutDefault.js +0 -13
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import { traverseBreakpoints } from './traverseBreakpoints';
|
|
3
2
|
function appendLevel(level) {
|
|
4
3
|
if (!level) {
|
|
@@ -32,7 +31,7 @@ export const generateGridSizeStyles = ({
|
|
|
32
31
|
theme,
|
|
33
32
|
ownerState
|
|
34
33
|
}) => {
|
|
35
|
-
const
|
|
34
|
+
const getParentSpacing = createGetParentSpacing(ownerState);
|
|
36
35
|
const styles = {};
|
|
37
36
|
traverseBreakpoints(theme.breakpoints, ownerState.gridSize, (appendStyle, value) => {
|
|
38
37
|
let style = {};
|
|
@@ -56,7 +55,7 @@ export const generateGridSizeStyles = ({
|
|
|
56
55
|
style = {
|
|
57
56
|
flexGrow: 0,
|
|
58
57
|
flexBasis: 'auto',
|
|
59
|
-
width: `calc(100% * ${value} / ${getParentColumns(ownerState)}${
|
|
58
|
+
width: `calc(100% * ${value} / ${getParentColumns(ownerState)} - (${getParentColumns(ownerState)} - ${value}) * (${getParentSpacing('column')} / ${getParentColumns(ownerState)}))`
|
|
60
59
|
};
|
|
61
60
|
}
|
|
62
61
|
appendStyle(styles, style);
|
|
@@ -67,6 +66,7 @@ export const generateGridOffsetStyles = ({
|
|
|
67
66
|
theme,
|
|
68
67
|
ownerState
|
|
69
68
|
}) => {
|
|
69
|
+
const getParentSpacing = createGetParentSpacing(ownerState);
|
|
70
70
|
const styles = {};
|
|
71
71
|
traverseBreakpoints(theme.breakpoints, ownerState.gridOffset, (appendStyle, value) => {
|
|
72
72
|
let style = {};
|
|
@@ -77,7 +77,7 @@ export const generateGridOffsetStyles = ({
|
|
|
77
77
|
}
|
|
78
78
|
if (typeof value === 'number') {
|
|
79
79
|
style = {
|
|
80
|
-
marginLeft: value === 0 ? '0px' : `calc(100% * ${value} / ${getParentColumns(ownerState)})`
|
|
80
|
+
marginLeft: value === 0 ? '0px' : `calc(100% * ${value} / ${getParentColumns(ownerState)} + ${getParentSpacing('column')} * ${value} / ${getParentColumns(ownerState)})`
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
appendStyle(styles, style);
|
|
@@ -162,24 +162,18 @@ export const generateGridStyles = ({
|
|
|
162
162
|
ownerState
|
|
163
163
|
}) => {
|
|
164
164
|
const getSelfSpacing = createGetSelfSpacing(ownerState);
|
|
165
|
-
|
|
166
|
-
return _extends({
|
|
165
|
+
return {
|
|
167
166
|
minWidth: 0,
|
|
168
|
-
boxSizing: 'border-box'
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}), (!ownerState.container || isNestedContainer(ownerState)) && _extends({
|
|
179
|
-
padding: `calc(${getParentSpacing('row')} / 2) calc(${getParentSpacing('column')} / 2)`
|
|
180
|
-
}, (ownerState.disableEqualOverflow || ownerState.parentDisableEqualOverflow) && {
|
|
181
|
-
padding: `${getParentSpacing('row')} 0px 0px ${getParentSpacing('column')}`
|
|
182
|
-
}));
|
|
167
|
+
boxSizing: 'border-box',
|
|
168
|
+
...(ownerState.container && {
|
|
169
|
+
display: 'flex',
|
|
170
|
+
flexWrap: 'wrap',
|
|
171
|
+
...(ownerState.wrap && ownerState.wrap !== 'wrap' && {
|
|
172
|
+
flexWrap: ownerState.wrap
|
|
173
|
+
}),
|
|
174
|
+
gap: `${getSelfSpacing('row')} ${getSelfSpacing('column')}`
|
|
175
|
+
})
|
|
176
|
+
};
|
|
183
177
|
};
|
|
184
178
|
export const generateSizeClassNames = gridSize => {
|
|
185
179
|
const classNames = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import PropTypes from 'prop-types';
|
|
3
2
|
import deepmerge from '@mui/utils/deepmerge';
|
|
4
3
|
import merge from '../merge';
|
|
4
|
+
import { isCqShorthand, getContainerQuery } from '../cssContainerQueries';
|
|
5
5
|
|
|
6
6
|
// The breakpoint **start** at this value.
|
|
7
7
|
// For instance with the first breakpoint xs: [xs, sm[.
|
|
@@ -22,6 +22,17 @@ const defaultBreakpoints = {
|
|
|
22
22
|
keys: ['xs', 'sm', 'md', 'lg', 'xl'],
|
|
23
23
|
up: key => `@media (min-width:${values[key]}px)`
|
|
24
24
|
};
|
|
25
|
+
const defaultContainerQueries = {
|
|
26
|
+
containerQueries: containerName => ({
|
|
27
|
+
up: key => {
|
|
28
|
+
let result = typeof key === 'number' ? key : values[key] || key;
|
|
29
|
+
if (typeof result === 'number') {
|
|
30
|
+
result = `${result}px`;
|
|
31
|
+
}
|
|
32
|
+
return containerName ? `@container ${containerName} (min-width:${result})` : `@container (min-width:${result})`;
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
};
|
|
25
36
|
export function handleBreakpoints(props, propValue, styleFromPropValue) {
|
|
26
37
|
const theme = props.theme || {};
|
|
27
38
|
if (Array.isArray(propValue)) {
|
|
@@ -34,8 +45,14 @@ export function handleBreakpoints(props, propValue, styleFromPropValue) {
|
|
|
34
45
|
if (typeof propValue === 'object') {
|
|
35
46
|
const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
|
|
36
47
|
return Object.keys(propValue).reduce((acc, breakpoint) => {
|
|
48
|
+
if (isCqShorthand(themeBreakpoints.keys, breakpoint)) {
|
|
49
|
+
const containerKey = getContainerQuery(theme.containerQueries ? theme : defaultContainerQueries, breakpoint);
|
|
50
|
+
if (containerKey) {
|
|
51
|
+
acc[containerKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
37
54
|
// key is breakpoint
|
|
38
|
-
if (Object.keys(themeBreakpoints.values || values).indexOf(breakpoint) !== -1) {
|
|
55
|
+
else if (Object.keys(themeBreakpoints.values || values).indexOf(breakpoint) !== -1) {
|
|
39
56
|
const mediaKey = themeBreakpoints.up(breakpoint);
|
|
40
57
|
acc[mediaKey] = styleFromPropValue(propValue[breakpoint], breakpoint);
|
|
41
58
|
} else {
|
|
@@ -58,21 +75,23 @@ function breakpoints(styleFunction) {
|
|
|
58
75
|
const extended = themeBreakpoints.keys.reduce((acc, key) => {
|
|
59
76
|
if (props[key]) {
|
|
60
77
|
acc = acc || {};
|
|
61
|
-
acc[themeBreakpoints.up(key)] = styleFunction(
|
|
62
|
-
theme
|
|
63
|
-
|
|
78
|
+
acc[themeBreakpoints.up(key)] = styleFunction({
|
|
79
|
+
theme,
|
|
80
|
+
...props[key]
|
|
81
|
+
});
|
|
64
82
|
}
|
|
65
83
|
return acc;
|
|
66
84
|
}, null);
|
|
67
85
|
return merge(base, extended);
|
|
68
86
|
};
|
|
69
|
-
newStyleFunction.propTypes = process.env.NODE_ENV !== 'production' ?
|
|
87
|
+
newStyleFunction.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
88
|
+
...styleFunction.propTypes,
|
|
70
89
|
xs: PropTypes.object,
|
|
71
90
|
sm: PropTypes.object,
|
|
72
91
|
md: PropTypes.object,
|
|
73
92
|
lg: PropTypes.object,
|
|
74
93
|
xl: PropTypes.object
|
|
75
|
-
}
|
|
94
|
+
} : {};
|
|
76
95
|
newStyleFunction.filterProps = ['xs', 'sm', 'md', 'lg', 'xl', ...styleFunction.filterProps];
|
|
77
96
|
return newStyleFunction;
|
|
78
97
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["className", "component"];
|
|
6
3
|
import * as React from 'react';
|
|
7
4
|
import clsx from 'clsx';
|
|
8
5
|
import styled from '@mui/styled-engine';
|
|
@@ -21,18 +18,18 @@ export default function createBox(options = {}) {
|
|
|
21
18
|
})(styleFunctionSx);
|
|
22
19
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
|
23
20
|
const theme = useTheme(defaultTheme);
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return /*#__PURE__*/_jsx(BoxRoot, _extends({
|
|
21
|
+
const {
|
|
22
|
+
className,
|
|
23
|
+
component = 'div',
|
|
24
|
+
...other
|
|
25
|
+
} = extendSxProp(inProps);
|
|
26
|
+
return /*#__PURE__*/_jsx(BoxRoot, {
|
|
31
27
|
as: component,
|
|
32
28
|
ref: ref,
|
|
33
29
|
className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
|
|
34
|
-
theme: themeId ? theme[themeId] || theme : theme
|
|
35
|
-
|
|
30
|
+
theme: themeId ? theme[themeId] || theme : theme,
|
|
31
|
+
...other
|
|
32
|
+
});
|
|
36
33
|
});
|
|
37
34
|
return Box;
|
|
38
35
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["ownerState"],
|
|
4
|
-
_excluded2 = ["variants"],
|
|
5
|
-
_excluded3 = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
6
1
|
/* eslint-disable no-underscore-dangle */
|
|
7
2
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
8
3
|
import { isPlainObject } from '@mui/utils/deepmerge';
|
|
@@ -47,31 +42,35 @@ function defaultOverridesResolver(slot) {
|
|
|
47
42
|
}
|
|
48
43
|
return (props, styles) => styles[slot];
|
|
49
44
|
}
|
|
50
|
-
function processStyleArg(callableStyle,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
45
|
+
function processStyleArg(callableStyle, {
|
|
46
|
+
ownerState,
|
|
47
|
+
...props
|
|
48
|
+
}) {
|
|
49
|
+
const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle({
|
|
50
|
+
ownerState,
|
|
51
|
+
...props
|
|
52
|
+
}) : callableStyle;
|
|
58
53
|
if (Array.isArray(resolvedStylesArg)) {
|
|
59
|
-
return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle,
|
|
60
|
-
ownerState
|
|
61
|
-
|
|
54
|
+
return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, {
|
|
55
|
+
ownerState,
|
|
56
|
+
...props
|
|
57
|
+
}));
|
|
62
58
|
}
|
|
59
|
+
const mergedState = {
|
|
60
|
+
...props,
|
|
61
|
+
...ownerState,
|
|
62
|
+
ownerState
|
|
63
|
+
};
|
|
63
64
|
if (!!resolvedStylesArg && typeof resolvedStylesArg === 'object' && Array.isArray(resolvedStylesArg.variants)) {
|
|
64
65
|
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
variants = [],
|
|
67
|
+
...otherStyles
|
|
68
|
+
} = resolvedStylesArg;
|
|
68
69
|
let result = otherStyles;
|
|
69
70
|
variants.forEach(variant => {
|
|
70
71
|
let isMatch = true;
|
|
71
72
|
if (typeof variant.props === 'function') {
|
|
72
|
-
isMatch = variant.props(
|
|
73
|
-
ownerState
|
|
74
|
-
}, props, ownerState));
|
|
73
|
+
isMatch = variant.props(mergedState);
|
|
75
74
|
} else {
|
|
76
75
|
Object.keys(variant.props).forEach(key => {
|
|
77
76
|
if (ownerState?.[key] !== variant.props[key] && props[key] !== variant.props[key]) {
|
|
@@ -83,9 +82,7 @@ function processStyleArg(callableStyle, _ref) {
|
|
|
83
82
|
if (!Array.isArray(result)) {
|
|
84
83
|
result = [result];
|
|
85
84
|
}
|
|
86
|
-
result.push(typeof variant.style === 'function' ? variant.style(
|
|
87
|
-
ownerState
|
|
88
|
-
}, props, ownerState)) : variant.style);
|
|
85
|
+
result.push(typeof variant.style === 'function' ? variant.style(mergedState) : variant.style);
|
|
89
86
|
}
|
|
90
87
|
});
|
|
91
88
|
return result;
|
|
@@ -100,27 +97,29 @@ export default function createStyled(input = {}) {
|
|
|
100
97
|
slotShouldForwardProp = shouldForwardProp
|
|
101
98
|
} = input;
|
|
102
99
|
const systemSx = props => {
|
|
103
|
-
return styleFunctionSx(
|
|
104
|
-
|
|
100
|
+
return styleFunctionSx({
|
|
101
|
+
...props,
|
|
102
|
+
theme: resolveTheme({
|
|
103
|
+
...props,
|
|
105
104
|
defaultTheme,
|
|
106
105
|
themeId
|
|
107
|
-
})
|
|
108
|
-
})
|
|
106
|
+
})
|
|
107
|
+
});
|
|
109
108
|
};
|
|
110
109
|
systemSx.__mui_systemSx = true;
|
|
111
110
|
return (tag, inputOptions = {}) => {
|
|
112
111
|
// Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
|
|
113
112
|
processStyles(tag, styles => styles.filter(style => !style?.__mui_systemSx));
|
|
114
113
|
const {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
name: componentName,
|
|
115
|
+
slot: componentSlot,
|
|
116
|
+
skipVariantsResolver: inputSkipVariantsResolver,
|
|
117
|
+
skipSx: inputSkipSx,
|
|
118
|
+
// TODO v6: remove `lowercaseFirstLetter()` in the next major release
|
|
119
|
+
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
120
|
+
overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot)),
|
|
121
|
+
...options
|
|
122
|
+
} = inputOptions;
|
|
124
123
|
|
|
125
124
|
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
126
125
|
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
|
|
@@ -149,22 +148,24 @@ export default function createStyled(input = {}) {
|
|
|
149
148
|
// for string (html) tag, preserve the behavior in emotion & styled-components.
|
|
150
149
|
shouldForwardPropOption = undefined;
|
|
151
150
|
}
|
|
152
|
-
const defaultStyledResolver = styledEngineStyled(tag,
|
|
151
|
+
const defaultStyledResolver = styledEngineStyled(tag, {
|
|
153
152
|
shouldForwardProp: shouldForwardPropOption,
|
|
154
|
-
label
|
|
155
|
-
|
|
153
|
+
label,
|
|
154
|
+
...options
|
|
155
|
+
});
|
|
156
156
|
const transformStyleArg = stylesArg => {
|
|
157
157
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
158
158
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
159
159
|
// which are basically components used as a selectors.
|
|
160
160
|
if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
|
|
161
|
-
return props => processStyleArg(stylesArg,
|
|
161
|
+
return props => processStyleArg(stylesArg, {
|
|
162
|
+
...props,
|
|
162
163
|
theme: resolveTheme({
|
|
163
164
|
theme: props.theme,
|
|
164
165
|
defaultTheme,
|
|
165
166
|
themeId
|
|
166
167
|
})
|
|
167
|
-
})
|
|
168
|
+
});
|
|
168
169
|
}
|
|
169
170
|
return stylesArg;
|
|
170
171
|
};
|
|
@@ -173,10 +174,11 @@ export default function createStyled(input = {}) {
|
|
|
173
174
|
const expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
|
|
174
175
|
if (componentName && overridesResolver) {
|
|
175
176
|
expressionsWithDefaultTheme.push(props => {
|
|
176
|
-
const theme = resolveTheme(
|
|
177
|
+
const theme = resolveTheme({
|
|
178
|
+
...props,
|
|
177
179
|
defaultTheme,
|
|
178
180
|
themeId
|
|
179
|
-
})
|
|
181
|
+
});
|
|
180
182
|
if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
|
|
181
183
|
return null;
|
|
182
184
|
}
|
|
@@ -184,25 +186,28 @@ export default function createStyled(input = {}) {
|
|
|
184
186
|
const resolvedStyleOverrides = {};
|
|
185
187
|
// TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
|
|
186
188
|
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
187
|
-
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle,
|
|
189
|
+
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, {
|
|
190
|
+
...props,
|
|
188
191
|
theme
|
|
189
|
-
})
|
|
192
|
+
});
|
|
190
193
|
});
|
|
191
194
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
197
|
if (componentName && !skipVariantsResolver) {
|
|
195
198
|
expressionsWithDefaultTheme.push(props => {
|
|
196
|
-
const theme = resolveTheme(
|
|
199
|
+
const theme = resolveTheme({
|
|
200
|
+
...props,
|
|
197
201
|
defaultTheme,
|
|
198
202
|
themeId
|
|
199
|
-
})
|
|
203
|
+
});
|
|
200
204
|
const themeVariants = theme?.components?.[componentName]?.variants;
|
|
201
205
|
return processStyleArg({
|
|
202
206
|
variants: themeVariants
|
|
203
|
-
},
|
|
207
|
+
}, {
|
|
208
|
+
...props,
|
|
204
209
|
theme
|
|
205
|
-
})
|
|
210
|
+
});
|
|
206
211
|
});
|
|
207
212
|
}
|
|
208
213
|
if (!skipSx) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
3
3
|
* It works with:
|
|
4
4
|
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
5
|
-
* - [CSS theme variables](https://mui.com/material-ui/
|
|
5
|
+
* - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/)
|
|
6
6
|
* - Zero-runtime engine
|
|
7
7
|
*
|
|
8
8
|
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["values", "unit", "step"];
|
|
4
1
|
// Sorted ASC by size. That's important.
|
|
5
2
|
// It can't be configured as it's used statically for propTypes.
|
|
6
3
|
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
@@ -12,32 +9,33 @@ const sortBreakpointsValues = values => {
|
|
|
12
9
|
// Sort in ascending order
|
|
13
10
|
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
14
11
|
return breakpointsAsArray.reduce((acc, obj) => {
|
|
15
|
-
return
|
|
12
|
+
return {
|
|
13
|
+
...acc,
|
|
16
14
|
[obj.key]: obj.val
|
|
17
|
-
}
|
|
15
|
+
};
|
|
18
16
|
}, {});
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
// Keep in mind that @media is inclusive by the CSS specification.
|
|
22
20
|
export default function createBreakpoints(breakpoints) {
|
|
23
21
|
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
// The breakpoint **start** at this value.
|
|
23
|
+
// For instance with the first breakpoint xs: [xs, sm).
|
|
24
|
+
values = {
|
|
25
|
+
xs: 0,
|
|
26
|
+
// phone
|
|
27
|
+
sm: 600,
|
|
28
|
+
// tablet
|
|
29
|
+
md: 900,
|
|
30
|
+
// small laptop
|
|
31
|
+
lg: 1200,
|
|
32
|
+
// desktop
|
|
33
|
+
xl: 1536 // large screen
|
|
34
|
+
},
|
|
35
|
+
unit = 'px',
|
|
36
|
+
step = 5,
|
|
37
|
+
...other
|
|
38
|
+
} = breakpoints;
|
|
41
39
|
const sortedValues = sortBreakpointsValues(values);
|
|
42
40
|
const keys = Object.keys(sortedValues);
|
|
43
41
|
function up(key) {
|
|
@@ -69,7 +67,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
69
67
|
}
|
|
70
68
|
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
71
69
|
}
|
|
72
|
-
return
|
|
70
|
+
return {
|
|
73
71
|
keys,
|
|
74
72
|
values: sortedValues,
|
|
75
73
|
up,
|
|
@@ -77,6 +75,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
77
75
|
between,
|
|
78
76
|
only,
|
|
79
77
|
not,
|
|
80
|
-
unit
|
|
81
|
-
|
|
78
|
+
unit,
|
|
79
|
+
...other
|
|
80
|
+
};
|
|
82
81
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["breakpoints", "palette", "spacing", "shape"];
|
|
4
1
|
import deepmerge from '@mui/utils/deepmerge';
|
|
5
2
|
import createBreakpoints from './createBreakpoints';
|
|
3
|
+
import cssContainerQueries from '../cssContainerQueries';
|
|
6
4
|
import shape from './shape';
|
|
7
5
|
import createSpacing from './createSpacing';
|
|
8
6
|
import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
|
|
@@ -10,12 +8,12 @@ import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
|
|
|
10
8
|
import applyStyles from './applyStyles';
|
|
11
9
|
function createTheme(options = {}, ...args) {
|
|
12
10
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
breakpoints: breakpointsInput = {},
|
|
12
|
+
palette: paletteInput = {},
|
|
13
|
+
spacing: spacingInput,
|
|
14
|
+
shape: shapeInput = {},
|
|
15
|
+
...other
|
|
16
|
+
} = options;
|
|
19
17
|
const breakpoints = createBreakpoints(breakpointsInput);
|
|
20
18
|
const spacing = createSpacing(spacingInput);
|
|
21
19
|
let muiTheme = deepmerge({
|
|
@@ -23,15 +21,23 @@ function createTheme(options = {}, ...args) {
|
|
|
23
21
|
direction: 'ltr',
|
|
24
22
|
components: {},
|
|
25
23
|
// Inject component definitions.
|
|
26
|
-
palette:
|
|
27
|
-
mode: 'light'
|
|
28
|
-
|
|
24
|
+
palette: {
|
|
25
|
+
mode: 'light',
|
|
26
|
+
...paletteInput
|
|
27
|
+
},
|
|
29
28
|
spacing,
|
|
30
|
-
shape:
|
|
29
|
+
shape: {
|
|
30
|
+
...shape,
|
|
31
|
+
...shapeInput
|
|
32
|
+
}
|
|
31
33
|
}, other);
|
|
34
|
+
muiTheme = cssContainerQueries(muiTheme);
|
|
32
35
|
muiTheme.applyStyles = applyStyles;
|
|
33
36
|
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
34
|
-
muiTheme.unstable_sxConfig =
|
|
37
|
+
muiTheme.unstable_sxConfig = {
|
|
38
|
+
...defaultSxConfig,
|
|
39
|
+
...other?.unstable_sxConfig
|
|
40
|
+
};
|
|
35
41
|
muiTheme.unstable_sx = function sx(props) {
|
|
36
42
|
return styleFunctionSx({
|
|
37
43
|
sx: props,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
|
|
2
|
+
/**
|
|
3
|
+
* For using in `sx` prop to sort the breakpoint from low to high.
|
|
4
|
+
* Note: this function does not work and will not support multiple units.
|
|
5
|
+
* e.g. input: { '@container (min-width:300px)': '1rem', '@container (min-width:40rem)': '2rem' }
|
|
6
|
+
* output: { '@container (min-width:40rem)': '2rem', '@container (min-width:300px)': '1rem' } // since 40 < 300 eventhough 40rem > 300px
|
|
7
|
+
*/
|
|
8
|
+
export function sortContainerQueries(theme, css) {
|
|
9
|
+
if (!theme.containerQueries) {
|
|
10
|
+
return css;
|
|
11
|
+
}
|
|
12
|
+
const sorted = Object.keys(css).filter(key => key.startsWith('@container')).sort((a, b) => {
|
|
13
|
+
const regex = /min-width:\s*([0-9.]+)/;
|
|
14
|
+
return +(a.match(regex)?.[1] || 0) - +(b.match(regex)?.[1] || 0);
|
|
15
|
+
});
|
|
16
|
+
if (!sorted.length) {
|
|
17
|
+
return css;
|
|
18
|
+
}
|
|
19
|
+
return sorted.reduce((acc, key) => {
|
|
20
|
+
const value = css[key];
|
|
21
|
+
delete acc[key];
|
|
22
|
+
acc[key] = value;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {
|
|
25
|
+
...css
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function isCqShorthand(breakpointKeys, value) {
|
|
29
|
+
return value === '@' || value.startsWith('@') && (breakpointKeys.some(key => value.startsWith(`@${key}`)) || !!value.match(/^@\d/));
|
|
30
|
+
}
|
|
31
|
+
export function getContainerQuery(theme, shorthand) {
|
|
32
|
+
const matches = shorthand.match(/^@([^/]+)?\/?(.+)?$/);
|
|
33
|
+
if (!matches) {
|
|
34
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
+
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>\`.
|
|
36
|
+
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.` : _formatMuiErrorMessage(21, `(${shorthand})`));
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const [, containerQuery, containerName] = matches;
|
|
41
|
+
const value = Number.isNaN(+containerQuery) ? containerQuery || 0 : +containerQuery;
|
|
42
|
+
return theme.containerQueries(containerName).up(value);
|
|
43
|
+
}
|
|
44
|
+
export default function cssContainerQueries(themeInput) {
|
|
45
|
+
const toContainerQuery = (mediaQuery, name) => mediaQuery.replace('@media', name ? `@container ${name}` : '@container');
|
|
46
|
+
function attachCq(node, name) {
|
|
47
|
+
node.up = (...args) => toContainerQuery(themeInput.breakpoints.up(...args), name);
|
|
48
|
+
node.down = (...args) => toContainerQuery(themeInput.breakpoints.down(...args), name);
|
|
49
|
+
node.between = (...args) => toContainerQuery(themeInput.breakpoints.between(...args), name);
|
|
50
|
+
node.only = (...args) => toContainerQuery(themeInput.breakpoints.only(...args), name);
|
|
51
|
+
node.not = (...args) => {
|
|
52
|
+
const result = toContainerQuery(themeInput.breakpoints.not(...args), name);
|
|
53
|
+
if (result.includes('not all and')) {
|
|
54
|
+
// `@container` does not work with `not all and`, so need to invert the logic
|
|
55
|
+
return result.replace('not all and ', '').replace('min-width:', 'width<').replace('max-width:', 'width>').replace('and', 'or');
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const node = {};
|
|
61
|
+
const containerQueries = name => {
|
|
62
|
+
attachCq(node, name);
|
|
63
|
+
return node;
|
|
64
|
+
};
|
|
65
|
+
attachCq(containerQueries);
|
|
66
|
+
return {
|
|
67
|
+
...themeInput,
|
|
68
|
+
containerQueries
|
|
69
|
+
};
|
|
70
|
+
}
|