@mui/system 5.11.15 → 5.12.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 +139 -26
- package/GlobalStyles/GlobalStyles.d.ts +13 -0
- package/GlobalStyles/GlobalStyles.js +45 -0
- package/GlobalStyles/index.d.ts +2 -0
- package/GlobalStyles/index.js +26 -0
- package/GlobalStyles/package.json +6 -0
- package/ThemeProvider/ThemeProvider.d.ts +4 -0
- package/ThemeProvider/ThemeProvider.js +43 -17
- package/createBox.d.ts +1 -0
- package/createBox.js +2 -1
- package/createStyled.d.ts +1 -0
- package/createStyled.js +34 -24
- package/cssVars/createCssVarsProvider.d.ts +22 -7
- package/cssVars/createCssVarsProvider.js +7 -3
- package/esm/GlobalStyles/GlobalStyles.js +35 -0
- package/esm/GlobalStyles/index.js +2 -0
- package/esm/ThemeProvider/ThemeProvider.js +44 -18
- package/esm/createBox.js +2 -1
- package/esm/createStyled.js +34 -24
- package/esm/cssVars/createCssVarsProvider.js +7 -3
- package/esm/index.js +2 -1
- package/esm/useThemeProps/useThemeProps.js +6 -2
- package/esm/useThemeWithoutDefault.js +3 -2
- package/index.d.ts +2 -2
- package/index.js +4 -3
- package/legacy/GlobalStyles/GlobalStyles.js +35 -0
- package/legacy/GlobalStyles/index.js +2 -0
- package/legacy/ThemeProvider/ThemeProvider.js +44 -19
- package/legacy/createBox.js +3 -2
- package/legacy/createStyled.js +34 -17
- package/legacy/cssVars/createCssVarsProvider.js +18 -14
- package/legacy/index.js +3 -2
- package/legacy/useThemeProps/useThemeProps.js +5 -1
- package/legacy/useThemeWithoutDefault.js +3 -2
- package/modern/GlobalStyles/GlobalStyles.js +35 -0
- package/modern/GlobalStyles/index.js +2 -0
- package/modern/ThemeProvider/ThemeProvider.js +44 -18
- package/modern/createBox.js +2 -1
- package/modern/createStyled.js +34 -24
- package/modern/cssVars/createCssVarsProvider.js +7 -3
- package/modern/index.js +3 -2
- package/modern/useThemeProps/useThemeProps.js +6 -2
- package/modern/useThemeWithoutDefault.js +3 -2
- package/package.json +6 -6
- package/useThemeProps/useThemeProps.d.ts +6 -1
- package/useThemeProps/useThemeProps.js +6 -2
- package/useThemeWithoutDefault.js +5 -2
- package/Box/Box.spec.d.ts +0 -1
- package/createBox.spec.d.ts +0 -1
- package/cssVars/createCssVarsProvider.spec.d.ts +0 -1
- package/index.spec.d.ts +0 -1
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +0 -1
package/createStyled.js
CHANGED
|
@@ -14,9 +14,7 @@ var _utils = require("@mui/utils");
|
|
|
14
14
|
var _createTheme = _interopRequireDefault(require("./createTheme"));
|
|
15
15
|
var _propsToClassKey = _interopRequireDefault(require("./propsToClassKey"));
|
|
16
16
|
var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
|
|
17
|
-
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"]
|
|
18
|
-
_excluded2 = ["theme"],
|
|
19
|
-
_excluded3 = ["theme"];
|
|
17
|
+
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
20
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
20
|
function isEmpty(obj) {
|
|
@@ -81,16 +79,26 @@ exports.systemDefaultTheme = systemDefaultTheme;
|
|
|
81
79
|
const lowercaseFirstLetter = string => {
|
|
82
80
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
83
81
|
};
|
|
82
|
+
function resolveTheme({
|
|
83
|
+
defaultTheme,
|
|
84
|
+
theme,
|
|
85
|
+
themeId
|
|
86
|
+
}) {
|
|
87
|
+
return isEmpty(theme) ? defaultTheme : theme[themeId] || theme;
|
|
88
|
+
}
|
|
84
89
|
function createStyled(input = {}) {
|
|
85
90
|
const {
|
|
91
|
+
themeId,
|
|
86
92
|
defaultTheme = systemDefaultTheme,
|
|
87
93
|
rootShouldForwardProp = shouldForwardProp,
|
|
88
94
|
slotShouldForwardProp = shouldForwardProp
|
|
89
95
|
} = input;
|
|
90
96
|
const systemSx = props => {
|
|
91
|
-
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
92
97
|
return (0, _styleFunctionSx.default)((0, _extends2.default)({}, props, {
|
|
93
|
-
theme
|
|
98
|
+
theme: resolveTheme((0, _extends2.default)({}, props, {
|
|
99
|
+
defaultTheme,
|
|
100
|
+
themeId
|
|
101
|
+
}))
|
|
94
102
|
}));
|
|
95
103
|
};
|
|
96
104
|
systemSx.__mui_systemSx = true;
|
|
@@ -134,20 +142,22 @@ function createStyled(input = {}) {
|
|
|
134
142
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
135
143
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
136
144
|
// which are basically components used as a selectors.
|
|
137
|
-
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ?
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}, other));
|
|
145
|
+
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? props => {
|
|
146
|
+
return stylesArg((0, _extends2.default)({}, props, {
|
|
147
|
+
theme: resolveTheme((0, _extends2.default)({}, props, {
|
|
148
|
+
defaultTheme,
|
|
149
|
+
themeId
|
|
150
|
+
}))
|
|
151
|
+
}));
|
|
145
152
|
} : stylesArg;
|
|
146
153
|
}) : [];
|
|
147
154
|
let transformedStyleArg = styleArg;
|
|
148
155
|
if (componentName && overridesResolver) {
|
|
149
156
|
expressionsWithDefaultTheme.push(props => {
|
|
150
|
-
const theme =
|
|
157
|
+
const theme = resolveTheme((0, _extends2.default)({}, props, {
|
|
158
|
+
defaultTheme,
|
|
159
|
+
themeId
|
|
160
|
+
}));
|
|
151
161
|
const styleOverrides = getStyleOverrides(componentName, theme);
|
|
152
162
|
if (styleOverrides) {
|
|
153
163
|
const resolvedStyleOverrides = {};
|
|
@@ -163,7 +173,10 @@ function createStyled(input = {}) {
|
|
|
163
173
|
}
|
|
164
174
|
if (componentName && !skipVariantsResolver) {
|
|
165
175
|
expressionsWithDefaultTheme.push(props => {
|
|
166
|
-
const theme =
|
|
176
|
+
const theme = resolveTheme((0, _extends2.default)({}, props, {
|
|
177
|
+
defaultTheme,
|
|
178
|
+
themeId
|
|
179
|
+
}));
|
|
167
180
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
168
181
|
});
|
|
169
182
|
}
|
|
@@ -182,15 +195,12 @@ function createStyled(input = {}) {
|
|
|
182
195
|
// which are basically components used as a selectors.
|
|
183
196
|
styleArg.__emotion_real !== styleArg) {
|
|
184
197
|
// If the type is function, we need to define the default theme.
|
|
185
|
-
transformedStyleArg =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
192
|
-
}, other));
|
|
193
|
-
};
|
|
198
|
+
transformedStyleArg = props => styleArg((0, _extends2.default)({}, props, {
|
|
199
|
+
theme: resolveTheme((0, _extends2.default)({}, props, {
|
|
200
|
+
defaultTheme,
|
|
201
|
+
themeId
|
|
202
|
+
}))
|
|
203
|
+
}));
|
|
194
204
|
}
|
|
195
205
|
const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
|
|
196
206
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -41,14 +41,22 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
|
|
|
41
41
|
disableTransitionOnChange?: boolean;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
type Identify<I extends string | undefined, T> = I extends string ? T | { [k in I]: T } : T;
|
|
45
|
+
|
|
46
|
+
export interface CreateCssVarsProviderResult<
|
|
47
|
+
ColorScheme extends string,
|
|
48
|
+
Identifier extends string | undefined = undefined,
|
|
49
|
+
> {
|
|
45
50
|
CssVarsProvider: (
|
|
46
51
|
props: React.PropsWithChildren<
|
|
47
52
|
Partial<CssVarsProviderConfig<ColorScheme>> & {
|
|
48
|
-
theme?:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
theme?: Identify<
|
|
54
|
+
Identifier,
|
|
55
|
+
{
|
|
56
|
+
cssVarPrefix?: string;
|
|
57
|
+
colorSchemes: Record<ColorScheme, Record<string, any>>;
|
|
58
|
+
}
|
|
59
|
+
>;
|
|
52
60
|
/**
|
|
53
61
|
* The document used to perform `disableTransitionOnChange` feature
|
|
54
62
|
* @default document
|
|
@@ -87,8 +95,15 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string> {
|
|
|
87
95
|
getInitColorSchemeScript: typeof getInitColorSchemeScript;
|
|
88
96
|
}
|
|
89
97
|
|
|
90
|
-
export default function createCssVarsProvider<
|
|
98
|
+
export default function createCssVarsProvider<
|
|
99
|
+
ColorScheme extends string,
|
|
100
|
+
Identifier extends string | undefined = undefined,
|
|
101
|
+
>(
|
|
91
102
|
options: CssVarsProviderConfig<ColorScheme> & {
|
|
103
|
+
/**
|
|
104
|
+
* The design system's unique id for getting the corresponded theme when there are multiple design systems.
|
|
105
|
+
*/
|
|
106
|
+
themeId?: Identifier;
|
|
92
107
|
/**
|
|
93
108
|
* Design system default theme
|
|
94
109
|
*
|
|
@@ -136,7 +151,7 @@ export default function createCssVarsProvider<ColorScheme extends string>(
|
|
|
136
151
|
*/
|
|
137
152
|
excludeVariablesFromRoot?: (cssVarPrefix: string) => string[];
|
|
138
153
|
},
|
|
139
|
-
): CreateCssVarsProviderResult<ColorScheme>;
|
|
154
|
+
): CreateCssVarsProviderResult<ColorScheme, Identifier>;
|
|
140
155
|
|
|
141
156
|
// disable automatic export
|
|
142
157
|
export {};
|
|
@@ -24,6 +24,7 @@ const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transit
|
|
|
24
24
|
exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
|
|
25
25
|
function createCssVarsProvider(options) {
|
|
26
26
|
const {
|
|
27
|
+
themeId,
|
|
27
28
|
theme: defaultTheme = {},
|
|
28
29
|
attribute: defaultAttribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
29
30
|
modeStorageKey: defaultModeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -65,7 +66,9 @@ function createCssVarsProvider(options) {
|
|
|
65
66
|
const upperTheme = (0, _privateTheming.useTheme)();
|
|
66
67
|
const ctx = React.useContext(ColorSchemeContext);
|
|
67
68
|
const nested = !!ctx && !disableNestedContext;
|
|
68
|
-
const
|
|
69
|
+
const scopedTheme = themeProp[themeId];
|
|
70
|
+
const _ref = scopedTheme || themeProp,
|
|
71
|
+
{
|
|
69
72
|
colorSchemes = {},
|
|
70
73
|
components = {},
|
|
71
74
|
generateCssVars = () => ({
|
|
@@ -73,8 +76,8 @@ function createCssVarsProvider(options) {
|
|
|
73
76
|
css: {}
|
|
74
77
|
}),
|
|
75
78
|
cssVarPrefix
|
|
76
|
-
} =
|
|
77
|
-
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(
|
|
79
|
+
} = _ref,
|
|
80
|
+
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
78
81
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
79
82
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
80
83
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -250,6 +253,7 @@ function createCssVarsProvider(options) {
|
|
|
250
253
|
styles: otherColorSchemesStyleSheet
|
|
251
254
|
})]
|
|
252
255
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
|
|
256
|
+
themeId: scopedTheme ? themeId : undefined,
|
|
253
257
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
254
258
|
children: children
|
|
255
259
|
})]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { GlobalStyles as MuiGlobalStyles } from '@mui/styled-engine';
|
|
4
|
+
import useTheme from '../useTheme';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
function GlobalStyles({
|
|
7
|
+
styles,
|
|
8
|
+
themeId,
|
|
9
|
+
defaultTheme = {}
|
|
10
|
+
}) {
|
|
11
|
+
const upperTheme = useTheme(defaultTheme);
|
|
12
|
+
const globalStyles = typeof styles === 'function' ? styles(themeId ? upperTheme[themeId] || upperTheme : upperTheme) : styles;
|
|
13
|
+
return /*#__PURE__*/_jsx(MuiGlobalStyles, {
|
|
14
|
+
styles: globalStyles
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
process.env.NODE_ENV !== "production" ? GlobalStyles.propTypes /* remove-proptypes */ = {
|
|
18
|
+
// ----------------------------- Warning --------------------------------
|
|
19
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
20
|
+
// | To update them edit TypeScript types and run "yarn proptypes" |
|
|
21
|
+
// ----------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
defaultTheme: PropTypes.object,
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
styles: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.array, PropTypes.func, PropTypes.number, PropTypes.object, PropTypes.string, PropTypes.bool]),
|
|
30
|
+
/**
|
|
31
|
+
* @ignore
|
|
32
|
+
*/
|
|
33
|
+
themeId: PropTypes.string
|
|
34
|
+
} : void 0;
|
|
35
|
+
export default GlobalStyles;
|
|
@@ -1,37 +1,59 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { ThemeProvider as MuiThemeProvider } from '@mui/private-theming';
|
|
4
|
+
import { ThemeProvider as MuiThemeProvider, useTheme as usePrivateTheme } from '@mui/private-theming';
|
|
4
5
|
import { exactProp } from '@mui/utils';
|
|
5
6
|
import { ThemeContext as StyledEngineThemeContext } from '@mui/styled-engine';
|
|
6
|
-
import
|
|
7
|
+
import useThemeWithoutDefault from '../useThemeWithoutDefault';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
const EMPTY_THEME = {};
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
|
|
11
|
+
return React.useMemo(() => {
|
|
12
|
+
const resolvedTheme = themeId ? upperTheme[themeId] || upperTheme : upperTheme;
|
|
13
|
+
if (typeof localTheme === 'function') {
|
|
14
|
+
const mergedTheme = localTheme(resolvedTheme);
|
|
15
|
+
const result = themeId ? _extends({}, upperTheme, {
|
|
16
|
+
[themeId]: mergedTheme
|
|
17
|
+
}) : mergedTheme;
|
|
18
|
+
// must return a function for the private theme to NOT merge with the upper theme.
|
|
19
|
+
// see the test case "use provided theme from a callback" in ThemeProvider.test.js
|
|
20
|
+
if (isPrivate) {
|
|
21
|
+
return () => result;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return themeId ? _extends({}, upperTheme, {
|
|
26
|
+
[themeId]: localTheme
|
|
27
|
+
}) : _extends({}, upperTheme, localTheme);
|
|
28
|
+
}, [themeId, upperTheme, localTheme, isPrivate]);
|
|
15
29
|
}
|
|
16
|
-
process.env.NODE_ENV !== "production" ? InnerThemeProvider.propTypes = {
|
|
17
|
-
/**
|
|
18
|
-
* Your component tree.
|
|
19
|
-
*/
|
|
20
|
-
children: PropTypes.node
|
|
21
|
-
} : void 0;
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
32
|
* This component makes the `theme` available down the React tree.
|
|
25
33
|
* It should preferably be used at **the root of your component tree**.
|
|
34
|
+
*
|
|
35
|
+
* <ThemeProvider theme={theme}> // existing use case
|
|
36
|
+
* <ThemeProvider theme={{ id: theme }}> // theme scoping
|
|
26
37
|
*/
|
|
27
38
|
function ThemeProvider(props) {
|
|
28
39
|
const {
|
|
29
40
|
children,
|
|
30
|
-
theme: localTheme
|
|
41
|
+
theme: localTheme,
|
|
42
|
+
themeId
|
|
31
43
|
} = props;
|
|
44
|
+
const upperTheme = useThemeWithoutDefault(EMPTY_THEME);
|
|
45
|
+
const upperPrivateTheme = usePrivateTheme() || EMPTY_THEME;
|
|
46
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
47
|
+
if (upperTheme === null && typeof localTheme === 'function' || themeId && upperTheme && !upperTheme[themeId] && typeof localTheme === 'function') {
|
|
48
|
+
console.error(['MUI: You are providing a theme function prop to the ThemeProvider component:', '<ThemeProvider theme={outerTheme => outerTheme} />', '', 'However, no outer theme is present.', 'Make sure a theme is already injected higher in the React tree ' + 'or provide a theme object.'].join('\n'));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const engineTheme = useThemeScoping(themeId, upperTheme, localTheme);
|
|
52
|
+
const privateTheme = useThemeScoping(themeId, upperPrivateTheme, localTheme, true);
|
|
32
53
|
return /*#__PURE__*/_jsx(MuiThemeProvider, {
|
|
33
|
-
theme:
|
|
34
|
-
children: /*#__PURE__*/_jsx(
|
|
54
|
+
theme: privateTheme,
|
|
55
|
+
children: /*#__PURE__*/_jsx(StyledEngineThemeContext.Provider, {
|
|
56
|
+
value: engineTheme,
|
|
35
57
|
children: children
|
|
36
58
|
})
|
|
37
59
|
});
|
|
@@ -48,7 +70,11 @@ process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes /* remove-propty
|
|
|
48
70
|
/**
|
|
49
71
|
* A theme object. You can provide a function to extend the outer theme.
|
|
50
72
|
*/
|
|
51
|
-
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired
|
|
73
|
+
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
|
|
74
|
+
/**
|
|
75
|
+
* The design system's unique id for getting the corresponded theme when there are multiple design systems.
|
|
76
|
+
*/
|
|
77
|
+
themeId: PropTypes.string
|
|
52
78
|
} : void 0;
|
|
53
79
|
if (process.env.NODE_ENV !== 'production') {
|
|
54
80
|
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes = exactProp(ThemeProvider.propTypes) : void 0;
|
package/esm/createBox.js
CHANGED
|
@@ -9,6 +9,7 @@ import useTheme from './useTheme';
|
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
export default function createBox(options = {}) {
|
|
11
11
|
const {
|
|
12
|
+
themeId,
|
|
12
13
|
defaultTheme,
|
|
13
14
|
defaultClassName = 'MuiBox-root',
|
|
14
15
|
generateClassName
|
|
@@ -28,7 +29,7 @@ export default function createBox(options = {}) {
|
|
|
28
29
|
as: component,
|
|
29
30
|
ref: ref,
|
|
30
31
|
className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
|
|
31
|
-
theme: theme
|
|
32
|
+
theme: themeId ? theme[themeId] || theme : theme
|
|
32
33
|
}, other));
|
|
33
34
|
});
|
|
34
35
|
return Box;
|
package/esm/createStyled.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"]
|
|
4
|
-
_excluded2 = ["theme"],
|
|
5
|
-
_excluded3 = ["theme"];
|
|
3
|
+
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
6
4
|
/* eslint-disable no-underscore-dangle */
|
|
7
5
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
8
6
|
import { getDisplayName } from '@mui/utils';
|
|
@@ -70,16 +68,26 @@ export const systemDefaultTheme = createTheme();
|
|
|
70
68
|
const lowercaseFirstLetter = string => {
|
|
71
69
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
72
70
|
};
|
|
71
|
+
function resolveTheme({
|
|
72
|
+
defaultTheme,
|
|
73
|
+
theme,
|
|
74
|
+
themeId
|
|
75
|
+
}) {
|
|
76
|
+
return isEmpty(theme) ? defaultTheme : theme[themeId] || theme;
|
|
77
|
+
}
|
|
73
78
|
export default function createStyled(input = {}) {
|
|
74
79
|
const {
|
|
80
|
+
themeId,
|
|
75
81
|
defaultTheme = systemDefaultTheme,
|
|
76
82
|
rootShouldForwardProp = shouldForwardProp,
|
|
77
83
|
slotShouldForwardProp = shouldForwardProp
|
|
78
84
|
} = input;
|
|
79
85
|
const systemSx = props => {
|
|
80
|
-
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
81
86
|
return styleFunctionSx(_extends({}, props, {
|
|
82
|
-
theme
|
|
87
|
+
theme: resolveTheme(_extends({}, props, {
|
|
88
|
+
defaultTheme,
|
|
89
|
+
themeId
|
|
90
|
+
}))
|
|
83
91
|
}));
|
|
84
92
|
};
|
|
85
93
|
systemSx.__mui_systemSx = true;
|
|
@@ -123,20 +131,22 @@ export default function createStyled(input = {}) {
|
|
|
123
131
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
124
132
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
125
133
|
// which are basically components used as a selectors.
|
|
126
|
-
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ?
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}, other));
|
|
134
|
+
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? props => {
|
|
135
|
+
return stylesArg(_extends({}, props, {
|
|
136
|
+
theme: resolveTheme(_extends({}, props, {
|
|
137
|
+
defaultTheme,
|
|
138
|
+
themeId
|
|
139
|
+
}))
|
|
140
|
+
}));
|
|
134
141
|
} : stylesArg;
|
|
135
142
|
}) : [];
|
|
136
143
|
let transformedStyleArg = styleArg;
|
|
137
144
|
if (componentName && overridesResolver) {
|
|
138
145
|
expressionsWithDefaultTheme.push(props => {
|
|
139
|
-
const theme =
|
|
146
|
+
const theme = resolveTheme(_extends({}, props, {
|
|
147
|
+
defaultTheme,
|
|
148
|
+
themeId
|
|
149
|
+
}));
|
|
140
150
|
const styleOverrides = getStyleOverrides(componentName, theme);
|
|
141
151
|
if (styleOverrides) {
|
|
142
152
|
const resolvedStyleOverrides = {};
|
|
@@ -152,7 +162,10 @@ export default function createStyled(input = {}) {
|
|
|
152
162
|
}
|
|
153
163
|
if (componentName && !skipVariantsResolver) {
|
|
154
164
|
expressionsWithDefaultTheme.push(props => {
|
|
155
|
-
const theme =
|
|
165
|
+
const theme = resolveTheme(_extends({}, props, {
|
|
166
|
+
defaultTheme,
|
|
167
|
+
themeId
|
|
168
|
+
}));
|
|
156
169
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
157
170
|
});
|
|
158
171
|
}
|
|
@@ -171,15 +184,12 @@ export default function createStyled(input = {}) {
|
|
|
171
184
|
// which are basically components used as a selectors.
|
|
172
185
|
styleArg.__emotion_real !== styleArg) {
|
|
173
186
|
// If the type is function, we need to define the default theme.
|
|
174
|
-
transformedStyleArg =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
theme: isEmpty(themeInput) ? defaultTheme : themeInput
|
|
181
|
-
}, other));
|
|
182
|
-
};
|
|
187
|
+
transformedStyleArg = props => styleArg(_extends({}, props, {
|
|
188
|
+
theme: resolveTheme(_extends({}, props, {
|
|
189
|
+
defaultTheme,
|
|
190
|
+
themeId
|
|
191
|
+
}))
|
|
192
|
+
}));
|
|
183
193
|
}
|
|
184
194
|
const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
|
|
185
195
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -15,6 +15,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
15
15
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
16
16
|
export default function createCssVarsProvider(options) {
|
|
17
17
|
const {
|
|
18
|
+
themeId,
|
|
18
19
|
theme: defaultTheme = {},
|
|
19
20
|
attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
|
|
20
21
|
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -56,7 +57,9 @@ export default function createCssVarsProvider(options) {
|
|
|
56
57
|
const upperTheme = muiUseTheme();
|
|
57
58
|
const ctx = React.useContext(ColorSchemeContext);
|
|
58
59
|
const nested = !!ctx && !disableNestedContext;
|
|
59
|
-
const
|
|
60
|
+
const scopedTheme = themeProp[themeId];
|
|
61
|
+
const _ref = scopedTheme || themeProp,
|
|
62
|
+
{
|
|
60
63
|
colorSchemes = {},
|
|
61
64
|
components = {},
|
|
62
65
|
generateCssVars = () => ({
|
|
@@ -64,8 +67,8 @@ export default function createCssVarsProvider(options) {
|
|
|
64
67
|
css: {}
|
|
65
68
|
}),
|
|
66
69
|
cssVarPrefix
|
|
67
|
-
} =
|
|
68
|
-
restThemeProp = _objectWithoutPropertiesLoose(
|
|
70
|
+
} = _ref,
|
|
71
|
+
restThemeProp = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
69
72
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
70
73
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
71
74
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -241,6 +244,7 @@ export default function createCssVarsProvider(options) {
|
|
|
241
244
|
styles: otherColorSchemesStyleSheet
|
|
242
245
|
})]
|
|
243
246
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
247
|
+
themeId: scopedTheme ? themeId : undefined,
|
|
244
248
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
245
249
|
children: children
|
|
246
250
|
})]
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
2
|
-
export { css, keyframes,
|
|
2
|
+
export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
|
|
3
|
+
export { default as GlobalStyles } from './GlobalStyles';
|
|
3
4
|
export { default as borders } from './borders';
|
|
4
5
|
export * from './borders';
|
|
5
6
|
export { default as breakpoints } from './breakpoints';
|
|
@@ -3,9 +3,13 @@ import useTheme from '../useTheme';
|
|
|
3
3
|
export default function useThemeProps({
|
|
4
4
|
props,
|
|
5
5
|
name,
|
|
6
|
-
defaultTheme
|
|
6
|
+
defaultTheme,
|
|
7
|
+
themeId
|
|
7
8
|
}) {
|
|
8
|
-
|
|
9
|
+
let theme = useTheme(defaultTheme);
|
|
10
|
+
if (themeId) {
|
|
11
|
+
theme = theme[themeId] || theme;
|
|
12
|
+
}
|
|
9
13
|
const mergedProps = getThemeProps({
|
|
10
14
|
theme,
|
|
11
15
|
name,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ThemeContext } from '@mui/styled-engine';
|
|
2
3
|
function isObjectEmpty(obj) {
|
|
3
4
|
return Object.keys(obj).length === 0;
|
|
4
5
|
}
|
|
5
6
|
function useTheme(defaultTheme = null) {
|
|
6
|
-
const contextTheme =
|
|
7
|
+
const contextTheme = React.useContext(ThemeContext);
|
|
7
8
|
return !contextTheme || isObjectEmpty(contextTheme) ? defaultTheme : contextTheme;
|
|
8
9
|
}
|
|
9
10
|
export default useTheme;
|
package/index.d.ts
CHANGED
|
@@ -104,13 +104,13 @@ export { DefaultTheme } from '@mui/private-theming';
|
|
|
104
104
|
export {
|
|
105
105
|
css,
|
|
106
106
|
keyframes,
|
|
107
|
-
GlobalStyles,
|
|
108
|
-
GlobalStylesProps,
|
|
109
107
|
StyledEngineProvider,
|
|
110
108
|
Interpolation,
|
|
111
109
|
CSSInterpolation,
|
|
112
110
|
CSSObject,
|
|
113
111
|
} from '@mui/styled-engine';
|
|
112
|
+
export { default as GlobalStyles } from './GlobalStyles';
|
|
113
|
+
export type { GlobalStylesProps } from './GlobalStyles';
|
|
114
114
|
|
|
115
115
|
export * from './style';
|
|
116
116
|
export * from './spacing';
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.
|
|
2
|
+
* @mui/system v5.12.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -15,8 +15,8 @@ var _exportNames = {
|
|
|
15
15
|
experimental_sx: true,
|
|
16
16
|
css: true,
|
|
17
17
|
keyframes: true,
|
|
18
|
-
GlobalStyles: true,
|
|
19
18
|
StyledEngineProvider: true,
|
|
19
|
+
GlobalStyles: true,
|
|
20
20
|
borders: true,
|
|
21
21
|
breakpoints: true,
|
|
22
22
|
handleBreakpoints: true,
|
|
@@ -79,7 +79,7 @@ Object.defineProperty(exports, "Container", {
|
|
|
79
79
|
Object.defineProperty(exports, "GlobalStyles", {
|
|
80
80
|
enumerable: true,
|
|
81
81
|
get: function () {
|
|
82
|
-
return
|
|
82
|
+
return _GlobalStyles.default;
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
Object.defineProperty(exports, "Stack", {
|
|
@@ -367,6 +367,7 @@ Object.defineProperty(exports, "useThemeWithoutDefault", {
|
|
|
367
367
|
});
|
|
368
368
|
var _utils = require("@mui/utils");
|
|
369
369
|
var _styledEngine = require("@mui/styled-engine");
|
|
370
|
+
var _GlobalStyles = _interopRequireDefault(require("./GlobalStyles"));
|
|
370
371
|
var _borders = _interopRequireWildcard(require("./borders"));
|
|
371
372
|
Object.keys(_borders).forEach(function (key) {
|
|
372
373
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { GlobalStyles as MuiGlobalStyles } from '@mui/styled-engine';
|
|
4
|
+
import useTheme from '../useTheme';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
function GlobalStyles(_ref) {
|
|
7
|
+
var styles = _ref.styles,
|
|
8
|
+
themeId = _ref.themeId,
|
|
9
|
+
_ref$defaultTheme = _ref.defaultTheme,
|
|
10
|
+
defaultTheme = _ref$defaultTheme === void 0 ? {} : _ref$defaultTheme;
|
|
11
|
+
var upperTheme = useTheme(defaultTheme);
|
|
12
|
+
var globalStyles = typeof styles === 'function' ? styles(themeId ? upperTheme[themeId] || upperTheme : upperTheme) : styles;
|
|
13
|
+
return /*#__PURE__*/_jsx(MuiGlobalStyles, {
|
|
14
|
+
styles: globalStyles
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
process.env.NODE_ENV !== "production" ? GlobalStyles.propTypes /* remove-proptypes */ = {
|
|
18
|
+
// ----------------------------- Warning --------------------------------
|
|
19
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
20
|
+
// | To update them edit TypeScript types and run "yarn proptypes" |
|
|
21
|
+
// ----------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
defaultTheme: PropTypes.object,
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
styles: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.array, PropTypes.func, PropTypes.number, PropTypes.object, PropTypes.string, PropTypes.bool]),
|
|
30
|
+
/**
|
|
31
|
+
* @ignore
|
|
32
|
+
*/
|
|
33
|
+
themeId: PropTypes.string
|
|
34
|
+
} : void 0;
|
|
35
|
+
export default GlobalStyles;
|