@mui/system 6.0.0-alpha.6 → 6.0.0-alpha.9
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 +113 -2
- package/Container/createContainer.js +41 -35
- package/RtlProvider/index.js +8 -11
- package/Stack/createStack.js +24 -26
- package/ThemeProvider/ThemeProvider.js +9 -5
- package/Unstable_Grid/createGrid.js +21 -23
- package/Unstable_Grid/gridGenerator.js +20 -17
- package/breakpoints/breakpoints.js +7 -6
- package/createBox/createBox.js +9 -12
- package/createStyled/createStyled.js +56 -51
- package/createTheme/applyStyles.d.ts +1 -1
- package/createTheme/applyStyles.js +1 -1
- package/createTheme/createBreakpoints.js +24 -25
- package/createTheme/createTheme.js +18 -14
- package/cssContainerQueries/cssContainerQueries.js +6 -4
- package/cssVars/createCssVarsProvider.d.ts +1 -1
- package/cssVars/createCssVarsProvider.js +17 -16
- package/cssVars/createCssVarsTheme.js +3 -3
- package/cssVars/prepareCssVars.js +30 -25
- package/cssVars/useCurrentColorScheme.js +18 -11
- package/index.js +1 -1
- package/modern/Container/createContainer.js +41 -35
- package/modern/RtlProvider/index.js +8 -11
- package/modern/Stack/createStack.js +24 -26
- package/modern/ThemeProvider/ThemeProvider.js +9 -5
- package/modern/Unstable_Grid/createGrid.js +21 -23
- package/modern/Unstable_Grid/gridGenerator.js +20 -17
- package/modern/breakpoints/breakpoints.js +7 -6
- package/modern/createBox/createBox.js +9 -12
- package/modern/createStyled/createStyled.js +56 -51
- package/modern/createTheme/applyStyles.js +1 -1
- package/modern/createTheme/createBreakpoints.js +24 -25
- package/modern/createTheme/createTheme.js +18 -14
- package/modern/cssContainerQueries/cssContainerQueries.js +6 -4
- package/modern/cssVars/createCssVarsProvider.js +17 -16
- package/modern/cssVars/createCssVarsTheme.js +3 -3
- package/modern/cssVars/prepareCssVars.js +30 -25
- package/modern/cssVars/useCurrentColorScheme.js +18 -11
- package/modern/index.js +1 -1
- package/modern/propsToClassKey/propsToClassKey.js +3 -5
- package/modern/styleFunctionSx/extendSxProp.js +14 -10
- package/node/Container/createContainer.js +41 -35
- package/node/RtlProvider/index.js +8 -11
- package/node/Stack/createStack.js +24 -26
- package/node/ThemeProvider/ThemeProvider.js +9 -5
- package/node/Unstable_Grid/createGrid.js +23 -25
- package/node/Unstable_Grid/gridGenerator.js +20 -18
- package/node/breakpoints/breakpoints.js +7 -6
- package/node/createBox/createBox.js +9 -12
- package/node/createStyled/createStyled.js +58 -52
- package/node/createTheme/applyStyles.js +1 -1
- package/node/createTheme/createBreakpoints.js +24 -26
- package/node/createTheme/createTheme.js +18 -14
- package/node/cssContainerQueries/cssContainerQueries.js +6 -4
- package/node/cssVars/createCssVarsProvider.js +17 -16
- package/node/cssVars/createCssVarsTheme.js +3 -3
- package/node/cssVars/prepareCssVars.js +30 -25
- package/node/cssVars/useCurrentColorScheme.js +18 -12
- package/node/index.js +1 -1
- package/node/propsToClassKey/propsToClassKey.js +3 -5
- package/node/styleFunctionSx/extendSxProp.js +14 -10
- package/package.json +5 -5
- package/propsToClassKey/propsToClassKey.js +3 -5
- package/styleFunctionSx/extendSxProp.js +14 -10
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["ownerState"],
|
|
4
|
-
_excluded2 = ["variants"],
|
|
5
|
-
_excluded3 = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
|
|
6
1
|
/* eslint-disable no-underscore-dangle */
|
|
7
2
|
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
|
|
8
3
|
import { isPlainObject } from '@mui/utils/deepmerge';
|
|
@@ -47,31 +42,35 @@ function defaultOverridesResolver(slot) {
|
|
|
47
42
|
}
|
|
48
43
|
return (props, styles) => styles[slot];
|
|
49
44
|
}
|
|
50
|
-
function processStyleArg(callableStyle,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
45
|
+
function processStyleArg(callableStyle, {
|
|
46
|
+
ownerState,
|
|
47
|
+
...props
|
|
48
|
+
}) {
|
|
49
|
+
const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle({
|
|
50
|
+
ownerState,
|
|
51
|
+
...props
|
|
52
|
+
}) : callableStyle;
|
|
58
53
|
if (Array.isArray(resolvedStylesArg)) {
|
|
59
|
-
return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle,
|
|
60
|
-
ownerState
|
|
61
|
-
|
|
54
|
+
return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, {
|
|
55
|
+
ownerState,
|
|
56
|
+
...props
|
|
57
|
+
}));
|
|
62
58
|
}
|
|
59
|
+
const mergedState = {
|
|
60
|
+
...props,
|
|
61
|
+
...ownerState,
|
|
62
|
+
ownerState
|
|
63
|
+
};
|
|
63
64
|
if (!!resolvedStylesArg && typeof resolvedStylesArg === 'object' && Array.isArray(resolvedStylesArg.variants)) {
|
|
64
65
|
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
variants = [],
|
|
67
|
+
...otherStyles
|
|
68
|
+
} = resolvedStylesArg;
|
|
68
69
|
let result = otherStyles;
|
|
69
70
|
variants.forEach(variant => {
|
|
70
71
|
let isMatch = true;
|
|
71
72
|
if (typeof variant.props === 'function') {
|
|
72
|
-
isMatch = variant.props(
|
|
73
|
-
ownerState
|
|
74
|
-
}, props, ownerState));
|
|
73
|
+
isMatch = variant.props(mergedState);
|
|
75
74
|
} else {
|
|
76
75
|
Object.keys(variant.props).forEach(key => {
|
|
77
76
|
if (ownerState?.[key] !== variant.props[key] && props[key] !== variant.props[key]) {
|
|
@@ -83,9 +82,7 @@ function processStyleArg(callableStyle, _ref) {
|
|
|
83
82
|
if (!Array.isArray(result)) {
|
|
84
83
|
result = [result];
|
|
85
84
|
}
|
|
86
|
-
result.push(typeof variant.style === 'function' ? variant.style(
|
|
87
|
-
ownerState
|
|
88
|
-
}, props, ownerState)) : variant.style);
|
|
85
|
+
result.push(typeof variant.style === 'function' ? variant.style(mergedState) : variant.style);
|
|
89
86
|
}
|
|
90
87
|
});
|
|
91
88
|
return result;
|
|
@@ -100,27 +97,29 @@ export default function createStyled(input = {}) {
|
|
|
100
97
|
slotShouldForwardProp = shouldForwardProp
|
|
101
98
|
} = input;
|
|
102
99
|
const systemSx = props => {
|
|
103
|
-
return styleFunctionSx(
|
|
104
|
-
|
|
100
|
+
return styleFunctionSx({
|
|
101
|
+
...props,
|
|
102
|
+
theme: resolveTheme({
|
|
103
|
+
...props,
|
|
105
104
|
defaultTheme,
|
|
106
105
|
themeId
|
|
107
|
-
})
|
|
108
|
-
})
|
|
106
|
+
})
|
|
107
|
+
});
|
|
109
108
|
};
|
|
110
109
|
systemSx.__mui_systemSx = true;
|
|
111
110
|
return (tag, inputOptions = {}) => {
|
|
112
111
|
// Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
|
|
113
112
|
processStyles(tag, styles => styles.filter(style => !style?.__mui_systemSx));
|
|
114
113
|
const {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
name: componentName,
|
|
115
|
+
slot: componentSlot,
|
|
116
|
+
skipVariantsResolver: inputSkipVariantsResolver,
|
|
117
|
+
skipSx: inputSkipSx,
|
|
118
|
+
// TODO v6: remove `lowercaseFirstLetter()` in the next major release
|
|
119
|
+
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
120
|
+
overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot)),
|
|
121
|
+
...options
|
|
122
|
+
} = inputOptions;
|
|
124
123
|
|
|
125
124
|
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
126
125
|
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
|
|
@@ -149,22 +148,24 @@ export default function createStyled(input = {}) {
|
|
|
149
148
|
// for string (html) tag, preserve the behavior in emotion & styled-components.
|
|
150
149
|
shouldForwardPropOption = undefined;
|
|
151
150
|
}
|
|
152
|
-
const defaultStyledResolver = styledEngineStyled(tag,
|
|
151
|
+
const defaultStyledResolver = styledEngineStyled(tag, {
|
|
153
152
|
shouldForwardProp: shouldForwardPropOption,
|
|
154
|
-
label
|
|
155
|
-
|
|
153
|
+
label,
|
|
154
|
+
...options
|
|
155
|
+
});
|
|
156
156
|
const transformStyleArg = stylesArg => {
|
|
157
157
|
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
158
158
|
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
159
159
|
// which are basically components used as a selectors.
|
|
160
160
|
if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
|
|
161
|
-
return props => processStyleArg(stylesArg,
|
|
161
|
+
return props => processStyleArg(stylesArg, {
|
|
162
|
+
...props,
|
|
162
163
|
theme: resolveTheme({
|
|
163
164
|
theme: props.theme,
|
|
164
165
|
defaultTheme,
|
|
165
166
|
themeId
|
|
166
167
|
})
|
|
167
|
-
})
|
|
168
|
+
});
|
|
168
169
|
}
|
|
169
170
|
return stylesArg;
|
|
170
171
|
};
|
|
@@ -173,10 +174,11 @@ export default function createStyled(input = {}) {
|
|
|
173
174
|
const expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
|
|
174
175
|
if (componentName && overridesResolver) {
|
|
175
176
|
expressionsWithDefaultTheme.push(props => {
|
|
176
|
-
const theme = resolveTheme(
|
|
177
|
+
const theme = resolveTheme({
|
|
178
|
+
...props,
|
|
177
179
|
defaultTheme,
|
|
178
180
|
themeId
|
|
179
|
-
})
|
|
181
|
+
});
|
|
180
182
|
if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
|
|
181
183
|
return null;
|
|
182
184
|
}
|
|
@@ -184,25 +186,28 @@ export default function createStyled(input = {}) {
|
|
|
184
186
|
const resolvedStyleOverrides = {};
|
|
185
187
|
// TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
|
|
186
188
|
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
187
|
-
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle,
|
|
189
|
+
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, {
|
|
190
|
+
...props,
|
|
188
191
|
theme
|
|
189
|
-
})
|
|
192
|
+
});
|
|
190
193
|
});
|
|
191
194
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
197
|
if (componentName && !skipVariantsResolver) {
|
|
195
198
|
expressionsWithDefaultTheme.push(props => {
|
|
196
|
-
const theme = resolveTheme(
|
|
199
|
+
const theme = resolveTheme({
|
|
200
|
+
...props,
|
|
197
201
|
defaultTheme,
|
|
198
202
|
themeId
|
|
199
|
-
})
|
|
203
|
+
});
|
|
200
204
|
const themeVariants = theme?.components?.[componentName]?.variants;
|
|
201
205
|
return processStyleArg({
|
|
202
206
|
variants: themeVariants
|
|
203
|
-
},
|
|
207
|
+
}, {
|
|
208
|
+
...props,
|
|
204
209
|
theme
|
|
205
|
-
})
|
|
210
|
+
});
|
|
206
211
|
});
|
|
207
212
|
}
|
|
208
213
|
if (!skipSx) {
|
|
@@ -6,7 +6,7 @@ export interface ApplyStyles<K extends string> {
|
|
|
6
6
|
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
7
7
|
* It works with:
|
|
8
8
|
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
9
|
-
* - [CSS theme variables](https://mui.com/material-ui/
|
|
9
|
+
* - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/)
|
|
10
10
|
* - Zero-runtime engine
|
|
11
11
|
*
|
|
12
12
|
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
3
3
|
* It works with:
|
|
4
4
|
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
5
|
-
* - [CSS theme variables](https://mui.com/material-ui/
|
|
5
|
+
* - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/)
|
|
6
6
|
* - Zero-runtime engine
|
|
7
7
|
*
|
|
8
8
|
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["values", "unit", "step"];
|
|
4
1
|
// Sorted ASC by size. That's important.
|
|
5
2
|
// It can't be configured as it's used statically for propTypes.
|
|
6
3
|
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
@@ -12,32 +9,33 @@ const sortBreakpointsValues = values => {
|
|
|
12
9
|
// Sort in ascending order
|
|
13
10
|
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
14
11
|
return breakpointsAsArray.reduce((acc, obj) => {
|
|
15
|
-
return
|
|
12
|
+
return {
|
|
13
|
+
...acc,
|
|
16
14
|
[obj.key]: obj.val
|
|
17
|
-
}
|
|
15
|
+
};
|
|
18
16
|
}, {});
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
// Keep in mind that @media is inclusive by the CSS specification.
|
|
22
20
|
export default function createBreakpoints(breakpoints) {
|
|
23
21
|
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
// The breakpoint **start** at this value.
|
|
23
|
+
// For instance with the first breakpoint xs: [xs, sm).
|
|
24
|
+
values = {
|
|
25
|
+
xs: 0,
|
|
26
|
+
// phone
|
|
27
|
+
sm: 600,
|
|
28
|
+
// tablet
|
|
29
|
+
md: 900,
|
|
30
|
+
// small laptop
|
|
31
|
+
lg: 1200,
|
|
32
|
+
// desktop
|
|
33
|
+
xl: 1536 // large screen
|
|
34
|
+
},
|
|
35
|
+
unit = 'px',
|
|
36
|
+
step = 5,
|
|
37
|
+
...other
|
|
38
|
+
} = breakpoints;
|
|
41
39
|
const sortedValues = sortBreakpointsValues(values);
|
|
42
40
|
const keys = Object.keys(sortedValues);
|
|
43
41
|
function up(key) {
|
|
@@ -69,7 +67,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
69
67
|
}
|
|
70
68
|
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
71
69
|
}
|
|
72
|
-
return
|
|
70
|
+
return {
|
|
73
71
|
keys,
|
|
74
72
|
values: sortedValues,
|
|
75
73
|
up,
|
|
@@ -77,6 +75,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
77
75
|
between,
|
|
78
76
|
only,
|
|
79
77
|
not,
|
|
80
|
-
unit
|
|
81
|
-
|
|
78
|
+
unit,
|
|
79
|
+
...other
|
|
80
|
+
};
|
|
82
81
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
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"];
|
|
4
1
|
import deepmerge from '@mui/utils/deepmerge';
|
|
5
2
|
import createBreakpoints from './createBreakpoints';
|
|
6
3
|
import cssContainerQueries from '../cssContainerQueries';
|
|
@@ -11,12 +8,12 @@ import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
|
|
|
11
8
|
import applyStyles from './applyStyles';
|
|
12
9
|
function createTheme(options = {}, ...args) {
|
|
13
10
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
breakpoints: breakpointsInput = {},
|
|
12
|
+
palette: paletteInput = {},
|
|
13
|
+
spacing: spacingInput,
|
|
14
|
+
shape: shapeInput = {},
|
|
15
|
+
...other
|
|
16
|
+
} = options;
|
|
20
17
|
const breakpoints = createBreakpoints(breakpointsInput);
|
|
21
18
|
const spacing = createSpacing(spacingInput);
|
|
22
19
|
let muiTheme = deepmerge({
|
|
@@ -24,16 +21,23 @@ function createTheme(options = {}, ...args) {
|
|
|
24
21
|
direction: 'ltr',
|
|
25
22
|
components: {},
|
|
26
23
|
// Inject component definitions.
|
|
27
|
-
palette:
|
|
28
|
-
mode: 'light'
|
|
29
|
-
|
|
24
|
+
palette: {
|
|
25
|
+
mode: 'light',
|
|
26
|
+
...paletteInput
|
|
27
|
+
},
|
|
30
28
|
spacing,
|
|
31
|
-
shape:
|
|
29
|
+
shape: {
|
|
30
|
+
...shape,
|
|
31
|
+
...shapeInput
|
|
32
|
+
}
|
|
32
33
|
}, other);
|
|
33
34
|
muiTheme = cssContainerQueries(muiTheme);
|
|
34
35
|
muiTheme.applyStyles = applyStyles;
|
|
35
36
|
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
36
|
-
muiTheme.unstable_sxConfig =
|
|
37
|
+
muiTheme.unstable_sxConfig = {
|
|
38
|
+
...defaultSxConfig,
|
|
39
|
+
...other?.unstable_sxConfig
|
|
40
|
+
};
|
|
37
41
|
muiTheme.unstable_sx = function sx(props) {
|
|
38
42
|
return styleFunctionSx({
|
|
39
43
|
sx: props,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
|
|
3
2
|
/**
|
|
4
3
|
* For using in `sx` prop to sort the breakpoint from low to high.
|
|
@@ -22,7 +21,9 @@ export function sortContainerQueries(theme, css) {
|
|
|
22
21
|
delete acc[key];
|
|
23
22
|
acc[key] = value;
|
|
24
23
|
return acc;
|
|
25
|
-
},
|
|
24
|
+
}, {
|
|
25
|
+
...css
|
|
26
|
+
});
|
|
26
27
|
}
|
|
27
28
|
export function isCqShorthand(breakpointKeys, value) {
|
|
28
29
|
return value.startsWith('@') && (breakpointKeys.some(key => value.startsWith(`@${key}`)) || !!value.match(/^@\d/));
|
|
@@ -62,7 +63,8 @@ export default function cssContainerQueries(themeInput) {
|
|
|
62
63
|
return node;
|
|
63
64
|
};
|
|
64
65
|
attachCq(containerQueries);
|
|
65
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
...themeInput,
|
|
66
68
|
containerQueries
|
|
67
|
-
}
|
|
69
|
+
};
|
|
68
70
|
}
|
|
@@ -90,7 +90,7 @@ export interface CreateCssVarsProviderResult<
|
|
|
90
90
|
disableStyleSheetGeneration?: boolean;
|
|
91
91
|
}
|
|
92
92
|
>,
|
|
93
|
-
) => React.ReactElement
|
|
93
|
+
) => React.ReactElement<any>;
|
|
94
94
|
useColorScheme: () => ColorSchemeContextValue<ColorScheme>;
|
|
95
95
|
getInitColorSchemeScript: typeof getInitColorSchemeScript;
|
|
96
96
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
1
|
import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
|
|
4
|
-
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
5
2
|
import * as React from 'react';
|
|
6
3
|
import PropTypes from 'prop-types';
|
|
7
4
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
@@ -65,13 +62,12 @@ export default function createCssVarsProvider(options) {
|
|
|
65
62
|
const ctx = React.useContext(ColorSchemeContext);
|
|
66
63
|
const nested = !!ctx && !disableNestedContext;
|
|
67
64
|
const scopedTheme = themeProp[themeId];
|
|
68
|
-
const
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
restThemeProp = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
65
|
+
const {
|
|
66
|
+
colorSchemes = {},
|
|
67
|
+
components = {},
|
|
68
|
+
cssVarPrefix,
|
|
69
|
+
...restThemeProp
|
|
70
|
+
} = scopedTheme || themeProp;
|
|
75
71
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
76
72
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
77
73
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -126,12 +122,13 @@ export default function createCssVarsProvider(options) {
|
|
|
126
122
|
const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
|
|
127
123
|
|
|
128
124
|
// 3. Start composing the theme object
|
|
129
|
-
const theme =
|
|
125
|
+
const theme = {
|
|
126
|
+
...restThemeProp,
|
|
130
127
|
components,
|
|
131
128
|
colorSchemes,
|
|
132
129
|
cssVarPrefix,
|
|
133
130
|
vars: themeVars
|
|
134
|
-
}
|
|
131
|
+
};
|
|
135
132
|
if (typeof theme.generateSpacing === 'function') {
|
|
136
133
|
theme.spacing = theme.generateSpacing();
|
|
137
134
|
}
|
|
@@ -143,7 +140,10 @@ export default function createCssVarsProvider(options) {
|
|
|
143
140
|
Object.keys(scheme).forEach(schemeKey => {
|
|
144
141
|
if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
|
|
145
142
|
// shallow merge the 1st level structure of the theme.
|
|
146
|
-
theme[schemeKey] =
|
|
143
|
+
theme[schemeKey] = {
|
|
144
|
+
...theme[schemeKey],
|
|
145
|
+
...scheme[schemeKey]
|
|
146
|
+
};
|
|
147
147
|
} else {
|
|
148
148
|
theme[schemeKey] = scheme[schemeKey];
|
|
149
149
|
}
|
|
@@ -299,14 +299,15 @@ export default function createCssVarsProvider(options) {
|
|
|
299
299
|
} : void 0;
|
|
300
300
|
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
301
301
|
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
302
|
-
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(
|
|
302
|
+
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript({
|
|
303
303
|
attribute: defaultAttribute,
|
|
304
304
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
305
305
|
defaultMode: designSystemMode,
|
|
306
306
|
defaultLightColorScheme,
|
|
307
307
|
defaultDarkColorScheme,
|
|
308
|
-
modeStorageKey: defaultModeStorageKey
|
|
309
|
-
|
|
308
|
+
modeStorageKey: defaultModeStorageKey,
|
|
309
|
+
...params
|
|
310
|
+
});
|
|
310
311
|
return {
|
|
311
312
|
CssVarsProvider,
|
|
312
313
|
useColorScheme,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import prepareCssVars from './prepareCssVars';
|
|
3
2
|
function createCssVarsTheme(theme) {
|
|
4
3
|
const output = theme;
|
|
5
|
-
const result = prepareCssVars(output,
|
|
4
|
+
const result = prepareCssVars(output, {
|
|
5
|
+
...theme,
|
|
6
6
|
prefix: theme.cssVarPrefix
|
|
7
|
-
})
|
|
7
|
+
});
|
|
8
8
|
output.vars = result.vars;
|
|
9
9
|
output.generateThemeVars = result.generateThemeVars;
|
|
10
10
|
output.generateStyleSheets = result.generateStyleSheets;
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
|
|
3
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
|
-
const _excluded = ["getSelector"],
|
|
5
|
-
_excluded2 = ["colorSchemes", "components", "defaultColorScheme"];
|
|
6
1
|
import deepmerge from '@mui/utils/deepmerge';
|
|
7
2
|
import cssVarsParser from './cssVarsParser';
|
|
8
|
-
function prepareCssVars(theme,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
parserConfig = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
3
|
+
function prepareCssVars(theme, {
|
|
4
|
+
getSelector,
|
|
5
|
+
...parserConfig
|
|
6
|
+
} = {}) {
|
|
13
7
|
// @ts-ignore - ignore components do not exist
|
|
14
8
|
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
otherTheme
|
|
9
|
+
colorSchemes = {},
|
|
10
|
+
components,
|
|
11
|
+
defaultColorScheme = 'light',
|
|
12
|
+
...otherTheme
|
|
13
|
+
} = theme;
|
|
19
14
|
const {
|
|
20
15
|
vars: rootVars,
|
|
21
16
|
css: rootCss,
|
|
@@ -24,9 +19,9 @@ function prepareCssVars(theme, _ref = {}) {
|
|
|
24
19
|
let themeVars = rootVarsWithDefaults;
|
|
25
20
|
const colorSchemesMap = {};
|
|
26
21
|
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
[defaultColorScheme]: defaultScheme,
|
|
23
|
+
...otherColorSchemes
|
|
24
|
+
} = colorSchemes;
|
|
30
25
|
Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
|
|
31
26
|
const {
|
|
32
27
|
vars,
|
|
@@ -53,7 +48,9 @@ function prepareCssVars(theme, _ref = {}) {
|
|
|
53
48
|
};
|
|
54
49
|
}
|
|
55
50
|
const generateThemeVars = () => {
|
|
56
|
-
let vars =
|
|
51
|
+
let vars = {
|
|
52
|
+
...rootVars
|
|
53
|
+
};
|
|
57
54
|
Object.entries(colorSchemesMap).forEach(([, {
|
|
58
55
|
vars: schemeVars
|
|
59
56
|
}]) => {
|
|
@@ -67,26 +64,34 @@ function prepareCssVars(theme, _ref = {}) {
|
|
|
67
64
|
function insertStyleSheet(selector, css) {
|
|
68
65
|
if (Object.keys(css).length) {
|
|
69
66
|
stylesheets.push(typeof selector === 'string' ? {
|
|
70
|
-
[selector]:
|
|
67
|
+
[selector]: {
|
|
68
|
+
...css
|
|
69
|
+
}
|
|
71
70
|
} : selector);
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
|
-
insertStyleSheet(getSelector?.(undefined,
|
|
73
|
+
insertStyleSheet(getSelector?.(undefined, {
|
|
74
|
+
...rootCss
|
|
75
|
+
}) || ':root', rootCss);
|
|
75
76
|
const {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
[colorScheme]: defaultSchemeVal,
|
|
78
|
+
...rest
|
|
79
|
+
} = colorSchemesMap;
|
|
79
80
|
if (defaultSchemeVal) {
|
|
80
81
|
// default color scheme has to come before other color schemes
|
|
81
82
|
const {
|
|
82
83
|
css
|
|
83
84
|
} = defaultSchemeVal;
|
|
84
|
-
insertStyleSheet(getSelector?.(colorScheme,
|
|
85
|
+
insertStyleSheet(getSelector?.(colorScheme, {
|
|
86
|
+
...css
|
|
87
|
+
}) || `[${theme.attribute || 'data-color-scheme'}="${colorScheme}"]`, css);
|
|
85
88
|
}
|
|
86
89
|
Object.entries(rest).forEach(([key, {
|
|
87
90
|
css
|
|
88
91
|
}]) => {
|
|
89
|
-
insertStyleSheet(getSelector?.(key,
|
|
92
|
+
insertStyleSheet(getSelector?.(key, {
|
|
93
|
+
...css
|
|
94
|
+
}) || `[${theme.attribute || 'data-color-scheme'}="${key}"]`, css);
|
|
90
95
|
});
|
|
91
96
|
return stylesheets;
|
|
92
97
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
3
|
import * as React from 'react';
|
|
5
4
|
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
6
5
|
export function getSystemMode(mode) {
|
|
@@ -84,10 +83,11 @@ export default function useCurrentColorScheme(options) {
|
|
|
84
83
|
} catch (e) {
|
|
85
84
|
// Unsupported
|
|
86
85
|
}
|
|
87
|
-
return
|
|
86
|
+
return {
|
|
87
|
+
...currentState,
|
|
88
88
|
mode: newMode,
|
|
89
89
|
systemMode: getSystemMode(newMode)
|
|
90
|
-
}
|
|
90
|
+
};
|
|
91
91
|
});
|
|
92
92
|
}, [modeStorageKey, defaultMode]);
|
|
93
93
|
const setColorScheme = React.useCallback(value => {
|
|
@@ -99,17 +99,20 @@ export default function useCurrentColorScheme(options) {
|
|
|
99
99
|
} catch (e) {
|
|
100
100
|
// Unsupported
|
|
101
101
|
}
|
|
102
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
...currentState,
|
|
103
104
|
lightColorScheme: defaultLightColorScheme,
|
|
104
105
|
darkColorScheme: defaultDarkColorScheme
|
|
105
|
-
}
|
|
106
|
+
};
|
|
106
107
|
});
|
|
107
108
|
} else if (typeof value === 'string') {
|
|
108
109
|
if (value && !joinedColorSchemes.includes(value)) {
|
|
109
110
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
110
111
|
} else {
|
|
111
112
|
setState(currentState => {
|
|
112
|
-
const newState =
|
|
113
|
+
const newState = {
|
|
114
|
+
...currentState
|
|
115
|
+
};
|
|
113
116
|
processState(currentState, mode => {
|
|
114
117
|
try {
|
|
115
118
|
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
@@ -128,7 +131,9 @@ export default function useCurrentColorScheme(options) {
|
|
|
128
131
|
}
|
|
129
132
|
} else {
|
|
130
133
|
setState(currentState => {
|
|
131
|
-
const newState =
|
|
134
|
+
const newState = {
|
|
135
|
+
...currentState
|
|
136
|
+
};
|
|
132
137
|
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
133
138
|
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
134
139
|
if (newLightColorScheme) {
|
|
@@ -168,9 +173,10 @@ export default function useCurrentColorScheme(options) {
|
|
|
168
173
|
if (currentState.systemMode === systemMode) {
|
|
169
174
|
return currentState;
|
|
170
175
|
}
|
|
171
|
-
return
|
|
176
|
+
return {
|
|
177
|
+
...currentState,
|
|
172
178
|
systemMode
|
|
173
|
-
}
|
|
179
|
+
};
|
|
174
180
|
});
|
|
175
181
|
}
|
|
176
182
|
}, [state.mode]);
|
|
@@ -222,9 +228,10 @@ export default function useCurrentColorScheme(options) {
|
|
|
222
228
|
}
|
|
223
229
|
return undefined;
|
|
224
230
|
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
|
225
|
-
return
|
|
231
|
+
return {
|
|
232
|
+
...state,
|
|
226
233
|
colorScheme,
|
|
227
234
|
setMode,
|
|
228
235
|
setColorScheme
|
|
229
|
-
}
|
|
236
|
+
};
|
|
230
237
|
}
|
package/index.js
CHANGED