@mui/system 5.8.5 → 5.9.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 +190 -0
- package/Unstable_Grid/Grid.d.ts +12 -0
- package/Unstable_Grid/Grid.js +190 -0
- package/Unstable_Grid/GridProps.d.ts +158 -0
- package/Unstable_Grid/GridProps.js +5 -0
- package/Unstable_Grid/createGrid.d.ts +11 -0
- package/Unstable_Grid/createGrid.js +174 -0
- package/Unstable_Grid/gridClasses.d.ts +20 -0
- package/Unstable_Grid/gridClasses.js +25 -0
- package/Unstable_Grid/gridGenerator.d.ts +26 -0
- package/Unstable_Grid/gridGenerator.js +269 -0
- package/Unstable_Grid/index.d.ts +5 -0
- package/Unstable_Grid/index.js +65 -0
- package/Unstable_Grid/package.json +6 -0
- package/{grid.js → cssGrid.js} +0 -0
- package/cssVars/createCssVarsProvider.d.ts +13 -18
- package/cssVars/createCssVarsProvider.js +13 -17
- package/cssVars/createGetCssVar.d.ts +1 -1
- package/cssVars/createGetCssVar.js +2 -2
- package/cssVars/cssVarsParser.d.ts +4 -9
- package/cssVars/cssVarsParser.js +4 -19
- package/cssVars/getInitColorSchemeScript.d.ts +5 -0
- package/cssVars/getInitColorSchemeScript.js +7 -0
- package/cssVars/index.d.ts +2 -1
- package/cssVars/index.js +9 -1
- package/cssVars/useCurrentColorScheme.js +1 -1
- package/esm/Unstable_Grid/Grid.js +179 -0
- package/esm/Unstable_Grid/GridProps.js +1 -0
- package/esm/Unstable_Grid/createGrid.js +152 -0
- package/esm/Unstable_Grid/gridClasses.js +14 -0
- package/esm/Unstable_Grid/gridGenerator.js +230 -0
- package/esm/Unstable_Grid/index.js +5 -0
- package/esm/{grid.js → cssGrid.js} +0 -0
- package/esm/cssVars/createCssVarsProvider.js +13 -16
- package/esm/cssVars/createGetCssVar.js +2 -2
- package/esm/cssVars/cssVarsParser.js +4 -19
- package/esm/cssVars/getInitColorSchemeScript.js +7 -0
- package/esm/cssVars/index.js +2 -1
- package/esm/cssVars/useCurrentColorScheme.js +1 -1
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +9 -3
- package/getThemeValue.js +3 -3
- package/index.d.ts +3 -0
- package/index.js +30 -7
- package/legacy/Unstable_Grid/Grid.js +179 -0
- package/legacy/Unstable_Grid/GridProps.js +1 -0
- package/legacy/Unstable_Grid/createGrid.js +166 -0
- package/legacy/Unstable_Grid/gridClasses.js +27 -0
- package/legacy/Unstable_Grid/gridGenerator.js +239 -0
- package/legacy/Unstable_Grid/index.js +5 -0
- package/legacy/{grid.js → cssGrid.js} +0 -0
- package/legacy/cssVars/createCssVarsProvider.js +13 -17
- package/legacy/cssVars/createGetCssVar.js +3 -3
- package/legacy/cssVars/cssVarsParser.js +4 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +3 -1
- package/legacy/cssVars/index.js +2 -1
- package/legacy/cssVars/useCurrentColorScheme.js +1 -1
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +10 -4
- package/modern/Unstable_Grid/Grid.js +179 -0
- package/modern/Unstable_Grid/GridProps.js +1 -0
- package/modern/Unstable_Grid/createGrid.js +150 -0
- package/modern/Unstable_Grid/gridClasses.js +14 -0
- package/modern/Unstable_Grid/gridGenerator.js +226 -0
- package/modern/Unstable_Grid/index.js +5 -0
- package/modern/{grid.js → cssGrid.js} +0 -0
- package/modern/cssVars/createCssVarsProvider.js +13 -16
- package/modern/cssVars/createGetCssVar.js +2 -2
- package/modern/cssVars/cssVarsParser.js +4 -19
- package/modern/cssVars/getInitColorSchemeScript.js +7 -0
- package/modern/cssVars/index.js +2 -1
- package/modern/cssVars/useCurrentColorScheme.js +1 -1
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +10 -4
- package/package.json +5 -5
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
export const traverseBreakpoints = (breakpoints, responsize, iterator) => {
|
|
3
|
+
const smallestBreakpoint = breakpoints.keys[0]; // the keys is sorted from smallest to largest by `createBreakpoints`.
|
|
4
|
+
|
|
5
|
+
if (Array.isArray(responsize)) {
|
|
6
|
+
responsize.forEach((breakpointValue, index) => {
|
|
7
|
+
iterator((responsizeStyles, style) => {
|
|
8
|
+
if (index <= breakpoints.keys.length - 1) {
|
|
9
|
+
if (index === 0) {
|
|
10
|
+
Object.assign(responsizeStyles, style);
|
|
11
|
+
} else {
|
|
12
|
+
responsizeStyles[breakpoints.up(breakpoints.keys[index])] = style;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}, breakpointValue);
|
|
16
|
+
});
|
|
17
|
+
} else if (responsize && typeof responsize === 'object') {
|
|
18
|
+
// prevent null
|
|
19
|
+
// responsize could be a very big object, pick the smallest responsive values
|
|
20
|
+
const keys = Object.keys(responsize).length > breakpoints.keys.length ? breakpoints.keys : Object.keys(responsize);
|
|
21
|
+
keys.forEach(key => {
|
|
22
|
+
if (breakpoints.keys.indexOf(key) !== -1) {
|
|
23
|
+
// @ts-ignore already checked that responsize is an object
|
|
24
|
+
const breakpointValue = responsize[key];
|
|
25
|
+
|
|
26
|
+
if (breakpointValue !== undefined) {
|
|
27
|
+
iterator((responsizeStyles, style) => {
|
|
28
|
+
if (smallestBreakpoint === key) {
|
|
29
|
+
Object.assign(responsizeStyles, style);
|
|
30
|
+
} else {
|
|
31
|
+
responsizeStyles[breakpoints.up(key)] = style;
|
|
32
|
+
}
|
|
33
|
+
}, breakpointValue);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
} else if (typeof responsize === 'number' || typeof responsize === 'string') {
|
|
38
|
+
iterator((responsizeStyles, style) => {
|
|
39
|
+
Object.assign(responsizeStyles, style);
|
|
40
|
+
}, responsize);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export const generateGridSizeStyles = ({
|
|
44
|
+
theme,
|
|
45
|
+
ownerState
|
|
46
|
+
}) => {
|
|
47
|
+
const styles = {};
|
|
48
|
+
traverseBreakpoints(theme.breakpoints, ownerState.gridSize, (appendStyle, value) => {
|
|
49
|
+
let style = {};
|
|
50
|
+
|
|
51
|
+
if (value === true) {
|
|
52
|
+
style = {
|
|
53
|
+
flexBasis: 0,
|
|
54
|
+
flexGrow: 1,
|
|
55
|
+
maxWidth: '100%'
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (value === 'auto') {
|
|
60
|
+
style = {
|
|
61
|
+
flexBasis: 'auto',
|
|
62
|
+
flexGrow: 0,
|
|
63
|
+
flexShrink: 0,
|
|
64
|
+
maxWidth: 'none',
|
|
65
|
+
width: 'auto'
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof value === 'number') {
|
|
70
|
+
style = {
|
|
71
|
+
flexGrow: 0,
|
|
72
|
+
flexBasis: 'auto',
|
|
73
|
+
width: `calc(100% * ${value} / var(--Grid-columns)${ownerState.nested && ownerState.container ? ` + var(--Grid-columnSpacing)` : ''})`
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
appendStyle(styles, style);
|
|
78
|
+
});
|
|
79
|
+
return styles;
|
|
80
|
+
};
|
|
81
|
+
export const generateGridOffsetStyles = ({
|
|
82
|
+
theme,
|
|
83
|
+
ownerState
|
|
84
|
+
}) => {
|
|
85
|
+
const styles = {};
|
|
86
|
+
traverseBreakpoints(theme.breakpoints, ownerState.gridOffset, (appendStyle, value) => {
|
|
87
|
+
let style = {};
|
|
88
|
+
|
|
89
|
+
if (value === 'auto') {
|
|
90
|
+
style = {
|
|
91
|
+
marginLeft: 'auto'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof value === 'number') {
|
|
96
|
+
style = {
|
|
97
|
+
marginLeft: value === 0 ? '0px' : `calc(100% * ${value} / var(--Grid-columns))`
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
appendStyle(styles, style);
|
|
102
|
+
});
|
|
103
|
+
return styles;
|
|
104
|
+
};
|
|
105
|
+
export const generateGridColumnsStyles = ({
|
|
106
|
+
theme,
|
|
107
|
+
ownerState
|
|
108
|
+
}) => {
|
|
109
|
+
if (!ownerState.container) {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const styles = {
|
|
114
|
+
'--Grid-columns': 12
|
|
115
|
+
};
|
|
116
|
+
traverseBreakpoints(theme.breakpoints, ownerState.columns, (appendStyle, value) => {
|
|
117
|
+
appendStyle(styles, {
|
|
118
|
+
'--Grid-columns': value
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
return styles;
|
|
122
|
+
};
|
|
123
|
+
export const generateGridRowSpacingStyles = ({
|
|
124
|
+
theme,
|
|
125
|
+
ownerState
|
|
126
|
+
}) => {
|
|
127
|
+
if (!ownerState.container) {
|
|
128
|
+
return {};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const styles = {};
|
|
132
|
+
traverseBreakpoints(theme.breakpoints, ownerState.rowSpacing, (appendStyle, value) => {
|
|
133
|
+
appendStyle(styles, {
|
|
134
|
+
'--Grid-rowSpacing': typeof value === 'string' ? value : theme.spacing?.(value)
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return styles;
|
|
138
|
+
};
|
|
139
|
+
export const generateGridColumnSpacingStyles = ({
|
|
140
|
+
theme,
|
|
141
|
+
ownerState
|
|
142
|
+
}) => {
|
|
143
|
+
if (!ownerState.container) {
|
|
144
|
+
return {};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const styles = {};
|
|
148
|
+
traverseBreakpoints(theme.breakpoints, ownerState.columnSpacing, (appendStyle, value) => {
|
|
149
|
+
appendStyle(styles, {
|
|
150
|
+
'--Grid-columnSpacing': typeof value === 'string' ? value : theme.spacing?.(value)
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
return styles;
|
|
154
|
+
};
|
|
155
|
+
export const generateGridDirectionStyles = ({
|
|
156
|
+
theme,
|
|
157
|
+
ownerState
|
|
158
|
+
}) => {
|
|
159
|
+
if (!ownerState.container) {
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const styles = {};
|
|
164
|
+
traverseBreakpoints(theme.breakpoints, ownerState.direction, (appendStyle, value) => {
|
|
165
|
+
appendStyle(styles, {
|
|
166
|
+
flexDirection: value
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
return styles;
|
|
170
|
+
};
|
|
171
|
+
export const generateGridStyles = ({
|
|
172
|
+
ownerState
|
|
173
|
+
}) => {
|
|
174
|
+
return _extends({
|
|
175
|
+
minWidth: 0,
|
|
176
|
+
boxSizing: 'border-box'
|
|
177
|
+
}, ownerState.container ? _extends({
|
|
178
|
+
display: 'flex',
|
|
179
|
+
flexWrap: 'wrap'
|
|
180
|
+
}, ownerState.wrap && ownerState.wrap !== 'wrap' && {
|
|
181
|
+
flexWrap: ownerState.wrap
|
|
182
|
+
}, {
|
|
183
|
+
margin: `calc(var(--Grid-rowSpacing) / -2) calc(var(--Grid-columnSpacing) / -2)`
|
|
184
|
+
}, ownerState.nested ? {
|
|
185
|
+
padding: `calc(var(--Grid-nested-rowSpacing) / 2) calc(var(--Grid-nested-columnSpacing) / 2)`
|
|
186
|
+
} : {
|
|
187
|
+
'--Grid-nested-rowSpacing': 'var(--Grid-rowSpacing)',
|
|
188
|
+
'--Grid-nested-columnSpacing': 'var(--Grid-columnSpacing)'
|
|
189
|
+
}) : {
|
|
190
|
+
padding: `calc(var(--Grid-rowSpacing) / 2) calc(var(--Grid-columnSpacing) / 2)`
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
export const generateSizeClassNames = gridSize => {
|
|
194
|
+
const classNames = [];
|
|
195
|
+
Object.entries(gridSize).forEach(([key, value]) => {
|
|
196
|
+
if (value !== false && value !== undefined) {
|
|
197
|
+
classNames.push(`grid-${key}-${String(value)}`);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return classNames;
|
|
201
|
+
};
|
|
202
|
+
export const generateSpacingClassNames = (spacing, smallestBreakpoint = 'xs') => {
|
|
203
|
+
function isValidSpacing(val) {
|
|
204
|
+
if (val === undefined) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return typeof val === 'string' && !Number.isNaN(Number(val)) || typeof val === 'number' && val > 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (isValidSpacing(spacing)) {
|
|
212
|
+
return [`spacing-${smallestBreakpoint}-${String(spacing)}`];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (typeof spacing === 'object' && !Array.isArray(spacing)) {
|
|
216
|
+
const classNames = [];
|
|
217
|
+
Object.entries(spacing).forEach(([key, value]) => {
|
|
218
|
+
if (isValidSpacing(value)) {
|
|
219
|
+
classNames.push(`spacing-${key}-${String(value)}`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return classNames;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return [];
|
|
226
|
+
};
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
-
const _excluded = ["colorSchemes", "components"];
|
|
4
|
+
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
@@ -10,7 +10,6 @@ import cssVarsParser from './cssVarsParser';
|
|
|
10
10
|
import ThemeProvider from '../ThemeProvider';
|
|
11
11
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
12
12
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
13
|
-
import createGetCssVar from './createGetCssVar';
|
|
14
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
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}';
|
|
@@ -24,8 +23,7 @@ export default function createCssVarsProvider(options) {
|
|
|
24
23
|
defaultColorScheme: designSystemColorScheme,
|
|
25
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
26
25
|
enableColorScheme: designSystemEnableColorScheme = true,
|
|
27
|
-
|
|
28
|
-
shouldSkipGeneratingVar,
|
|
26
|
+
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
29
27
|
resolveTheme
|
|
30
28
|
} = options;
|
|
31
29
|
|
|
@@ -48,7 +46,6 @@ export default function createCssVarsProvider(options) {
|
|
|
48
46
|
function CssVarsProvider({
|
|
49
47
|
children,
|
|
50
48
|
theme: themeProp = defaultTheme,
|
|
51
|
-
prefix = designSystemPrefix,
|
|
52
49
|
modeStorageKey = defaultModeStorageKey,
|
|
53
50
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
54
51
|
attribute = defaultAttribute,
|
|
@@ -59,13 +56,15 @@ export default function createCssVarsProvider(options) {
|
|
|
59
56
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
60
57
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
61
58
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
62
|
-
colorSchemeSelector = ':root'
|
|
59
|
+
colorSchemeSelector = ':root',
|
|
60
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
63
61
|
}) {
|
|
64
62
|
const hasMounted = React.useRef(false);
|
|
65
63
|
|
|
66
64
|
const {
|
|
67
65
|
colorSchemes = {},
|
|
68
|
-
components = {}
|
|
66
|
+
components = {},
|
|
67
|
+
cssVarPrefix
|
|
69
68
|
} = themeProp,
|
|
70
69
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
71
70
|
|
|
@@ -110,16 +109,14 @@ export default function createCssVarsProvider(options) {
|
|
|
110
109
|
vars: rootVars,
|
|
111
110
|
parsedTheme
|
|
112
111
|
} = cssVarsParser(theme, {
|
|
113
|
-
prefix,
|
|
114
|
-
basePrefix: designSystemPrefix,
|
|
112
|
+
prefix: cssVarPrefix,
|
|
115
113
|
shouldSkipGeneratingVar
|
|
116
114
|
});
|
|
117
115
|
theme = _extends({}, parsedTheme, {
|
|
118
116
|
components,
|
|
119
117
|
colorSchemes,
|
|
120
|
-
|
|
118
|
+
cssVarPrefix,
|
|
121
119
|
vars: rootVars,
|
|
122
|
-
getCssVar: createGetCssVar(prefix),
|
|
123
120
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
124
121
|
});
|
|
125
122
|
const defaultColorSchemeStyleSheet = {};
|
|
@@ -130,8 +127,7 @@ export default function createCssVarsProvider(options) {
|
|
|
130
127
|
vars,
|
|
131
128
|
parsedTheme: parsedScheme
|
|
132
129
|
} = cssVarsParser(scheme, {
|
|
133
|
-
prefix,
|
|
134
|
-
basePrefix: designSystemPrefix,
|
|
130
|
+
prefix: cssVarPrefix,
|
|
135
131
|
shouldSkipGeneratingVar
|
|
136
132
|
});
|
|
137
133
|
theme.vars = deepmerge(theme.vars, vars);
|
|
@@ -295,9 +291,9 @@ export default function createCssVarsProvider(options) {
|
|
|
295
291
|
modeStorageKey: PropTypes.string,
|
|
296
292
|
|
|
297
293
|
/**
|
|
298
|
-
* CSS
|
|
294
|
+
* A function to determine if the key, value should be attached as CSS Variable
|
|
299
295
|
*/
|
|
300
|
-
|
|
296
|
+
shouldSkipGeneratingVar: PropTypes.func,
|
|
301
297
|
|
|
302
298
|
/**
|
|
303
299
|
* The window that attaches the 'storage' event listener
|
|
@@ -314,7 +310,8 @@ export default function createCssVarsProvider(options) {
|
|
|
314
310
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
315
311
|
attribute: defaultAttribute,
|
|
316
312
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
317
|
-
modeStorageKey: defaultModeStorageKey
|
|
313
|
+
modeStorageKey: defaultModeStorageKey,
|
|
314
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
318
315
|
}, params));
|
|
319
316
|
|
|
320
317
|
return {
|
|
@@ -18,8 +18,8 @@ export default function createGetCssVar(prefix = '') {
|
|
|
18
18
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
const getCssVar = (field, ...
|
|
22
|
-
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...
|
|
21
|
+
const getCssVar = (field, ...fallbacks) => {
|
|
22
|
+
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
return getCssVar;
|
|
@@ -88,13 +88,9 @@ const getCssValue = (keys, value) => {
|
|
|
88
88
|
* @param {Object} theme
|
|
89
89
|
* @param {{
|
|
90
90
|
* prefix?: string,
|
|
91
|
-
* basePrefix?: string,
|
|
92
91
|
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
93
92
|
* }} options.
|
|
94
|
-
* `
|
|
95
|
-
* `prefix`: defined by application
|
|
96
|
-
*
|
|
97
|
-
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
93
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
98
94
|
*
|
|
99
95
|
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
100
96
|
*
|
|
@@ -105,16 +101,15 @@ const getCssValue = (keys, value) => {
|
|
|
105
101
|
* palette: { primary: { 500: 'var(--color)' } }
|
|
106
102
|
* }, { prefix: 'foo' })
|
|
107
103
|
*
|
|
108
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--
|
|
109
|
-
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
110
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--
|
|
104
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
105
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
106
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
111
107
|
*/
|
|
112
108
|
|
|
113
109
|
|
|
114
110
|
export default function cssVarsParser(theme, options) {
|
|
115
111
|
const {
|
|
116
112
|
prefix,
|
|
117
|
-
basePrefix = '',
|
|
118
113
|
shouldSkipGeneratingVar
|
|
119
114
|
} = options || {};
|
|
120
115
|
const css = {};
|
|
@@ -122,16 +117,6 @@ export default function cssVarsParser(theme, options) {
|
|
|
122
117
|
const parsedTheme = {};
|
|
123
118
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
124
119
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
125
|
-
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
126
|
-
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
127
|
-
if (!basePrefix && prefix) {
|
|
128
|
-
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
129
|
-
} else {
|
|
130
|
-
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
131
|
-
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
120
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
136
121
|
// only create css & var if `shouldSkipGeneratingVar` return false
|
|
137
122
|
const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
|
|
@@ -5,6 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
+
enableColorScheme = true,
|
|
8
9
|
enableSystem = false,
|
|
9
10
|
defaultLightColorScheme = 'light',
|
|
10
11
|
defaultDarkColorScheme = 'dark',
|
|
@@ -18,13 +19,16 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
19
|
dangerouslySetInnerHTML: {
|
|
19
20
|
__html: `(function() { try {
|
|
20
21
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
22
|
+
var cssColorScheme = mode;
|
|
21
23
|
var colorScheme = '';
|
|
22
24
|
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
23
25
|
// handle system mode
|
|
24
26
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
25
27
|
if (mql.matches) {
|
|
28
|
+
cssColorScheme = 'dark';
|
|
26
29
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
27
30
|
} else {
|
|
31
|
+
cssColorScheme = 'light';
|
|
28
32
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -37,6 +41,9 @@ export default function getInitColorSchemeScript(options) {
|
|
|
37
41
|
if (colorScheme) {
|
|
38
42
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
39
43
|
}
|
|
44
|
+
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
+
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
+
}
|
|
40
47
|
} catch (e) {} })();`
|
|
41
48
|
}
|
|
42
49
|
});
|
package/modern/cssVars/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
@@ -153,7 +153,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
153
153
|
const handleMediaQuery = React.useCallback(e => {
|
|
154
154
|
if (state.mode === 'system') {
|
|
155
155
|
setState(currentState => _extends({}, currentState, {
|
|
156
|
-
systemMode: e
|
|
156
|
+
systemMode: e?.matches ? 'dark' : 'light'
|
|
157
157
|
}));
|
|
158
158
|
}
|
|
159
159
|
}, [state.mode]); // Ref hack to avoid adding handleMediaQuery as a dep
|
package/modern/getThemeValue.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import borders from './borders';
|
|
2
2
|
import display from './display';
|
|
3
3
|
import flexbox from './flexbox';
|
|
4
|
-
import grid from './
|
|
4
|
+
import grid from './cssGrid';
|
|
5
5
|
import positions from './positions';
|
|
6
6
|
import palette from './palette';
|
|
7
7
|
import shadows from './shadows';
|
package/modern/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.9.0
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,8 +12,8 @@ export { default as compose } from './compose';
|
|
|
12
12
|
export { default as display } from './display';
|
|
13
13
|
export { default as flexbox } from './flexbox';
|
|
14
14
|
export * from './flexbox';
|
|
15
|
-
export { default as grid } from './
|
|
16
|
-
export * from './
|
|
15
|
+
export { default as grid } from './cssGrid';
|
|
16
|
+
export * from './cssGrid';
|
|
17
17
|
export { default as palette } from './palette';
|
|
18
18
|
export * from './palette';
|
|
19
19
|
export { default as positions } from './positions';
|
|
@@ -45,6 +45,12 @@ export * from './colorManipulator';
|
|
|
45
45
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
46
46
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
47
47
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
48
|
+
/** ----------------- */
|
|
49
|
+
|
|
50
|
+
/** Layout components */
|
|
51
|
+
|
|
48
52
|
export { default as createContainer } from './Container/createContainer';
|
|
49
53
|
export { default as Container } from './Container';
|
|
50
|
-
export * from './Container';
|
|
54
|
+
export * from './Container';
|
|
55
|
+
export { default as Unstable_Grid } from './Unstable_Grid/Grid';
|
|
56
|
+
export * from './Unstable_Grid';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.17.2",
|
|
47
|
-
"@mui/private-theming": "^5.
|
|
48
|
-
"@mui/styled-engine": "^5.8.
|
|
47
|
+
"@mui/private-theming": "^5.9.0",
|
|
48
|
+
"@mui/styled-engine": "^5.8.7",
|
|
49
49
|
"@mui/types": "^7.1.4",
|
|
50
|
-
"@mui/utils": "^5.
|
|
51
|
-
"clsx": "^1.
|
|
50
|
+
"@mui/utils": "^5.9.0",
|
|
51
|
+
"clsx": "^1.2.1",
|
|
52
52
|
"csstype": "^3.1.0",
|
|
53
53
|
"prop-types": "^15.8.1"
|
|
54
54
|
},
|