@mui/system 5.15.12 → 5.15.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/CHANGELOG.md +203 -51
- package/RtlProvider/index.d.ts +11 -0
- package/RtlProvider/index.js +35 -0
- package/RtlProvider/package.json +6 -0
- package/ThemeProvider/ThemeProvider.js +6 -1
- package/cssVars/createCssVarsProvider.js +23 -22
- package/cssVars/useCurrentColorScheme.js +37 -25
- package/esm/RtlProvider/index.js +25 -0
- package/esm/ThemeProvider/ThemeProvider.js +6 -1
- package/esm/cssVars/createCssVarsProvider.js +23 -22
- package/esm/cssVars/useCurrentColorScheme.js +37 -25
- package/esm/index.js +2 -0
- package/index.js +20 -1
- package/legacy/RtlProvider/index.js +22 -0
- package/legacy/ThemeProvider/ThemeProvider.js +6 -1
- package/legacy/cssVars/createCssVarsProvider.js +48 -48
- package/legacy/cssVars/useCurrentColorScheme.js +29 -23
- package/legacy/index.js +3 -1
- package/modern/RtlProvider/index.js +25 -0
- package/modern/ThemeProvider/ThemeProvider.js +6 -1
- package/modern/cssVars/createCssVarsProvider.js +23 -22
- package/modern/cssVars/useCurrentColorScheme.js +37 -25
- package/modern/index.js +3 -1
- package/package.json +5 -5
|
@@ -83,7 +83,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
83
83
|
// do nothing if mode does not change
|
|
84
84
|
return currentState;
|
|
85
85
|
}
|
|
86
|
-
var newMode =
|
|
86
|
+
var newMode = mode != null ? mode : defaultMode;
|
|
87
87
|
try {
|
|
88
88
|
localStorage.setItem(modeStorageKey, newMode);
|
|
89
89
|
} catch (e) {
|
|
@@ -164,11 +164,17 @@ export default function useCurrentColorScheme(options) {
|
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
167
|
-
var handleMediaQuery = React.useCallback(function (
|
|
167
|
+
var handleMediaQuery = React.useCallback(function (event) {
|
|
168
168
|
if (state.mode === 'system') {
|
|
169
169
|
setState(function (currentState) {
|
|
170
|
+
var systemMode = event != null && event.matches ? 'dark' : 'light';
|
|
171
|
+
|
|
172
|
+
// Early exit, nothing changed.
|
|
173
|
+
if (currentState.systemMode === systemMode) {
|
|
174
|
+
return currentState;
|
|
175
|
+
}
|
|
170
176
|
return _extends({}, currentState, {
|
|
171
|
-
systemMode:
|
|
177
|
+
systemMode: systemMode
|
|
172
178
|
});
|
|
173
179
|
});
|
|
174
180
|
}
|
|
@@ -189,36 +195,36 @@ export default function useCurrentColorScheme(options) {
|
|
|
189
195
|
media.addListener(handler);
|
|
190
196
|
handler(media);
|
|
191
197
|
return function () {
|
|
192
|
-
|
|
198
|
+
media.removeListener(handler);
|
|
193
199
|
};
|
|
194
200
|
}, []);
|
|
195
201
|
|
|
196
202
|
// Handle when localStorage has changed
|
|
197
203
|
React.useEffect(function () {
|
|
198
|
-
|
|
199
|
-
var
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
if (storageWindow) {
|
|
205
|
+
var handleStorage = function handleStorage(event) {
|
|
206
|
+
var value = event.newValue;
|
|
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
|
+
if (event.key.endsWith('dark')) {
|
|
215
|
+
setColorScheme({
|
|
216
|
+
dark: value
|
|
217
|
+
});
|
|
218
|
+
}
|
|
206
219
|
}
|
|
207
|
-
if (event.key
|
|
208
|
-
|
|
209
|
-
dark: value
|
|
210
|
-
});
|
|
220
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
221
|
+
setMode(value || defaultMode);
|
|
211
222
|
}
|
|
212
|
-
}
|
|
213
|
-
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
214
|
-
setMode(value || defaultMode);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
if (storageWindow) {
|
|
223
|
+
};
|
|
218
224
|
// For syncing color-scheme changes between iframes
|
|
219
225
|
storageWindow.addEventListener('storage', handleStorage);
|
|
220
226
|
return function () {
|
|
221
|
-
|
|
227
|
+
storageWindow.removeEventListener('storage', handleStorage);
|
|
222
228
|
};
|
|
223
229
|
}
|
|
224
230
|
return undefined;
|
package/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.15.
|
|
2
|
+
* @mui/system v5.15.14
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -58,6 +58,8 @@ export { default as unstable_cssVarsParser } from './cssVars/cssVarsParser';
|
|
|
58
58
|
export { default as unstable_prepareCssVars } from './cssVars/prepareCssVars';
|
|
59
59
|
export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsTheme';
|
|
60
60
|
export { default as responsivePropType } from './responsivePropType';
|
|
61
|
+
export { default as RtlProvider } from './RtlProvider';
|
|
62
|
+
export * from './RtlProvider';
|
|
61
63
|
|
|
62
64
|
/** ----------------- */
|
|
63
65
|
/** Layout components */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["value"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const RtlContext = /*#__PURE__*/React.createContext();
|
|
8
|
+
function RtlProvider(_ref) {
|
|
9
|
+
let {
|
|
10
|
+
value
|
|
11
|
+
} = _ref,
|
|
12
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
return /*#__PURE__*/_jsx(RtlContext.Provider, _extends({
|
|
14
|
+
value: value ?? true
|
|
15
|
+
}, props));
|
|
16
|
+
}
|
|
17
|
+
process.env.NODE_ENV !== "production" ? RtlProvider.propTypes = {
|
|
18
|
+
children: PropTypes.node,
|
|
19
|
+
value: PropTypes.bool
|
|
20
|
+
} : void 0;
|
|
21
|
+
export const useRtl = () => {
|
|
22
|
+
const value = React.useContext(RtlContext);
|
|
23
|
+
return value ?? false;
|
|
24
|
+
};
|
|
25
|
+
export default RtlProvider;
|
|
@@ -7,6 +7,7 @@ import { ThemeProvider as MuiThemeProvider, useTheme as usePrivateTheme } from '
|
|
|
7
7
|
import exactProp from '@mui/utils/exactProp';
|
|
8
8
|
import { ThemeContext as StyledEngineThemeContext } from '@mui/styled-engine';
|
|
9
9
|
import useThemeWithoutDefault from '../useThemeWithoutDefault';
|
|
10
|
+
import RtlProvider from '../RtlProvider';
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
const EMPTY_THEME = {};
|
|
12
13
|
function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
|
|
@@ -52,11 +53,15 @@ function ThemeProvider(props) {
|
|
|
52
53
|
}
|
|
53
54
|
const engineTheme = useThemeScoping(themeId, upperTheme, localTheme);
|
|
54
55
|
const privateTheme = useThemeScoping(themeId, upperPrivateTheme, localTheme, true);
|
|
56
|
+
const rtlValue = engineTheme.direction === 'rtl';
|
|
55
57
|
return /*#__PURE__*/_jsx(MuiThemeProvider, {
|
|
56
58
|
theme: privateTheme,
|
|
57
59
|
children: /*#__PURE__*/_jsx(StyledEngineThemeContext.Provider, {
|
|
58
60
|
value: engineTheme,
|
|
59
|
-
children:
|
|
61
|
+
children: /*#__PURE__*/_jsx(RtlProvider, {
|
|
62
|
+
value: rtlValue,
|
|
63
|
+
children: children
|
|
64
|
+
})
|
|
60
65
|
})
|
|
61
66
|
});
|
|
62
67
|
}
|
|
@@ -46,22 +46,23 @@ export default function createCssVarsProvider(options) {
|
|
|
46
46
|
}
|
|
47
47
|
return value;
|
|
48
48
|
};
|
|
49
|
-
function CssVarsProvider({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
function CssVarsProvider(props) {
|
|
50
|
+
const {
|
|
51
|
+
children,
|
|
52
|
+
theme: themeProp = defaultTheme,
|
|
53
|
+
modeStorageKey = defaultModeStorageKey,
|
|
54
|
+
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
55
|
+
attribute = defaultAttribute,
|
|
56
|
+
defaultMode = designSystemMode,
|
|
57
|
+
defaultColorScheme = designSystemColorScheme,
|
|
58
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
59
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
60
|
+
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
61
|
+
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
62
|
+
colorSchemeSelector = ':root',
|
|
63
|
+
disableNestedContext = false,
|
|
64
|
+
disableStyleSheetGeneration = false
|
|
65
|
+
} = props;
|
|
65
66
|
const hasMounted = React.useRef(false);
|
|
66
67
|
const upperTheme = muiUseTheme();
|
|
67
68
|
const ctx = React.useContext(ColorSchemeContext);
|
|
@@ -228,14 +229,14 @@ export default function createCssVarsProvider(options) {
|
|
|
228
229
|
};
|
|
229
230
|
}, []);
|
|
230
231
|
const contextValue = React.useMemo(() => ({
|
|
231
|
-
|
|
232
|
-
systemMode,
|
|
233
|
-
setMode,
|
|
234
|
-
lightColorScheme,
|
|
235
|
-
darkColorScheme,
|
|
232
|
+
allColorSchemes,
|
|
236
233
|
colorScheme,
|
|
234
|
+
darkColorScheme,
|
|
235
|
+
lightColorScheme,
|
|
236
|
+
mode,
|
|
237
237
|
setColorScheme,
|
|
238
|
-
|
|
238
|
+
setMode,
|
|
239
|
+
systemMode
|
|
239
240
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
240
241
|
let shouldGenerateStyleSheet = true;
|
|
241
242
|
if (disableStyleSheetGeneration || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
|
|
@@ -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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.15.
|
|
2
|
+
* @mui/system v5.15.14
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -58,6 +58,8 @@ export { default as unstable_cssVarsParser } from './cssVars/cssVarsParser';
|
|
|
58
58
|
export { default as unstable_prepareCssVars } from './cssVars/prepareCssVars';
|
|
59
59
|
export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsTheme';
|
|
60
60
|
export { default as responsivePropType } from './responsivePropType';
|
|
61
|
+
export { default as RtlProvider } from './RtlProvider';
|
|
62
|
+
export * from './RtlProvider';
|
|
61
63
|
|
|
62
64
|
/** ----------------- */
|
|
63
65
|
/** Layout components */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.15.
|
|
3
|
+
"version": "5.15.14",
|
|
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/private-theming": "^5.15.14",
|
|
34
|
+
"@mui/types": "^7.2.14",
|
|
35
|
+
"@mui/utils": "^5.15.14",
|
|
36
|
+
"@mui/styled-engine": "^5.15.14"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@emotion/react": "^11.5.0",
|