@mui/system 5.10.13 → 5.10.15
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/Box/Box.js +1 -10
- package/Box/index.js +0 -2
- package/CHANGELOG.md +132 -2
- package/Container/Container.js +2 -17
- package/Container/containerClasses.js +0 -3
- package/Container/createContainer.js +15 -37
- package/Container/index.js +0 -6
- package/Stack/Stack.js +1 -12
- package/Stack/createStack.js +10 -48
- package/Stack/index.js +0 -9
- package/Stack/stackClasses.js +0 -3
- package/ThemeProvider/ThemeProvider.js +2 -22
- package/ThemeProvider/index.js +0 -2
- package/Unstable_Grid/Grid.js +6 -42
- package/Unstable_Grid/createGrid.js +19 -49
- package/Unstable_Grid/gridClasses.js +8 -7
- package/Unstable_Grid/gridGenerator.d.ts +4 -3
- package/Unstable_Grid/gridGenerator.js +22 -63
- package/Unstable_Grid/index.js +0 -9
- package/borders.js +0 -14
- package/breakpoints.js +3 -32
- package/colorManipulator.js +13 -55
- package/compose.js +0 -7
- package/createBox.js +5 -20
- package/createStyled.js +27 -71
- package/createTheme/createBreakpoints.js +22 -37
- package/createTheme/createSpacing.js +4 -8
- package/createTheme/createTheme.js +6 -16
- package/createTheme/index.js +0 -2
- package/cssGrid.js +0 -21
- package/cssVars/createCssVarsProvider.js +33 -74
- package/cssVars/createGetCssVar.js +2 -7
- package/cssVars/cssVarsParser.js +3 -15
- package/cssVars/getInitColorSchemeScript.js +0 -6
- package/cssVars/index.js +0 -3
- package/cssVars/useCurrentColorScheme.js +20 -49
- package/display.js +0 -6
- package/esm/Box/Box.js +1 -6
- package/esm/Container/Container.js +3 -14
- package/esm/Container/createContainer.js +15 -25
- package/esm/Stack/Stack.js +1 -9
- package/esm/Stack/createStack.js +10 -29
- package/esm/ThemeProvider/ThemeProvider.js +2 -11
- package/esm/Unstable_Grid/Grid.js +6 -39
- package/esm/Unstable_Grid/createGrid.js +18 -35
- package/esm/Unstable_Grid/gridClasses.js +8 -4
- package/esm/Unstable_Grid/gridGenerator.js +20 -38
- package/esm/borders.js +0 -6
- package/esm/breakpoints.js +7 -22
- package/esm/colorManipulator.js +13 -43
- package/esm/compose.js +0 -5
- package/esm/createBox.js +5 -7
- package/esm/createStyled.js +27 -64
- package/esm/createTheme/createBreakpoints.js +22 -34
- package/esm/createTheme/createSpacing.js +4 -7
- package/esm/createTheme/createTheme.js +6 -9
- package/esm/cssGrid.js +0 -9
- package/esm/cssVars/createCssVarsProvider.js +33 -60
- package/esm/cssVars/createGetCssVar.js +2 -6
- package/esm/cssVars/cssVarsParser.js +3 -11
- package/esm/cssVars/useCurrentColorScheme.js +20 -44
- package/esm/getThemeValue.js +0 -2
- package/esm/index.js +3 -3
- package/esm/memoize.js +0 -1
- package/esm/merge.js +0 -3
- package/esm/palette.js +0 -3
- package/esm/propsToClassKey.js +4 -7
- package/esm/sizing.js +0 -5
- package/esm/spacing.js +3 -23
- package/esm/style.js +5 -22
- package/esm/styleFunctionSx/extendSxProp.js +3 -10
- package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
- package/esm/sx/sx.js +0 -2
- package/esm/useTheme.js +0 -2
- package/esm/useThemeProps/getThemeProps.js +0 -2
- package/esm/useThemeWithoutDefault.js +0 -3
- package/flexbox.js +0 -4
- package/getThemeValue.js +0 -14
- package/index.d.ts +2 -0
- package/index.js +16 -55
- package/legacy/Box/Box.js +1 -6
- package/legacy/Container/Container.js +3 -14
- package/legacy/Container/createContainer.js +29 -39
- package/legacy/Stack/Stack.js +1 -9
- package/legacy/Stack/createStack.js +17 -37
- package/legacy/ThemeProvider/ThemeProvider.js +3 -12
- package/legacy/Unstable_Grid/Grid.js +6 -39
- package/legacy/Unstable_Grid/createGrid.js +34 -53
- package/legacy/Unstable_Grid/gridGenerator.js +36 -58
- package/legacy/borders.js +0 -6
- package/legacy/breakpoints.js +9 -28
- package/legacy/colorManipulator.js +16 -48
- package/legacy/compose.js +0 -6
- package/legacy/createBox.js +9 -11
- package/legacy/createStyled.js +27 -68
- package/legacy/createTheme/createBreakpoints.js +20 -33
- package/legacy/createTheme/createSpacing.js +4 -9
- package/legacy/createTheme/createTheme.js +7 -13
- package/legacy/cssGrid.js +0 -9
- package/legacy/cssVars/createCssVarsProvider.js +98 -130
- package/legacy/cssVars/createGetCssVar.js +2 -10
- package/legacy/cssVars/cssVarsParser.js +7 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
- package/legacy/cssVars/useCurrentColorScheme.js +43 -69
- package/legacy/getThemeValue.js +0 -3
- package/legacy/index.js +4 -4
- package/legacy/memoize.js +0 -1
- package/legacy/merge.js +0 -3
- package/legacy/palette.js +0 -3
- package/legacy/propsToClassKey.js +2 -5
- package/legacy/sizing.js +0 -5
- package/legacy/spacing.js +6 -27
- package/legacy/style.js +9 -27
- package/legacy/styleFunctionSx/extendSxProp.js +3 -11
- package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
- package/legacy/sx/sx.js +0 -2
- package/legacy/useTheme.js +0 -2
- package/legacy/useThemeProps/getThemeProps.js +2 -4
- package/legacy/useThemeProps/useThemeProps.js +2 -2
- package/legacy/useThemeWithoutDefault.js +0 -3
- package/memoize.js +0 -2
- package/merge.js +0 -5
- package/modern/Box/Box.js +1 -6
- package/modern/Container/Container.js +3 -14
- package/modern/Container/createContainer.js +15 -25
- package/modern/Stack/Stack.js +1 -9
- package/modern/Stack/createStack.js +10 -29
- package/modern/ThemeProvider/ThemeProvider.js +2 -11
- package/modern/Unstable_Grid/Grid.js +6 -39
- package/modern/Unstable_Grid/createGrid.js +18 -34
- package/modern/Unstable_Grid/gridClasses.js +8 -4
- package/modern/Unstable_Grid/gridGenerator.js +20 -36
- package/modern/borders.js +0 -6
- package/modern/breakpoints.js +7 -21
- package/modern/colorManipulator.js +13 -43
- package/modern/compose.js +0 -5
- package/modern/createBox.js +5 -7
- package/modern/createStyled.js +27 -63
- package/modern/createTheme/createBreakpoints.js +22 -34
- package/modern/createTheme/createSpacing.js +4 -7
- package/modern/createTheme/createTheme.js +6 -9
- package/modern/cssGrid.js +0 -9
- package/modern/cssVars/createCssVarsProvider.js +33 -60
- package/modern/cssVars/createGetCssVar.js +2 -6
- package/modern/cssVars/cssVarsParser.js +3 -11
- package/modern/cssVars/useCurrentColorScheme.js +20 -44
- package/modern/getThemeValue.js +0 -2
- package/modern/index.js +4 -4
- package/modern/memoize.js +0 -1
- package/modern/merge.js +0 -3
- package/modern/palette.js +0 -3
- package/modern/propsToClassKey.js +4 -7
- package/modern/sizing.js +0 -4
- package/modern/spacing.js +3 -22
- package/modern/style.js +5 -22
- package/modern/styleFunctionSx/extendSxProp.js +3 -10
- package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
- package/modern/sx/sx.js +0 -2
- package/modern/useTheme.js +0 -2
- package/modern/useThemeProps/getThemeProps.js +0 -2
- package/modern/useThemeWithoutDefault.js +0 -3
- package/package.json +6 -6
- package/palette.js +0 -6
- package/positions.js +0 -6
- package/propsToClassKey.js +4 -10
- package/responsivePropType.d.ts +3 -0
- package/responsivePropType.js +0 -3
- package/shadows.js +0 -3
- package/sizing.js +0 -11
- package/spacing.d.ts +14 -0
- package/spacing.js +3 -37
- package/style.d.ts +6 -0
- package/style.js +6 -27
- package/styleFunctionSx/extendSxProp.js +3 -15
- package/styleFunctionSx/index.js +0 -5
- package/styleFunctionSx/styleFunctionSx.js +3 -21
- package/styled.js +0 -3
- package/sx/index.js +0 -2
- package/sx/sx.js +0 -4
- package/typography.js +0 -4
- package/useTheme.js +0 -6
- package/useThemeProps/getThemeProps.js +0 -4
- package/useThemeProps/index.js +0 -3
- package/useThemeProps/useThemeProps.js +0 -4
- package/useThemeWithoutDefault.js +0 -4
package/modern/createStyled.js
CHANGED
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"],
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
_excluded2 = ["theme"],
|
|
5
|
+
_excluded3 = ["theme"];
|
|
7
6
|
/* eslint-disable no-underscore-dangle */
|
|
8
7
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
9
8
|
import { getDisplayName } from '@mui/utils';
|
|
10
9
|
import createTheme from './createTheme';
|
|
11
10
|
import propsToClassKey from './propsToClassKey';
|
|
12
11
|
import defaultStyleFunctionSx from './styleFunctionSx';
|
|
13
|
-
|
|
14
12
|
function isEmpty(obj) {
|
|
15
13
|
return Object.keys(obj).length === 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
14
|
+
}
|
|
18
15
|
|
|
16
|
+
// https://github.com/emotion-js/emotion/blob/26ded6109fcd8ca9875cc2ce4564fee678a3f3c5/packages/styled/src/utils.js#L40
|
|
19
17
|
function isStringTag(tag) {
|
|
20
|
-
return typeof tag === 'string' &&
|
|
18
|
+
return typeof tag === 'string' &&
|
|
19
|
+
// 96 is one less than the char code
|
|
21
20
|
// for "a" so this is checking that
|
|
22
21
|
// it's a lowercase character
|
|
23
22
|
tag.charCodeAt(0) > 96;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
const getStyleOverrides = (name, theme) => {
|
|
27
25
|
if (theme.components && theme.components[name] && theme.components[name].styleOverrides) {
|
|
28
26
|
return theme.components[name].styleOverrides;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
return null;
|
|
32
29
|
};
|
|
33
|
-
|
|
34
30
|
const getVariantStyles = (name, theme) => {
|
|
35
31
|
let variants = [];
|
|
36
|
-
|
|
37
32
|
if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
|
|
38
33
|
variants = theme.components[name].variants;
|
|
39
34
|
}
|
|
40
|
-
|
|
41
35
|
const variantsStyles = {};
|
|
42
36
|
variants.forEach(definition => {
|
|
43
37
|
const key = propsToClassKey(definition.props);
|
|
@@ -45,14 +39,12 @@ const getVariantStyles = (name, theme) => {
|
|
|
45
39
|
});
|
|
46
40
|
return variantsStyles;
|
|
47
41
|
};
|
|
48
|
-
|
|
49
42
|
const variantsResolver = (props, styles, theme, name) => {
|
|
50
43
|
const {
|
|
51
44
|
ownerState = {}
|
|
52
45
|
} = props;
|
|
53
46
|
const variantsStyles = [];
|
|
54
47
|
const themeVariants = theme?.components?.[name]?.variants;
|
|
55
|
-
|
|
56
48
|
if (themeVariants) {
|
|
57
49
|
themeVariants.forEach(themeVariant => {
|
|
58
50
|
let isMatch = true;
|
|
@@ -61,26 +53,22 @@ const variantsResolver = (props, styles, theme, name) => {
|
|
|
61
53
|
isMatch = false;
|
|
62
54
|
}
|
|
63
55
|
});
|
|
64
|
-
|
|
65
56
|
if (isMatch) {
|
|
66
57
|
variantsStyles.push(styles[propsToClassKey(themeVariant.props)]);
|
|
67
58
|
}
|
|
68
59
|
});
|
|
69
60
|
}
|
|
70
|
-
|
|
71
61
|
return variantsStyles;
|
|
72
|
-
};
|
|
73
|
-
|
|
62
|
+
};
|
|
74
63
|
|
|
64
|
+
// Update /system/styled/#api in case if this changes
|
|
75
65
|
export function shouldForwardProp(prop) {
|
|
76
66
|
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
77
67
|
}
|
|
78
68
|
export const systemDefaultTheme = createTheme();
|
|
79
|
-
|
|
80
69
|
const lowercaseFirstLetter = string => {
|
|
81
70
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
82
71
|
};
|
|
83
|
-
|
|
84
72
|
export default function createStyled(input = {}) {
|
|
85
73
|
const {
|
|
86
74
|
defaultTheme = systemDefaultTheme,
|
|
@@ -88,41 +76,35 @@ export default function createStyled(input = {}) {
|
|
|
88
76
|
slotShouldForwardProp = shouldForwardProp,
|
|
89
77
|
styleFunctionSx = defaultStyleFunctionSx
|
|
90
78
|
} = input;
|
|
91
|
-
|
|
92
79
|
const systemSx = props => {
|
|
93
80
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
94
81
|
return styleFunctionSx(_extends({}, props, {
|
|
95
82
|
theme
|
|
96
83
|
}));
|
|
97
84
|
};
|
|
98
|
-
|
|
99
85
|
systemSx.__mui_systemSx = true;
|
|
100
86
|
return (tag, inputOptions = {}) => {
|
|
101
87
|
// Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
|
|
102
88
|
processStyles(tag, styles => styles.filter(style => !style?.__mui_systemSx));
|
|
103
|
-
|
|
104
89
|
const {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
90
|
+
name: componentName,
|
|
91
|
+
slot: componentSlot,
|
|
92
|
+
skipVariantsResolver: inputSkipVariantsResolver,
|
|
93
|
+
skipSx: inputSkipSx,
|
|
94
|
+
overridesResolver
|
|
95
|
+
} = inputOptions,
|
|
96
|
+
options = _objectWithoutPropertiesLoose(inputOptions, _excluded);
|
|
97
|
+
|
|
98
|
+
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
114
99
|
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver : componentSlot && componentSlot !== 'Root' || false;
|
|
115
100
|
const skipSx = inputSkipSx || false;
|
|
116
101
|
let label;
|
|
117
|
-
|
|
118
102
|
if (process.env.NODE_ENV !== 'production') {
|
|
119
103
|
if (componentName) {
|
|
120
104
|
label = `${componentName}-${lowercaseFirstLetter(componentSlot || 'Root')}`;
|
|
121
105
|
}
|
|
122
106
|
}
|
|
123
|
-
|
|
124
107
|
let shouldForwardPropOption = shouldForwardProp;
|
|
125
|
-
|
|
126
108
|
if (componentSlot === 'Root') {
|
|
127
109
|
shouldForwardPropOption = rootShouldForwardProp;
|
|
128
110
|
} else if (componentSlot) {
|
|
@@ -132,12 +114,10 @@ export default function createStyled(input = {}) {
|
|
|
132
114
|
// for string (html) tag, preserve the behavior in emotion & styled-components.
|
|
133
115
|
shouldForwardPropOption = undefined;
|
|
134
116
|
}
|
|
135
|
-
|
|
136
117
|
const defaultStyledResolver = styledEngineStyled(tag, _extends({
|
|
137
118
|
shouldForwardProp: shouldForwardPropOption,
|
|
138
119
|
label
|
|
139
120
|
}, options));
|
|
140
|
-
|
|
141
121
|
const muiStyledResolver = (styleArg, ...expressions) => {
|
|
142
122
|
const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
|
|
143
123
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
@@ -145,22 +125,19 @@ export default function createStyled(input = {}) {
|
|
|
145
125
|
// which are basically components used as a selectors.
|
|
146
126
|
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
|
|
147
127
|
let {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
128
|
+
theme: themeInput
|
|
129
|
+
} = _ref,
|
|
130
|
+
other = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
152
131
|
return stylesArg(_extends({
|
|
153
132
|
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
154
133
|
}, other));
|
|
155
134
|
} : stylesArg;
|
|
156
135
|
}) : [];
|
|
157
136
|
let transformedStyleArg = styleArg;
|
|
158
|
-
|
|
159
137
|
if (componentName && overridesResolver) {
|
|
160
138
|
expressionsWithDefaultTheme.push(props => {
|
|
161
139
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
162
140
|
const styleOverrides = getStyleOverrides(componentName, theme);
|
|
163
|
-
|
|
164
141
|
if (styleOverrides) {
|
|
165
142
|
const resolvedStyleOverrides = {};
|
|
166
143
|
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
@@ -170,69 +147,56 @@ export default function createStyled(input = {}) {
|
|
|
170
147
|
});
|
|
171
148
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
172
149
|
}
|
|
173
|
-
|
|
174
150
|
return null;
|
|
175
151
|
});
|
|
176
152
|
}
|
|
177
|
-
|
|
178
153
|
if (componentName && !skipVariantsResolver) {
|
|
179
154
|
expressionsWithDefaultTheme.push(props => {
|
|
180
155
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
181
156
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
182
157
|
});
|
|
183
158
|
}
|
|
184
|
-
|
|
185
159
|
if (!skipSx) {
|
|
186
160
|
expressionsWithDefaultTheme.push(systemSx);
|
|
187
161
|
}
|
|
188
|
-
|
|
189
162
|
const numOfCustomFnsApplied = expressionsWithDefaultTheme.length - expressions.length;
|
|
190
|
-
|
|
191
163
|
if (Array.isArray(styleArg) && numOfCustomFnsApplied > 0) {
|
|
192
|
-
const placeholders = new Array(numOfCustomFnsApplied).fill('');
|
|
193
|
-
|
|
164
|
+
const placeholders = new Array(numOfCustomFnsApplied).fill('');
|
|
165
|
+
// If the type is array, than we need to add placeholders in the template for the overrides, variants and the sx styles.
|
|
194
166
|
transformedStyleArg = [...styleArg, ...placeholders];
|
|
195
167
|
transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
|
|
196
|
-
} else if (typeof styleArg === 'function' &&
|
|
168
|
+
} else if (typeof styleArg === 'function' &&
|
|
169
|
+
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
197
170
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
198
171
|
// which are basically components used as a selectors.
|
|
199
172
|
styleArg.__emotion_real !== styleArg) {
|
|
200
173
|
// If the type is function, we need to define the default theme.
|
|
201
174
|
transformedStyleArg = _ref2 => {
|
|
202
175
|
let {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
176
|
+
theme: themeInput
|
|
177
|
+
} = _ref2,
|
|
178
|
+
other = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
207
179
|
return styleArg(_extends({
|
|
208
180
|
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
209
181
|
}, other));
|
|
210
182
|
};
|
|
211
183
|
}
|
|
212
|
-
|
|
213
184
|
const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
|
|
214
|
-
|
|
215
185
|
if (process.env.NODE_ENV !== 'production') {
|
|
216
186
|
let displayName;
|
|
217
|
-
|
|
218
187
|
if (componentName) {
|
|
219
188
|
displayName = `${componentName}${componentSlot || ''}`;
|
|
220
189
|
}
|
|
221
|
-
|
|
222
190
|
if (displayName === undefined) {
|
|
223
191
|
displayName = `Styled(${getDisplayName(tag)})`;
|
|
224
192
|
}
|
|
225
|
-
|
|
226
193
|
Component.displayName = displayName;
|
|
227
194
|
}
|
|
228
|
-
|
|
229
195
|
return Component;
|
|
230
196
|
};
|
|
231
|
-
|
|
232
197
|
if (defaultStyledResolver.withConfig) {
|
|
233
198
|
muiStyledResolver.withConfig = defaultStyledResolver.withConfig;
|
|
234
199
|
}
|
|
235
|
-
|
|
236
200
|
return muiStyledResolver;
|
|
237
201
|
};
|
|
238
202
|
}
|
|
@@ -4,84 +4,72 @@ const _excluded = ["values", "unit", "step"];
|
|
|
4
4
|
// Sorted ASC by size. That's important.
|
|
5
5
|
// It can't be configured as it's used statically for propTypes.
|
|
6
6
|
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
7
|
-
|
|
8
7
|
const sortBreakpointsValues = values => {
|
|
9
8
|
const breakpointsAsArray = Object.keys(values).map(key => ({
|
|
10
9
|
key,
|
|
11
10
|
val: values[key]
|
|
12
|
-
})) || [];
|
|
13
|
-
|
|
11
|
+
})) || [];
|
|
12
|
+
// Sort in ascending order
|
|
14
13
|
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
15
14
|
return breakpointsAsArray.reduce((acc, obj) => {
|
|
16
15
|
return _extends({}, acc, {
|
|
17
16
|
[obj.key]: obj.val
|
|
18
17
|
});
|
|
19
18
|
}, {});
|
|
20
|
-
};
|
|
21
|
-
|
|
19
|
+
};
|
|
22
20
|
|
|
21
|
+
// Keep in mind that @media is inclusive by the CSS specification.
|
|
23
22
|
export default function createBreakpoints(breakpoints) {
|
|
24
23
|
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
// The breakpoint **start** at this value.
|
|
25
|
+
// For instance with the first breakpoint xs: [xs, sm).
|
|
26
|
+
values = {
|
|
27
|
+
xs: 0,
|
|
28
|
+
// phone
|
|
29
|
+
sm: 600,
|
|
30
|
+
// tablet
|
|
31
|
+
md: 900,
|
|
32
|
+
// small laptop
|
|
33
|
+
lg: 1200,
|
|
34
|
+
// desktop
|
|
35
|
+
xl: 1536 // large screen
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
unit = 'px',
|
|
39
|
+
step = 5
|
|
40
|
+
} = breakpoints,
|
|
41
|
+
other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
|
|
44
42
|
const sortedValues = sortBreakpointsValues(values);
|
|
45
43
|
const keys = Object.keys(sortedValues);
|
|
46
|
-
|
|
47
44
|
function up(key) {
|
|
48
45
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
49
46
|
return `@media (min-width:${value}${unit})`;
|
|
50
47
|
}
|
|
51
|
-
|
|
52
48
|
function down(key) {
|
|
53
49
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
54
50
|
return `@media (max-width:${value - step / 100}${unit})`;
|
|
55
51
|
}
|
|
56
|
-
|
|
57
52
|
function between(start, end) {
|
|
58
53
|
const endIndex = keys.indexOf(end);
|
|
59
54
|
return `@media (min-width:${typeof values[start] === 'number' ? values[start] : start}${unit}) and ` + `(max-width:${(endIndex !== -1 && typeof values[keys[endIndex]] === 'number' ? values[keys[endIndex]] : end) - step / 100}${unit})`;
|
|
60
55
|
}
|
|
61
|
-
|
|
62
56
|
function only(key) {
|
|
63
57
|
if (keys.indexOf(key) + 1 < keys.length) {
|
|
64
58
|
return between(key, keys[keys.indexOf(key) + 1]);
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
return up(key);
|
|
68
61
|
}
|
|
69
|
-
|
|
70
62
|
function not(key) {
|
|
71
63
|
// handle first and last key separately, for better readability
|
|
72
64
|
const keyIndex = keys.indexOf(key);
|
|
73
|
-
|
|
74
65
|
if (keyIndex === 0) {
|
|
75
66
|
return up(keys[1]);
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
if (keyIndex === keys.length - 1) {
|
|
79
69
|
return down(keys[keyIndex]);
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
return _extends({
|
|
86
74
|
keys,
|
|
87
75
|
values: sortedValues,
|
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
import { createUnarySpacing } from '../spacing';
|
|
2
|
-
|
|
3
2
|
/* tslint:enable:unified-signatures */
|
|
3
|
+
|
|
4
4
|
export default function createSpacing(spacingInput = 8) {
|
|
5
5
|
// Already transformed.
|
|
6
6
|
if (spacingInput.mui) {
|
|
7
7
|
return spacingInput;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
|
|
9
11
|
// Smaller components, such as icons, can align to a 4dp grid.
|
|
10
12
|
// https://m2.material.io/design/layout/understanding-layout.html
|
|
11
|
-
|
|
12
|
-
|
|
13
13
|
const transform = createUnarySpacing({
|
|
14
14
|
spacing: spacingInput
|
|
15
15
|
});
|
|
16
|
-
|
|
17
16
|
const spacing = (...argsInput) => {
|
|
18
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
19
18
|
if (!(argsInput.length <= 4)) {
|
|
20
19
|
console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${argsInput.length}`);
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
const args = argsInput.length === 0 ? [1] : argsInput;
|
|
25
23
|
return args.map(argument => {
|
|
26
24
|
const output = transform(argument);
|
|
27
25
|
return typeof output === 'number' ? `${output}px` : output;
|
|
28
26
|
}).join(' ');
|
|
29
27
|
};
|
|
30
|
-
|
|
31
28
|
spacing.mui = true;
|
|
32
29
|
return spacing;
|
|
33
30
|
}
|
|
@@ -5,16 +5,14 @@ import { deepmerge } from '@mui/utils';
|
|
|
5
5
|
import createBreakpoints from './createBreakpoints';
|
|
6
6
|
import shape from './shape';
|
|
7
7
|
import createSpacing from './createSpacing';
|
|
8
|
-
|
|
9
8
|
function createTheme(options = {}, ...args) {
|
|
10
9
|
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
breakpoints: breakpointsInput = {},
|
|
11
|
+
palette: paletteInput = {},
|
|
12
|
+
spacing: spacingInput,
|
|
13
|
+
shape: shapeInput = {}
|
|
14
|
+
} = options,
|
|
15
|
+
other = _objectWithoutPropertiesLoose(options, _excluded);
|
|
18
16
|
const breakpoints = createBreakpoints(breakpointsInput);
|
|
19
17
|
const spacing = createSpacing(spacingInput);
|
|
20
18
|
let muiTheme = deepmerge({
|
|
@@ -31,5 +29,4 @@ function createTheme(options = {}, ...args) {
|
|
|
31
29
|
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
32
30
|
return muiTheme;
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
export default createTheme;
|
package/modern/cssGrid.js
CHANGED
|
@@ -6,14 +6,11 @@ import responsivePropType from './responsivePropType';
|
|
|
6
6
|
export const gap = props => {
|
|
7
7
|
if (props.gap !== undefined && props.gap !== null) {
|
|
8
8
|
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'gap');
|
|
9
|
-
|
|
10
9
|
const styleFromPropValue = propValue => ({
|
|
11
10
|
gap: getValue(transformer, propValue)
|
|
12
11
|
});
|
|
13
|
-
|
|
14
12
|
return handleBreakpoints(props, props.gap, styleFromPropValue);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return null;
|
|
18
15
|
};
|
|
19
16
|
gap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
@@ -23,14 +20,11 @@ gap.filterProps = ['gap'];
|
|
|
23
20
|
export const columnGap = props => {
|
|
24
21
|
if (props.columnGap !== undefined && props.columnGap !== null) {
|
|
25
22
|
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'columnGap');
|
|
26
|
-
|
|
27
23
|
const styleFromPropValue = propValue => ({
|
|
28
24
|
columnGap: getValue(transformer, propValue)
|
|
29
25
|
});
|
|
30
|
-
|
|
31
26
|
return handleBreakpoints(props, props.columnGap, styleFromPropValue);
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
return null;
|
|
35
29
|
};
|
|
36
30
|
columnGap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
@@ -40,14 +34,11 @@ columnGap.filterProps = ['columnGap'];
|
|
|
40
34
|
export const rowGap = props => {
|
|
41
35
|
if (props.rowGap !== undefined && props.rowGap !== null) {
|
|
42
36
|
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'rowGap');
|
|
43
|
-
|
|
44
37
|
const styleFromPropValue = propValue => ({
|
|
45
38
|
rowGap: getValue(transformer, propValue)
|
|
46
39
|
});
|
|
47
|
-
|
|
48
40
|
return handleBreakpoints(props, props.rowGap, styleFromPropValue);
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
return null;
|
|
52
43
|
};
|
|
53
44
|
rowGap.propTypes = process.env.NODE_ENV !== 'production' ? {
|