@mui/system 5.6.3 → 5.8.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 +238 -0
- package/Container/Container.d.ts +13 -0
- package/Container/Container.js +81 -0
- package/Container/ContainerProps.d.ts +40 -0
- package/Container/ContainerProps.js +5 -0
- package/Container/containerClasses.d.ts +22 -0
- package/Container/containerClasses.js +17 -0
- package/Container/createContainer.d.ts +18 -0
- package/Container/createContainer.js +172 -0
- package/Container/index.d.ts +5 -0
- package/Container/index.js +42 -0
- package/Container/package.json +6 -0
- package/ThemeProvider/ThemeProvider.d.ts +1 -1
- package/createBox.spec.d.ts +1 -1
- package/createStyled.js +3 -1
- package/createTheme/createBreakpoints.d.ts +5 -0
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +25 -0
- package/cssVars/createCssVarsProvider.js +74 -57
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +70 -70
- package/cssVars/cssVarsParser.js +11 -9
- package/cssVars/getInitColorSchemeScript.d.ts +40 -12
- package/cssVars/getInitColorSchemeScript.js +4 -3
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +53 -50
- package/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/Container/Container.js +70 -0
- package/esm/Container/ContainerProps.js +1 -0
- package/esm/Container/containerClasses.js +6 -0
- package/esm/Container/createContainer.js +151 -0
- package/esm/Container/index.js +3 -0
- package/esm/createStyled.js +3 -1
- package/esm/cssVars/createCssVarsProvider.js +76 -57
- package/esm/cssVars/cssVarsParser.js +11 -9
- package/esm/cssVars/getInitColorSchemeScript.js +4 -3
- package/esm/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/index.js +4 -1
- package/index.d.ts +6 -0
- package/index.js +32 -2
- package/index.spec.d.ts +1 -1
- package/legacy/Container/Container.js +70 -0
- package/legacy/Container/ContainerProps.js +1 -0
- package/legacy/Container/containerClasses.js +6 -0
- package/legacy/Container/createContainer.js +148 -0
- package/legacy/Container/index.js +3 -0
- package/legacy/createStyled.js +3 -1
- package/legacy/cssVars/createCssVarsProvider.js +83 -55
- package/legacy/cssVars/cssVarsParser.js +11 -7
- package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
- package/legacy/cssVars/useCurrentColorScheme.js +20 -9
- package/legacy/index.js +5 -2
- package/modern/Container/Container.js +70 -0
- package/modern/Container/ContainerProps.js +1 -0
- package/modern/Container/containerClasses.js +6 -0
- package/modern/Container/createContainer.js +151 -0
- package/modern/Container/index.js +3 -0
- package/modern/createStyled.js +3 -1
- package/modern/cssVars/createCssVarsProvider.js +76 -55
- package/modern/cssVars/cssVarsParser.js +11 -9
- package/modern/cssVars/getInitColorSchemeScript.js +4 -3
- package/modern/cssVars/useCurrentColorScheme.js +17 -7
- package/modern/index.js +5 -2
- package/package.json +5 -5
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
import { unstable_capitalize as capitalize, unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass } from '@mui/utils';
|
|
8
|
+
import useThemePropsSystem from '../useThemeProps';
|
|
9
|
+
import systemStyled from '../styled';
|
|
10
|
+
import createTheme from '../createTheme';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
var defaultTheme = createTheme();
|
|
13
|
+
var defaultCreateStyledComponent = systemStyled('div', {
|
|
14
|
+
name: 'MuiContainer',
|
|
15
|
+
slot: 'Root',
|
|
16
|
+
overridesResolver: function overridesResolver(props, styles) {
|
|
17
|
+
var ownerState = props.ownerState;
|
|
18
|
+
return [styles.root, styles["maxWidth".concat(capitalize(String(ownerState.maxWidth)))], ownerState.fixed && styles.fixed, ownerState.disableGutters && styles.disableGutters];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
var useThemePropsDefault = function useThemePropsDefault(inProps) {
|
|
23
|
+
return useThemePropsSystem({
|
|
24
|
+
props: inProps,
|
|
25
|
+
name: 'MuiContainer',
|
|
26
|
+
defaultTheme: defaultTheme
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var useUtilityClasses = function useUtilityClasses(ownerState, componentName) {
|
|
31
|
+
var getContainerUtilityClass = function getContainerUtilityClass(slot) {
|
|
32
|
+
return generateUtilityClass(componentName, slot);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var classes = ownerState.classes,
|
|
36
|
+
fixed = ownerState.fixed,
|
|
37
|
+
disableGutters = ownerState.disableGutters,
|
|
38
|
+
maxWidth = ownerState.maxWidth;
|
|
39
|
+
var slots = {
|
|
40
|
+
root: ['root', maxWidth && "maxWidth".concat(capitalize(String(maxWidth))), fixed && 'fixed', disableGutters && 'disableGutters']
|
|
41
|
+
};
|
|
42
|
+
return composeClasses(slots, getContainerUtilityClass, classes);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default function createContainer() {
|
|
46
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
47
|
+
var _options$createStyled = options.createStyledComponent,
|
|
48
|
+
createStyledComponent = _options$createStyled === void 0 ? defaultCreateStyledComponent : _options$createStyled,
|
|
49
|
+
_options$useThemeProp = options.useThemeProps,
|
|
50
|
+
useThemeProps = _options$useThemeProp === void 0 ? useThemePropsDefault : _options$useThemeProp,
|
|
51
|
+
_options$componentNam = options.componentName,
|
|
52
|
+
componentName = _options$componentNam === void 0 ? 'MuiContainer' : _options$componentNam;
|
|
53
|
+
var ContainerRoot = createStyledComponent(function (_ref) {
|
|
54
|
+
var theme = _ref.theme,
|
|
55
|
+
ownerState = _ref.ownerState;
|
|
56
|
+
return _extends({
|
|
57
|
+
width: '100%',
|
|
58
|
+
marginLeft: 'auto',
|
|
59
|
+
boxSizing: 'border-box',
|
|
60
|
+
marginRight: 'auto',
|
|
61
|
+
display: 'block'
|
|
62
|
+
}, !ownerState.disableGutters && _defineProperty({
|
|
63
|
+
paddingLeft: theme.spacing(2),
|
|
64
|
+
paddingRight: theme.spacing(2)
|
|
65
|
+
}, theme.breakpoints.up('sm'), {
|
|
66
|
+
paddingLeft: theme.spacing(3),
|
|
67
|
+
paddingRight: theme.spacing(3)
|
|
68
|
+
}));
|
|
69
|
+
}, function (_ref3) {
|
|
70
|
+
var theme = _ref3.theme,
|
|
71
|
+
ownerState = _ref3.ownerState;
|
|
72
|
+
return ownerState.fixed && Object.keys(theme.breakpoints.values).reduce(function (acc, breakpointValueKey) {
|
|
73
|
+
var breakpoint = breakpointValueKey;
|
|
74
|
+
var value = theme.breakpoints.values[breakpoint];
|
|
75
|
+
|
|
76
|
+
if (value !== 0) {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
acc[theme.breakpoints.up(breakpoint)] = {
|
|
79
|
+
maxWidth: "".concat(value).concat(theme.breakpoints.unit)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return acc;
|
|
84
|
+
}, {});
|
|
85
|
+
}, function (_ref4) {
|
|
86
|
+
var theme = _ref4.theme,
|
|
87
|
+
ownerState = _ref4.ownerState;
|
|
88
|
+
return _extends({}, ownerState.maxWidth === 'xs' && _defineProperty({}, theme.breakpoints.up('xs'), {
|
|
89
|
+
// @ts-ignore module augmentation fails if custom breakpoints are used
|
|
90
|
+
maxWidth: Math.max(theme.breakpoints.values.xs, 444)
|
|
91
|
+
}), ownerState.maxWidth && // @ts-ignore module augmentation fails if custom breakpoints are used
|
|
92
|
+
ownerState.maxWidth !== 'xs' && _defineProperty({}, theme.breakpoints.up(ownerState.maxWidth), {
|
|
93
|
+
// @ts-ignore module augmentation fails if custom breakpoints are used
|
|
94
|
+
maxWidth: "".concat(theme.breakpoints.values[ownerState.maxWidth]).concat(theme.breakpoints.unit)
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
var Container = /*#__PURE__*/React.forwardRef(function Container(inProps, ref) {
|
|
98
|
+
var props = useThemeProps(inProps);
|
|
99
|
+
|
|
100
|
+
var className = props.className,
|
|
101
|
+
_props$component = props.component,
|
|
102
|
+
component = _props$component === void 0 ? 'div' : _props$component,
|
|
103
|
+
_props$disableGutters = props.disableGutters,
|
|
104
|
+
disableGutters = _props$disableGutters === void 0 ? false : _props$disableGutters,
|
|
105
|
+
_props$fixed = props.fixed,
|
|
106
|
+
fixed = _props$fixed === void 0 ? false : _props$fixed,
|
|
107
|
+
_props$maxWidth = props.maxWidth,
|
|
108
|
+
maxWidth = _props$maxWidth === void 0 ? 'lg' : _props$maxWidth,
|
|
109
|
+
classesProp = props.classes,
|
|
110
|
+
other = _objectWithoutProperties(props, ["className", "component", "disableGutters", "fixed", "maxWidth", "classes"]);
|
|
111
|
+
|
|
112
|
+
var ownerState = _extends({}, props, {
|
|
113
|
+
component: component,
|
|
114
|
+
disableGutters: disableGutters,
|
|
115
|
+
fixed: fixed,
|
|
116
|
+
maxWidth: maxWidth
|
|
117
|
+
}); // @ts-ignore module augmentation fails if custom breakpoints are used
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
var classes = useUtilityClasses(ownerState, componentName);
|
|
121
|
+
return (
|
|
122
|
+
/*#__PURE__*/
|
|
123
|
+
// @ts-ignore theme is injected by the styled util
|
|
124
|
+
_jsx(ContainerRoot, _extends({
|
|
125
|
+
as: component // @ts-ignore module augmentation fails if custom breakpoints are used
|
|
126
|
+
,
|
|
127
|
+
ownerState: ownerState,
|
|
128
|
+
className: clsx(classes.root, className),
|
|
129
|
+
ref: ref
|
|
130
|
+
}, other))
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
process.env.NODE_ENV !== "production" ? Container.propTypes
|
|
134
|
+
/* remove-proptypes */
|
|
135
|
+
= {
|
|
136
|
+
children: PropTypes.node,
|
|
137
|
+
classes: PropTypes.object,
|
|
138
|
+
className: PropTypes.string,
|
|
139
|
+
component: PropTypes.elementType,
|
|
140
|
+
disableGutters: PropTypes.bool,
|
|
141
|
+
fixed: PropTypes.bool,
|
|
142
|
+
maxWidth: PropTypes
|
|
143
|
+
/* @typescript-to-proptypes-ignore */
|
|
144
|
+
.oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', false]), PropTypes.string]),
|
|
145
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
146
|
+
} : void 0;
|
|
147
|
+
return Container;
|
|
148
|
+
}
|
package/legacy/createStyled.js
CHANGED
|
@@ -149,7 +149,9 @@ export default function createStyled() {
|
|
|
149
149
|
slotKey = _ref3[0],
|
|
150
150
|
slotStyle = _ref3[1];
|
|
151
151
|
|
|
152
|
-
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(props
|
|
152
|
+
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
|
|
153
|
+
theme: theme
|
|
154
|
+
})) : slotStyle;
|
|
153
155
|
});
|
|
154
156
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
155
157
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
@@ -5,23 +6,19 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
5
6
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import PropTypes from 'prop-types';
|
|
8
|
-
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
10
|
-
import
|
|
11
|
-
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
10
|
+
import { GlobalStyles } from '@mui/styled-engine';
|
|
12
11
|
import cssVarsParser from './cssVarsParser';
|
|
13
12
|
import ThemeProvider from '../ThemeProvider';
|
|
14
|
-
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
|
+
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
15
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
16
15
|
import createGetCssVar from './createGetCssVar';
|
|
17
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
18
|
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
20
19
|
export default function createCssVarsProvider(options) {
|
|
21
|
-
var _baseTheme$breakpoint;
|
|
22
|
-
|
|
23
20
|
var _options$theme = options.theme,
|
|
24
|
-
|
|
21
|
+
defaultTheme = _options$theme === void 0 ? {} : _options$theme,
|
|
25
22
|
_options$defaultMode = options.defaultMode,
|
|
26
23
|
desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
27
24
|
designSystemColorScheme = options.defaultColorScheme,
|
|
@@ -33,10 +30,8 @@ export default function createCssVarsProvider(options) {
|
|
|
33
30
|
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
34
31
|
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
35
32
|
resolveTheme = options.resolveTheme;
|
|
36
|
-
var systemSpacing = createSpacing(baseTheme.spacing);
|
|
37
|
-
var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
38
33
|
|
|
39
|
-
if (!
|
|
34
|
+
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
40
35
|
console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
|
|
41
36
|
}
|
|
42
37
|
|
|
@@ -55,11 +50,13 @@ export default function createCssVarsProvider(options) {
|
|
|
55
50
|
function CssVarsProvider(_ref) {
|
|
56
51
|
var children = _ref.children,
|
|
57
52
|
_ref$theme = _ref.theme,
|
|
58
|
-
themeProp = _ref$theme === void 0 ?
|
|
53
|
+
themeProp = _ref$theme === void 0 ? defaultTheme : _ref$theme,
|
|
59
54
|
_ref$prefix = _ref.prefix,
|
|
60
55
|
prefix = _ref$prefix === void 0 ? designSystemPrefix : _ref$prefix,
|
|
61
56
|
_ref$modeStorageKey = _ref.modeStorageKey,
|
|
62
57
|
modeStorageKey = _ref$modeStorageKey === void 0 ? DEFAULT_MODE_STORAGE_KEY : _ref$modeStorageKey,
|
|
58
|
+
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
59
|
+
colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
|
|
63
60
|
_ref$attribute = _ref.attribute,
|
|
64
61
|
attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
|
|
65
62
|
_ref$defaultMode = _ref.defaultMode,
|
|
@@ -69,24 +66,23 @@ export default function createCssVarsProvider(options) {
|
|
|
69
66
|
_ref$disableTransitio = _ref.disableTransitionOnChange,
|
|
70
67
|
disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
|
|
71
68
|
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
72
|
-
enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem,
|
|
70
|
+
_ref$storageWindow = _ref.storageWindow,
|
|
71
|
+
storageWindow = _ref$storageWindow === void 0 ? typeof window === 'undefined' ? undefined : window : _ref$storageWindow,
|
|
72
|
+
_ref$documentNode = _ref.documentNode,
|
|
73
|
+
documentNode = _ref$documentNode === void 0 ? typeof document === 'undefined' ? undefined : document : _ref$documentNode,
|
|
74
|
+
_ref$colorSchemeNode = _ref.colorSchemeNode,
|
|
75
|
+
colorSchemeNode = _ref$colorSchemeNode === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _ref$colorSchemeNode,
|
|
76
|
+
_ref$colorSchemeSelec = _ref.colorSchemeSelector,
|
|
77
|
+
colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec;
|
|
78
|
+
var hasMounted = React.useRef(false);
|
|
77
79
|
|
|
78
80
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
82
|
+
_themeProp$components = themeProp.components,
|
|
83
|
+
components = _themeProp$components === void 0 ? {} : _themeProp$components,
|
|
84
|
+
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components"]);
|
|
81
85
|
|
|
82
|
-
var hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
83
|
-
|
|
84
|
-
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
85
|
-
_deepmerge$components = _deepmerge.components,
|
|
86
|
-
components = _deepmerge$components === void 0 ? {} : _deepmerge$components,
|
|
87
|
-
mergedTheme = _objectWithoutProperties(_deepmerge, ["components"]);
|
|
88
|
-
|
|
89
|
-
var colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
90
86
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
91
87
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
92
88
|
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -96,7 +92,9 @@ export default function createCssVarsProvider(options) {
|
|
|
96
92
|
defaultLightColorScheme: defaultLightColorScheme,
|
|
97
93
|
defaultDarkColorScheme: defaultDarkColorScheme,
|
|
98
94
|
modeStorageKey: modeStorageKey,
|
|
99
|
-
|
|
95
|
+
colorSchemeStorageKey: colorSchemeStorageKey,
|
|
96
|
+
defaultMode: defaultMode,
|
|
97
|
+
storageWindow: storageWindow
|
|
100
98
|
}),
|
|
101
99
|
mode = _useCurrentColorSchem.mode,
|
|
102
100
|
setMode = _useCurrentColorSchem.setMode,
|
|
@@ -120,7 +118,9 @@ export default function createCssVarsProvider(options) {
|
|
|
120
118
|
return colorScheme;
|
|
121
119
|
}();
|
|
122
120
|
|
|
123
|
-
var
|
|
121
|
+
var theme = restThemeProp;
|
|
122
|
+
|
|
123
|
+
var _cssVarsParser = cssVarsParser(theme, {
|
|
124
124
|
prefix: prefix,
|
|
125
125
|
basePrefix: designSystemPrefix,
|
|
126
126
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
@@ -129,13 +129,11 @@ export default function createCssVarsProvider(options) {
|
|
|
129
129
|
rootVars = _cssVarsParser.vars,
|
|
130
130
|
parsedTheme = _cssVarsParser.parsedTheme;
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
theme = _extends({}, parsedTheme, {
|
|
133
133
|
components: components,
|
|
134
134
|
colorSchemes: colorSchemes,
|
|
135
135
|
prefix: prefix,
|
|
136
136
|
vars: rootVars,
|
|
137
|
-
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
138
|
-
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
139
137
|
getCssVar: createGetCssVar(prefix)
|
|
140
138
|
});
|
|
141
139
|
var styleSheet = {};
|
|
@@ -153,10 +151,16 @@ export default function createCssVarsProvider(options) {
|
|
|
153
151
|
vars = _cssVarsParser2.vars,
|
|
154
152
|
parsedScheme = _cssVarsParser2.parsedTheme;
|
|
155
153
|
|
|
156
|
-
|
|
154
|
+
theme.vars = deepmerge(theme.vars, vars);
|
|
157
155
|
|
|
158
156
|
if (key === resolvedColorScheme) {
|
|
159
|
-
|
|
157
|
+
theme = _extends({}, theme, parsedScheme);
|
|
158
|
+
|
|
159
|
+
if (theme.palette) {
|
|
160
|
+
// assign runtime mode & colorScheme
|
|
161
|
+
theme.palette.mode = mode;
|
|
162
|
+
theme.palette.colorScheme = resolvedColorScheme;
|
|
163
|
+
}
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
var resolvedDefaultColorScheme = function () {
|
|
@@ -172,56 +176,56 @@ export default function createCssVarsProvider(options) {
|
|
|
172
176
|
}();
|
|
173
177
|
|
|
174
178
|
if (key === resolvedDefaultColorScheme) {
|
|
175
|
-
styleSheet[
|
|
179
|
+
styleSheet[colorSchemeSelector] = css;
|
|
176
180
|
} else {
|
|
177
|
-
styleSheet["[".concat(attribute, "=\"").concat(key, "\"]")] = css;
|
|
181
|
+
styleSheet["".concat(colorSchemeSelector === ':root' ? '' : colorSchemeSelector, "[").concat(attribute, "=\"").concat(key, "\"]")] = css;
|
|
178
182
|
}
|
|
179
183
|
});
|
|
180
184
|
React.useEffect(function () {
|
|
181
|
-
if (colorScheme) {
|
|
185
|
+
if (colorScheme && colorSchemeNode) {
|
|
182
186
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
183
|
-
|
|
187
|
+
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
184
188
|
}
|
|
185
|
-
}, [colorScheme, attribute]);
|
|
189
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
186
190
|
useEnhancedEffect(function () {
|
|
187
|
-
if (!mode || !enableColorScheme) {
|
|
191
|
+
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
188
192
|
return undefined;
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
var priorColorScheme =
|
|
195
|
+
var priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
192
196
|
|
|
193
197
|
if (mode === 'system') {
|
|
194
|
-
|
|
198
|
+
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
195
199
|
} else {
|
|
196
|
-
|
|
200
|
+
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
return function () {
|
|
200
|
-
|
|
204
|
+
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
201
205
|
};
|
|
202
|
-
}, [mode, systemMode, enableColorScheme]);
|
|
206
|
+
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
203
207
|
React.useEffect(function () {
|
|
204
208
|
var timer;
|
|
205
209
|
|
|
206
|
-
if (disableTransitionOnChange && hasMounted.current) {
|
|
210
|
+
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
207
211
|
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
208
|
-
var css =
|
|
209
|
-
css.appendChild(
|
|
210
|
-
|
|
212
|
+
var css = documentNode.createElement('style');
|
|
213
|
+
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
214
|
+
documentNode.head.appendChild(css); // Force browser repaint
|
|
211
215
|
|
|
212
216
|
(function () {
|
|
213
|
-
return window.getComputedStyle(
|
|
217
|
+
return window.getComputedStyle(documentNode.body);
|
|
214
218
|
})();
|
|
215
219
|
|
|
216
220
|
timer = setTimeout(function () {
|
|
217
|
-
|
|
221
|
+
documentNode.head.removeChild(css);
|
|
218
222
|
}, 1);
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
return function () {
|
|
222
226
|
clearTimeout(timer);
|
|
223
227
|
};
|
|
224
|
-
}, [colorScheme, disableTransitionOnChange]);
|
|
228
|
+
}, [colorScheme, disableTransitionOnChange, documentNode]);
|
|
225
229
|
React.useEffect(function () {
|
|
226
230
|
hasMounted.current = true;
|
|
227
231
|
return function () {
|
|
@@ -239,13 +243,11 @@ export default function createCssVarsProvider(options) {
|
|
|
239
243
|
allColorSchemes: allColorSchemes
|
|
240
244
|
},
|
|
241
245
|
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
242
|
-
styles: {
|
|
243
|
-
':root': rootCss
|
|
244
|
-
}
|
|
246
|
+
styles: _defineProperty({}, colorSchemeSelector, rootCss)
|
|
245
247
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
246
248
|
styles: styleSheet
|
|
247
249
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
248
|
-
theme: resolveTheme ? resolveTheme(
|
|
250
|
+
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
249
251
|
children: children
|
|
250
252
|
})]
|
|
251
253
|
});
|
|
@@ -262,6 +264,21 @@ export default function createCssVarsProvider(options) {
|
|
|
262
264
|
*/
|
|
263
265
|
children: PropTypes.node,
|
|
264
266
|
|
|
267
|
+
/**
|
|
268
|
+
* The node used to attach the color-scheme attribute
|
|
269
|
+
*/
|
|
270
|
+
colorSchemeNode: PropTypes.any,
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The CSS selector for attaching the generated custom properties
|
|
274
|
+
*/
|
|
275
|
+
colorSchemeSelector: PropTypes.string,
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* localStorage key used to store `colorScheme`
|
|
279
|
+
*/
|
|
280
|
+
colorSchemeStorageKey: PropTypes.string,
|
|
281
|
+
|
|
265
282
|
/**
|
|
266
283
|
* The initial color scheme used.
|
|
267
284
|
*/
|
|
@@ -277,6 +294,11 @@ export default function createCssVarsProvider(options) {
|
|
|
277
294
|
*/
|
|
278
295
|
disableTransitionOnChange: PropTypes.bool,
|
|
279
296
|
|
|
297
|
+
/**
|
|
298
|
+
* The document to attach the attribute to
|
|
299
|
+
*/
|
|
300
|
+
documentNode: PropTypes.any,
|
|
301
|
+
|
|
280
302
|
/**
|
|
281
303
|
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
282
304
|
*/
|
|
@@ -292,6 +314,12 @@ export default function createCssVarsProvider(options) {
|
|
|
292
314
|
*/
|
|
293
315
|
prefix: PropTypes.string,
|
|
294
316
|
|
|
317
|
+
/**
|
|
318
|
+
* The window that attaches the 'storage' event listener
|
|
319
|
+
* @default window
|
|
320
|
+
*/
|
|
321
|
+
storageWindow: PropTypes.any,
|
|
322
|
+
|
|
295
323
|
/**
|
|
296
324
|
* The calculated theme object that will be passed through context.
|
|
297
325
|
*/
|
|
@@ -22,15 +22,18 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
22
22
|
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
23
23
|
*/
|
|
24
24
|
export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
|
|
25
|
+
var arrayKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
25
26
|
var temp = obj;
|
|
26
27
|
keys.forEach(function (k, index) {
|
|
27
28
|
if (index === keys.length - 1) {
|
|
28
|
-
if (
|
|
29
|
+
if (Array.isArray(temp)) {
|
|
30
|
+
temp[Number(k)] = value;
|
|
31
|
+
} else if (temp && _typeof(temp) === 'object') {
|
|
29
32
|
temp[k] = value;
|
|
30
33
|
}
|
|
31
34
|
} else if (temp && _typeof(temp) === 'object') {
|
|
32
35
|
if (!temp[k]) {
|
|
33
|
-
temp[k] = {};
|
|
36
|
+
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
temp = temp[k];
|
|
@@ -52,6 +55,7 @@ export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
|
|
|
52
55
|
export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPaths) {
|
|
53
56
|
function recurse(object) {
|
|
54
57
|
var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
58
|
+
var arrayKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
55
59
|
Object.entries(object).forEach(function (_ref) {
|
|
56
60
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
57
61
|
key = _ref2[0],
|
|
@@ -60,9 +64,9 @@ export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPat
|
|
|
60
64
|
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([].concat(_toConsumableArray(parentKeys), [key]))) {
|
|
61
65
|
if (value !== undefined && value !== null) {
|
|
62
66
|
if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
|
|
63
|
-
recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
|
|
67
|
+
recurse(value, [].concat(_toConsumableArray(parentKeys), [key]), Array.isArray(value) ? [].concat(_toConsumableArray(arrayKeys), [key]) : arrayKeys);
|
|
64
68
|
} else {
|
|
65
|
-
callback([].concat(_toConsumableArray(parentKeys), [key]), value,
|
|
69
|
+
callback([].concat(_toConsumableArray(parentKeys), [key]), value, arrayKeys);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -132,7 +136,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
132
136
|
var css = {};
|
|
133
137
|
var vars = {};
|
|
134
138
|
var parsedTheme = {};
|
|
135
|
-
walkObjectDeep(theme, function (keys, value) {
|
|
139
|
+
walkObjectDeep(theme, function (keys, value, arrayKeys) {
|
|
136
140
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
137
141
|
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
138
142
|
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
@@ -150,11 +154,11 @@ export default function cssVarsParser(theme, options) {
|
|
|
150
154
|
|
|
151
155
|
_extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
|
|
152
156
|
|
|
153
|
-
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
|
|
157
|
+
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"), arrayKeys);
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
assignNestedKeys(parsedTheme, keys, value);
|
|
161
|
+
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
158
162
|
}, function (keys) {
|
|
159
163
|
return keys[0] === 'vars';
|
|
160
164
|
} // skip 'vars/*' paths
|
|
@@ -5,7 +5,8 @@ export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export var DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
var _ref = options || {},
|
|
8
|
-
enableSystem = _ref.enableSystem,
|
|
8
|
+
_ref$enableSystem = _ref.enableSystem,
|
|
9
|
+
enableSystem = _ref$enableSystem === void 0 ? false : _ref$enableSystem,
|
|
9
10
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
10
11
|
defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
|
|
11
12
|
_ref$defaultDarkColor = _ref.defaultDarkColorScheme,
|
|
@@ -15,12 +16,14 @@ export default function getInitColorSchemeScript(options) {
|
|
|
15
16
|
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
16
17
|
colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
|
|
17
18
|
_ref$attribute = _ref.attribute,
|
|
18
|
-
attribute = _ref$attribute === void 0 ? DEFAULT_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;
|
|
19
22
|
|
|
20
23
|
return /*#__PURE__*/_jsx("script", {
|
|
21
24
|
// eslint-disable-next-line react/no-danger
|
|
22
25
|
dangerouslySetInnerHTML: {
|
|
23
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\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
|
|
26
|
+
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\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) {} })();")
|
|
24
27
|
}
|
|
25
28
|
});
|
|
26
29
|
}
|
|
@@ -66,7 +66,9 @@ export default function useCurrentColorScheme(options) {
|
|
|
66
66
|
_options$modeStorageK = options.modeStorageKey,
|
|
67
67
|
modeStorageKey = _options$modeStorageK === void 0 ? DEFAULT_MODE_STORAGE_KEY : _options$modeStorageK,
|
|
68
68
|
_options$colorSchemeS = options.colorSchemeStorageKey,
|
|
69
|
-
colorSchemeStorageKey = _options$colorSchemeS === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _options$colorSchemeS
|
|
69
|
+
colorSchemeStorageKey = _options$colorSchemeS === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _options$colorSchemeS,
|
|
70
|
+
_options$storageWindo = options.storageWindow,
|
|
71
|
+
storageWindow = _options$storageWindo === void 0 ? typeof window === 'undefined' ? undefined : window : _options$storageWindo;
|
|
70
72
|
var joinedColorSchemes = supportedColorSchemes.join(',');
|
|
71
73
|
|
|
72
74
|
var _React$useState = React.useState(function () {
|
|
@@ -86,6 +88,10 @@ export default function useCurrentColorScheme(options) {
|
|
|
86
88
|
setState(function (currentState) {
|
|
87
89
|
var newMode = !mode ? defaultMode : mode;
|
|
88
90
|
|
|
91
|
+
if (mode === currentState.mode) {
|
|
92
|
+
return currentState;
|
|
93
|
+
}
|
|
94
|
+
|
|
89
95
|
if (typeof localStorage !== 'undefined') {
|
|
90
96
|
localStorage.setItem(modeStorageKey, newMode);
|
|
91
97
|
}
|
|
@@ -98,7 +104,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
98
104
|
}, [modeStorageKey, defaultMode]);
|
|
99
105
|
var setColorScheme = React.useCallback(function (value) {
|
|
100
106
|
if (!value || typeof value === 'string') {
|
|
101
|
-
if (value && !
|
|
107
|
+
if (value && !joinedColorSchemes.includes(value)) {
|
|
102
108
|
console.error("`".concat(value, "` does not exist in `theme.colorSchemes`."));
|
|
103
109
|
} else {
|
|
104
110
|
setState(function (currentState) {
|
|
@@ -125,7 +131,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
125
131
|
return newState;
|
|
126
132
|
});
|
|
127
133
|
}
|
|
128
|
-
} else if (value.light && !
|
|
134
|
+
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
129
135
|
console.error("`".concat(value, "` does not exist in `theme.colorSchemes`."));
|
|
130
136
|
} else {
|
|
131
137
|
setState(function (currentState) {
|
|
@@ -150,7 +156,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
150
156
|
localStorage.setItem("".concat(colorSchemeStorageKey, "-dark"), value.dark);
|
|
151
157
|
}
|
|
152
158
|
}
|
|
153
|
-
}, [
|
|
159
|
+
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
154
160
|
var handleMediaQuery = React.useCallback(function (e) {
|
|
155
161
|
if (state.mode === 'system') {
|
|
156
162
|
setState(function (currentState) {
|
|
@@ -218,11 +224,16 @@ export default function useCurrentColorScheme(options) {
|
|
|
218
224
|
}
|
|
219
225
|
};
|
|
220
226
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
227
|
+
if (storageWindow) {
|
|
228
|
+
// For syncing color-scheme changes between iframes
|
|
229
|
+
storageWindow.addEventListener('storage', handleStorage);
|
|
230
|
+
return function () {
|
|
231
|
+
return storageWindow.removeEventListener('storage', handleStorage);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return undefined;
|
|
236
|
+
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
|
226
237
|
return _extends({}, state, {
|
|
227
238
|
colorScheme: colorScheme,
|
|
228
239
|
setMode: setMode,
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.8.0
|
|
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.
|
|
@@ -44,4 +44,7 @@ export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
|
|
|
44
44
|
export * from './colorManipulator';
|
|
45
45
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
46
46
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
47
|
-
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
47
|
+
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
48
|
+
export { default as createContainer } from './Container/createContainer';
|
|
49
|
+
export { default as Container } from './Container';
|
|
50
|
+
export * from './Container';
|