@mui/system 5.0.6 → 5.2.1
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.spec.d.ts +1 -1
- package/CHANGELOG.md +299 -9
- package/LICENSE +21 -21
- package/breakpoints.js +42 -9
- package/createBox.d.ts +5 -1
- package/createBox.js +5 -3
- package/createTheme/createBreakpoints.js +2 -2
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +88 -38
- package/cssVars/createCssVarsProvider.js +84 -64
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/cssVarsParser.d.ts +68 -57
- package/cssVars/cssVarsParser.js +41 -11
- package/cssVars/getInitColorSchemeScript.d.ts +12 -7
- package/cssVars/getInitColorSchemeScript.js +27 -5
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -0
- package/cssVars/useCurrentColorScheme.js +235 -0
- package/esm/breakpoints.js +40 -9
- package/esm/createBox.js +5 -3
- package/esm/createTheme/createBreakpoints.js +2 -2
- package/esm/cssVars/createCssVarsProvider.js +83 -66
- package/esm/cssVars/cssVarsParser.js +40 -11
- package/esm/cssVars/getInitColorSchemeScript.js +24 -3
- package/esm/cssVars/useCurrentColorScheme.js +217 -0
- package/esm/index.js +1 -0
- package/esm/styleFunctionSx/extendSxProp.js +20 -1
- package/esm/styleFunctionSx/styleFunctionSx.js +47 -35
- package/esm/sx/index.js +1 -0
- package/esm/sx/sx.js +12 -0
- package/index.d.ts +2 -0
- package/index.js +10 -1
- package/index.spec.d.ts +1 -1
- package/legacy/breakpoints.js +40 -9
- package/legacy/createBox.js +6 -3
- package/legacy/createTheme/createBreakpoints.js +2 -2
- package/legacy/cssVars/createCssVarsProvider.js +85 -73
- package/legacy/cssVars/cssVarsParser.js +37 -9
- package/legacy/cssVars/getInitColorSchemeScript.js +12 -4
- package/legacy/cssVars/useCurrentColorScheme.js +231 -0
- package/legacy/index.js +2 -1
- package/legacy/styleFunctionSx/extendSxProp.js +21 -1
- package/legacy/styleFunctionSx/styleFunctionSx.js +47 -35
- package/legacy/sx/index.js +1 -0
- package/legacy/sx/sx.js +13 -0
- package/modern/breakpoints.js +40 -9
- package/modern/createBox.js +5 -3
- package/modern/createTheme/createBreakpoints.js +2 -2
- package/modern/cssVars/createCssVarsProvider.js +83 -66
- package/modern/cssVars/cssVarsParser.js +40 -11
- package/modern/cssVars/getInitColorSchemeScript.js +24 -3
- package/modern/cssVars/useCurrentColorScheme.js +217 -0
- package/modern/index.js +2 -1
- package/modern/styleFunctionSx/extendSxProp.js +20 -1
- package/modern/styleFunctionSx/styleFunctionSx.js +47 -35
- package/modern/sx/index.js +1 -0
- package/modern/sx/sx.js +12 -0
- package/package.json +8 -8
- package/styleFunctionSx/extendSxProp.js +21 -1
- package/styleFunctionSx/styleFunctionSx.d.ts +2 -1
- package/styleFunctionSx/styleFunctionSx.js +49 -37
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -0
- package/sx/index.d.ts +1 -0
- package/sx/index.js +15 -0
- package/sx/package.json +6 -0
- package/sx/sx.d.ts +4 -0
- package/sx/sx.js +22 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
4
|
+
export function getSystemMode(mode) {
|
|
5
|
+
if (typeof window !== 'undefined' && mode === 'system') {
|
|
6
|
+
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
7
|
+
|
|
8
|
+
if (mql.matches) {
|
|
9
|
+
return 'dark';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return 'light';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function processState(state, callback) {
|
|
19
|
+
if (state.mode === 'light' || state.mode === 'system' && state.systemMode === 'light') {
|
|
20
|
+
return callback('light');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (state.mode === 'dark' || state.mode === 'system' && state.systemMode === 'dark') {
|
|
24
|
+
return callback('dark');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getColorScheme(state) {
|
|
31
|
+
return processState(state, function (mode) {
|
|
32
|
+
if (mode === 'light') {
|
|
33
|
+
return state.lightColorScheme;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (mode === 'dark') {
|
|
37
|
+
return state.darkColorScheme;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return undefined;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveValue(key, defaultValue) {
|
|
45
|
+
if (typeof window === 'undefined') {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var value;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
value = localStorage.getItem(key) || undefined;
|
|
53
|
+
} catch (e) {// Unsupported
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return value || defaultValue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default function useCurrentColorScheme(options) {
|
|
60
|
+
var _options$defaultMode = options.defaultMode,
|
|
61
|
+
defaultMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
62
|
+
defaultLightColorScheme = options.defaultLightColorScheme,
|
|
63
|
+
defaultDarkColorScheme = options.defaultDarkColorScheme,
|
|
64
|
+
_options$supportedCol = options.supportedColorSchemes,
|
|
65
|
+
supportedColorSchemes = _options$supportedCol === void 0 ? [] : _options$supportedCol,
|
|
66
|
+
_options$modeStorageK = options.modeStorageKey,
|
|
67
|
+
modeStorageKey = _options$modeStorageK === void 0 ? DEFAULT_MODE_STORAGE_KEY : _options$modeStorageK,
|
|
68
|
+
_options$colorSchemeS = options.colorSchemeStorageKey,
|
|
69
|
+
colorSchemeStorageKey = _options$colorSchemeS === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _options$colorSchemeS;
|
|
70
|
+
var joinedColorSchemes = supportedColorSchemes.join(',');
|
|
71
|
+
|
|
72
|
+
var _React$useState = React.useState(function () {
|
|
73
|
+
var initialMode = resolveValue(modeStorageKey, defaultMode);
|
|
74
|
+
return {
|
|
75
|
+
mode: initialMode,
|
|
76
|
+
systemMode: getSystemMode(initialMode),
|
|
77
|
+
lightColorScheme: resolveValue("".concat(colorSchemeStorageKey, "-light")) || defaultLightColorScheme,
|
|
78
|
+
darkColorScheme: resolveValue("".concat(colorSchemeStorageKey, "-dark")) || defaultDarkColorScheme
|
|
79
|
+
};
|
|
80
|
+
}),
|
|
81
|
+
state = _React$useState[0],
|
|
82
|
+
setState = _React$useState[1];
|
|
83
|
+
|
|
84
|
+
var colorScheme = getColorScheme(state);
|
|
85
|
+
var setMode = React.useCallback(function (mode) {
|
|
86
|
+
setState(function (currentState) {
|
|
87
|
+
var newMode = !mode ? defaultMode : mode;
|
|
88
|
+
|
|
89
|
+
if (typeof localStorage !== 'undefined') {
|
|
90
|
+
localStorage.setItem(modeStorageKey, newMode);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return _extends({}, currentState, {
|
|
94
|
+
mode: newMode,
|
|
95
|
+
systemMode: getSystemMode(newMode)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}, [modeStorageKey, defaultMode]);
|
|
99
|
+
var setColorScheme = React.useCallback(function (value) {
|
|
100
|
+
if (!value || typeof value === 'string') {
|
|
101
|
+
if (value && !supportedColorSchemes.includes(value)) {
|
|
102
|
+
console.error("`".concat(value, "` does not exist in `theme.colorSchemes`."));
|
|
103
|
+
} else {
|
|
104
|
+
setState(function (currentState) {
|
|
105
|
+
var newState = _extends({}, currentState);
|
|
106
|
+
|
|
107
|
+
if (!value) {
|
|
108
|
+
// reset to default color scheme
|
|
109
|
+
newState.lightColorScheme = defaultLightColorScheme;
|
|
110
|
+
newState.darkColorScheme = defaultDarkColorScheme;
|
|
111
|
+
return newState;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
processState(currentState, function (mode) {
|
|
115
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-").concat(mode), value);
|
|
116
|
+
|
|
117
|
+
if (mode === 'light') {
|
|
118
|
+
newState.lightColorScheme = value;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (mode === 'dark') {
|
|
122
|
+
newState.darkColorScheme = value;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return newState;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
} else if (value.light && !supportedColorSchemes.includes(value.light) || value.dark && !supportedColorSchemes.includes(value.dark)) {
|
|
129
|
+
console.error("`".concat(value, "` does not exist in `theme.colorSchemes`."));
|
|
130
|
+
} else {
|
|
131
|
+
setState(function (currentState) {
|
|
132
|
+
var newState = _extends({}, currentState);
|
|
133
|
+
|
|
134
|
+
if (value.light || value.light === null) {
|
|
135
|
+
newState.lightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (value.dark || value.dark === null) {
|
|
139
|
+
newState.darkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return newState;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (value.light) {
|
|
146
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-light"), value.light);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (value.dark) {
|
|
150
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-dark"), value.dark);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}, [colorSchemeStorageKey, supportedColorSchemes, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
154
|
+
var handleMediaQuery = React.useCallback(function (e) {
|
|
155
|
+
if (state.mode === 'system') {
|
|
156
|
+
setState(function (currentState) {
|
|
157
|
+
return _extends({}, currentState, {
|
|
158
|
+
systemMode: e.matches ? 'dark' : 'light'
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}, [state.mode]); // Ref hack to avoid adding handleMediaQuery as a dep
|
|
163
|
+
|
|
164
|
+
var mediaListener = React.useRef(handleMediaQuery);
|
|
165
|
+
mediaListener.current = handleMediaQuery;
|
|
166
|
+
React.useEffect(function () {
|
|
167
|
+
var handler = function handler() {
|
|
168
|
+
return mediaListener.current.apply(mediaListener, arguments);
|
|
169
|
+
}; // Always listen to System preference
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
var media = window.matchMedia('(prefers-color-scheme: dark)'); // Intentionally use deprecated listener methods to support iOS & old browsers
|
|
173
|
+
|
|
174
|
+
media.addListener(handler);
|
|
175
|
+
handler(media);
|
|
176
|
+
return function () {
|
|
177
|
+
return media.removeListener(handler);
|
|
178
|
+
};
|
|
179
|
+
}, []); // Save mode, lightColorScheme & darkColorScheme to localStorage
|
|
180
|
+
|
|
181
|
+
React.useEffect(function () {
|
|
182
|
+
if (state.mode) {
|
|
183
|
+
localStorage.setItem(modeStorageKey, state.mode);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
processState(state, function (mode) {
|
|
187
|
+
if (mode === 'light') {
|
|
188
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-light"), state.lightColorScheme);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (mode === 'dark') {
|
|
192
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-dark"), state.darkColorScheme);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
|
|
196
|
+
|
|
197
|
+
React.useEffect(function () {
|
|
198
|
+
var handleStorage = function handleStorage(event) {
|
|
199
|
+
var value = event.newValue;
|
|
200
|
+
|
|
201
|
+
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
202
|
+
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
203
|
+
if (event.key.endsWith('light')) {
|
|
204
|
+
setColorScheme({
|
|
205
|
+
light: value
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (event.key.endsWith('dark')) {
|
|
210
|
+
setColorScheme({
|
|
211
|
+
dark: value
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
217
|
+
setMode(value || defaultMode);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
window.addEventListener('storage', handleStorage);
|
|
222
|
+
return function () {
|
|
223
|
+
return window.removeEventListener('storage', handleStorage);
|
|
224
|
+
};
|
|
225
|
+
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode]);
|
|
226
|
+
return _extends({}, state, {
|
|
227
|
+
colorScheme: colorScheme,
|
|
228
|
+
setMode: setMode,
|
|
229
|
+
setColorScheme: setColorScheme
|
|
230
|
+
});
|
|
231
|
+
}
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.2.1
|
|
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.
|
|
@@ -27,6 +27,7 @@ export { default as style, getPath } from './style';
|
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
29
|
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
|
+
export { default as experimental_sx } from './sx';
|
|
30
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
31
32
|
export { default as Box } from './Box';
|
|
32
33
|
export { default as createBox } from './createBox';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
import { isPlainObject } from '@mui/utils';
|
|
3
5
|
import { propToStyleFunction } from '../getThemeValue';
|
|
4
6
|
|
|
5
7
|
var splitProps = function splitProps(props) {
|
|
@@ -25,7 +27,25 @@ export default function extendSxProp(props) {
|
|
|
25
27
|
systemProps = _splitProps.systemProps,
|
|
26
28
|
otherProps = _splitProps.otherProps;
|
|
27
29
|
|
|
30
|
+
var finalSx;
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(inSx)) {
|
|
33
|
+
finalSx = [systemProps].concat(_toConsumableArray(inSx));
|
|
34
|
+
} else if (typeof inSx === 'function') {
|
|
35
|
+
finalSx = function finalSx() {
|
|
36
|
+
var result = inSx.apply(void 0, arguments);
|
|
37
|
+
|
|
38
|
+
if (!isPlainObject(result)) {
|
|
39
|
+
return systemProps;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return _extends({}, systemProps, result);
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
finalSx = _extends({}, systemProps, inSx);
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
return _extends({}, otherProps, {
|
|
29
|
-
sx:
|
|
49
|
+
sx: finalSx
|
|
30
50
|
});
|
|
31
51
|
}
|
|
@@ -24,53 +24,65 @@ function callIfFn(maybeFn, arg) {
|
|
|
24
24
|
|
|
25
25
|
function styleFunctionSx(props) {
|
|
26
26
|
var _ref = props || {},
|
|
27
|
-
|
|
27
|
+
sx = _ref.sx,
|
|
28
28
|
_ref$theme = _ref.theme,
|
|
29
29
|
theme = _ref$theme === void 0 ? {} : _ref$theme;
|
|
30
30
|
|
|
31
|
-
if (!
|
|
32
|
-
return null;
|
|
31
|
+
if (!sx) {
|
|
32
|
+
return null; // emotion & styled-components will neglect null
|
|
33
33
|
}
|
|
34
|
+
/*
|
|
35
|
+
* Receive `sxInput` as object or callback
|
|
36
|
+
* and then recursively check keys & values to create media query object styles.
|
|
37
|
+
* (the result will be used in `styled`)
|
|
38
|
+
*/
|
|
34
39
|
|
|
35
|
-
var stylesObject = styles;
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
function traverse(sxInput) {
|
|
42
|
+
var sxObject = sxInput;
|
|
43
|
+
|
|
44
|
+
if (typeof sxInput === 'function') {
|
|
45
|
+
sxObject = sxInput(theme);
|
|
46
|
+
} else if (_typeof(sxInput) !== 'object') {
|
|
47
|
+
// value
|
|
48
|
+
return sxInput;
|
|
49
|
+
}
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
var emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
52
|
+
var breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
53
|
+
var css = emptyBreakpoints;
|
|
54
|
+
Object.keys(sxObject).forEach(function (styleKey) {
|
|
55
|
+
var value = callIfFn(sxObject[styleKey], theme);
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
if (value !== null && value !== undefined) {
|
|
58
|
+
if (_typeof(value) === 'object') {
|
|
59
|
+
if (propToStyleFunction[styleKey]) {
|
|
60
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
61
|
+
} else {
|
|
62
|
+
var breakpointsValues = handleBreakpoints({
|
|
63
|
+
theme: theme
|
|
64
|
+
}, value, function (x) {
|
|
65
|
+
return _defineProperty({}, styleKey, x);
|
|
66
|
+
});
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
69
|
+
css[styleKey] = styleFunctionSx({
|
|
70
|
+
sx: value,
|
|
71
|
+
theme: theme
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
css = merge(css, breakpointsValues);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
65
77
|
} else {
|
|
66
|
-
css = merge(css,
|
|
78
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
81
|
+
});
|
|
82
|
+
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
styleFunctionSx.filterProps = ['sx'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sx';
|
package/legacy/sx/sx.js
ADDED
package/modern/breakpoints.js
CHANGED
|
@@ -8,12 +8,12 @@ export const values = {
|
|
|
8
8
|
xs: 0,
|
|
9
9
|
// phone
|
|
10
10
|
sm: 600,
|
|
11
|
-
//
|
|
11
|
+
// tablet
|
|
12
12
|
md: 900,
|
|
13
13
|
// small laptop
|
|
14
14
|
lg: 1200,
|
|
15
15
|
// desktop
|
|
16
|
-
xl: 1536 // large
|
|
16
|
+
xl: 1536 // large screen
|
|
17
17
|
|
|
18
18
|
};
|
|
19
19
|
const defaultBreakpoints = {
|
|
@@ -93,7 +93,7 @@ export function createEmptyBreakpointObject(breakpointsInput = {}) {
|
|
|
93
93
|
export function removeUnusedBreakpoints(breakpointKeys, style) {
|
|
94
94
|
return breakpointKeys.reduce((acc, key) => {
|
|
95
95
|
const breakpointOutput = acc[key];
|
|
96
|
-
const isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
|
|
96
|
+
const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
|
|
97
97
|
|
|
98
98
|
if (isBreakpointUnused) {
|
|
99
99
|
delete acc[key];
|
|
@@ -106,11 +106,41 @@ export function mergeBreakpointsInOrder(breakpointsInput, ...styles) {
|
|
|
106
106
|
const emptyBreakpoints = createEmptyBreakpointObject(breakpointsInput);
|
|
107
107
|
const mergedOutput = [emptyBreakpoints, ...styles].reduce((prev, next) => deepmerge(prev, next), {});
|
|
108
108
|
return removeUnusedBreakpoints(Object.keys(emptyBreakpoints), mergedOutput);
|
|
109
|
+
} // compute base for responsive values; e.g.,
|
|
110
|
+
// [1,2,3] => {xs: true, sm: true, md: true}
|
|
111
|
+
// {xs: 1, sm: 2, md: 3} => {xs: true, sm: true, md: true}
|
|
112
|
+
|
|
113
|
+
export function computeBreakpointsBase(breakpointValues, themeBreakpoints) {
|
|
114
|
+
// fixed value
|
|
115
|
+
if (typeof breakpointValues !== 'object') {
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const base = {};
|
|
120
|
+
const breakpointsKeys = Object.keys(themeBreakpoints);
|
|
121
|
+
|
|
122
|
+
if (Array.isArray(breakpointValues)) {
|
|
123
|
+
breakpointsKeys.forEach((breakpoint, i) => {
|
|
124
|
+
if (i < breakpointValues.length) {
|
|
125
|
+
base[breakpoint] = true;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
breakpointsKeys.forEach(breakpoint => {
|
|
130
|
+
if (breakpointValues[breakpoint] != null) {
|
|
131
|
+
base[breakpoint] = true;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return base;
|
|
109
137
|
}
|
|
110
138
|
export function resolveBreakpointValues({
|
|
111
139
|
values: breakpointValues,
|
|
112
|
-
|
|
140
|
+
breakpoints: themeBreakpoints,
|
|
141
|
+
base: customBase
|
|
113
142
|
}) {
|
|
143
|
+
const base = customBase || computeBreakpointsBase(breakpointValues, themeBreakpoints);
|
|
114
144
|
const keys = Object.keys(base);
|
|
115
145
|
|
|
116
146
|
if (keys.length === 0) {
|
|
@@ -118,14 +148,15 @@ export function resolveBreakpointValues({
|
|
|
118
148
|
}
|
|
119
149
|
|
|
120
150
|
let previous;
|
|
121
|
-
return keys.reduce((acc, breakpoint) => {
|
|
122
|
-
if (
|
|
123
|
-
acc[breakpoint] = breakpointValues[
|
|
151
|
+
return keys.reduce((acc, breakpoint, i) => {
|
|
152
|
+
if (Array.isArray(breakpointValues)) {
|
|
153
|
+
acc[breakpoint] = breakpointValues[i] != null ? breakpointValues[i] : breakpointValues[previous];
|
|
154
|
+
previous = i;
|
|
124
155
|
} else {
|
|
125
|
-
acc[breakpoint] = breakpointValues;
|
|
156
|
+
acc[breakpoint] = breakpointValues[breakpoint] != null ? breakpointValues[breakpoint] : breakpointValues[previous] || breakpointValues;
|
|
157
|
+
previous = breakpoint;
|
|
126
158
|
}
|
|
127
159
|
|
|
128
|
-
previous = breakpoint;
|
|
129
160
|
return acc;
|
|
130
161
|
}, {});
|
|
131
162
|
}
|
package/modern/createBox.js
CHANGED
|
@@ -10,7 +10,9 @@ import useTheme from './useTheme';
|
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
export default function createBox(options = {}) {
|
|
12
12
|
const {
|
|
13
|
-
defaultTheme
|
|
13
|
+
defaultTheme,
|
|
14
|
+
defaultClassName = 'MuiBox-root',
|
|
15
|
+
generateClassName
|
|
14
16
|
} = options;
|
|
15
17
|
const BoxRoot = styled('div')(styleFunctionSx);
|
|
16
18
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
|
@@ -26,7 +28,7 @@ export default function createBox(options = {}) {
|
|
|
26
28
|
return /*#__PURE__*/_jsx(BoxRoot, _extends({
|
|
27
29
|
as: component,
|
|
28
30
|
ref: ref,
|
|
29
|
-
className: clsx(className,
|
|
31
|
+
className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
|
|
30
32
|
theme: theme
|
|
31
33
|
}, other));
|
|
32
34
|
});
|
|
@@ -52,7 +54,7 @@ export default function createBox(options = {}) {
|
|
|
52
54
|
/**
|
|
53
55
|
* @ignore
|
|
54
56
|
*/
|
|
55
|
-
sx: PropTypes.object
|
|
57
|
+
sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func])
|
|
56
58
|
} : void 0;
|
|
57
59
|
return Box;
|
|
58
60
|
}
|
|
@@ -13,12 +13,12 @@ export default function createBreakpoints(breakpoints) {
|
|
|
13
13
|
xs: 0,
|
|
14
14
|
// phone
|
|
15
15
|
sm: 600,
|
|
16
|
-
//
|
|
16
|
+
// tablet
|
|
17
17
|
md: 900,
|
|
18
18
|
// small laptop
|
|
19
19
|
lg: 1200,
|
|
20
20
|
// desktop
|
|
21
|
-
xl: 1536 // large
|
|
21
|
+
xl: 1536 // large screen
|
|
22
22
|
|
|
23
23
|
},
|
|
24
24
|
unit = 'px',
|