@mui/system 5.15.15 → 5.16.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/CHANGELOG.md +250 -4
- package/DefaultPropsProvider/DefaultPropsProvider.d.ts +12 -0
- package/DefaultPropsProvider/DefaultPropsProvider.js +73 -0
- package/DefaultPropsProvider/index.d.ts +1 -0
- package/DefaultPropsProvider/index.js +20 -0
- package/DefaultPropsProvider/package.json +6 -0
- package/InitColorSchemeScript/InitColorSchemeScript.d.ts +49 -0
- package/InitColorSchemeScript/InitColorSchemeScript.js +61 -0
- package/InitColorSchemeScript/index.d.ts +2 -0
- package/InitColorSchemeScript/index.js +13 -0
- package/InitColorSchemeScript/package.json +6 -0
- package/ThemeProvider/ThemeProvider.js +5 -1
- package/cssVars/createCssVarsProvider.d.ts +2 -2
- package/cssVars/createCssVarsProvider.js +5 -5
- package/cssVars/getInitColorSchemeScript.d.ts +2 -41
- package/cssVars/getInitColorSchemeScript.js +7 -42
- package/cssVars/useCurrentColorScheme.js +3 -3
- package/esm/DefaultPropsProvider/DefaultPropsProvider.js +64 -0
- package/esm/DefaultPropsProvider/index.js +1 -0
- package/esm/InitColorSchemeScript/InitColorSchemeScript.js +51 -0
- package/esm/InitColorSchemeScript/index.js +1 -0
- package/esm/ThemeProvider/ThemeProvider.js +5 -1
- package/esm/cssVars/createCssVarsProvider.js +2 -2
- package/esm/cssVars/getInitColorSchemeScript.js +5 -41
- package/esm/cssVars/index.js +1 -0
- package/esm/cssVars/useCurrentColorScheme.js +1 -1
- package/index.js +1 -1
- package/legacy/DefaultPropsProvider/DefaultPropsProvider.js +60 -0
- package/legacy/DefaultPropsProvider/index.js +1 -0
- package/legacy/InitColorSchemeScript/InitColorSchemeScript.js +35 -0
- package/legacy/InitColorSchemeScript/index.js +1 -0
- package/legacy/ThemeProvider/ThemeProvider.js +5 -1
- package/legacy/cssVars/createCssVarsProvider.js +2 -2
- package/legacy/cssVars/getInitColorSchemeScript.js +5 -25
- package/legacy/cssVars/index.js +1 -0
- package/legacy/cssVars/useCurrentColorScheme.js +1 -1
- package/legacy/index.js +1 -1
- package/modern/DefaultPropsProvider/DefaultPropsProvider.js +64 -0
- package/modern/DefaultPropsProvider/index.js +1 -0
- package/modern/InitColorSchemeScript/InitColorSchemeScript.js +51 -0
- package/modern/InitColorSchemeScript/index.js +1 -0
- package/modern/ThemeProvider/ThemeProvider.js +5 -1
- package/modern/cssVars/createCssVarsProvider.js +2 -2
- package/modern/cssVars/getInitColorSchemeScript.js +5 -41
- package/modern/cssVars/index.js +1 -0
- package/modern/cssVars/useCurrentColorScheme.js +1 -1
- package/modern/index.js +1 -1
- package/package.json +4 -4
|
@@ -1,53 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.DEFAULT_MODE_STORAGE_KEY = exports.DEFAULT_COLOR_SCHEME_STORAGE_KEY = exports.DEFAULT_ATTRIBUTE = void 0;
|
|
7
7
|
exports.default = getInitColorSchemeScript;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
8
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _InitColorSchemeScript = _interopRequireDefault(require("../InitColorSchemeScript"));
|
|
9
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
defaultMode = 'light',
|
|
18
|
-
defaultLightColorScheme = 'light',
|
|
19
|
-
defaultDarkColorScheme = 'dark',
|
|
20
|
-
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
21
|
-
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
22
|
-
attribute = DEFAULT_ATTRIBUTE,
|
|
23
|
-
colorSchemeNode = 'document.documentElement'
|
|
24
|
-
} = options || {};
|
|
25
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("script", {
|
|
26
|
-
// eslint-disable-next-line react/no-danger
|
|
27
|
-
dangerouslySetInnerHTML: {
|
|
28
|
-
__html: `(function() {
|
|
29
|
-
try {
|
|
30
|
-
var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
|
|
31
|
-
var colorScheme = '';
|
|
32
|
-
if (mode === 'system') {
|
|
33
|
-
// handle system mode
|
|
34
|
-
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
35
|
-
if (mql.matches) {
|
|
36
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
37
|
-
} else {
|
|
38
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (mode === 'light') {
|
|
42
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
43
|
-
}
|
|
44
|
-
if (mode === 'dark') {
|
|
45
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
46
|
-
}
|
|
47
|
-
if (colorScheme) {
|
|
48
|
-
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
49
|
-
}
|
|
50
|
-
} catch(e){}})();`
|
|
51
|
-
}
|
|
52
|
-
}, "mui-color-scheme-init");
|
|
14
|
+
// TODO: remove this file in v6
|
|
15
|
+
|
|
16
|
+
function getInitColorSchemeScript(params) {
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InitColorSchemeScript.default, (0, _extends2.default)({}, params));
|
|
53
18
|
}
|
|
@@ -10,7 +10,7 @@ exports.getColorScheme = getColorScheme;
|
|
|
10
10
|
exports.getSystemMode = getSystemMode;
|
|
11
11
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
|
-
var
|
|
13
|
+
var _InitColorSchemeScript = require("../InitColorSchemeScript/InitColorSchemeScript");
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
function getSystemMode(mode) {
|
|
@@ -65,8 +65,8 @@ function useCurrentColorScheme(options) {
|
|
|
65
65
|
defaultLightColorScheme,
|
|
66
66
|
defaultDarkColorScheme,
|
|
67
67
|
supportedColorSchemes = [],
|
|
68
|
-
modeStorageKey =
|
|
69
|
-
colorSchemeStorageKey =
|
|
68
|
+
modeStorageKey = _InitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
69
|
+
colorSchemeStorageKey = _InitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
70
70
|
storageWindow = typeof window === 'undefined' ? undefined : window
|
|
71
71
|
} = options;
|
|
72
72
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import resolveProps from '@mui/utils/resolveProps';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const PropsContext = /*#__PURE__*/React.createContext(undefined);
|
|
8
|
+
function DefaultPropsProvider({
|
|
9
|
+
value,
|
|
10
|
+
children
|
|
11
|
+
}) {
|
|
12
|
+
return /*#__PURE__*/_jsx(PropsContext.Provider, {
|
|
13
|
+
value: value,
|
|
14
|
+
children: children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
process.env.NODE_ENV !== "production" ? DefaultPropsProvider.propTypes /* remove-proptypes */ = {
|
|
18
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
19
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
20
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
21
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
children: PropTypes.node,
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
value: PropTypes.object
|
|
30
|
+
} : void 0;
|
|
31
|
+
function getThemeProps(params) {
|
|
32
|
+
const {
|
|
33
|
+
theme,
|
|
34
|
+
name,
|
|
35
|
+
props
|
|
36
|
+
} = params;
|
|
37
|
+
if (!theme || !theme.components || !theme.components[name]) {
|
|
38
|
+
return props;
|
|
39
|
+
}
|
|
40
|
+
const config = theme.components[name];
|
|
41
|
+
if (config.defaultProps) {
|
|
42
|
+
// compatible with v5 signature
|
|
43
|
+
return resolveProps(config.defaultProps, props);
|
|
44
|
+
}
|
|
45
|
+
if (!config.styleOverrides && !config.variants) {
|
|
46
|
+
// v6 signature, no property 'defaultProps'
|
|
47
|
+
return resolveProps(config, props);
|
|
48
|
+
}
|
|
49
|
+
return props;
|
|
50
|
+
}
|
|
51
|
+
export function useDefaultProps({
|
|
52
|
+
props,
|
|
53
|
+
name
|
|
54
|
+
}) {
|
|
55
|
+
const ctx = React.useContext(PropsContext);
|
|
56
|
+
return getThemeProps({
|
|
57
|
+
props,
|
|
58
|
+
name,
|
|
59
|
+
theme: {
|
|
60
|
+
components: ctx
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export default DefaultPropsProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, useDefaultProps } from './DefaultPropsProvider';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split this component for RSC import
|
|
3
|
+
*/
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const DEFAULT_MODE_STORAGE_KEY = 'mode';
|
|
7
|
+
export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
8
|
+
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
9
|
+
export default function InitColorSchemeScript(options) {
|
|
10
|
+
const {
|
|
11
|
+
defaultMode = 'light',
|
|
12
|
+
defaultLightColorScheme = 'light',
|
|
13
|
+
defaultDarkColorScheme = 'dark',
|
|
14
|
+
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
15
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
16
|
+
attribute = DEFAULT_ATTRIBUTE,
|
|
17
|
+
colorSchemeNode = 'document.documentElement',
|
|
18
|
+
nonce
|
|
19
|
+
} = options || {};
|
|
20
|
+
return /*#__PURE__*/_jsx("script", {
|
|
21
|
+
suppressHydrationWarning: true,
|
|
22
|
+
nonce: typeof window === 'undefined' ? nonce : ''
|
|
23
|
+
// eslint-disable-next-line react/no-danger
|
|
24
|
+
,
|
|
25
|
+
dangerouslySetInnerHTML: {
|
|
26
|
+
__html: `(function() {
|
|
27
|
+
try {
|
|
28
|
+
var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
|
|
29
|
+
var colorScheme = '';
|
|
30
|
+
if (mode === 'system') {
|
|
31
|
+
// handle system mode
|
|
32
|
+
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
33
|
+
if (mql.matches) {
|
|
34
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
|
+
} else {
|
|
36
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (mode === 'light') {
|
|
40
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
41
|
+
}
|
|
42
|
+
if (mode === 'dark') {
|
|
43
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
44
|
+
}
|
|
45
|
+
if (colorScheme) {
|
|
46
|
+
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
47
|
+
}
|
|
48
|
+
} catch(e){}})();`
|
|
49
|
+
}
|
|
50
|
+
}, "mui-color-scheme-init");
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './InitColorSchemeScript';
|
|
@@ -8,6 +8,7 @@ import exactProp from '@mui/utils/exactProp';
|
|
|
8
8
|
import { ThemeContext as StyledEngineThemeContext } from '@mui/styled-engine';
|
|
9
9
|
import useThemeWithoutDefault from '../useThemeWithoutDefault';
|
|
10
10
|
import RtlProvider from '../RtlProvider';
|
|
11
|
+
import DefaultPropsProvider from '../DefaultPropsProvider';
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
const EMPTY_THEME = {};
|
|
13
14
|
function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
|
|
@@ -60,7 +61,10 @@ function ThemeProvider(props) {
|
|
|
60
61
|
value: engineTheme,
|
|
61
62
|
children: /*#__PURE__*/_jsx(RtlProvider, {
|
|
62
63
|
value: rtlValue,
|
|
63
|
-
children:
|
|
64
|
+
children: /*#__PURE__*/_jsx(DefaultPropsProvider, {
|
|
65
|
+
value: engineTheme == null ? void 0 : engineTheme.components,
|
|
66
|
+
children: children
|
|
67
|
+
})
|
|
64
68
|
})
|
|
65
69
|
})
|
|
66
70
|
});
|
|
@@ -8,7 +8,7 @@ import deepmerge from '@mui/utils/deepmerge';
|
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
10
10
|
import ThemeProvider from '../ThemeProvider';
|
|
11
|
-
import
|
|
11
|
+
import InitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from '../InitColorSchemeScript/InitColorSchemeScript';
|
|
12
12
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -330,7 +330,7 @@ export default function createCssVarsProvider(options) {
|
|
|
330
330
|
} : void 0;
|
|
331
331
|
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
332
332
|
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
333
|
-
const getInitColorSchemeScript = params =>
|
|
333
|
+
const getInitColorSchemeScript = params => InitColorSchemeScript(_extends({
|
|
334
334
|
attribute: defaultAttribute,
|
|
335
335
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
336
336
|
defaultMode: designSystemMode,
|
|
@@ -1,44 +1,8 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
// TODO: remove this file in v6
|
|
1
3
|
import * as React from 'react';
|
|
4
|
+
import InitColorSchemeScript from '../InitColorSchemeScript';
|
|
2
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
|
-
export default function getInitColorSchemeScript(options) {
|
|
7
|
-
const {
|
|
8
|
-
defaultMode = 'light',
|
|
9
|
-
defaultLightColorScheme = 'light',
|
|
10
|
-
defaultDarkColorScheme = 'dark',
|
|
11
|
-
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
12
|
-
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
13
|
-
attribute = DEFAULT_ATTRIBUTE,
|
|
14
|
-
colorSchemeNode = 'document.documentElement'
|
|
15
|
-
} = options || {};
|
|
16
|
-
return /*#__PURE__*/_jsx("script", {
|
|
17
|
-
// eslint-disable-next-line react/no-danger
|
|
18
|
-
dangerouslySetInnerHTML: {
|
|
19
|
-
__html: `(function() {
|
|
20
|
-
try {
|
|
21
|
-
var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
|
|
22
|
-
var colorScheme = '';
|
|
23
|
-
if (mode === 'system') {
|
|
24
|
-
// handle system mode
|
|
25
|
-
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
26
|
-
if (mql.matches) {
|
|
27
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
28
|
-
} else {
|
|
29
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (mode === 'light') {
|
|
33
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
34
|
-
}
|
|
35
|
-
if (mode === 'dark') {
|
|
36
|
-
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
37
|
-
}
|
|
38
|
-
if (colorScheme) {
|
|
39
|
-
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
40
|
-
}
|
|
41
|
-
} catch(e){}})();`
|
|
42
|
-
}
|
|
43
|
-
}, "mui-color-scheme-init");
|
|
6
|
+
export default function getInitColorSchemeScript(params) {
|
|
7
|
+
return /*#__PURE__*/_jsx(InitColorSchemeScript, _extends({}, params));
|
|
44
8
|
}
|
package/esm/cssVars/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
export { default } from './createCssVarsProvider';
|
|
4
|
+
// TODO: remove this export in v6 in favor of InitColorSchemeScript
|
|
4
5
|
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
5
6
|
export { default as prepareCssVars } from './prepareCssVars';
|
|
6
7
|
export { default as createCssVarsTheme } from './createCssVarsTheme';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from '
|
|
5
|
+
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from '../InitColorSchemeScript/InitColorSchemeScript';
|
|
6
6
|
export function getSystemMode(mode) {
|
|
7
7
|
if (typeof window !== 'undefined' && mode === 'system') {
|
|
8
8
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
package/index.js
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import resolveProps from '@mui/utils/resolveProps';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
var PropsContext = /*#__PURE__*/React.createContext(undefined);
|
|
8
|
+
function DefaultPropsProvider(_ref) {
|
|
9
|
+
var value = _ref.value,
|
|
10
|
+
children = _ref.children;
|
|
11
|
+
return /*#__PURE__*/_jsx(PropsContext.Provider, {
|
|
12
|
+
value: value,
|
|
13
|
+
children: children
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
process.env.NODE_ENV !== "production" ? DefaultPropsProvider.propTypes /* remove-proptypes */ = {
|
|
17
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
18
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
19
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
20
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
21
|
+
/**
|
|
22
|
+
* @ignore
|
|
23
|
+
*/
|
|
24
|
+
children: PropTypes.node,
|
|
25
|
+
/**
|
|
26
|
+
* @ignore
|
|
27
|
+
*/
|
|
28
|
+
value: PropTypes.object
|
|
29
|
+
} : void 0;
|
|
30
|
+
function getThemeProps(params) {
|
|
31
|
+
var theme = params.theme,
|
|
32
|
+
name = params.name,
|
|
33
|
+
props = params.props;
|
|
34
|
+
if (!theme || !theme.components || !theme.components[name]) {
|
|
35
|
+
return props;
|
|
36
|
+
}
|
|
37
|
+
var config = theme.components[name];
|
|
38
|
+
if (config.defaultProps) {
|
|
39
|
+
// compatible with v5 signature
|
|
40
|
+
return resolveProps(config.defaultProps, props);
|
|
41
|
+
}
|
|
42
|
+
if (!config.styleOverrides && !config.variants) {
|
|
43
|
+
// v6 signature, no property 'defaultProps'
|
|
44
|
+
return resolveProps(config, props);
|
|
45
|
+
}
|
|
46
|
+
return props;
|
|
47
|
+
}
|
|
48
|
+
export function useDefaultProps(_ref2) {
|
|
49
|
+
var props = _ref2.props,
|
|
50
|
+
name = _ref2.name;
|
|
51
|
+
var ctx = React.useContext(PropsContext);
|
|
52
|
+
return getThemeProps({
|
|
53
|
+
props: props,
|
|
54
|
+
name: name,
|
|
55
|
+
theme: {
|
|
56
|
+
components: ctx
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export default DefaultPropsProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, useDefaultProps } from './DefaultPropsProvider';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split this component for RSC import
|
|
3
|
+
*/
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export var DEFAULT_MODE_STORAGE_KEY = 'mode';
|
|
7
|
+
export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
8
|
+
export var DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
9
|
+
export default function InitColorSchemeScript(options) {
|
|
10
|
+
var _ref = options || {},
|
|
11
|
+
_ref$defaultMode = _ref.defaultMode,
|
|
12
|
+
defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
|
|
13
|
+
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
14
|
+
defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
|
|
15
|
+
_ref$defaultDarkColor = _ref.defaultDarkColorScheme,
|
|
16
|
+
defaultDarkColorScheme = _ref$defaultDarkColor === void 0 ? 'dark' : _ref$defaultDarkColor,
|
|
17
|
+
_ref$modeStorageKey = _ref.modeStorageKey,
|
|
18
|
+
modeStorageKey = _ref$modeStorageKey === void 0 ? DEFAULT_MODE_STORAGE_KEY : _ref$modeStorageKey,
|
|
19
|
+
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
20
|
+
colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
|
|
21
|
+
_ref$attribute = _ref.attribute,
|
|
22
|
+
attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
|
|
23
|
+
_ref$colorSchemeNode = _ref.colorSchemeNode,
|
|
24
|
+
colorSchemeNode = _ref$colorSchemeNode === void 0 ? 'document.documentElement' : _ref$colorSchemeNode,
|
|
25
|
+
nonce = _ref.nonce;
|
|
26
|
+
return /*#__PURE__*/_jsx("script", {
|
|
27
|
+
suppressHydrationWarning: true,
|
|
28
|
+
nonce: typeof window === 'undefined' ? nonce : ''
|
|
29
|
+
// eslint-disable-next-line react/no-danger
|
|
30
|
+
,
|
|
31
|
+
dangerouslySetInnerHTML: {
|
|
32
|
+
__html: "(function() {\ntry {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var colorScheme = '';\n if (mode === 'system') {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n} catch(e){}})();")
|
|
33
|
+
}
|
|
34
|
+
}, "mui-color-scheme-init");
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './InitColorSchemeScript';
|
|
@@ -9,6 +9,7 @@ import exactProp from '@mui/utils/exactProp';
|
|
|
9
9
|
import { ThemeContext as StyledEngineThemeContext } from '@mui/styled-engine';
|
|
10
10
|
import useThemeWithoutDefault from '../useThemeWithoutDefault';
|
|
11
11
|
import RtlProvider from '../RtlProvider';
|
|
12
|
+
import DefaultPropsProvider from '../DefaultPropsProvider';
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
var EMPTY_THEME = {};
|
|
14
15
|
function useThemeScoping(themeId, upperTheme, localTheme) {
|
|
@@ -58,7 +59,10 @@ function ThemeProvider(props) {
|
|
|
58
59
|
value: engineTheme,
|
|
59
60
|
children: /*#__PURE__*/_jsx(RtlProvider, {
|
|
60
61
|
value: rtlValue,
|
|
61
|
-
children:
|
|
62
|
+
children: /*#__PURE__*/_jsx(DefaultPropsProvider, {
|
|
63
|
+
value: engineTheme == null ? void 0 : engineTheme.components,
|
|
64
|
+
children: children
|
|
65
|
+
})
|
|
62
66
|
})
|
|
63
67
|
})
|
|
64
68
|
});
|
|
@@ -10,7 +10,7 @@ import deepmerge from '@mui/utils/deepmerge';
|
|
|
10
10
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
11
11
|
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
12
12
|
import ThemeProvider from '../ThemeProvider';
|
|
13
|
-
import
|
|
13
|
+
import InitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from '../InitColorSchemeScript/InitColorSchemeScript';
|
|
14
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -347,7 +347,7 @@ export default function createCssVarsProvider(options) {
|
|
|
347
347
|
var defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
348
348
|
var defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
349
349
|
var getInitColorSchemeScript = function getInitColorSchemeScript(params) {
|
|
350
|
-
return
|
|
350
|
+
return InitColorSchemeScript(_extends({
|
|
351
351
|
attribute: defaultAttribute,
|
|
352
352
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
353
353
|
defaultMode: designSystemMode,
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
// TODO: remove this file in v6
|
|
1
3
|
import * as React from 'react';
|
|
4
|
+
import InitColorSchemeScript from '../InitColorSchemeScript';
|
|
2
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export var DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
|
-
export default function getInitColorSchemeScript(options) {
|
|
7
|
-
var _ref = options || {},
|
|
8
|
-
_ref$defaultMode = _ref.defaultMode,
|
|
9
|
-
defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
|
|
10
|
-
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
11
|
-
defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
|
|
12
|
-
_ref$defaultDarkColor = _ref.defaultDarkColorScheme,
|
|
13
|
-
defaultDarkColorScheme = _ref$defaultDarkColor === void 0 ? 'dark' : _ref$defaultDarkColor,
|
|
14
|
-
_ref$modeStorageKey = _ref.modeStorageKey,
|
|
15
|
-
modeStorageKey = _ref$modeStorageKey === void 0 ? DEFAULT_MODE_STORAGE_KEY : _ref$modeStorageKey,
|
|
16
|
-
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
17
|
-
colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
|
|
18
|
-
_ref$attribute = _ref.attribute,
|
|
19
|
-
attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
|
|
20
|
-
_ref$colorSchemeNode = _ref.colorSchemeNode,
|
|
21
|
-
colorSchemeNode = _ref$colorSchemeNode === void 0 ? 'document.documentElement' : _ref$colorSchemeNode;
|
|
22
|
-
return /*#__PURE__*/_jsx("script", {
|
|
23
|
-
// eslint-disable-next-line react/no-danger
|
|
24
|
-
dangerouslySetInnerHTML: {
|
|
25
|
-
__html: "(function() {\ntry {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var colorScheme = '';\n if (mode === 'system') {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n} catch(e){}})();")
|
|
26
|
-
}
|
|
27
|
-
}, "mui-color-scheme-init");
|
|
6
|
+
export default function getInitColorSchemeScript(params) {
|
|
7
|
+
return /*#__PURE__*/_jsx(InitColorSchemeScript, _extends({}, params));
|
|
28
8
|
}
|
package/legacy/cssVars/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
export { default } from './createCssVarsProvider';
|
|
4
|
+
// TODO: remove this export in v6 in favor of InitColorSchemeScript
|
|
4
5
|
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
5
6
|
export { default as prepareCssVars } from './prepareCssVars';
|
|
6
7
|
export { default as createCssVarsTheme } from './createCssVarsTheme';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from '
|
|
5
|
+
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from '../InitColorSchemeScript/InitColorSchemeScript';
|
|
6
6
|
export function getSystemMode(mode) {
|
|
7
7
|
if (typeof window !== 'undefined' && mode === 'system') {
|
|
8
8
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
package/legacy/index.js
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import resolveProps from '@mui/utils/resolveProps';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const PropsContext = /*#__PURE__*/React.createContext(undefined);
|
|
8
|
+
function DefaultPropsProvider({
|
|
9
|
+
value,
|
|
10
|
+
children
|
|
11
|
+
}) {
|
|
12
|
+
return /*#__PURE__*/_jsx(PropsContext.Provider, {
|
|
13
|
+
value: value,
|
|
14
|
+
children: children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
process.env.NODE_ENV !== "production" ? DefaultPropsProvider.propTypes /* remove-proptypes */ = {
|
|
18
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
19
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
20
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
21
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
children: PropTypes.node,
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
value: PropTypes.object
|
|
30
|
+
} : void 0;
|
|
31
|
+
function getThemeProps(params) {
|
|
32
|
+
const {
|
|
33
|
+
theme,
|
|
34
|
+
name,
|
|
35
|
+
props
|
|
36
|
+
} = params;
|
|
37
|
+
if (!theme || !theme.components || !theme.components[name]) {
|
|
38
|
+
return props;
|
|
39
|
+
}
|
|
40
|
+
const config = theme.components[name];
|
|
41
|
+
if (config.defaultProps) {
|
|
42
|
+
// compatible with v5 signature
|
|
43
|
+
return resolveProps(config.defaultProps, props);
|
|
44
|
+
}
|
|
45
|
+
if (!config.styleOverrides && !config.variants) {
|
|
46
|
+
// v6 signature, no property 'defaultProps'
|
|
47
|
+
return resolveProps(config, props);
|
|
48
|
+
}
|
|
49
|
+
return props;
|
|
50
|
+
}
|
|
51
|
+
export function useDefaultProps({
|
|
52
|
+
props,
|
|
53
|
+
name
|
|
54
|
+
}) {
|
|
55
|
+
const ctx = React.useContext(PropsContext);
|
|
56
|
+
return getThemeProps({
|
|
57
|
+
props,
|
|
58
|
+
name,
|
|
59
|
+
theme: {
|
|
60
|
+
components: ctx
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export default DefaultPropsProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, useDefaultProps } from './DefaultPropsProvider';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split this component for RSC import
|
|
3
|
+
*/
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const DEFAULT_MODE_STORAGE_KEY = 'mode';
|
|
7
|
+
export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
8
|
+
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
9
|
+
export default function InitColorSchemeScript(options) {
|
|
10
|
+
const {
|
|
11
|
+
defaultMode = 'light',
|
|
12
|
+
defaultLightColorScheme = 'light',
|
|
13
|
+
defaultDarkColorScheme = 'dark',
|
|
14
|
+
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
15
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
16
|
+
attribute = DEFAULT_ATTRIBUTE,
|
|
17
|
+
colorSchemeNode = 'document.documentElement',
|
|
18
|
+
nonce
|
|
19
|
+
} = options || {};
|
|
20
|
+
return /*#__PURE__*/_jsx("script", {
|
|
21
|
+
suppressHydrationWarning: true,
|
|
22
|
+
nonce: typeof window === 'undefined' ? nonce : ''
|
|
23
|
+
// eslint-disable-next-line react/no-danger
|
|
24
|
+
,
|
|
25
|
+
dangerouslySetInnerHTML: {
|
|
26
|
+
__html: `(function() {
|
|
27
|
+
try {
|
|
28
|
+
var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
|
|
29
|
+
var colorScheme = '';
|
|
30
|
+
if (mode === 'system') {
|
|
31
|
+
// handle system mode
|
|
32
|
+
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
33
|
+
if (mql.matches) {
|
|
34
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
|
+
} else {
|
|
36
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (mode === 'light') {
|
|
40
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
41
|
+
}
|
|
42
|
+
if (mode === 'dark') {
|
|
43
|
+
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
44
|
+
}
|
|
45
|
+
if (colorScheme) {
|
|
46
|
+
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
47
|
+
}
|
|
48
|
+
} catch(e){}})();`
|
|
49
|
+
}
|
|
50
|
+
}, "mui-color-scheme-init");
|
|
51
|
+
}
|