@mui/system 5.15.13 → 5.15.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/CHANGELOG.md +156 -60
- package/colorManipulator.js +1 -1
- package/cssVars/createCssVarsProvider.js +23 -22
- package/cssVars/useCurrentColorScheme.js +37 -25
- package/esm/colorManipulator.js +1 -1
- package/esm/cssVars/createCssVarsProvider.js +23 -22
- package/esm/cssVars/useCurrentColorScheme.js +37 -25
- package/index.js +1 -1
- package/legacy/colorManipulator.js +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +48 -48
- package/legacy/cssVars/useCurrentColorScheme.js +29 -23
- package/legacy/index.js +1 -1
- package/modern/colorManipulator.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +23 -22
- package/modern/cssVars/useCurrentColorScheme.js +37 -25
- package/modern/index.js +1 -1
- package/package.json +5 -5
|
@@ -78,7 +78,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
78
78
|
// do nothing if mode does not change
|
|
79
79
|
return currentState;
|
|
80
80
|
}
|
|
81
|
-
const newMode =
|
|
81
|
+
const newMode = mode ?? defaultMode;
|
|
82
82
|
try {
|
|
83
83
|
localStorage.setItem(modeStorageKey, newMode);
|
|
84
84
|
} catch (e) {
|
|
@@ -159,11 +159,19 @@ export default function useCurrentColorScheme(options) {
|
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
162
|
-
const handleMediaQuery = React.useCallback(
|
|
162
|
+
const handleMediaQuery = React.useCallback(event => {
|
|
163
163
|
if (state.mode === 'system') {
|
|
164
|
-
setState(currentState =>
|
|
165
|
-
systemMode
|
|
166
|
-
|
|
164
|
+
setState(currentState => {
|
|
165
|
+
const systemMode = event?.matches ? 'dark' : 'light';
|
|
166
|
+
|
|
167
|
+
// Early exit, nothing changed.
|
|
168
|
+
if (currentState.systemMode === systemMode) {
|
|
169
|
+
return currentState;
|
|
170
|
+
}
|
|
171
|
+
return _extends({}, currentState, {
|
|
172
|
+
systemMode
|
|
173
|
+
});
|
|
174
|
+
});
|
|
167
175
|
}
|
|
168
176
|
}, [state.mode]);
|
|
169
177
|
|
|
@@ -179,34 +187,38 @@ export default function useCurrentColorScheme(options) {
|
|
|
179
187
|
// Intentionally use deprecated listener methods to support iOS & old browsers
|
|
180
188
|
media.addListener(handler);
|
|
181
189
|
handler(media);
|
|
182
|
-
return () =>
|
|
190
|
+
return () => {
|
|
191
|
+
media.removeListener(handler);
|
|
192
|
+
};
|
|
183
193
|
}, []);
|
|
184
194
|
|
|
185
195
|
// Handle when localStorage has changed
|
|
186
196
|
React.useEffect(() => {
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
if (storageWindow) {
|
|
198
|
+
const handleStorage = event => {
|
|
199
|
+
const value = event.newValue;
|
|
200
|
+
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
201
|
+
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
202
|
+
if (event.key.endsWith('light')) {
|
|
203
|
+
setColorScheme({
|
|
204
|
+
light: value
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (event.key.endsWith('dark')) {
|
|
208
|
+
setColorScheme({
|
|
209
|
+
dark: value
|
|
210
|
+
});
|
|
211
|
+
}
|
|
195
212
|
}
|
|
196
|
-
if (event.key
|
|
197
|
-
|
|
198
|
-
dark: value
|
|
199
|
-
});
|
|
213
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
214
|
+
setMode(value || defaultMode);
|
|
200
215
|
}
|
|
201
|
-
}
|
|
202
|
-
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
203
|
-
setMode(value || defaultMode);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
if (storageWindow) {
|
|
216
|
+
};
|
|
207
217
|
// For syncing color-scheme changes between iframes
|
|
208
218
|
storageWindow.addEventListener('storage', handleStorage);
|
|
209
|
-
return () =>
|
|
219
|
+
return () => {
|
|
220
|
+
storageWindow.removeEventListener('storage', handleStorage);
|
|
221
|
+
};
|
|
210
222
|
}
|
|
211
223
|
return undefined;
|
|
212
224
|
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.15.
|
|
3
|
+
"version": "5.15.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "MUI System is a set of CSS utilities to help you build custom designs more efficiently. It makes it possible to rapidly lay out custom designs.",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"clsx": "^2.1.0",
|
|
31
31
|
"csstype": "^3.1.3",
|
|
32
32
|
"prop-types": "^15.8.1",
|
|
33
|
-
"@mui/
|
|
34
|
-
"@mui/
|
|
35
|
-
"@mui/
|
|
36
|
-
"@mui/styled-engine": "^5.15.
|
|
33
|
+
"@mui/utils": "^5.15.14",
|
|
34
|
+
"@mui/private-theming": "^5.15.14",
|
|
35
|
+
"@mui/types": "^7.2.14",
|
|
36
|
+
"@mui/styled-engine": "^5.15.14"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@emotion/react": "^11.5.0",
|