@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,230 @@
|
|
|
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
|
+
var _theme$spacing;
|
|
134
|
+
|
|
135
|
+
appendStyle(styles, {
|
|
136
|
+
'--Grid-rowSpacing': typeof value === 'string' ? value : (_theme$spacing = theme.spacing) == null ? void 0 : _theme$spacing.call(theme, value)
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
return styles;
|
|
140
|
+
};
|
|
141
|
+
export const generateGridColumnSpacingStyles = ({
|
|
142
|
+
theme,
|
|
143
|
+
ownerState
|
|
144
|
+
}) => {
|
|
145
|
+
if (!ownerState.container) {
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const styles = {};
|
|
150
|
+
traverseBreakpoints(theme.breakpoints, ownerState.columnSpacing, (appendStyle, value) => {
|
|
151
|
+
var _theme$spacing2;
|
|
152
|
+
|
|
153
|
+
appendStyle(styles, {
|
|
154
|
+
'--Grid-columnSpacing': typeof value === 'string' ? value : (_theme$spacing2 = theme.spacing) == null ? void 0 : _theme$spacing2.call(theme, value)
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return styles;
|
|
158
|
+
};
|
|
159
|
+
export const generateGridDirectionStyles = ({
|
|
160
|
+
theme,
|
|
161
|
+
ownerState
|
|
162
|
+
}) => {
|
|
163
|
+
if (!ownerState.container) {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const styles = {};
|
|
168
|
+
traverseBreakpoints(theme.breakpoints, ownerState.direction, (appendStyle, value) => {
|
|
169
|
+
appendStyle(styles, {
|
|
170
|
+
flexDirection: value
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
return styles;
|
|
174
|
+
};
|
|
175
|
+
export const generateGridStyles = ({
|
|
176
|
+
ownerState
|
|
177
|
+
}) => {
|
|
178
|
+
return _extends({
|
|
179
|
+
minWidth: 0,
|
|
180
|
+
boxSizing: 'border-box'
|
|
181
|
+
}, ownerState.container ? _extends({
|
|
182
|
+
display: 'flex',
|
|
183
|
+
flexWrap: 'wrap'
|
|
184
|
+
}, ownerState.wrap && ownerState.wrap !== 'wrap' && {
|
|
185
|
+
flexWrap: ownerState.wrap
|
|
186
|
+
}, {
|
|
187
|
+
margin: `calc(var(--Grid-rowSpacing) / -2) calc(var(--Grid-columnSpacing) / -2)`
|
|
188
|
+
}, ownerState.nested ? {
|
|
189
|
+
padding: `calc(var(--Grid-nested-rowSpacing) / 2) calc(var(--Grid-nested-columnSpacing) / 2)`
|
|
190
|
+
} : {
|
|
191
|
+
'--Grid-nested-rowSpacing': 'var(--Grid-rowSpacing)',
|
|
192
|
+
'--Grid-nested-columnSpacing': 'var(--Grid-columnSpacing)'
|
|
193
|
+
}) : {
|
|
194
|
+
padding: `calc(var(--Grid-rowSpacing) / 2) calc(var(--Grid-columnSpacing) / 2)`
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
export const generateSizeClassNames = gridSize => {
|
|
198
|
+
const classNames = [];
|
|
199
|
+
Object.entries(gridSize).forEach(([key, value]) => {
|
|
200
|
+
if (value !== false && value !== undefined) {
|
|
201
|
+
classNames.push(`grid-${key}-${String(value)}`);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
return classNames;
|
|
205
|
+
};
|
|
206
|
+
export const generateSpacingClassNames = (spacing, smallestBreakpoint = 'xs') => {
|
|
207
|
+
function isValidSpacing(val) {
|
|
208
|
+
if (val === undefined) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return typeof val === 'string' && !Number.isNaN(Number(val)) || typeof val === 'number' && val > 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (isValidSpacing(spacing)) {
|
|
216
|
+
return [`spacing-${smallestBreakpoint}-${String(spacing)}`];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (typeof spacing === 'object' && !Array.isArray(spacing)) {
|
|
220
|
+
const classNames = [];
|
|
221
|
+
Object.entries(spacing).forEach(([key, value]) => {
|
|
222
|
+
if (isValidSpacing(value)) {
|
|
223
|
+
classNames.push(`spacing-${key}-${String(value)}`);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return classNames;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return [];
|
|
230
|
+
};
|
|
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/esm/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.matches ? 'dark' : 'light'
|
|
156
|
+
systemMode: e != null && e.matches ? 'dark' : 'light'
|
|
157
157
|
}));
|
|
158
158
|
}
|
|
159
159
|
}, [state.mode]); // Ref hack to avoid adding handleMediaQuery as a dep
|
package/esm/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/esm/index.js
CHANGED
|
@@ -7,8 +7,8 @@ export { default as compose } from './compose';
|
|
|
7
7
|
export { default as display } from './display';
|
|
8
8
|
export { default as flexbox } from './flexbox';
|
|
9
9
|
export * from './flexbox';
|
|
10
|
-
export { default as grid } from './
|
|
11
|
-
export * from './
|
|
10
|
+
export { default as grid } from './cssGrid';
|
|
11
|
+
export * from './cssGrid';
|
|
12
12
|
export { default as palette } from './palette';
|
|
13
13
|
export * from './palette';
|
|
14
14
|
export { default as positions } from './positions';
|
|
@@ -40,6 +40,12 @@ export * from './colorManipulator';
|
|
|
40
40
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
41
41
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
42
42
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
43
|
+
/** ----------------- */
|
|
44
|
+
|
|
45
|
+
/** Layout components */
|
|
46
|
+
|
|
43
47
|
export { default as createContainer } from './Container/createContainer';
|
|
44
48
|
export { default as Container } from './Container';
|
|
45
|
-
export * from './Container';
|
|
49
|
+
export * from './Container';
|
|
50
|
+
export { default as Unstable_Grid } from './Unstable_Grid/Grid';
|
|
51
|
+
export * from './Unstable_Grid';
|
package/getThemeValue.js
CHANGED
|
@@ -13,7 +13,7 @@ var _display = _interopRequireDefault(require("./display"));
|
|
|
13
13
|
|
|
14
14
|
var _flexbox = _interopRequireDefault(require("./flexbox"));
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _cssGrid = _interopRequireDefault(require("./cssGrid"));
|
|
17
17
|
|
|
18
18
|
var _positions = _interopRequireDefault(require("./positions"));
|
|
19
19
|
|
|
@@ -31,7 +31,7 @@ const filterPropsMapping = {
|
|
|
31
31
|
borders: _borders.default.filterProps,
|
|
32
32
|
display: _display.default.filterProps,
|
|
33
33
|
flexbox: _flexbox.default.filterProps,
|
|
34
|
-
grid:
|
|
34
|
+
grid: _cssGrid.default.filterProps,
|
|
35
35
|
positions: _positions.default.filterProps,
|
|
36
36
|
palette: _palette.default.filterProps,
|
|
37
37
|
shadows: _shadows.default.filterProps,
|
|
@@ -43,7 +43,7 @@ const styleFunctionMapping = {
|
|
|
43
43
|
borders: _borders.default,
|
|
44
44
|
display: _display.default,
|
|
45
45
|
flexbox: _flexbox.default,
|
|
46
|
-
grid:
|
|
46
|
+
grid: _cssGrid.default,
|
|
47
47
|
positions: _positions.default,
|
|
48
48
|
palette: _palette.default,
|
|
49
49
|
shadows: _shadows.default,
|
package/index.d.ts
CHANGED
package/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.
|
|
@@ -53,7 +53,8 @@ var _exportNames = {
|
|
|
53
53
|
unstable_createCssVarsProvider: true,
|
|
54
54
|
unstable_createGetCssVar: true,
|
|
55
55
|
createContainer: true,
|
|
56
|
-
Container: true
|
|
56
|
+
Container: true,
|
|
57
|
+
Unstable_Grid: true
|
|
57
58
|
};
|
|
58
59
|
Object.defineProperty(exports, "Box", {
|
|
59
60
|
enumerable: true,
|
|
@@ -85,6 +86,12 @@ Object.defineProperty(exports, "ThemeProvider", {
|
|
|
85
86
|
return _ThemeProvider.default;
|
|
86
87
|
}
|
|
87
88
|
});
|
|
89
|
+
Object.defineProperty(exports, "Unstable_Grid", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () {
|
|
92
|
+
return _Grid.default;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
88
95
|
Object.defineProperty(exports, "borders", {
|
|
89
96
|
enumerable: true,
|
|
90
97
|
get: function () {
|
|
@@ -178,7 +185,7 @@ Object.defineProperty(exports, "getThemeProps", {
|
|
|
178
185
|
Object.defineProperty(exports, "grid", {
|
|
179
186
|
enumerable: true,
|
|
180
187
|
get: function () {
|
|
181
|
-
return
|
|
188
|
+
return _cssGrid.default;
|
|
182
189
|
}
|
|
183
190
|
});
|
|
184
191
|
Object.defineProperty(exports, "handleBreakpoints", {
|
|
@@ -350,16 +357,16 @@ Object.keys(_flexbox).forEach(function (key) {
|
|
|
350
357
|
});
|
|
351
358
|
});
|
|
352
359
|
|
|
353
|
-
var
|
|
360
|
+
var _cssGrid = _interopRequireWildcard(require("./cssGrid"));
|
|
354
361
|
|
|
355
|
-
Object.keys(
|
|
362
|
+
Object.keys(_cssGrid).forEach(function (key) {
|
|
356
363
|
if (key === "default" || key === "__esModule") return;
|
|
357
364
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
358
|
-
if (key in exports && exports[key] ===
|
|
365
|
+
if (key in exports && exports[key] === _cssGrid[key]) return;
|
|
359
366
|
Object.defineProperty(exports, key, {
|
|
360
367
|
enumerable: true,
|
|
361
368
|
get: function () {
|
|
362
|
-
return
|
|
369
|
+
return _cssGrid[key];
|
|
363
370
|
}
|
|
364
371
|
});
|
|
365
372
|
});
|
|
@@ -514,6 +521,22 @@ Object.keys(_Container).forEach(function (key) {
|
|
|
514
521
|
});
|
|
515
522
|
});
|
|
516
523
|
|
|
524
|
+
var _Grid = _interopRequireDefault(require("./Unstable_Grid/Grid"));
|
|
525
|
+
|
|
526
|
+
var _Unstable_Grid = require("./Unstable_Grid");
|
|
527
|
+
|
|
528
|
+
Object.keys(_Unstable_Grid).forEach(function (key) {
|
|
529
|
+
if (key === "default" || key === "__esModule") return;
|
|
530
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
531
|
+
if (key in exports && exports[key] === _Unstable_Grid[key]) return;
|
|
532
|
+
Object.defineProperty(exports, key, {
|
|
533
|
+
enumerable: true,
|
|
534
|
+
get: function () {
|
|
535
|
+
return _Unstable_Grid[key];
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
|
|
517
540
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
518
541
|
|
|
519
542
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|