@mui/system 5.13.1 → 5.13.5
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 +184 -4
- package/Container/createContainer.js +35 -41
- package/GlobalStyles/GlobalStyles.d.ts +2 -2
- package/Stack/createStack.js +26 -24
- package/ThemeProvider/ThemeProvider.js +5 -9
- package/Unstable_Grid/createGrid.js +23 -21
- package/Unstable_Grid/gridGenerator.d.ts +1 -6
- package/Unstable_Grid/gridGenerator.js +26 -71
- package/Unstable_Grid/index.d.ts +1 -0
- package/Unstable_Grid/index.js +9 -1
- package/Unstable_Grid/traverseBreakpoints.d.ts +7 -0
- package/Unstable_Grid/traverseBreakpoints.js +50 -0
- package/breakpoints.js +6 -7
- package/createBox.js +12 -9
- package/createStyled.js +32 -40
- package/createTheme/createBreakpoints.js +26 -24
- package/createTheme/createTheme.js +14 -18
- package/cssVars/createCssVarsProvider.js +26 -21
- package/cssVars/createCssVarsTheme.js +10 -10
- package/cssVars/getInitColorSchemeScript.d.ts +2 -2
- package/cssVars/prepareCssVars.js +12 -13
- package/cssVars/useCurrentColorScheme.js +11 -17
- package/esm/Container/createContainer.js +35 -41
- package/esm/Stack/createStack.js +26 -24
- package/esm/ThemeProvider/ThemeProvider.js +5 -9
- package/esm/Unstable_Grid/createGrid.js +23 -21
- package/esm/Unstable_Grid/gridGenerator.js +18 -62
- package/esm/Unstable_Grid/index.js +2 -1
- package/esm/Unstable_Grid/traverseBreakpoints.js +42 -0
- package/esm/breakpoints.js +6 -7
- package/esm/createBox.js +12 -9
- package/esm/createStyled.js +31 -38
- package/esm/createTheme/createBreakpoints.js +25 -24
- package/esm/createTheme/createTheme.js +14 -18
- package/esm/cssVars/createCssVarsProvider.js +26 -21
- package/esm/cssVars/createCssVarsTheme.js +10 -10
- package/esm/cssVars/prepareCssVars.js +12 -13
- package/esm/cssVars/useCurrentColorScheme.js +10 -17
- package/esm/propsToClassKey.js +5 -3
- package/esm/styleFunctionSx/extendSxProp.js +10 -14
- package/index.js +1 -1
- package/legacy/Container/createContainer.js +6 -7
- package/legacy/Stack/createStack.js +5 -6
- package/legacy/ThemeProvider/ThemeProvider.js +3 -4
- package/legacy/Unstable_Grid/createGrid.js +4 -6
- package/legacy/Unstable_Grid/gridGenerator.js +7 -54
- package/legacy/Unstable_Grid/index.js +2 -1
- package/legacy/Unstable_Grid/traverseBreakpoints.js +48 -0
- package/legacy/breakpoints.js +3 -5
- package/legacy/createBox.js +2 -4
- package/legacy/createStyled.js +11 -13
- package/legacy/createTheme/createBreakpoints.js +3 -4
- package/legacy/createTheme/createTheme.js +4 -6
- package/legacy/cssVars/createCssVarsProvider.js +5 -6
- package/legacy/cssVars/createCssVarsTheme.js +2 -4
- package/legacy/cssVars/prepareCssVars.js +3 -5
- package/legacy/cssVars/useCurrentColorScheme.js +7 -9
- package/legacy/index.js +1 -1
- package/legacy/styleFunctionSx/extendSxProp.js +4 -6
- package/modern/Container/createContainer.js +35 -41
- package/modern/Stack/createStack.js +26 -24
- package/modern/ThemeProvider/ThemeProvider.js +5 -9
- package/modern/Unstable_Grid/createGrid.js +23 -21
- package/modern/Unstable_Grid/gridGenerator.js +18 -62
- package/modern/Unstable_Grid/index.js +2 -1
- package/modern/Unstable_Grid/traverseBreakpoints.js +42 -0
- package/modern/breakpoints.js +6 -7
- package/modern/createBox.js +12 -9
- package/modern/createStyled.js +31 -38
- package/modern/createTheme/createBreakpoints.js +25 -24
- package/modern/createTheme/createTheme.js +14 -18
- package/modern/cssVars/createCssVarsProvider.js +26 -21
- package/modern/cssVars/createCssVarsTheme.js +10 -10
- package/modern/cssVars/prepareCssVars.js +12 -13
- package/modern/cssVars/useCurrentColorScheme.js +10 -17
- package/modern/index.js +1 -1
- package/modern/propsToClassKey.js +5 -3
- package/modern/styleFunctionSx/extendSxProp.js +10 -14
- package/package.json +2 -2
- package/propsToClassKey.js +6 -3
- package/styleFunctionSx/extendSxProp.js +10 -14
package/modern/breakpoints.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import PropTypes from 'prop-types';
|
|
2
3
|
import { deepmerge } from '@mui/utils';
|
|
3
4
|
import merge from './merge';
|
|
@@ -58,23 +59,21 @@ function breakpoints(styleFunction) {
|
|
|
58
59
|
const extended = themeBreakpoints.keys.reduce((acc, key) => {
|
|
59
60
|
if (props[key]) {
|
|
60
61
|
acc = acc || {};
|
|
61
|
-
acc[themeBreakpoints.up(key)] = styleFunction({
|
|
62
|
-
theme
|
|
63
|
-
|
|
64
|
-
});
|
|
62
|
+
acc[themeBreakpoints.up(key)] = styleFunction(_extends({
|
|
63
|
+
theme
|
|
64
|
+
}, props[key]));
|
|
65
65
|
}
|
|
66
66
|
return acc;
|
|
67
67
|
}, null);
|
|
68
68
|
return merge(base, extended);
|
|
69
69
|
};
|
|
70
|
-
newStyleFunction.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
71
|
-
...styleFunction.propTypes,
|
|
70
|
+
newStyleFunction.propTypes = process.env.NODE_ENV !== 'production' ? _extends({}, styleFunction.propTypes, {
|
|
72
71
|
xs: PropTypes.object,
|
|
73
72
|
sm: PropTypes.object,
|
|
74
73
|
md: PropTypes.object,
|
|
75
74
|
lg: PropTypes.object,
|
|
76
75
|
xl: PropTypes.object
|
|
77
|
-
} : {};
|
|
76
|
+
}) : {};
|
|
78
77
|
newStyleFunction.filterProps = ['xs', 'sm', 'md', 'lg', 'xl', ...styleFunction.filterProps];
|
|
79
78
|
return newStyleFunction;
|
|
80
79
|
}
|
package/modern/createBox.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["className", "component"];
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import clsx from 'clsx';
|
|
3
6
|
import styled from '@mui/styled-engine';
|
|
@@ -16,18 +19,18 @@ export default function createBox(options = {}) {
|
|
|
16
19
|
})(styleFunctionSx);
|
|
17
20
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
|
18
21
|
const theme = useTheme(defaultTheme);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const _extendSxProp = extendSxProp(inProps),
|
|
23
|
+
{
|
|
24
|
+
className,
|
|
25
|
+
component = 'div'
|
|
26
|
+
} = _extendSxProp,
|
|
27
|
+
other = _objectWithoutPropertiesLoose(_extendSxProp, _excluded);
|
|
28
|
+
return /*#__PURE__*/_jsx(BoxRoot, _extends({
|
|
25
29
|
as: component,
|
|
26
30
|
ref: ref,
|
|
27
31
|
className: clsx(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
|
|
28
|
-
theme: themeId ? theme[themeId] || theme : theme
|
|
29
|
-
|
|
30
|
-
});
|
|
32
|
+
theme: themeId ? theme[themeId] || theme : theme
|
|
33
|
+
}, other));
|
|
31
34
|
});
|
|
32
35
|
return Box;
|
|
33
36
|
}
|
package/modern/createStyled.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
1
4
|
/* eslint-disable no-underscore-dangle */
|
|
2
5
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
3
6
|
import { getDisplayName } from '@mui/utils';
|
|
@@ -79,27 +82,25 @@ export default function createStyled(input = {}) {
|
|
|
79
82
|
slotShouldForwardProp = shouldForwardProp
|
|
80
83
|
} = input;
|
|
81
84
|
const systemSx = props => {
|
|
82
|
-
return styleFunctionSx({
|
|
83
|
-
|
|
84
|
-
theme: resolveTheme({
|
|
85
|
-
...props,
|
|
85
|
+
return styleFunctionSx(_extends({}, props, {
|
|
86
|
+
theme: resolveTheme(_extends({}, props, {
|
|
86
87
|
defaultTheme,
|
|
87
88
|
themeId
|
|
88
|
-
})
|
|
89
|
-
});
|
|
89
|
+
}))
|
|
90
|
+
}));
|
|
90
91
|
};
|
|
91
92
|
systemSx.__mui_systemSx = true;
|
|
92
93
|
return (tag, inputOptions = {}) => {
|
|
93
94
|
// Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
|
|
94
95
|
processStyles(tag, styles => styles.filter(style => !style?.__mui_systemSx));
|
|
95
96
|
const {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
name: componentName,
|
|
98
|
+
slot: componentSlot,
|
|
99
|
+
skipVariantsResolver: inputSkipVariantsResolver,
|
|
100
|
+
skipSx: inputSkipSx,
|
|
101
|
+
overridesResolver
|
|
102
|
+
} = inputOptions,
|
|
103
|
+
options = _objectWithoutPropertiesLoose(inputOptions, _excluded);
|
|
103
104
|
|
|
104
105
|
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
105
106
|
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver : componentSlot && componentSlot !== 'Root' || false;
|
|
@@ -120,43 +121,38 @@ export default function createStyled(input = {}) {
|
|
|
120
121
|
// for string (html) tag, preserve the behavior in emotion & styled-components.
|
|
121
122
|
shouldForwardPropOption = undefined;
|
|
122
123
|
}
|
|
123
|
-
const defaultStyledResolver = styledEngineStyled(tag, {
|
|
124
|
+
const defaultStyledResolver = styledEngineStyled(tag, _extends({
|
|
124
125
|
shouldForwardProp: shouldForwardPropOption,
|
|
125
|
-
label
|
|
126
|
-
|
|
127
|
-
});
|
|
126
|
+
label
|
|
127
|
+
}, options));
|
|
128
128
|
const muiStyledResolver = (styleArg, ...expressions) => {
|
|
129
129
|
const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
|
|
130
130
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
131
131
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
132
132
|
// which are basically components used as a selectors.
|
|
133
133
|
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? props => {
|
|
134
|
-
return stylesArg({
|
|
135
|
-
|
|
136
|
-
theme: resolveTheme({
|
|
137
|
-
...props,
|
|
134
|
+
return stylesArg(_extends({}, props, {
|
|
135
|
+
theme: resolveTheme(_extends({}, props, {
|
|
138
136
|
defaultTheme,
|
|
139
137
|
themeId
|
|
140
|
-
})
|
|
141
|
-
});
|
|
138
|
+
}))
|
|
139
|
+
}));
|
|
142
140
|
} : stylesArg;
|
|
143
141
|
}) : [];
|
|
144
142
|
let transformedStyleArg = styleArg;
|
|
145
143
|
if (componentName && overridesResolver) {
|
|
146
144
|
expressionsWithDefaultTheme.push(props => {
|
|
147
|
-
const theme = resolveTheme({
|
|
148
|
-
...props,
|
|
145
|
+
const theme = resolveTheme(_extends({}, props, {
|
|
149
146
|
defaultTheme,
|
|
150
147
|
themeId
|
|
151
|
-
});
|
|
148
|
+
}));
|
|
152
149
|
const styleOverrides = getStyleOverrides(componentName, theme);
|
|
153
150
|
if (styleOverrides) {
|
|
154
151
|
const resolvedStyleOverrides = {};
|
|
155
152
|
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
156
|
-
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle({
|
|
157
|
-
...props,
|
|
153
|
+
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
|
|
158
154
|
theme
|
|
159
|
-
}) : slotStyle;
|
|
155
|
+
})) : slotStyle;
|
|
160
156
|
});
|
|
161
157
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
162
158
|
}
|
|
@@ -165,11 +161,10 @@ export default function createStyled(input = {}) {
|
|
|
165
161
|
}
|
|
166
162
|
if (componentName && !skipVariantsResolver) {
|
|
167
163
|
expressionsWithDefaultTheme.push(props => {
|
|
168
|
-
const theme = resolveTheme({
|
|
169
|
-
...props,
|
|
164
|
+
const theme = resolveTheme(_extends({}, props, {
|
|
170
165
|
defaultTheme,
|
|
171
166
|
themeId
|
|
172
|
-
});
|
|
167
|
+
}));
|
|
173
168
|
return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
|
|
174
169
|
});
|
|
175
170
|
}
|
|
@@ -188,14 +183,12 @@ export default function createStyled(input = {}) {
|
|
|
188
183
|
// which are basically components used as a selectors.
|
|
189
184
|
styleArg.__emotion_real !== styleArg) {
|
|
190
185
|
// If the type is function, we need to define the default theme.
|
|
191
|
-
transformedStyleArg = props => styleArg({
|
|
192
|
-
|
|
193
|
-
theme: resolveTheme({
|
|
194
|
-
...props,
|
|
186
|
+
transformedStyleArg = props => styleArg(_extends({}, props, {
|
|
187
|
+
theme: resolveTheme(_extends({}, props, {
|
|
195
188
|
defaultTheme,
|
|
196
189
|
themeId
|
|
197
|
-
})
|
|
198
|
-
});
|
|
190
|
+
}))
|
|
191
|
+
}));
|
|
199
192
|
}
|
|
200
193
|
const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
|
|
201
194
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["values", "unit", "step"];
|
|
1
4
|
// Sorted ASC by size. That's important.
|
|
2
5
|
// It can't be configured as it's used statically for propTypes.
|
|
3
6
|
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
@@ -9,34 +12,33 @@ const sortBreakpointsValues = values => {
|
|
|
9
12
|
// Sort in ascending order
|
|
10
13
|
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
11
14
|
return breakpointsAsArray.reduce((acc, obj) => {
|
|
12
|
-
return {
|
|
13
|
-
...acc,
|
|
15
|
+
return _extends({}, acc, {
|
|
14
16
|
[obj.key]: obj.val
|
|
15
|
-
};
|
|
17
|
+
});
|
|
16
18
|
}, {});
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
// Keep in mind that @media is inclusive by the CSS specification.
|
|
20
22
|
export default function createBreakpoints(breakpoints) {
|
|
21
23
|
const {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
// The breakpoint **start** at this value.
|
|
25
|
+
// For instance with the first breakpoint xs: [xs, sm).
|
|
26
|
+
values = {
|
|
27
|
+
xs: 0,
|
|
28
|
+
// phone
|
|
29
|
+
sm: 600,
|
|
30
|
+
// tablet
|
|
31
|
+
md: 900,
|
|
32
|
+
// small laptop
|
|
33
|
+
lg: 1200,
|
|
34
|
+
// desktop
|
|
35
|
+
xl: 1536 // large screen
|
|
36
|
+
},
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
unit = 'px',
|
|
39
|
+
step = 5
|
|
40
|
+
} = breakpoints,
|
|
41
|
+
other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
|
|
40
42
|
const sortedValues = sortBreakpointsValues(values);
|
|
41
43
|
const keys = Object.keys(sortedValues);
|
|
42
44
|
function up(key) {
|
|
@@ -68,7 +70,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
68
70
|
}
|
|
69
71
|
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
70
72
|
}
|
|
71
|
-
return {
|
|
73
|
+
return _extends({
|
|
72
74
|
keys,
|
|
73
75
|
values: sortedValues,
|
|
74
76
|
up,
|
|
@@ -76,7 +78,6 @@ export default function createBreakpoints(breakpoints) {
|
|
|
76
78
|
between,
|
|
77
79
|
only,
|
|
78
80
|
not,
|
|
79
|
-
unit
|
|
80
|
-
|
|
81
|
-
};
|
|
81
|
+
unit
|
|
82
|
+
}, other);
|
|
82
83
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["breakpoints", "palette", "spacing", "shape"];
|
|
1
4
|
import { deepmerge } from '@mui/utils';
|
|
2
5
|
import createBreakpoints from './createBreakpoints';
|
|
3
6
|
import shape from './shape';
|
|
@@ -6,12 +9,12 @@ import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
|
|
|
6
9
|
import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
|
|
7
10
|
function createTheme(options = {}, ...args) {
|
|
8
11
|
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
breakpoints: breakpointsInput = {},
|
|
13
|
+
palette: paletteInput = {},
|
|
14
|
+
spacing: spacingInput,
|
|
15
|
+
shape: shapeInput = {}
|
|
16
|
+
} = options,
|
|
17
|
+
other = _objectWithoutPropertiesLoose(options, _excluded);
|
|
15
18
|
const breakpoints = createBreakpoints(breakpointsInput);
|
|
16
19
|
const spacing = createSpacing(spacingInput);
|
|
17
20
|
let muiTheme = deepmerge({
|
|
@@ -19,21 +22,14 @@ function createTheme(options = {}, ...args) {
|
|
|
19
22
|
direction: 'ltr',
|
|
20
23
|
components: {},
|
|
21
24
|
// Inject component definitions.
|
|
22
|
-
palette: {
|
|
23
|
-
mode: 'light'
|
|
24
|
-
|
|
25
|
-
},
|
|
25
|
+
palette: _extends({
|
|
26
|
+
mode: 'light'
|
|
27
|
+
}, paletteInput),
|
|
26
28
|
spacing,
|
|
27
|
-
shape: {
|
|
28
|
-
...shape,
|
|
29
|
-
...shapeInput
|
|
30
|
-
}
|
|
29
|
+
shape: _extends({}, shape, shapeInput)
|
|
31
30
|
}, other);
|
|
32
31
|
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
33
|
-
muiTheme.unstable_sxConfig = {
|
|
34
|
-
...defaultSxConfig,
|
|
35
|
-
...other?.unstable_sxConfig
|
|
36
|
-
};
|
|
32
|
+
muiTheme.unstable_sxConfig = _extends({}, defaultSxConfig, other?.unstable_sxConfig);
|
|
37
33
|
muiTheme.unstable_sx = function sx(props) {
|
|
38
34
|
return styleFunctionSx({
|
|
39
35
|
sx: props,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
1
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
+
const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
|
|
2
5
|
import * as React from 'react';
|
|
3
6
|
import PropTypes from 'prop-types';
|
|
4
7
|
import { deepmerge } from '@mui/utils';
|
|
@@ -13,6 +16,12 @@ export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-
|
|
|
13
16
|
export default function createCssVarsProvider(options) {
|
|
14
17
|
const {
|
|
15
18
|
themeId,
|
|
19
|
+
/**
|
|
20
|
+
* This `theme` object needs to follow a certain structure to
|
|
21
|
+
* be used correctly by the finel `CssVarsProvider`. It should have a
|
|
22
|
+
* `colorSchemes` key with the light and dark (and any other) palette.
|
|
23
|
+
* It should also ideally have a vars object created using `prepareCssVars`.
|
|
24
|
+
*/
|
|
16
25
|
theme: defaultTheme = {},
|
|
17
26
|
attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
|
|
18
27
|
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
@@ -55,16 +64,17 @@ export default function createCssVarsProvider(options) {
|
|
|
55
64
|
const ctx = React.useContext(ColorSchemeContext);
|
|
56
65
|
const nested = !!ctx && !disableNestedContext;
|
|
57
66
|
const scopedTheme = themeProp[themeId];
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const _ref = scopedTheme || themeProp,
|
|
68
|
+
{
|
|
69
|
+
colorSchemes = {},
|
|
70
|
+
components = {},
|
|
71
|
+
generateCssVars = () => ({
|
|
72
|
+
vars: {},
|
|
73
|
+
css: {}
|
|
74
|
+
}),
|
|
75
|
+
cssVarPrefix
|
|
76
|
+
} = _ref,
|
|
77
|
+
restThemeProp = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
68
78
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
69
79
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
70
80
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -122,14 +132,13 @@ export default function createCssVarsProvider(options) {
|
|
|
122
132
|
} = generateCssVars();
|
|
123
133
|
|
|
124
134
|
// 3. Start composing the theme object
|
|
125
|
-
const theme = {
|
|
126
|
-
...restThemeProp,
|
|
135
|
+
const theme = _extends({}, restThemeProp, {
|
|
127
136
|
components,
|
|
128
137
|
colorSchemes,
|
|
129
138
|
cssVarPrefix,
|
|
130
139
|
vars: rootVars,
|
|
131
140
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
132
|
-
};
|
|
141
|
+
});
|
|
133
142
|
|
|
134
143
|
// 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
135
144
|
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
@@ -147,10 +156,7 @@ export default function createCssVarsProvider(options) {
|
|
|
147
156
|
Object.keys(scheme).forEach(schemeKey => {
|
|
148
157
|
if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
|
|
149
158
|
// shallow merge the 1st level structure of the theme.
|
|
150
|
-
theme[schemeKey] = {
|
|
151
|
-
...theme[schemeKey],
|
|
152
|
-
...scheme[schemeKey]
|
|
153
|
-
};
|
|
159
|
+
theme[schemeKey] = _extends({}, theme[schemeKey], scheme[schemeKey]);
|
|
154
160
|
} else {
|
|
155
161
|
theme[schemeKey] = scheme[schemeKey];
|
|
156
162
|
}
|
|
@@ -320,15 +326,14 @@ export default function createCssVarsProvider(options) {
|
|
|
320
326
|
} : void 0;
|
|
321
327
|
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
322
328
|
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
323
|
-
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript({
|
|
329
|
+
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
324
330
|
attribute: defaultAttribute,
|
|
325
331
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
326
332
|
defaultMode: designSystemMode,
|
|
327
333
|
defaultLightColorScheme,
|
|
328
334
|
defaultDarkColorScheme,
|
|
329
|
-
modeStorageKey: defaultModeStorageKey
|
|
330
|
-
|
|
331
|
-
});
|
|
335
|
+
modeStorageKey: defaultModeStorageKey
|
|
336
|
+
}, params));
|
|
332
337
|
return {
|
|
333
338
|
CssVarsProvider,
|
|
334
339
|
useColorScheme,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
|
|
1
4
|
import prepareCssVars from './prepareCssVars';
|
|
2
5
|
function createCssVarsTheme(theme) {
|
|
3
6
|
const {
|
|
4
|
-
|
|
5
|
-
shouldSkipGeneratingVar,
|
|
6
|
-
...otherTheme
|
|
7
|
-
} = theme;
|
|
8
|
-
return {
|
|
9
|
-
...theme,
|
|
10
|
-
...prepareCssVars(otherTheme, {
|
|
11
|
-
prefix: cssVarPrefix,
|
|
7
|
+
cssVarPrefix,
|
|
12
8
|
shouldSkipGeneratingVar
|
|
13
|
-
}
|
|
14
|
-
|
|
9
|
+
} = theme,
|
|
10
|
+
otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
|
|
11
|
+
return _extends({}, theme, prepareCssVars(otherTheme, {
|
|
12
|
+
prefix: cssVarPrefix,
|
|
13
|
+
shouldSkipGeneratingVar
|
|
14
|
+
}));
|
|
15
15
|
}
|
|
16
16
|
export default createCssVarsTheme;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["colorSchemes", "components"],
|
|
4
|
+
_excluded2 = ["light"];
|
|
1
5
|
import { deepmerge } from '@mui/utils';
|
|
2
6
|
import cssVarsParser from './cssVarsParser';
|
|
3
7
|
function prepareCssVars(theme, parserConfig) {
|
|
4
8
|
// @ts-ignore - ignore components do not exist
|
|
5
9
|
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} = theme;
|
|
10
|
+
colorSchemes = {}
|
|
11
|
+
} = theme,
|
|
12
|
+
otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
|
|
10
13
|
const {
|
|
11
14
|
vars: rootVars,
|
|
12
15
|
css: rootCss,
|
|
@@ -15,9 +18,9 @@ function prepareCssVars(theme, parserConfig) {
|
|
|
15
18
|
let themeVars = rootVarsWithDefaults;
|
|
16
19
|
const colorSchemesMap = {};
|
|
17
20
|
const {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
light
|
|
22
|
+
} = colorSchemes,
|
|
23
|
+
otherColorSchemes = _objectWithoutPropertiesLoose(colorSchemes, _excluded2);
|
|
21
24
|
Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
|
|
22
25
|
const {
|
|
23
26
|
vars,
|
|
@@ -46,16 +49,12 @@ function prepareCssVars(theme, parserConfig) {
|
|
|
46
49
|
const generateCssVars = colorScheme => {
|
|
47
50
|
if (!colorScheme) {
|
|
48
51
|
return {
|
|
49
|
-
css: {
|
|
50
|
-
...rootCss
|
|
51
|
-
},
|
|
52
|
+
css: _extends({}, rootCss),
|
|
52
53
|
vars: rootVars
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
return {
|
|
56
|
-
css: {
|
|
57
|
-
...colorSchemesMap[colorScheme].css
|
|
58
|
-
},
|
|
57
|
+
css: _extends({}, colorSchemesMap[colorScheme].css),
|
|
59
58
|
vars: colorSchemesMap[colorScheme].vars
|
|
60
59
|
};
|
|
61
60
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
3
4
|
export function getSystemMode(mode) {
|
|
@@ -81,11 +82,10 @@ export default function useCurrentColorScheme(options) {
|
|
|
81
82
|
} catch (e) {
|
|
82
83
|
// Unsupported
|
|
83
84
|
}
|
|
84
|
-
return {
|
|
85
|
-
...currentState,
|
|
85
|
+
return _extends({}, currentState, {
|
|
86
86
|
mode: newMode,
|
|
87
87
|
systemMode: getSystemMode(newMode)
|
|
88
|
-
};
|
|
88
|
+
});
|
|
89
89
|
});
|
|
90
90
|
}, [modeStorageKey, defaultMode]);
|
|
91
91
|
const setColorScheme = React.useCallback(value => {
|
|
@@ -97,20 +97,17 @@ export default function useCurrentColorScheme(options) {
|
|
|
97
97
|
} catch (e) {
|
|
98
98
|
// Unsupported
|
|
99
99
|
}
|
|
100
|
-
return {
|
|
101
|
-
...currentState,
|
|
100
|
+
return _extends({}, currentState, {
|
|
102
101
|
lightColorScheme: defaultLightColorScheme,
|
|
103
102
|
darkColorScheme: defaultDarkColorScheme
|
|
104
|
-
};
|
|
103
|
+
});
|
|
105
104
|
});
|
|
106
105
|
} else if (typeof value === 'string') {
|
|
107
106
|
if (value && !joinedColorSchemes.includes(value)) {
|
|
108
107
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
109
108
|
} else {
|
|
110
109
|
setState(currentState => {
|
|
111
|
-
const newState = {
|
|
112
|
-
...currentState
|
|
113
|
-
};
|
|
110
|
+
const newState = _extends({}, currentState);
|
|
114
111
|
processState(currentState, mode => {
|
|
115
112
|
try {
|
|
116
113
|
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
@@ -129,9 +126,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
129
126
|
}
|
|
130
127
|
} else {
|
|
131
128
|
setState(currentState => {
|
|
132
|
-
const newState = {
|
|
133
|
-
...currentState
|
|
134
|
-
};
|
|
129
|
+
const newState = _extends({}, currentState);
|
|
135
130
|
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
136
131
|
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
137
132
|
if (newLightColorScheme) {
|
|
@@ -164,8 +159,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
164
159
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
165
160
|
const handleMediaQuery = React.useCallback(e => {
|
|
166
161
|
if (state.mode === 'system') {
|
|
167
|
-
setState(currentState => ({
|
|
168
|
-
...currentState,
|
|
162
|
+
setState(currentState => _extends({}, currentState, {
|
|
169
163
|
systemMode: e?.matches ? 'dark' : 'light'
|
|
170
164
|
}));
|
|
171
165
|
}
|
|
@@ -214,10 +208,9 @@ export default function useCurrentColorScheme(options) {
|
|
|
214
208
|
}
|
|
215
209
|
return undefined;
|
|
216
210
|
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
|
217
|
-
return {
|
|
218
|
-
...state,
|
|
211
|
+
return _extends({}, state, {
|
|
219
212
|
colorScheme,
|
|
220
213
|
setMode,
|
|
221
214
|
setColorScheme
|
|
222
|
-
};
|
|
215
|
+
});
|
|
223
216
|
}
|
package/modern/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
const _excluded = ["variant"];
|
|
1
3
|
import { unstable_capitalize as capitalize } from '@mui/utils';
|
|
2
4
|
function isEmpty(string) {
|
|
3
5
|
return string.length === 0;
|
|
@@ -10,9 +12,9 @@ function isEmpty(string) {
|
|
|
10
12
|
*/
|
|
11
13
|
export default function propsToClassKey(props) {
|
|
12
14
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
variant
|
|
16
|
+
} = props,
|
|
17
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
16
18
|
let classKey = variant || '';
|
|
17
19
|
Object.keys(other).sort().forEach(key => {
|
|
18
20
|
if (key === 'color') {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["sx"];
|
|
1
4
|
import { isPlainObject } from '@mui/utils';
|
|
2
5
|
import defaultSxConfig from './defaultSxConfig';
|
|
3
6
|
const splitProps = props => {
|
|
@@ -17,9 +20,9 @@ const splitProps = props => {
|
|
|
17
20
|
};
|
|
18
21
|
export default function extendSxProp(props) {
|
|
19
22
|
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
sx: inSx
|
|
24
|
+
} = props,
|
|
25
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
23
26
|
const {
|
|
24
27
|
systemProps,
|
|
25
28
|
otherProps
|
|
@@ -33,19 +36,12 @@ export default function extendSxProp(props) {
|
|
|
33
36
|
if (!isPlainObject(result)) {
|
|
34
37
|
return systemProps;
|
|
35
38
|
}
|
|
36
|
-
return {
|
|
37
|
-
...systemProps,
|
|
38
|
-
...result
|
|
39
|
-
};
|
|
39
|
+
return _extends({}, systemProps, result);
|
|
40
40
|
};
|
|
41
41
|
} else {
|
|
42
|
-
finalSx = {
|
|
43
|
-
...systemProps,
|
|
44
|
-
...inSx
|
|
45
|
-
};
|
|
42
|
+
finalSx = _extends({}, systemProps, inSx);
|
|
46
43
|
}
|
|
47
|
-
return {
|
|
48
|
-
...otherProps,
|
|
44
|
+
return _extends({}, otherProps, {
|
|
49
45
|
sx: finalSx
|
|
50
|
-
};
|
|
46
|
+
});
|
|
51
47
|
}
|