@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/esm/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,16 +39,13 @@ const getVariantStyles = (name, theme) => {
|
|
|
45
39
|
});
|
|
46
40
|
return variantsStyles;
|
|
47
41
|
};
|
|
48
|
-
|
|
49
42
|
const variantsResolver = (props, styles, theme, name) => {
|
|
50
43
|
var _theme$components, _theme$components$nam;
|
|
51
|
-
|
|
52
44
|
const {
|
|
53
45
|
ownerState = {}
|
|
54
46
|
} = props;
|
|
55
47
|
const variantsStyles = [];
|
|
56
48
|
const themeVariants = theme == null ? void 0 : (_theme$components = theme.components) == null ? void 0 : (_theme$components$nam = _theme$components[name]) == null ? void 0 : _theme$components$nam.variants;
|
|
57
|
-
|
|
58
49
|
if (themeVariants) {
|
|
59
50
|
themeVariants.forEach(themeVariant => {
|
|
60
51
|
let isMatch = true;
|
|
@@ -63,26 +54,22 @@ const variantsResolver = (props, styles, theme, name) => {
|
|
|
63
54
|
isMatch = false;
|
|
64
55
|
}
|
|
65
56
|
});
|
|
66
|
-
|
|
67
57
|
if (isMatch) {
|
|
68
58
|
variantsStyles.push(styles[propsToClassKey(themeVariant.props)]);
|
|
69
59
|
}
|
|
70
60
|
});
|
|
71
61
|
}
|
|
72
|
-
|
|
73
62
|
return variantsStyles;
|
|
74
|
-
};
|
|
75
|
-
|
|
63
|
+
};
|
|
76
64
|
|
|
65
|
+
// Update /system/styled/#api in case if this changes
|
|
77
66
|
export function shouldForwardProp(prop) {
|
|
78
67
|
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
79
68
|
}
|
|
80
69
|
export const systemDefaultTheme = createTheme();
|
|
81
|
-
|
|
82
70
|
const lowercaseFirstLetter = string => {
|
|
83
71
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
84
72
|
};
|
|
85
|
-
|
|
86
73
|
export default function createStyled(input = {}) {
|
|
87
74
|
const {
|
|
88
75
|
defaultTheme = systemDefaultTheme,
|
|
@@ -90,41 +77,35 @@ export default function createStyled(input = {}) {
|
|
|
90
77
|
slotShouldForwardProp = shouldForwardProp,
|
|
91
78
|
styleFunctionSx = defaultStyleFunctionSx
|
|
92
79
|
} = input;
|
|
93
|
-
|
|
94
80
|
const systemSx = props => {
|
|
95
81
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
96
82
|
return styleFunctionSx(_extends({}, props, {
|
|
97
83
|
theme
|
|
98
84
|
}));
|
|
99
85
|
};
|
|
100
|
-
|
|
101
86
|
systemSx.__mui_systemSx = true;
|
|
102
87
|
return (tag, inputOptions = {}) => {
|
|
103
88
|
// Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
|
|
104
89
|
processStyles(tag, styles => styles.filter(style => !(style != null && style.__mui_systemSx)));
|
|
105
|
-
|
|
106
90
|
const {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
name: componentName,
|
|
92
|
+
slot: componentSlot,
|
|
93
|
+
skipVariantsResolver: inputSkipVariantsResolver,
|
|
94
|
+
skipSx: inputSkipSx,
|
|
95
|
+
overridesResolver
|
|
96
|
+
} = inputOptions,
|
|
97
|
+
options = _objectWithoutPropertiesLoose(inputOptions, _excluded);
|
|
98
|
+
|
|
99
|
+
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
116
100
|
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver : componentSlot && componentSlot !== 'Root' || false;
|
|
117
101
|
const skipSx = inputSkipSx || false;
|
|
118
102
|
let label;
|
|
119
|
-
|
|
120
103
|
if (process.env.NODE_ENV !== 'production') {
|
|
121
104
|
if (componentName) {
|
|
122
105
|
label = `${componentName}-${lowercaseFirstLetter(componentSlot || 'Root')}`;
|
|
123
106
|
}
|
|
124
107
|
}
|
|
125
|
-
|
|
126
108
|
let shouldForwardPropOption = shouldForwardProp;
|
|
127
|
-
|
|
128
109
|
if (componentSlot === 'Root') {
|
|
129
110
|
shouldForwardPropOption = rootShouldForwardProp;
|
|
130
111
|
} else if (componentSlot) {
|
|
@@ -134,12 +115,10 @@ export default function createStyled(input = {}) {
|
|
|
134
115
|
// for string (html) tag, preserve the behavior in emotion & styled-components.
|
|
135
116
|
shouldForwardPropOption = undefined;
|
|
136
117
|
}
|
|
137
|
-
|
|
138
118
|
const defaultStyledResolver = styledEngineStyled(tag, _extends({
|
|
139
119
|
shouldForwardProp: shouldForwardPropOption,
|
|
140
120
|
label
|
|
141
121
|
}, options));
|
|
142
|
-
|
|
143
122
|
const muiStyledResolver = (styleArg, ...expressions) => {
|
|
144
123
|
const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
|
|
145
124
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
@@ -147,22 +126,19 @@ export default function createStyled(input = {}) {
|
|
|
147
126
|
// which are basically components used as a selectors.
|
|
148
127
|
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
|
|
149
128
|
let {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
129
|
+
theme: themeInput
|
|
130
|
+
} = _ref,
|
|
131
|
+
other = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
154
132
|
return stylesArg(_extends({
|
|
155
133
|
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
156
134
|
}, other));
|
|
157
135
|
} : stylesArg;
|
|
158
136
|
}) : [];
|
|
159
137
|
let transformedStyleArg = styleArg;
|
|
160
|
-
|
|
161
138
|
if (componentName && overridesResolver) {
|
|
162
139
|
expressionsWithDefaultTheme.push(props => {
|
|
163
140
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
164
141
|
const styleOverrides = getStyleOverrides(componentName, theme);
|
|
165
|
-
|
|
166
142
|
if (styleOverrides) {
|
|
167
143
|
const resolvedStyleOverrides = {};
|
|
168
144
|
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
@@ -172,69 +148,56 @@ export default function createStyled(input = {}) {
|
|
|
172
148
|
});
|
|
173
149
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
174
150
|
}
|
|
175
|
-
|
|
176
151
|
return null;
|
|
177
152
|
});
|
|
178
153
|
}
|
|
179
|
-
|
|
180
154
|
if (componentName && !skipVariantsResolver) {
|
|
181
155
|
expressionsWithDefaultTheme.push(props => {
|
|
182
156
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
183
157
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
184
158
|
});
|
|
185
159
|
}
|
|
186
|
-
|
|
187
160
|
if (!skipSx) {
|
|
188
161
|
expressionsWithDefaultTheme.push(systemSx);
|
|
189
162
|
}
|
|
190
|
-
|
|
191
163
|
const numOfCustomFnsApplied = expressionsWithDefaultTheme.length - expressions.length;
|
|
192
|
-
|
|
193
164
|
if (Array.isArray(styleArg) && numOfCustomFnsApplied > 0) {
|
|
194
|
-
const placeholders = new Array(numOfCustomFnsApplied).fill('');
|
|
195
|
-
|
|
165
|
+
const placeholders = new Array(numOfCustomFnsApplied).fill('');
|
|
166
|
+
// If the type is array, than we need to add placeholders in the template for the overrides, variants and the sx styles.
|
|
196
167
|
transformedStyleArg = [...styleArg, ...placeholders];
|
|
197
168
|
transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
|
|
198
|
-
} else if (typeof styleArg === 'function' &&
|
|
169
|
+
} else if (typeof styleArg === 'function' &&
|
|
170
|
+
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
199
171
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
200
172
|
// which are basically components used as a selectors.
|
|
201
173
|
styleArg.__emotion_real !== styleArg) {
|
|
202
174
|
// If the type is function, we need to define the default theme.
|
|
203
175
|
transformedStyleArg = _ref2 => {
|
|
204
176
|
let {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
177
|
+
theme: themeInput
|
|
178
|
+
} = _ref2,
|
|
179
|
+
other = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
209
180
|
return styleArg(_extends({
|
|
210
181
|
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
211
182
|
}, other));
|
|
212
183
|
};
|
|
213
184
|
}
|
|
214
|
-
|
|
215
185
|
const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
|
|
216
|
-
|
|
217
186
|
if (process.env.NODE_ENV !== 'production') {
|
|
218
187
|
let displayName;
|
|
219
|
-
|
|
220
188
|
if (componentName) {
|
|
221
189
|
displayName = `${componentName}${componentSlot || ''}`;
|
|
222
190
|
}
|
|
223
|
-
|
|
224
191
|
if (displayName === undefined) {
|
|
225
192
|
displayName = `Styled(${getDisplayName(tag)})`;
|
|
226
193
|
}
|
|
227
|
-
|
|
228
194
|
Component.displayName = displayName;
|
|
229
195
|
}
|
|
230
|
-
|
|
231
196
|
return Component;
|
|
232
197
|
};
|
|
233
|
-
|
|
234
198
|
if (defaultStyledResolver.withConfig) {
|
|
235
199
|
muiStyledResolver.withConfig = defaultStyledResolver.withConfig;
|
|
236
200
|
}
|
|
237
|
-
|
|
238
201
|
return muiStyledResolver;
|
|
239
202
|
};
|
|
240
203
|
}
|
|
@@ -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/esm/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' ? {
|