@mui/system 5.15.6 → 5.15.8
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 +186 -12
- package/colorManipulator.d.ts +1 -0
- package/colorManipulator.js +20 -0
- package/createStyled.js +80 -160
- package/createTheme/applyStyles.d.ts +63 -0
- package/createTheme/applyStyles.js +80 -0
- package/createTheme/createTheme.d.ts +2 -0
- package/createTheme/createTheme.js +2 -0
- package/createTheme/index.d.ts +2 -0
- package/createTheme/index.js +8 -1
- package/esm/colorManipulator.js +19 -0
- package/esm/createStyled.js +81 -161
- package/esm/createTheme/applyStyles.js +74 -0
- package/esm/createTheme/createTheme.js +2 -0
- package/esm/createTheme/index.js +2 -1
- package/esm/index.js +0 -2
- package/index.js +1 -2
- package/legacy/colorManipulator.js +22 -0
- package/legacy/createStyled.js +85 -167
- package/legacy/createTheme/applyStyles.js +73 -0
- package/legacy/createTheme/createTheme.js +2 -0
- package/legacy/createTheme/index.js +2 -1
- package/legacy/index.js +1 -3
- package/modern/colorManipulator.js +19 -0
- package/modern/createStyled.js +80 -160
- package/modern/createTheme/applyStyles.js +74 -0
- package/modern/createTheme/createTheme.js +2 -0
- package/modern/createTheme/index.js +2 -1
- package/modern/index.js +1 -3
- package/package.json +5 -5
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CSSObject } from '@mui/styled-engine';
|
|
2
|
+
export interface ApplyStyles<K extends string> {
|
|
3
|
+
(key: K, styles: CSSObject): CSSObject;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
7
|
+
* It works with:
|
|
8
|
+
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
9
|
+
* - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
|
|
10
|
+
* - Zero-runtime engine
|
|
11
|
+
*
|
|
12
|
+
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
13
|
+
*
|
|
14
|
+
* ✅ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })]
|
|
15
|
+
*
|
|
16
|
+
* 🚫 { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })}
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* 1. using with `styled`:
|
|
20
|
+
* ```jsx
|
|
21
|
+
* const Component = styled('div')(({ theme }) => [
|
|
22
|
+
* { background: '#e5e5e5' },
|
|
23
|
+
* theme.applyStyles('dark', {
|
|
24
|
+
* background: '#1c1c1c',
|
|
25
|
+
* color: '#fff',
|
|
26
|
+
* }),
|
|
27
|
+
* ]);
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* 2. using with `sx` prop:
|
|
32
|
+
* ```jsx
|
|
33
|
+
* <Box sx={theme => [
|
|
34
|
+
* { background: '#e5e5e5' },
|
|
35
|
+
* theme.applyStyles('dark', {
|
|
36
|
+
* background: '#1c1c1c',
|
|
37
|
+
* color: '#fff',
|
|
38
|
+
* }),
|
|
39
|
+
* ]}
|
|
40
|
+
* />
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* 3. theming a component:
|
|
45
|
+
* ```jsx
|
|
46
|
+
* extendTheme({
|
|
47
|
+
* components: {
|
|
48
|
+
* MuiButton: {
|
|
49
|
+
* styleOverrides: {
|
|
50
|
+
* root: ({ theme }) => [
|
|
51
|
+
* { background: '#e5e5e5' },
|
|
52
|
+
* theme.applyStyles('dark', {
|
|
53
|
+
* background: '#1c1c1c',
|
|
54
|
+
* color: '#fff',
|
|
55
|
+
* }),
|
|
56
|
+
* ],
|
|
57
|
+
* },
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* })
|
|
61
|
+
*```
|
|
62
|
+
*/
|
|
63
|
+
export default function applyStyles<K extends string>(key: K, styles: CSSObject): CSSObject;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = applyStyles;
|
|
7
|
+
/**
|
|
8
|
+
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
9
|
+
* It works with:
|
|
10
|
+
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
11
|
+
* - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
|
|
12
|
+
* - Zero-runtime engine
|
|
13
|
+
*
|
|
14
|
+
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
15
|
+
*
|
|
16
|
+
* ✅ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })]
|
|
17
|
+
*
|
|
18
|
+
* 🚫 { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })}
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* 1. using with `styled`:
|
|
22
|
+
* ```jsx
|
|
23
|
+
* const Component = styled('div')(({ theme }) => [
|
|
24
|
+
* { background: '#e5e5e5' },
|
|
25
|
+
* theme.applyStyles('dark', {
|
|
26
|
+
* background: '#1c1c1c',
|
|
27
|
+
* color: '#fff',
|
|
28
|
+
* }),
|
|
29
|
+
* ]);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* 2. using with `sx` prop:
|
|
34
|
+
* ```jsx
|
|
35
|
+
* <Box sx={theme => [
|
|
36
|
+
* { background: '#e5e5e5' },
|
|
37
|
+
* theme.applyStyles('dark', {
|
|
38
|
+
* background: '#1c1c1c',
|
|
39
|
+
* color: '#fff',
|
|
40
|
+
* }),
|
|
41
|
+
* ]}
|
|
42
|
+
* />
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* 3. theming a component:
|
|
47
|
+
* ```jsx
|
|
48
|
+
* extendTheme({
|
|
49
|
+
* components: {
|
|
50
|
+
* MuiButton: {
|
|
51
|
+
* styleOverrides: {
|
|
52
|
+
* root: ({ theme }) => [
|
|
53
|
+
* { background: '#e5e5e5' },
|
|
54
|
+
* theme.applyStyles('dark', {
|
|
55
|
+
* background: '#1c1c1c',
|
|
56
|
+
* color: '#fff',
|
|
57
|
+
* }),
|
|
58
|
+
* ],
|
|
59
|
+
* },
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* })
|
|
63
|
+
*```
|
|
64
|
+
*/
|
|
65
|
+
function applyStyles(key, styles) {
|
|
66
|
+
// @ts-expect-error this is 'any' type
|
|
67
|
+
const theme = this;
|
|
68
|
+
if (theme.vars && typeof theme.getColorSchemeSelector === 'function') {
|
|
69
|
+
// If CssVarsProvider is used as a provider,
|
|
70
|
+
// returns '* :where([data-mui-color-scheme="light|dark"]) &'
|
|
71
|
+
const selector = theme.getColorSchemeSelector(key).replace(/(\[[^\]]+\])/, '*:where($1)');
|
|
72
|
+
return {
|
|
73
|
+
[selector]: styles
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (theme.palette.mode === key) {
|
|
77
|
+
return styles;
|
|
78
|
+
}
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Breakpoints, BreakpointsOptions } from './createBreakpoints';
|
|
|
3
3
|
import { Shape, ShapeOptions } from './shape';
|
|
4
4
|
import { Spacing, SpacingOptions } from './createSpacing';
|
|
5
5
|
import { SxConfig, SxProps } from '../styleFunctionSx';
|
|
6
|
+
import { ApplyStyles } from './applyStyles';
|
|
6
7
|
|
|
7
8
|
export { Breakpoint, BreakpointOverrides } from './createBreakpoints';
|
|
8
9
|
|
|
@@ -35,6 +36,7 @@ export interface Theme {
|
|
|
35
36
|
mixins?: unknown;
|
|
36
37
|
typography?: unknown;
|
|
37
38
|
zIndex?: unknown;
|
|
39
|
+
applyStyles: ApplyStyles<'light' | 'dark'>;
|
|
38
40
|
unstable_sxConfig: SxConfig;
|
|
39
41
|
unstable_sx: (props: SxProps<Theme>) => CSSObject;
|
|
40
42
|
}
|
|
@@ -13,6 +13,7 @@ var _shape = _interopRequireDefault(require("./shape"));
|
|
|
13
13
|
var _createSpacing = _interopRequireDefault(require("./createSpacing"));
|
|
14
14
|
var _styleFunctionSx = _interopRequireDefault(require("../styleFunctionSx/styleFunctionSx"));
|
|
15
15
|
var _defaultSxConfig = _interopRequireDefault(require("../styleFunctionSx/defaultSxConfig"));
|
|
16
|
+
var _applyStyles = _interopRequireDefault(require("./applyStyles"));
|
|
16
17
|
const _excluded = ["breakpoints", "palette", "spacing", "shape"];
|
|
17
18
|
function createTheme(options = {}, ...args) {
|
|
18
19
|
const {
|
|
@@ -35,6 +36,7 @@ function createTheme(options = {}, ...args) {
|
|
|
35
36
|
spacing,
|
|
36
37
|
shape: (0, _extends2.default)({}, _shape.default, shapeInput)
|
|
37
38
|
}, other);
|
|
39
|
+
muiTheme.applyStyles = _applyStyles.default;
|
|
38
40
|
muiTheme = args.reduce((acc, argument) => (0, _utils.deepmerge)(acc, argument), muiTheme);
|
|
39
41
|
muiTheme.unstable_sxConfig = (0, _extends2.default)({}, _defaultSxConfig.default, other == null ? void 0 : other.unstable_sxConfig);
|
|
40
42
|
muiTheme.unstable_sx = function sx(props) {
|
package/createTheme/index.d.ts
CHANGED
package/createTheme/index.js
CHANGED
|
@@ -16,5 +16,12 @@ Object.defineProperty(exports, "private_createBreakpoints", {
|
|
|
16
16
|
return _createBreakpoints.default;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
Object.defineProperty(exports, "unstable_applyStyles", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _applyStyles.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
19
25
|
var _createTheme = _interopRequireDefault(require("./createTheme"));
|
|
20
|
-
var _createBreakpoints = _interopRequireDefault(require("./createBreakpoints"));
|
|
26
|
+
var _createBreakpoints = _interopRequireDefault(require("./createBreakpoints"));
|
|
27
|
+
var _applyStyles = _interopRequireDefault(require("./applyStyles"));
|
package/esm/colorManipulator.js
CHANGED
|
@@ -323,4 +323,23 @@ export function private_safeEmphasize(color, coefficient, warning) {
|
|
|
323
323
|
}
|
|
324
324
|
return color;
|
|
325
325
|
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Blend a transparent overlay color with a background color, resulting in a single
|
|
330
|
+
* RGB color.
|
|
331
|
+
* @param {string} background - CSS color
|
|
332
|
+
* @param {string} overlay - CSS color
|
|
333
|
+
* @param {number} opacity - Opacity multiplier in the range 0 - 1
|
|
334
|
+
* @param {number} [gamma=1.0] - Gamma correction factor. For gamma-correct blending, 2.2 is usual.
|
|
335
|
+
*/
|
|
336
|
+
export function blend(background, overlay, opacity, gamma = 1.0) {
|
|
337
|
+
const blendChannel = (b, o) => Math.round((b ** (1 / gamma) * (1 - opacity) + o ** (1 / gamma) * opacity) ** gamma);
|
|
338
|
+
const backgroundColor = decomposeColor(background);
|
|
339
|
+
const overlayColor = decomposeColor(overlay);
|
|
340
|
+
const rgb = [blendChannel(backgroundColor.values[0], overlayColor.values[0]), blendChannel(backgroundColor.values[1], overlayColor.values[1]), blendChannel(backgroundColor.values[2], overlayColor.values[2])];
|
|
341
|
+
return recomposeColor({
|
|
342
|
+
type: 'rgb',
|
|
343
|
+
values: rgb
|
|
344
|
+
});
|
|
326
345
|
}
|
package/esm/createStyled.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["ownerState"],
|
|
4
|
+
_excluded2 = ["variants"],
|
|
5
|
+
_excluded3 = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
4
6
|
/* eslint-disable no-underscore-dangle */
|
|
5
7
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
6
|
-
import { getDisplayName, unstable_capitalize as capitalize, isPlainObject
|
|
8
|
+
import { getDisplayName, unstable_capitalize as capitalize, isPlainObject } from '@mui/utils';
|
|
7
9
|
import createTheme from './createTheme';
|
|
8
|
-
import propsToClassKey from './propsToClassKey';
|
|
9
10
|
import styleFunctionSx from './styleFunctionSx';
|
|
10
11
|
function isEmpty(obj) {
|
|
11
12
|
return Object.keys(obj).length === 0;
|
|
@@ -19,74 +20,6 @@ function isStringTag(tag) {
|
|
|
19
20
|
// it's a lowercase character
|
|
20
21
|
tag.charCodeAt(0) > 96;
|
|
21
22
|
}
|
|
22
|
-
const getStyleOverrides = (name, theme) => {
|
|
23
|
-
if (theme.components && theme.components[name] && theme.components[name].styleOverrides) {
|
|
24
|
-
return theme.components[name].styleOverrides;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
};
|
|
28
|
-
const transformVariants = variants => {
|
|
29
|
-
let numOfCallbacks = 0;
|
|
30
|
-
const variantsStyles = {};
|
|
31
|
-
if (variants) {
|
|
32
|
-
variants.forEach(definition => {
|
|
33
|
-
let key = '';
|
|
34
|
-
if (typeof definition.props === 'function') {
|
|
35
|
-
key = `callback${numOfCallbacks}`;
|
|
36
|
-
numOfCallbacks += 1;
|
|
37
|
-
} else {
|
|
38
|
-
key = propsToClassKey(definition.props);
|
|
39
|
-
}
|
|
40
|
-
variantsStyles[key] = definition.style;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return variantsStyles;
|
|
44
|
-
};
|
|
45
|
-
const getVariantStyles = (name, theme) => {
|
|
46
|
-
let variants = [];
|
|
47
|
-
if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
|
|
48
|
-
variants = theme.components[name].variants;
|
|
49
|
-
}
|
|
50
|
-
return transformVariants(variants);
|
|
51
|
-
};
|
|
52
|
-
const variantsResolver = (props, styles, variants) => {
|
|
53
|
-
const {
|
|
54
|
-
ownerState = {}
|
|
55
|
-
} = props;
|
|
56
|
-
const variantsStyles = [];
|
|
57
|
-
let numOfCallbacks = 0;
|
|
58
|
-
if (variants) {
|
|
59
|
-
variants.forEach(variant => {
|
|
60
|
-
let isMatch = true;
|
|
61
|
-
if (typeof variant.props === 'function') {
|
|
62
|
-
const propsToCheck = _extends({}, props, ownerState);
|
|
63
|
-
isMatch = variant.props(propsToCheck);
|
|
64
|
-
} else {
|
|
65
|
-
Object.keys(variant.props).forEach(key => {
|
|
66
|
-
if (ownerState[key] !== variant.props[key] && props[key] !== variant.props[key]) {
|
|
67
|
-
isMatch = false;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (isMatch) {
|
|
72
|
-
if (typeof variant.props === 'function') {
|
|
73
|
-
variantsStyles.push(styles[`callback${numOfCallbacks}`]);
|
|
74
|
-
} else {
|
|
75
|
-
variantsStyles.push(styles[propsToClassKey(variant.props)]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (typeof variant.props === 'function') {
|
|
79
|
-
numOfCallbacks += 1;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return variantsStyles;
|
|
84
|
-
};
|
|
85
|
-
const themeVariantsResolver = (props, styles, theme, name) => {
|
|
86
|
-
var _theme$components;
|
|
87
|
-
const themeVariants = theme == null || (_theme$components = theme.components) == null || (_theme$components = _theme$components[name]) == null ? void 0 : _theme$components.variants;
|
|
88
|
-
return variantsResolver(props, styles, themeVariants);
|
|
89
|
-
};
|
|
90
23
|
|
|
91
24
|
// Update /system/styled/#api in case if this changes
|
|
92
25
|
export function shouldForwardProp(prop) {
|
|
@@ -112,29 +45,51 @@ function defaultOverridesResolver(slot) {
|
|
|
112
45
|
}
|
|
113
46
|
return (props, styles) => styles[slot];
|
|
114
47
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
let optionalVariants;
|
|
128
|
-
if (resolvedStyles && resolvedStyles.variants) {
|
|
129
|
-
optionalVariants = resolvedStyles.variants;
|
|
130
|
-
delete resolvedStyles.variants;
|
|
48
|
+
function processStyleArg(callableStyle, _ref) {
|
|
49
|
+
let {
|
|
50
|
+
ownerState
|
|
51
|
+
} = _ref,
|
|
52
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
53
|
+
const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle(_extends({
|
|
54
|
+
ownerState
|
|
55
|
+
}, props)) : callableStyle;
|
|
56
|
+
if (Array.isArray(resolvedStylesArg)) {
|
|
57
|
+
return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, _extends({
|
|
58
|
+
ownerState
|
|
59
|
+
}, props)));
|
|
131
60
|
}
|
|
132
|
-
if (
|
|
133
|
-
const
|
|
134
|
-
|
|
61
|
+
if (!!resolvedStylesArg && typeof resolvedStylesArg === 'object' && Array.isArray(resolvedStylesArg.variants)) {
|
|
62
|
+
const {
|
|
63
|
+
variants = []
|
|
64
|
+
} = resolvedStylesArg,
|
|
65
|
+
otherStyles = _objectWithoutPropertiesLoose(resolvedStylesArg, _excluded2);
|
|
66
|
+
let result = otherStyles;
|
|
67
|
+
variants.forEach(variant => {
|
|
68
|
+
let isMatch = true;
|
|
69
|
+
if (typeof variant.props === 'function') {
|
|
70
|
+
isMatch = variant.props(_extends({
|
|
71
|
+
ownerState
|
|
72
|
+
}, props));
|
|
73
|
+
} else {
|
|
74
|
+
Object.keys(variant.props).forEach(key => {
|
|
75
|
+
if ((ownerState == null ? void 0 : ownerState[key]) !== variant.props[key] && props[key] !== variant.props[key]) {
|
|
76
|
+
isMatch = false;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (isMatch) {
|
|
81
|
+
if (!Array.isArray(result)) {
|
|
82
|
+
result = [result];
|
|
83
|
+
}
|
|
84
|
+
result.push(typeof variant.style === 'function' ? variant.style(_extends({
|
|
85
|
+
ownerState
|
|
86
|
+
}, props)) : variant.style);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
135
90
|
}
|
|
136
|
-
return
|
|
137
|
-
}
|
|
91
|
+
return resolvedStylesArg;
|
|
92
|
+
}
|
|
138
93
|
export default function createStyled(input = {}) {
|
|
139
94
|
const {
|
|
140
95
|
themeId,
|
|
@@ -163,7 +118,7 @@ export default function createStyled(input = {}) {
|
|
|
163
118
|
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
164
119
|
overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot))
|
|
165
120
|
} = inputOptions,
|
|
166
|
-
options = _objectWithoutPropertiesLoose(inputOptions,
|
|
121
|
+
options = _objectWithoutPropertiesLoose(inputOptions, _excluded3);
|
|
167
122
|
|
|
168
123
|
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
169
124
|
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
|
|
@@ -196,92 +151,57 @@ export default function createStyled(input = {}) {
|
|
|
196
151
|
shouldForwardProp: shouldForwardPropOption,
|
|
197
152
|
label
|
|
198
153
|
}, options));
|
|
199
|
-
const
|
|
200
|
-
const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
|
|
201
|
-
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
202
|
-
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
203
|
-
// which are basically components used as a selectors.
|
|
204
|
-
if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg) {
|
|
205
|
-
return props => muiStyledFunctionResolver({
|
|
206
|
-
styledArg: stylesArg,
|
|
207
|
-
props,
|
|
208
|
-
defaultTheme,
|
|
209
|
-
themeId
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
if (isPlainObject(stylesArg)) {
|
|
213
|
-
let transformedStylesArg = stylesArg;
|
|
214
|
-
let styledArgVariants;
|
|
215
|
-
if (stylesArg && stylesArg.variants) {
|
|
216
|
-
styledArgVariants = stylesArg.variants;
|
|
217
|
-
delete transformedStylesArg.variants;
|
|
218
|
-
transformedStylesArg = props => {
|
|
219
|
-
let result = stylesArg;
|
|
220
|
-
const variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
|
|
221
|
-
variantStyles.forEach(variantStyle => {
|
|
222
|
-
result = deepmerge(result, variantStyle);
|
|
223
|
-
});
|
|
224
|
-
return result;
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return transformedStylesArg;
|
|
228
|
-
}
|
|
229
|
-
return stylesArg;
|
|
230
|
-
}) : [];
|
|
231
|
-
let transformedStyleArg = styleArg;
|
|
232
|
-
if (isPlainObject(styleArg)) {
|
|
233
|
-
let styledArgVariants;
|
|
234
|
-
if (styleArg && styleArg.variants) {
|
|
235
|
-
styledArgVariants = styleArg.variants;
|
|
236
|
-
delete transformedStyleArg.variants;
|
|
237
|
-
transformedStyleArg = props => {
|
|
238
|
-
let result = styleArg;
|
|
239
|
-
const variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
|
|
240
|
-
variantStyles.forEach(variantStyle => {
|
|
241
|
-
result = deepmerge(result, variantStyle);
|
|
242
|
-
});
|
|
243
|
-
return result;
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
} else if (typeof styleArg === 'function' &&
|
|
154
|
+
const transformStyleArg = stylesArg => {
|
|
247
155
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
248
156
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
249
157
|
// which are basically components used as a selectors.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
});
|
|
158
|
+
if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
|
|
159
|
+
return props => processStyleArg(stylesArg, _extends({}, props, {
|
|
160
|
+
theme: resolveTheme({
|
|
161
|
+
theme: props.theme,
|
|
162
|
+
defaultTheme,
|
|
163
|
+
themeId
|
|
164
|
+
})
|
|
165
|
+
}));
|
|
258
166
|
}
|
|
167
|
+
return stylesArg;
|
|
168
|
+
};
|
|
169
|
+
const muiStyledResolver = (styleArg, ...expressions) => {
|
|
170
|
+
let transformedStyleArg = transformStyleArg(styleArg);
|
|
171
|
+
const expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
|
|
259
172
|
if (componentName && overridesResolver) {
|
|
260
173
|
expressionsWithDefaultTheme.push(props => {
|
|
261
174
|
const theme = resolveTheme(_extends({}, props, {
|
|
262
175
|
defaultTheme,
|
|
263
176
|
themeId
|
|
264
177
|
}));
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const resolvedStyleOverrides = {};
|
|
268
|
-
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
269
|
-
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
|
|
270
|
-
theme
|
|
271
|
-
})) : slotStyle;
|
|
272
|
-
});
|
|
273
|
-
return overridesResolver(props, resolvedStyleOverrides);
|
|
178
|
+
if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
|
|
179
|
+
return null;
|
|
274
180
|
}
|
|
275
|
-
|
|
181
|
+
const styleOverrides = theme.components[componentName].styleOverrides;
|
|
182
|
+
const resolvedStyleOverrides = {};
|
|
183
|
+
// TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
|
|
184
|
+
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
185
|
+
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, _extends({}, props, {
|
|
186
|
+
theme
|
|
187
|
+
}));
|
|
188
|
+
});
|
|
189
|
+
return overridesResolver(props, resolvedStyleOverrides);
|
|
276
190
|
});
|
|
277
191
|
}
|
|
278
192
|
if (componentName && !skipVariantsResolver) {
|
|
279
193
|
expressionsWithDefaultTheme.push(props => {
|
|
194
|
+
var _theme$components;
|
|
280
195
|
const theme = resolveTheme(_extends({}, props, {
|
|
281
196
|
defaultTheme,
|
|
282
197
|
themeId
|
|
283
198
|
}));
|
|
284
|
-
|
|
199
|
+
const themeVariants = theme == null || (_theme$components = theme.components) == null || (_theme$components = _theme$components[componentName]) == null ? void 0 : _theme$components.variants;
|
|
200
|
+
return processStyleArg({
|
|
201
|
+
variants: themeVariants
|
|
202
|
+
}, _extends({}, props, {
|
|
203
|
+
theme
|
|
204
|
+
}));
|
|
285
205
|
});
|
|
286
206
|
}
|
|
287
207
|
if (!skipSx) {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
3
|
+
* It works with:
|
|
4
|
+
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
5
|
+
* - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
|
|
6
|
+
* - Zero-runtime engine
|
|
7
|
+
*
|
|
8
|
+
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
9
|
+
*
|
|
10
|
+
* ✅ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })]
|
|
11
|
+
*
|
|
12
|
+
* 🚫 { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })}
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* 1. using with `styled`:
|
|
16
|
+
* ```jsx
|
|
17
|
+
* const Component = styled('div')(({ theme }) => [
|
|
18
|
+
* { background: '#e5e5e5' },
|
|
19
|
+
* theme.applyStyles('dark', {
|
|
20
|
+
* background: '#1c1c1c',
|
|
21
|
+
* color: '#fff',
|
|
22
|
+
* }),
|
|
23
|
+
* ]);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* 2. using with `sx` prop:
|
|
28
|
+
* ```jsx
|
|
29
|
+
* <Box sx={theme => [
|
|
30
|
+
* { background: '#e5e5e5' },
|
|
31
|
+
* theme.applyStyles('dark', {
|
|
32
|
+
* background: '#1c1c1c',
|
|
33
|
+
* color: '#fff',
|
|
34
|
+
* }),
|
|
35
|
+
* ]}
|
|
36
|
+
* />
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* 3. theming a component:
|
|
41
|
+
* ```jsx
|
|
42
|
+
* extendTheme({
|
|
43
|
+
* components: {
|
|
44
|
+
* MuiButton: {
|
|
45
|
+
* styleOverrides: {
|
|
46
|
+
* root: ({ theme }) => [
|
|
47
|
+
* { background: '#e5e5e5' },
|
|
48
|
+
* theme.applyStyles('dark', {
|
|
49
|
+
* background: '#1c1c1c',
|
|
50
|
+
* color: '#fff',
|
|
51
|
+
* }),
|
|
52
|
+
* ],
|
|
53
|
+
* },
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* })
|
|
57
|
+
*```
|
|
58
|
+
*/
|
|
59
|
+
export default function applyStyles(key, styles) {
|
|
60
|
+
// @ts-expect-error this is 'any' type
|
|
61
|
+
const theme = this;
|
|
62
|
+
if (theme.vars && typeof theme.getColorSchemeSelector === 'function') {
|
|
63
|
+
// If CssVarsProvider is used as a provider,
|
|
64
|
+
// returns '* :where([data-mui-color-scheme="light|dark"]) &'
|
|
65
|
+
const selector = theme.getColorSchemeSelector(key).replace(/(\[[^\]]+\])/, '*:where($1)');
|
|
66
|
+
return {
|
|
67
|
+
[selector]: styles
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (theme.palette.mode === key) {
|
|
71
|
+
return styles;
|
|
72
|
+
}
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
@@ -7,6 +7,7 @@ import shape from './shape';
|
|
|
7
7
|
import createSpacing from './createSpacing';
|
|
8
8
|
import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
|
|
9
9
|
import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
|
|
10
|
+
import applyStyles from './applyStyles';
|
|
10
11
|
function createTheme(options = {}, ...args) {
|
|
11
12
|
const {
|
|
12
13
|
breakpoints: breakpointsInput = {},
|
|
@@ -28,6 +29,7 @@ function createTheme(options = {}, ...args) {
|
|
|
28
29
|
spacing,
|
|
29
30
|
shape: _extends({}, shape, shapeInput)
|
|
30
31
|
}, other);
|
|
32
|
+
muiTheme.applyStyles = applyStyles;
|
|
31
33
|
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
32
34
|
muiTheme.unstable_sxConfig = _extends({}, defaultSxConfig, other == null ? void 0 : other.unstable_sxConfig);
|
|
33
35
|
muiTheme.unstable_sx = function sx(props) {
|
package/esm/createTheme/index.js
CHANGED
package/esm/index.js
CHANGED
package/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.15.
|
|
2
|
+
* @mui/system v5.15.8
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
"use strict";
|
|
9
|
-
'use client';
|
|
10
9
|
|
|
11
10
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
12
11
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -331,4 +331,26 @@ export function private_safeEmphasize(color, coefficient, warning) {
|
|
|
331
331
|
}
|
|
332
332
|
return color;
|
|
333
333
|
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Blend a transparent overlay color with a background color, resulting in a single
|
|
338
|
+
* RGB color.
|
|
339
|
+
* @param {string} background - CSS color
|
|
340
|
+
* @param {string} overlay - CSS color
|
|
341
|
+
* @param {number} opacity - Opacity multiplier in the range 0 - 1
|
|
342
|
+
* @param {number} [gamma=1.0] - Gamma correction factor. For gamma-correct blending, 2.2 is usual.
|
|
343
|
+
*/
|
|
344
|
+
export function blend(background, overlay, opacity) {
|
|
345
|
+
var gamma = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1.0;
|
|
346
|
+
var blendChannel = function blendChannel(b, o) {
|
|
347
|
+
return Math.round(Math.pow(Math.pow(b, 1 / gamma) * (1 - opacity) + Math.pow(o, 1 / gamma) * opacity, gamma));
|
|
348
|
+
};
|
|
349
|
+
var backgroundColor = decomposeColor(background);
|
|
350
|
+
var overlayColor = decomposeColor(overlay);
|
|
351
|
+
var rgb = [blendChannel(backgroundColor.values[0], overlayColor.values[0]), blendChannel(backgroundColor.values[1], overlayColor.values[1]), blendChannel(backgroundColor.values[2], overlayColor.values[2])];
|
|
352
|
+
return recomposeColor({
|
|
353
|
+
type: 'rgb',
|
|
354
|
+
values: rgb
|
|
355
|
+
});
|
|
334
356
|
}
|