@mui/system 5.0.5 → 5.2.0
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 +302 -9
- package/breakpoints.js +42 -9
- package/createBox.d.ts +5 -1
- package/createBox.js +5 -3
- package/createStyled.js +5 -1
- 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/createStyled.js +5 -1
- 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/styleFunctionSx/extendSxProp.js +20 -1
- package/esm/styleFunctionSx/styleFunctionSx.js +47 -35
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/breakpoints.js +40 -9
- package/legacy/createBox.js +6 -3
- package/legacy/createStyled.js +5 -1
- 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 +1 -1
- package/legacy/styleFunctionSx/extendSxProp.js +21 -1
- package/legacy/styleFunctionSx/styleFunctionSx.js +47 -35
- package/modern/breakpoints.js +40 -9
- package/modern/createBox.js +5 -3
- package/modern/createStyled.js +5 -1
- 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 +1 -1
- package/modern/styleFunctionSx/extendSxProp.js +20 -1
- package/modern/styleFunctionSx/styleFunctionSx.js +47 -35
- 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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.DEFAULT_MODE_STORAGE_KEY = exports.DEFAULT_COLOR_SCHEME_STORAGE_KEY = exports.DEFAULT_ATTRIBUTE = void 0;
|
|
7
7
|
exports.default = getInitColorSchemeScript;
|
|
8
8
|
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
@@ -14,21 +14,43 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
14
14
|
|
|
15
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
exports.
|
|
17
|
+
const DEFAULT_MODE_STORAGE_KEY = 'mui-mode';
|
|
18
|
+
exports.DEFAULT_MODE_STORAGE_KEY = DEFAULT_MODE_STORAGE_KEY;
|
|
19
|
+
const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
20
|
+
exports.DEFAULT_COLOR_SCHEME_STORAGE_KEY = DEFAULT_COLOR_SCHEME_STORAGE_KEY;
|
|
19
21
|
const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
20
22
|
exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
21
23
|
|
|
22
24
|
function getInitColorSchemeScript(options) {
|
|
23
25
|
const {
|
|
24
|
-
|
|
26
|
+
enableSystem,
|
|
27
|
+
defaultLightColorScheme = 'light',
|
|
28
|
+
defaultDarkColorScheme = 'dark',
|
|
29
|
+
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
30
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
25
31
|
attribute = DEFAULT_ATTRIBUTE
|
|
26
32
|
} = options || {};
|
|
27
33
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("script", {
|
|
28
34
|
// eslint-disable-next-line react/no-danger
|
|
29
35
|
dangerouslySetInnerHTML: {
|
|
30
36
|
__html: `(function() { try {
|
|
31
|
-
var
|
|
37
|
+
var mode = localStorage.getItem('${modeStorageKey}');
|
|
38
|
+
var colorScheme = '';
|
|
39
|
+
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
40
|
+
// handle system mode
|
|
41
|
+
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
42
|
+
if (mql.matches) {
|
|
43
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
44
|
+
} else {
|
|
45
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (mode === 'light') {
|
|
49
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
50
|
+
}
|
|
51
|
+
if (mode === 'dark') {
|
|
52
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
53
|
+
}
|
|
32
54
|
if (colorScheme) {
|
|
33
55
|
document.body.setAttribute('${attribute}', colorScheme);
|
|
34
56
|
}
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { BuildCssVarsTheme } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export type { BuildCssVarsTheme } from './createCssVarsProvider';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare type Mode = 'light' | 'dark' | 'system';
|
|
2
|
+
export declare type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
+
export interface State<SupportedColorScheme extends string> {
|
|
4
|
+
/**
|
|
5
|
+
* User selected mode.
|
|
6
|
+
* Note: on the server, mode is always undefined
|
|
7
|
+
*/
|
|
8
|
+
mode: Mode | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
+
*/
|
|
12
|
+
systemMode: SystemMode | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The color scheme for the light mode.
|
|
15
|
+
*/
|
|
16
|
+
lightColorScheme: SupportedColorScheme;
|
|
17
|
+
/**
|
|
18
|
+
* The color scheme for the dark mode.
|
|
19
|
+
*/
|
|
20
|
+
darkColorScheme: SupportedColorScheme;
|
|
21
|
+
}
|
|
22
|
+
export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
+
/**
|
|
24
|
+
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
+
*/
|
|
26
|
+
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* `mode` is saved to internal state and localStorage
|
|
29
|
+
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
+
*/
|
|
31
|
+
setMode: (mode: Mode | null) => void;
|
|
32
|
+
/**
|
|
33
|
+
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
+
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
+
*/
|
|
36
|
+
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
+
light: SupportedColorScheme | null;
|
|
38
|
+
dark: SupportedColorScheme | null;
|
|
39
|
+
}> | null) => void;
|
|
40
|
+
};
|
|
41
|
+
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
+
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
+
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
|
|
44
|
+
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
+
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
+
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
+
defaultMode?: Mode;
|
|
48
|
+
modeStorageKey?: string;
|
|
49
|
+
colorSchemeStorageKey?: string;
|
|
50
|
+
}): Result<SupportedColorScheme>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useCurrentColorScheme;
|
|
9
|
+
exports.getColorScheme = getColorScheme;
|
|
10
|
+
exports.getSystemMode = getSystemMode;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var React = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _getInitColorSchemeScript = require("./getInitColorSchemeScript");
|
|
17
|
+
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
function getSystemMode(mode) {
|
|
23
|
+
if (typeof window !== 'undefined' && mode === 'system') {
|
|
24
|
+
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
25
|
+
|
|
26
|
+
if (mql.matches) {
|
|
27
|
+
return 'dark';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return 'light';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function processState(state, callback) {
|
|
37
|
+
if (state.mode === 'light' || state.mode === 'system' && state.systemMode === 'light') {
|
|
38
|
+
return callback('light');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (state.mode === 'dark' || state.mode === 'system' && state.systemMode === 'dark') {
|
|
42
|
+
return callback('dark');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getColorScheme(state) {
|
|
49
|
+
return processState(state, mode => {
|
|
50
|
+
if (mode === 'light') {
|
|
51
|
+
return state.lightColorScheme;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (mode === 'dark') {
|
|
55
|
+
return state.darkColorScheme;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return undefined;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resolveValue(key, defaultValue) {
|
|
63
|
+
if (typeof window === 'undefined') {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let value;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
value = localStorage.getItem(key) || undefined;
|
|
71
|
+
} catch (e) {// Unsupported
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return value || defaultValue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function useCurrentColorScheme(options) {
|
|
78
|
+
const {
|
|
79
|
+
defaultMode = 'light',
|
|
80
|
+
defaultLightColorScheme,
|
|
81
|
+
defaultDarkColorScheme,
|
|
82
|
+
supportedColorSchemes = [],
|
|
83
|
+
modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
84
|
+
colorSchemeStorageKey = _getInitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY
|
|
85
|
+
} = options;
|
|
86
|
+
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
87
|
+
const [state, setState] = React.useState(() => {
|
|
88
|
+
const initialMode = resolveValue(modeStorageKey, defaultMode);
|
|
89
|
+
return {
|
|
90
|
+
mode: initialMode,
|
|
91
|
+
systemMode: getSystemMode(initialMode),
|
|
92
|
+
lightColorScheme: resolveValue(`${colorSchemeStorageKey}-light`) || defaultLightColorScheme,
|
|
93
|
+
darkColorScheme: resolveValue(`${colorSchemeStorageKey}-dark`) || defaultDarkColorScheme
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
const colorScheme = getColorScheme(state);
|
|
97
|
+
const setMode = React.useCallback(mode => {
|
|
98
|
+
setState(currentState => {
|
|
99
|
+
const newMode = !mode ? defaultMode : mode;
|
|
100
|
+
|
|
101
|
+
if (typeof localStorage !== 'undefined') {
|
|
102
|
+
localStorage.setItem(modeStorageKey, newMode);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (0, _extends2.default)({}, currentState, {
|
|
106
|
+
mode: newMode,
|
|
107
|
+
systemMode: getSystemMode(newMode)
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}, [modeStorageKey, defaultMode]);
|
|
111
|
+
const setColorScheme = React.useCallback(value => {
|
|
112
|
+
if (!value || typeof value === 'string') {
|
|
113
|
+
if (value && !supportedColorSchemes.includes(value)) {
|
|
114
|
+
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
115
|
+
} else {
|
|
116
|
+
setState(currentState => {
|
|
117
|
+
const newState = (0, _extends2.default)({}, currentState);
|
|
118
|
+
|
|
119
|
+
if (!value) {
|
|
120
|
+
// reset to default color scheme
|
|
121
|
+
newState.lightColorScheme = defaultLightColorScheme;
|
|
122
|
+
newState.darkColorScheme = defaultDarkColorScheme;
|
|
123
|
+
return newState;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
processState(currentState, mode => {
|
|
127
|
+
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
128
|
+
|
|
129
|
+
if (mode === 'light') {
|
|
130
|
+
newState.lightColorScheme = value;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (mode === 'dark') {
|
|
134
|
+
newState.darkColorScheme = value;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return newState;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
} else if (value.light && !supportedColorSchemes.includes(value.light) || value.dark && !supportedColorSchemes.includes(value.dark)) {
|
|
141
|
+
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
142
|
+
} else {
|
|
143
|
+
setState(currentState => {
|
|
144
|
+
const newState = (0, _extends2.default)({}, currentState);
|
|
145
|
+
|
|
146
|
+
if (value.light || value.light === null) {
|
|
147
|
+
newState.lightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (value.dark || value.dark === null) {
|
|
151
|
+
newState.darkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return newState;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (value.light) {
|
|
158
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, value.light);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (value.dark) {
|
|
162
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, value.dark);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, [colorSchemeStorageKey, supportedColorSchemes, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
166
|
+
const handleMediaQuery = React.useCallback(e => {
|
|
167
|
+
if (state.mode === 'system') {
|
|
168
|
+
setState(currentState => (0, _extends2.default)({}, currentState, {
|
|
169
|
+
systemMode: e.matches ? 'dark' : 'light'
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
}, [state.mode]); // Ref hack to avoid adding handleMediaQuery as a dep
|
|
173
|
+
|
|
174
|
+
const mediaListener = React.useRef(handleMediaQuery);
|
|
175
|
+
mediaListener.current = handleMediaQuery;
|
|
176
|
+
React.useEffect(() => {
|
|
177
|
+
const handler = (...args) => mediaListener.current(...args); // Always listen to System preference
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
const media = window.matchMedia('(prefers-color-scheme: dark)'); // Intentionally use deprecated listener methods to support iOS & old browsers
|
|
181
|
+
|
|
182
|
+
media.addListener(handler);
|
|
183
|
+
handler(media);
|
|
184
|
+
return () => media.removeListener(handler);
|
|
185
|
+
}, []); // Save mode, lightColorScheme & darkColorScheme to localStorage
|
|
186
|
+
|
|
187
|
+
React.useEffect(() => {
|
|
188
|
+
if (state.mode) {
|
|
189
|
+
localStorage.setItem(modeStorageKey, state.mode);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
processState(state, mode => {
|
|
193
|
+
if (mode === 'light') {
|
|
194
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, state.lightColorScheme);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (mode === 'dark') {
|
|
198
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, state.darkColorScheme);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
|
|
202
|
+
|
|
203
|
+
React.useEffect(() => {
|
|
204
|
+
const handleStorage = event => {
|
|
205
|
+
const value = event.newValue;
|
|
206
|
+
|
|
207
|
+
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
208
|
+
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
209
|
+
if (event.key.endsWith('light')) {
|
|
210
|
+
setColorScheme({
|
|
211
|
+
light: value
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (event.key.endsWith('dark')) {
|
|
216
|
+
setColorScheme({
|
|
217
|
+
dark: value
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
223
|
+
setMode(value || defaultMode);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
window.addEventListener('storage', handleStorage);
|
|
228
|
+
return () => window.removeEventListener('storage', handleStorage);
|
|
229
|
+
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode]);
|
|
230
|
+
return (0, _extends2.default)({}, state, {
|
|
231
|
+
colorScheme,
|
|
232
|
+
setMode,
|
|
233
|
+
setColorScheme
|
|
234
|
+
});
|
|
235
|
+
}
|
package/esm/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 = {
|
|
@@ -95,7 +95,7 @@ export function createEmptyBreakpointObject(breakpointsInput = {}) {
|
|
|
95
95
|
export function removeUnusedBreakpoints(breakpointKeys, style) {
|
|
96
96
|
return breakpointKeys.reduce((acc, key) => {
|
|
97
97
|
const breakpointOutput = acc[key];
|
|
98
|
-
const isBreakpointUnused = Object.keys(breakpointOutput).length === 0;
|
|
98
|
+
const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
|
|
99
99
|
|
|
100
100
|
if (isBreakpointUnused) {
|
|
101
101
|
delete acc[key];
|
|
@@ -108,11 +108,41 @@ export function mergeBreakpointsInOrder(breakpointsInput, ...styles) {
|
|
|
108
108
|
const emptyBreakpoints = createEmptyBreakpointObject(breakpointsInput);
|
|
109
109
|
const mergedOutput = [emptyBreakpoints, ...styles].reduce((prev, next) => deepmerge(prev, next), {});
|
|
110
110
|
return removeUnusedBreakpoints(Object.keys(emptyBreakpoints), mergedOutput);
|
|
111
|
+
} // compute base for responsive values; e.g.,
|
|
112
|
+
// [1,2,3] => {xs: true, sm: true, md: true}
|
|
113
|
+
// {xs: 1, sm: 2, md: 3} => {xs: true, sm: true, md: true}
|
|
114
|
+
|
|
115
|
+
export function computeBreakpointsBase(breakpointValues, themeBreakpoints) {
|
|
116
|
+
// fixed value
|
|
117
|
+
if (typeof breakpointValues !== 'object') {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const base = {};
|
|
122
|
+
const breakpointsKeys = Object.keys(themeBreakpoints);
|
|
123
|
+
|
|
124
|
+
if (Array.isArray(breakpointValues)) {
|
|
125
|
+
breakpointsKeys.forEach((breakpoint, i) => {
|
|
126
|
+
if (i < breakpointValues.length) {
|
|
127
|
+
base[breakpoint] = true;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
breakpointsKeys.forEach(breakpoint => {
|
|
132
|
+
if (breakpointValues[breakpoint] != null) {
|
|
133
|
+
base[breakpoint] = true;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return base;
|
|
111
139
|
}
|
|
112
140
|
export function resolveBreakpointValues({
|
|
113
141
|
values: breakpointValues,
|
|
114
|
-
|
|
142
|
+
breakpoints: themeBreakpoints,
|
|
143
|
+
base: customBase
|
|
115
144
|
}) {
|
|
145
|
+
const base = customBase || computeBreakpointsBase(breakpointValues, themeBreakpoints);
|
|
116
146
|
const keys = Object.keys(base);
|
|
117
147
|
|
|
118
148
|
if (keys.length === 0) {
|
|
@@ -120,14 +150,15 @@ export function resolveBreakpointValues({
|
|
|
120
150
|
}
|
|
121
151
|
|
|
122
152
|
let previous;
|
|
123
|
-
return keys.reduce((acc, breakpoint) => {
|
|
124
|
-
if (
|
|
125
|
-
acc[breakpoint] = breakpointValues[
|
|
153
|
+
return keys.reduce((acc, breakpoint, i) => {
|
|
154
|
+
if (Array.isArray(breakpointValues)) {
|
|
155
|
+
acc[breakpoint] = breakpointValues[i] != null ? breakpointValues[i] : breakpointValues[previous];
|
|
156
|
+
previous = i;
|
|
126
157
|
} else {
|
|
127
|
-
acc[breakpoint] = breakpointValues;
|
|
158
|
+
acc[breakpoint] = breakpointValues[breakpoint] != null ? breakpointValues[breakpoint] : breakpointValues[previous] || breakpointValues;
|
|
159
|
+
previous = breakpoint;
|
|
128
160
|
}
|
|
129
161
|
|
|
130
|
-
previous = breakpoint;
|
|
131
162
|
return acc;
|
|
132
163
|
}, {});
|
|
133
164
|
}
|
package/esm/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
|
}
|
package/esm/createStyled.js
CHANGED
|
@@ -115,7 +115,11 @@ export default function createStyled(input = {}) {
|
|
|
115
115
|
|
|
116
116
|
const muiStyledResolver = (styleArg, ...expressions) => {
|
|
117
117
|
const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
|
|
118
|
-
|
|
118
|
+
// On the server emotion doesn't use React.forwardRef for creating components, so the created
|
|
119
|
+
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
120
|
+
// which are basically components used as a selectors.
|
|
121
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
122
|
+
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
|
|
119
123
|
let {
|
|
120
124
|
theme: themeInput
|
|
121
125
|
} = _ref,
|
|
@@ -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',
|