@mui/system 5.10.13 → 5.10.14
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/Box.spec.d.ts +1 -1
- package/Box/index.js +0 -2
- package/CHANGELOG.md +70 -2
- package/Container/Container.d.ts +13 -13
- package/Container/Container.js +2 -17
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/containerClasses.js +0 -3
- package/Container/createContainer.d.ts +18 -18
- package/Container/createContainer.js +15 -37
- package/Container/index.js +0 -6
- package/Stack/Stack.d.ts +13 -13
- package/Stack/Stack.js +1 -12
- package/Stack/StackProps.d.ts +42 -42
- package/Stack/createStack.d.ts +21 -21
- package/Stack/createStack.js +10 -48
- package/Stack/index.d.ts +5 -5
- package/Stack/index.js +0 -9
- package/Stack/stackClasses.d.ts +8 -8
- package/Stack/stackClasses.js +0 -3
- package/ThemeProvider/ThemeProvider.js +2 -22
- package/ThemeProvider/index.js +0 -2
- package/Unstable_Grid/Grid.d.ts +12 -12
- package/Unstable_Grid/Grid.js +6 -42
- package/Unstable_Grid/GridProps.d.ts +162 -162
- package/Unstable_Grid/createGrid.d.ts +11 -11
- package/Unstable_Grid/createGrid.js +19 -49
- package/Unstable_Grid/gridClasses.d.ts +20 -20
- package/Unstable_Grid/gridClasses.js +8 -7
- package/Unstable_Grid/gridGenerator.d.ts +29 -28
- package/Unstable_Grid/gridGenerator.js +22 -63
- package/Unstable_Grid/index.d.ts +5 -5
- 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/createBox.spec.d.ts +1 -1
- package/createStyled.js +27 -71
- package/createTheme/createBreakpoints.js +22 -37
- package/createTheme/createSpacing.d.ts +10 -10
- 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 +24 -72
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +2 -7
- package/cssVars/cssVarsParser.d.ts +65 -65
- package/cssVars/cssVarsParser.js +3 -15
- package/cssVars/getInitColorSchemeScript.d.ts +42 -42
- package/cssVars/getInitColorSchemeScript.js +0 -6
- package/cssVars/index.d.ts +3 -3
- package/cssVars/index.js +0 -3
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- 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 +24 -58
- 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 +1 -2
- 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 +2 -19
- 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.js +1 -55
- package/index.spec.d.ts +1 -1
- 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 +90 -129
- 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 +2 -3
- 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 +6 -24
- 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 +24 -58
- 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 +2 -3
- 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 +2 -19
- 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.js +0 -3
- package/shadows.js +0 -3
- package/sizing.js +0 -11
- package/spacing.js +3 -37
- package/style.js +2 -24
- package/styleFunctionSx/extendSxProp.js +3 -15
- package/styleFunctionSx/index.js +0 -5
- package/styleFunctionSx/styleFunctionSx.js +3 -21
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
- 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
|
@@ -4,63 +4,49 @@ import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from './ge
|
|
|
4
4
|
export function getSystemMode(mode) {
|
|
5
5
|
if (typeof window !== 'undefined' && mode === 'system') {
|
|
6
6
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
7
|
-
|
|
8
7
|
if (mql.matches) {
|
|
9
8
|
return 'dark';
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
return 'light';
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
return undefined;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function processState(state, callback) {
|
|
19
15
|
if (state.mode === 'light' || state.mode === 'system' && state.systemMode === 'light') {
|
|
20
16
|
return callback('light');
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
if (state.mode === 'dark' || state.mode === 'system' && state.systemMode === 'dark') {
|
|
24
19
|
return callback('dark');
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
return undefined;
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
export function getColorScheme(state) {
|
|
31
24
|
return processState(state, mode => {
|
|
32
25
|
if (mode === 'light') {
|
|
33
26
|
return state.lightColorScheme;
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
if (mode === 'dark') {
|
|
37
29
|
return state.darkColorScheme;
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
return undefined;
|
|
41
32
|
});
|
|
42
33
|
}
|
|
43
|
-
|
|
44
34
|
function initializeValue(key, defaultValue) {
|
|
45
35
|
if (typeof window === 'undefined') {
|
|
46
36
|
return undefined;
|
|
47
37
|
}
|
|
48
|
-
|
|
49
38
|
let value;
|
|
50
|
-
|
|
51
39
|
try {
|
|
52
40
|
value = localStorage.getItem(key) || undefined;
|
|
53
|
-
|
|
54
41
|
if (!value) {
|
|
55
42
|
// the first time that user enters the site.
|
|
56
43
|
localStorage.setItem(key, defaultValue);
|
|
57
44
|
}
|
|
58
|
-
} catch (e) {
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// Unsupported
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
return value || defaultValue;
|
|
62
49
|
}
|
|
63
|
-
|
|
64
50
|
export default function useCurrentColorScheme(options) {
|
|
65
51
|
const {
|
|
66
52
|
defaultMode = 'light',
|
|
@@ -90,14 +76,12 @@ export default function useCurrentColorScheme(options) {
|
|
|
90
76
|
// do nothing if mode does not change
|
|
91
77
|
return currentState;
|
|
92
78
|
}
|
|
93
|
-
|
|
94
79
|
const newMode = !mode ? defaultMode : mode;
|
|
95
|
-
|
|
96
80
|
try {
|
|
97
81
|
localStorage.setItem(modeStorageKey, newMode);
|
|
98
|
-
} catch (e) {
|
|
82
|
+
} catch (e) {
|
|
83
|
+
// Unsupported
|
|
99
84
|
}
|
|
100
|
-
|
|
101
85
|
return _extends({}, currentState, {
|
|
102
86
|
mode: newMode,
|
|
103
87
|
systemMode: getSystemMode(newMode)
|
|
@@ -110,9 +94,9 @@ export default function useCurrentColorScheme(options) {
|
|
|
110
94
|
try {
|
|
111
95
|
localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
112
96
|
localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
113
|
-
} catch (e) {
|
|
97
|
+
} catch (e) {
|
|
98
|
+
// Unsupported
|
|
114
99
|
}
|
|
115
|
-
|
|
116
100
|
return _extends({}, currentState, {
|
|
117
101
|
lightColorScheme: defaultLightColorScheme,
|
|
118
102
|
darkColorScheme: defaultDarkColorScheme
|
|
@@ -124,17 +108,15 @@ export default function useCurrentColorScheme(options) {
|
|
|
124
108
|
} else {
|
|
125
109
|
setState(currentState => {
|
|
126
110
|
const newState = _extends({}, currentState);
|
|
127
|
-
|
|
128
111
|
processState(currentState, mode => {
|
|
129
112
|
try {
|
|
130
113
|
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
131
|
-
} catch (e) {
|
|
114
|
+
} catch (e) {
|
|
115
|
+
// Unsupported
|
|
132
116
|
}
|
|
133
|
-
|
|
134
117
|
if (mode === 'light') {
|
|
135
118
|
newState.lightColorScheme = value;
|
|
136
119
|
}
|
|
137
|
-
|
|
138
120
|
if (mode === 'dark') {
|
|
139
121
|
newState.darkColorScheme = value;
|
|
140
122
|
}
|
|
@@ -145,36 +127,32 @@ export default function useCurrentColorScheme(options) {
|
|
|
145
127
|
} else {
|
|
146
128
|
setState(currentState => {
|
|
147
129
|
const newState = _extends({}, currentState);
|
|
148
|
-
|
|
149
130
|
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
150
131
|
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
151
|
-
|
|
152
132
|
if (newLightColorScheme) {
|
|
153
133
|
if (!joinedColorSchemes.includes(newLightColorScheme)) {
|
|
154
134
|
console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
155
135
|
} else {
|
|
156
136
|
newState.lightColorScheme = newLightColorScheme;
|
|
157
|
-
|
|
158
137
|
try {
|
|
159
138
|
localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
|
|
160
|
-
} catch (error) {
|
|
139
|
+
} catch (error) {
|
|
140
|
+
// Unsupported
|
|
161
141
|
}
|
|
162
142
|
}
|
|
163
143
|
}
|
|
164
|
-
|
|
165
144
|
if (newDarkColorScheme) {
|
|
166
145
|
if (!joinedColorSchemes.includes(newDarkColorScheme)) {
|
|
167
146
|
console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
168
147
|
} else {
|
|
169
148
|
newState.darkColorScheme = newDarkColorScheme;
|
|
170
|
-
|
|
171
149
|
try {
|
|
172
150
|
localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
|
|
173
|
-
} catch (error) {
|
|
151
|
+
} catch (error) {
|
|
152
|
+
// Unsupported
|
|
174
153
|
}
|
|
175
154
|
}
|
|
176
155
|
}
|
|
177
|
-
|
|
178
156
|
return newState;
|
|
179
157
|
});
|
|
180
158
|
}
|
|
@@ -185,25 +163,27 @@ export default function useCurrentColorScheme(options) {
|
|
|
185
163
|
systemMode: e?.matches ? 'dark' : 'light'
|
|
186
164
|
}));
|
|
187
165
|
}
|
|
188
|
-
}, [state.mode]);
|
|
166
|
+
}, [state.mode]);
|
|
189
167
|
|
|
168
|
+
// Ref hack to avoid adding handleMediaQuery as a dep
|
|
190
169
|
const mediaListener = React.useRef(handleMediaQuery);
|
|
191
170
|
mediaListener.current = handleMediaQuery;
|
|
192
171
|
React.useEffect(() => {
|
|
193
|
-
const handler = (...args) => mediaListener.current(...args);
|
|
172
|
+
const handler = (...args) => mediaListener.current(...args);
|
|
194
173
|
|
|
174
|
+
// Always listen to System preference
|
|
175
|
+
const media = window.matchMedia('(prefers-color-scheme: dark)');
|
|
195
176
|
|
|
196
|
-
|
|
197
|
-
|
|
177
|
+
// Intentionally use deprecated listener methods to support iOS & old browsers
|
|
198
178
|
media.addListener(handler);
|
|
199
179
|
handler(media);
|
|
200
180
|
return () => media.removeListener(handler);
|
|
201
|
-
}, []);
|
|
181
|
+
}, []);
|
|
202
182
|
|
|
183
|
+
// Handle when localStorage has changed
|
|
203
184
|
React.useEffect(() => {
|
|
204
185
|
const handleStorage = event => {
|
|
205
186
|
const value = event.newValue;
|
|
206
|
-
|
|
207
187
|
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
208
188
|
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
209
189
|
if (event.key.endsWith('light')) {
|
|
@@ -211,25 +191,21 @@ export default function useCurrentColorScheme(options) {
|
|
|
211
191
|
light: value
|
|
212
192
|
});
|
|
213
193
|
}
|
|
214
|
-
|
|
215
194
|
if (event.key.endsWith('dark')) {
|
|
216
195
|
setColorScheme({
|
|
217
196
|
dark: value
|
|
218
197
|
});
|
|
219
198
|
}
|
|
220
199
|
}
|
|
221
|
-
|
|
222
200
|
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
223
201
|
setMode(value || defaultMode);
|
|
224
202
|
}
|
|
225
203
|
};
|
|
226
|
-
|
|
227
204
|
if (storageWindow) {
|
|
228
205
|
// For syncing color-scheme changes between iframes
|
|
229
206
|
storageWindow.addEventListener('storage', handleStorage);
|
|
230
207
|
return () => storageWindow.removeEventListener('storage', handleStorage);
|
|
231
208
|
}
|
|
232
|
-
|
|
233
209
|
return undefined;
|
|
234
210
|
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
|
235
211
|
return _extends({}, state, {
|
package/modern/getThemeValue.js
CHANGED
|
@@ -38,7 +38,6 @@ export const propToStyleFunction = Object.keys(filterPropsMapping).reduce((acc,
|
|
|
38
38
|
});
|
|
39
39
|
return acc;
|
|
40
40
|
}, {});
|
|
41
|
-
|
|
42
41
|
function getThemeValue(prop, value, theme) {
|
|
43
42
|
const inputProps = {
|
|
44
43
|
[prop]: value,
|
|
@@ -49,5 +48,4 @@ function getThemeValue(prop, value, theme) {
|
|
|
49
48
|
[prop]: value
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
|
-
|
|
53
51
|
export default getThemeValue;
|
package/modern/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.10.
|
|
1
|
+
/** @license MUI v5.10.14
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -45,10 +45,9 @@ export * from './colorManipulator';
|
|
|
45
45
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
46
46
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
47
47
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
48
|
-
/** ----------------- */
|
|
49
48
|
|
|
49
|
+
/** ----------------- */
|
|
50
50
|
/** Layout components */
|
|
51
|
-
|
|
52
51
|
export { default as createContainer } from './Container/createContainer';
|
|
53
52
|
export { default as Container } from './Container';
|
|
54
53
|
export * from './Container';
|
package/modern/memoize.js
CHANGED
package/modern/merge.js
CHANGED
package/modern/palette.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import style from './style';
|
|
2
2
|
import compose from './compose';
|
|
3
|
-
|
|
4
3
|
function transform(value, userValue) {
|
|
5
4
|
if (userValue === 'grey') {
|
|
6
5
|
return userValue;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
return value;
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
export const color = style({
|
|
13
10
|
prop: 'color',
|
|
14
11
|
themeKey: 'palette',
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
const _excluded = ["variant"];
|
|
3
3
|
import { unstable_capitalize as capitalize } from '@mui/utils';
|
|
4
|
-
|
|
5
4
|
function isEmpty(string) {
|
|
6
5
|
return string.length === 0;
|
|
7
6
|
}
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* Generates string classKey based on the properties provided. It starts with the
|
|
10
10
|
* variant if defined, and then it appends all other properties in alphabetical order.
|
|
11
11
|
* @param {object} props - the properties for which the classKey should be created.
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
13
|
export default function propsToClassKey(props) {
|
|
16
14
|
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
variant
|
|
16
|
+
} = props,
|
|
17
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
21
18
|
let classKey = variant || '';
|
|
22
19
|
Object.keys(other).sort().forEach(key => {
|
|
23
20
|
if (key === 'color') {
|
package/modern/sizing.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import style from './style';
|
|
2
2
|
import compose from './compose';
|
|
3
3
|
import { handleBreakpoints, values as breakpointsValues } from './breakpoints';
|
|
4
|
-
|
|
5
4
|
function transform(value) {
|
|
6
5
|
return value <= 1 && value !== 0 ? `${value * 100}%` : value;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
export const width = style({
|
|
10
8
|
prop: 'width',
|
|
11
9
|
transform
|
|
@@ -18,10 +16,8 @@ export const maxWidth = props => {
|
|
|
18
16
|
maxWidth: breakpoint || transform(propValue)
|
|
19
17
|
};
|
|
20
18
|
};
|
|
21
|
-
|
|
22
19
|
return handleBreakpoints(props, props.maxWidth, styleFromPropValue);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
return null;
|
|
26
22
|
};
|
|
27
23
|
maxWidth.filterProps = ['maxWidth'];
|
package/modern/spacing.js
CHANGED
|
@@ -20,10 +20,11 @@ const aliases = {
|
|
|
20
20
|
marginY: 'my',
|
|
21
21
|
paddingX: 'px',
|
|
22
22
|
paddingY: 'py'
|
|
23
|
-
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// memoize() impact:
|
|
24
26
|
// From 300,000 ops/sec
|
|
25
27
|
// To 350,000 ops/sec
|
|
26
|
-
|
|
27
28
|
const getCssProperties = memoize(prop => {
|
|
28
29
|
// It's not a shorthand notation.
|
|
29
30
|
if (prop.length > 2) {
|
|
@@ -33,7 +34,6 @@ const getCssProperties = memoize(prop => {
|
|
|
33
34
|
return [prop];
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
|
|
37
37
|
const [a, b] = prop.split('');
|
|
38
38
|
const property = properties[a];
|
|
39
39
|
const direction = directions[b] || '';
|
|
@@ -44,29 +44,24 @@ const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddin
|
|
|
44
44
|
const spacingKeys = [...marginKeys, ...paddingKeys];
|
|
45
45
|
export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
|
|
46
46
|
const themeSpacing = getPath(theme, themeKey, false) ?? defaultValue;
|
|
47
|
-
|
|
48
47
|
if (typeof themeSpacing === 'number') {
|
|
49
48
|
return abs => {
|
|
50
49
|
if (typeof abs === 'string') {
|
|
51
50
|
return abs;
|
|
52
51
|
}
|
|
53
|
-
|
|
54
52
|
if (process.env.NODE_ENV !== 'production') {
|
|
55
53
|
if (typeof abs !== 'number') {
|
|
56
54
|
console.error(`MUI: Expected ${propName} argument to be a number or a string, got ${abs}.`);
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
|
-
|
|
60
57
|
return themeSpacing * abs;
|
|
61
58
|
};
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
if (Array.isArray(themeSpacing)) {
|
|
65
61
|
return abs => {
|
|
66
62
|
if (typeof abs === 'string') {
|
|
67
63
|
return abs;
|
|
68
64
|
}
|
|
69
|
-
|
|
70
65
|
if (process.env.NODE_ENV !== 'production') {
|
|
71
66
|
if (!Number.isInteger(abs)) {
|
|
72
67
|
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'));
|
|
@@ -74,19 +69,15 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
|
|
|
74
69
|
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'));
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
|
-
|
|
78
72
|
return themeSpacing[abs];
|
|
79
73
|
};
|
|
80
74
|
}
|
|
81
|
-
|
|
82
75
|
if (typeof themeSpacing === 'function') {
|
|
83
76
|
return themeSpacing;
|
|
84
77
|
}
|
|
85
|
-
|
|
86
78
|
if (process.env.NODE_ENV !== 'production') {
|
|
87
79
|
console.error([`MUI: The \`theme.${themeKey}\` value (${themeSpacing}) is invalid.`, 'It should be a number, an array or a function.'].join('\n'));
|
|
88
80
|
}
|
|
89
|
-
|
|
90
81
|
return () => undefined;
|
|
91
82
|
}
|
|
92
83
|
export function createUnarySpacing(theme) {
|
|
@@ -96,18 +87,14 @@ export function getValue(transformer, propValue) {
|
|
|
96
87
|
if (typeof propValue === 'string' || propValue == null) {
|
|
97
88
|
return propValue;
|
|
98
89
|
}
|
|
99
|
-
|
|
100
90
|
const abs = Math.abs(propValue);
|
|
101
91
|
const transformed = transformer(abs);
|
|
102
|
-
|
|
103
92
|
if (propValue >= 0) {
|
|
104
93
|
return transformed;
|
|
105
94
|
}
|
|
106
|
-
|
|
107
95
|
if (typeof transformed === 'number') {
|
|
108
96
|
return -transformed;
|
|
109
97
|
}
|
|
110
|
-
|
|
111
98
|
return `-${transformed}`;
|
|
112
99
|
}
|
|
113
100
|
export function getStyleFromPropValue(cssProperties, transformer) {
|
|
@@ -116,25 +103,21 @@ export function getStyleFromPropValue(cssProperties, transformer) {
|
|
|
116
103
|
return acc;
|
|
117
104
|
}, {});
|
|
118
105
|
}
|
|
119
|
-
|
|
120
106
|
function resolveCssProperty(props, keys, prop, transformer) {
|
|
121
107
|
// Using a hash computation over an array iteration could be faster, but with only 28 items,
|
|
122
108
|
// it's doesn't worth the bundle size.
|
|
123
109
|
if (keys.indexOf(prop) === -1) {
|
|
124
110
|
return null;
|
|
125
111
|
}
|
|
126
|
-
|
|
127
112
|
const cssProperties = getCssProperties(prop);
|
|
128
113
|
const styleFromPropValue = getStyleFromPropValue(cssProperties, transformer);
|
|
129
114
|
const propValue = props[prop];
|
|
130
115
|
return handleBreakpoints(props, propValue, styleFromPropValue);
|
|
131
116
|
}
|
|
132
|
-
|
|
133
117
|
function style(props, keys) {
|
|
134
118
|
const transformer = createUnarySpacing(props.theme);
|
|
135
119
|
return Object.keys(props).map(prop => resolveCssProperty(props, keys, prop, transformer)).reduce(merge, {});
|
|
136
120
|
}
|
|
137
|
-
|
|
138
121
|
export function margin(props) {
|
|
139
122
|
return style(props, marginKeys);
|
|
140
123
|
}
|
|
@@ -151,11 +134,9 @@ padding.propTypes = process.env.NODE_ENV !== 'production' ? paddingKeys.reduce((
|
|
|
151
134
|
return obj;
|
|
152
135
|
}, {}) : {};
|
|
153
136
|
padding.filterProps = paddingKeys;
|
|
154
|
-
|
|
155
137
|
function spacing(props) {
|
|
156
138
|
return style(props, spacingKeys);
|
|
157
139
|
}
|
|
158
|
-
|
|
159
140
|
spacing.propTypes = process.env.NODE_ENV !== 'production' ? spacingKeys.reduce((obj, key) => {
|
|
160
141
|
obj[key] = responsivePropType;
|
|
161
142
|
return obj;
|
package/modern/style.js
CHANGED
|
@@ -4,29 +4,24 @@ import { handleBreakpoints } from './breakpoints';
|
|
|
4
4
|
export function getPath(obj, path, checkVars = true) {
|
|
5
5
|
if (!path || typeof path !== 'string') {
|
|
6
6
|
return null;
|
|
7
|
-
}
|
|
8
|
-
|
|
7
|
+
}
|
|
9
8
|
|
|
9
|
+
// Check if CSS variables are used
|
|
10
10
|
if (obj && obj.vars && checkVars) {
|
|
11
11
|
const val = `vars.${path}`.split('.').reduce((acc, item) => acc && acc[item] ? acc[item] : null, obj);
|
|
12
|
-
|
|
13
12
|
if (val != null) {
|
|
14
13
|
return val;
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
return path.split('.').reduce((acc, item) => {
|
|
19
17
|
if (acc && acc[item] != null) {
|
|
20
18
|
return acc[item];
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
return null;
|
|
24
21
|
}, obj);
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
function getValue(themeMapping, transform, propValueFinal, userValue = propValueFinal) {
|
|
28
24
|
let value;
|
|
29
|
-
|
|
30
25
|
if (typeof themeMapping === 'function') {
|
|
31
26
|
value = themeMapping(propValueFinal);
|
|
32
27
|
} else if (Array.isArray(themeMapping)) {
|
|
@@ -34,14 +29,11 @@ function getValue(themeMapping, transform, propValueFinal, userValue = propValue
|
|
|
34
29
|
} else {
|
|
35
30
|
value = getPath(themeMapping, propValueFinal) || userValue;
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
if (transform) {
|
|
39
33
|
value = transform(value, userValue);
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
return value;
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
function style(options) {
|
|
46
38
|
const {
|
|
47
39
|
prop,
|
|
@@ -49,41 +41,32 @@ function style(options) {
|
|
|
49
41
|
themeKey,
|
|
50
42
|
transform
|
|
51
43
|
} = options;
|
|
52
|
-
|
|
53
44
|
const fn = props => {
|
|
54
45
|
if (props[prop] == null) {
|
|
55
46
|
return null;
|
|
56
47
|
}
|
|
57
|
-
|
|
58
48
|
const propValue = props[prop];
|
|
59
49
|
const theme = props.theme;
|
|
60
50
|
const themeMapping = getPath(theme, themeKey) || {};
|
|
61
|
-
|
|
62
51
|
const styleFromPropValue = propValueFinal => {
|
|
63
52
|
let value = getValue(themeMapping, transform, propValueFinal);
|
|
64
|
-
|
|
65
53
|
if (propValueFinal === value && typeof propValueFinal === 'string') {
|
|
66
54
|
// Haven't found value
|
|
67
55
|
value = getValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : capitalize(propValueFinal)}`, propValueFinal);
|
|
68
56
|
}
|
|
69
|
-
|
|
70
57
|
if (cssProperty === false) {
|
|
71
58
|
return value;
|
|
72
59
|
}
|
|
73
|
-
|
|
74
60
|
return {
|
|
75
61
|
[cssProperty]: value
|
|
76
62
|
};
|
|
77
63
|
};
|
|
78
|
-
|
|
79
64
|
return handleBreakpoints(props, propValue, styleFromPropValue);
|
|
80
65
|
};
|
|
81
|
-
|
|
82
66
|
fn.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
83
67
|
[prop]: responsivePropType
|
|
84
68
|
} : {};
|
|
85
69
|
fn.filterProps = [prop];
|
|
86
70
|
return fn;
|
|
87
71
|
}
|
|
88
|
-
|
|
89
72
|
export default style;
|
|
@@ -3,7 +3,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
3
3
|
const _excluded = ["sx"];
|
|
4
4
|
import { isPlainObject } from '@mui/utils';
|
|
5
5
|
import { propToStyleFunction } from '../getThemeValue';
|
|
6
|
-
|
|
7
6
|
const splitProps = props => {
|
|
8
7
|
const result = {
|
|
9
8
|
systemProps: {},
|
|
@@ -18,35 +17,29 @@ const splitProps = props => {
|
|
|
18
17
|
});
|
|
19
18
|
return result;
|
|
20
19
|
};
|
|
21
|
-
|
|
22
20
|
export default function extendSxProp(props) {
|
|
23
21
|
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
sx: inSx
|
|
23
|
+
} = props,
|
|
24
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
28
25
|
const {
|
|
29
26
|
systemProps,
|
|
30
27
|
otherProps
|
|
31
28
|
} = splitProps(other);
|
|
32
29
|
let finalSx;
|
|
33
|
-
|
|
34
30
|
if (Array.isArray(inSx)) {
|
|
35
31
|
finalSx = [systemProps, ...inSx];
|
|
36
32
|
} else if (typeof inSx === 'function') {
|
|
37
33
|
finalSx = (...args) => {
|
|
38
34
|
const result = inSx(...args);
|
|
39
|
-
|
|
40
35
|
if (!isPlainObject(result)) {
|
|
41
36
|
return systemProps;
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
return _extends({}, systemProps, result);
|
|
45
39
|
};
|
|
46
40
|
} else {
|
|
47
41
|
finalSx = _extends({}, systemProps, inSx);
|
|
48
42
|
}
|
|
49
|
-
|
|
50
43
|
return _extends({}, otherProps, {
|
|
51
44
|
sx: finalSx
|
|
52
45
|
});
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import merge from '../merge';
|
|
2
2
|
import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
|
|
3
3
|
import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
|
|
4
|
-
|
|
5
4
|
function objectsHaveSameKeys(...objects) {
|
|
6
5
|
const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
|
|
7
6
|
const union = new Set(allKeys);
|
|
8
7
|
return objects.every(object => union.size === Object.keys(object).length);
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
function callIfFn(maybeFn, arg) {
|
|
12
10
|
return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
|
|
13
|
-
}
|
|
14
|
-
|
|
11
|
+
}
|
|
15
12
|
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
14
|
export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultStyleFunctionMapping) {
|
|
17
15
|
const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
|
|
18
16
|
styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
|
|
@@ -20,7 +18,6 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
|
|
|
20
18
|
});
|
|
21
19
|
return acc;
|
|
22
20
|
}, {});
|
|
23
|
-
|
|
24
21
|
function getThemeValue(prop, value, theme) {
|
|
25
22
|
const inputProps = {
|
|
26
23
|
[prop]: value,
|
|
@@ -31,43 +28,36 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
|
|
|
31
28
|
[prop]: value
|
|
32
29
|
};
|
|
33
30
|
}
|
|
34
|
-
|
|
35
31
|
function styleFunctionSx(props) {
|
|
36
32
|
const {
|
|
37
33
|
sx,
|
|
38
34
|
theme = {}
|
|
39
35
|
} = props || {};
|
|
40
|
-
|
|
41
36
|
if (!sx) {
|
|
42
37
|
return null; // Emotion & styled-components will neglect null
|
|
43
38
|
}
|
|
39
|
+
|
|
44
40
|
/*
|
|
45
41
|
* Receive `sxInput` as object or callback
|
|
46
42
|
* and then recursively check keys & values to create media query object styles.
|
|
47
43
|
* (the result will be used in `styled`)
|
|
48
44
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
45
|
function traverse(sxInput) {
|
|
52
46
|
let sxObject = sxInput;
|
|
53
|
-
|
|
54
47
|
if (typeof sxInput === 'function') {
|
|
55
48
|
sxObject = sxInput(theme);
|
|
56
49
|
} else if (typeof sxInput !== 'object') {
|
|
57
50
|
// value
|
|
58
51
|
return sxInput;
|
|
59
52
|
}
|
|
60
|
-
|
|
61
53
|
if (!sxObject) {
|
|
62
54
|
return null;
|
|
63
55
|
}
|
|
64
|
-
|
|
65
56
|
const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
66
57
|
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
67
58
|
let css = emptyBreakpoints;
|
|
68
59
|
Object.keys(sxObject).forEach(styleKey => {
|
|
69
60
|
const value = callIfFn(sxObject[styleKey], theme);
|
|
70
|
-
|
|
71
61
|
if (value !== null && value !== undefined) {
|
|
72
62
|
if (typeof value === 'object') {
|
|
73
63
|
if (propToStyleFunction[styleKey]) {
|
|
@@ -78,7 +68,6 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
|
|
|
78
68
|
}, value, x => ({
|
|
79
69
|
[styleKey]: x
|
|
80
70
|
}));
|
|
81
|
-
|
|
82
71
|
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
83
72
|
css[styleKey] = styleFunctionSx({
|
|
84
73
|
sx: value,
|
|
@@ -95,10 +84,8 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
|
|
|
95
84
|
});
|
|
96
85
|
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
97
86
|
}
|
|
98
|
-
|
|
99
87
|
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
100
88
|
}
|
|
101
|
-
|
|
102
89
|
return styleFunctionSx;
|
|
103
90
|
}
|
|
104
91
|
const styleFunctionSx = unstable_createStyleFunctionSx();
|