@mui/system 5.4.1 → 5.4.4
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/Box/Box.d.ts +1 -1
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +177 -0
- package/createBox.d.ts +2 -0
- package/createBox.js +3 -2
- package/createBox.spec.d.ts +1 -1
- package/createStyled.d.ts +2 -1
- package/createStyled.js +12 -6
- package/createTheme/createBreakpoints.js +21 -6
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +59 -95
- package/cssVars/createCssVarsProvider.js +32 -15
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +7 -1
- package/cssVars/cssVarsParser.d.ts +70 -68
- package/cssVars/cssVarsParser.js +21 -20
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +1 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/createBox.js +3 -2
- package/esm/createStyled.js +10 -4
- package/esm/createTheme/createBreakpoints.js +20 -4
- package/esm/cssVars/createCssVarsProvider.js +32 -16
- package/esm/cssVars/createGetCssVar.js +7 -1
- package/esm/cssVars/cssVarsParser.js +21 -20
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +1 -1
- package/esm/styleFunctionSx/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
- package/getThemeValue.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +8 -1
- package/index.spec.d.ts +1 -1
- package/legacy/createBox.js +4 -2
- package/legacy/createStyled.js +11 -4
- package/legacy/createTheme/createBreakpoints.js +23 -4
- package/legacy/cssVars/createCssVarsProvider.js +35 -18
- package/legacy/cssVars/createGetCssVar.js +7 -1
- package/legacy/cssVars/cssVarsParser.js +23 -22
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +2 -2
- package/legacy/styleFunctionSx/index.js +1 -0
- package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
- package/modern/createBox.js +3 -2
- package/modern/createStyled.js +10 -4
- package/modern/createTheme/createBreakpoints.js +20 -4
- package/modern/cssVars/createCssVarsProvider.js +32 -16
- package/modern/cssVars/createGetCssVar.js +7 -1
- package/modern/cssVars/cssVarsParser.js +21 -20
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +2 -2
- package/modern/styleFunctionSx/index.js +1 -0
- package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
- package/package.json +6 -6
- package/style.d.ts +1 -1
- package/styleFunctionSx/index.js +12 -2
- package/styleFunctionSx/styleFunctionSx.d.ts +25 -3
- package/styleFunctionSx/styleFunctionSx.js +79 -54
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -54,10 +54,11 @@ function createCssVarsProvider(options) {
|
|
|
54
54
|
theme: baseTheme = {},
|
|
55
55
|
defaultMode: desisgnSystemMode = 'light',
|
|
56
56
|
defaultColorScheme: designSystemColorScheme,
|
|
57
|
-
disableTransitionOnChange = false,
|
|
58
|
-
enableColorScheme = true,
|
|
57
|
+
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
58
|
+
enableColorScheme: designSystemEnableColorScheme = true,
|
|
59
59
|
prefix: designSystemPrefix = '',
|
|
60
|
-
shouldSkipGeneratingVar
|
|
60
|
+
shouldSkipGeneratingVar,
|
|
61
|
+
resolveTheme
|
|
61
62
|
} = options;
|
|
62
63
|
const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
|
|
63
64
|
const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
@@ -85,15 +86,14 @@ function createCssVarsProvider(options) {
|
|
|
85
86
|
modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
86
87
|
attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
87
88
|
defaultMode = desisgnSystemMode,
|
|
88
|
-
defaultColorScheme = designSystemColorScheme
|
|
89
|
+
defaultColorScheme = designSystemColorScheme,
|
|
90
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
91
|
+
enableColorScheme = designSystemEnableColorScheme
|
|
89
92
|
}) {
|
|
90
|
-
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
91
|
-
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
92
|
-
const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
|
|
93
93
|
const {
|
|
94
94
|
colorSchemes: baseColorSchemes = {}
|
|
95
|
-
} =
|
|
96
|
-
restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(
|
|
95
|
+
} = baseTheme,
|
|
96
|
+
restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
|
|
97
97
|
const {
|
|
98
98
|
colorSchemes: colorSchemesProp = {}
|
|
99
99
|
} = themeProp,
|
|
@@ -142,15 +142,17 @@ function createCssVarsProvider(options) {
|
|
|
142
142
|
|
|
143
143
|
const {
|
|
144
144
|
css: rootCss,
|
|
145
|
-
vars: rootVars
|
|
145
|
+
vars: rootVars,
|
|
146
|
+
parsedTheme
|
|
146
147
|
} = (0, _cssVarsParser.default)(mergedTheme, {
|
|
147
148
|
prefix,
|
|
148
149
|
basePrefix: designSystemPrefix,
|
|
149
150
|
shouldSkipGeneratingVar
|
|
150
151
|
});
|
|
151
|
-
mergedTheme = (0, _extends2.default)({},
|
|
152
|
+
mergedTheme = (0, _extends2.default)({}, parsedTheme, {
|
|
152
153
|
components,
|
|
153
154
|
colorSchemes,
|
|
155
|
+
prefix,
|
|
154
156
|
vars: rootVars,
|
|
155
157
|
spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
|
|
156
158
|
breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints,
|
|
@@ -160,7 +162,8 @@ function createCssVarsProvider(options) {
|
|
|
160
162
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
161
163
|
const {
|
|
162
164
|
css,
|
|
163
|
-
vars
|
|
165
|
+
vars,
|
|
166
|
+
parsedTheme: parsedScheme
|
|
164
167
|
} = (0, _cssVarsParser.default)(scheme, {
|
|
165
168
|
prefix,
|
|
166
169
|
basePrefix: designSystemPrefix,
|
|
@@ -168,6 +171,10 @@ function createCssVarsProvider(options) {
|
|
|
168
171
|
});
|
|
169
172
|
mergedTheme.vars = (0, _utils.deepmerge)(mergedTheme.vars, vars);
|
|
170
173
|
|
|
174
|
+
if (key === resolvedColorScheme) {
|
|
175
|
+
mergedTheme = (0, _extends2.default)({}, mergedTheme, parsedScheme);
|
|
176
|
+
}
|
|
177
|
+
|
|
171
178
|
const resolvedDefaultColorScheme = (() => {
|
|
172
179
|
if (typeof defaultColorScheme === 'string') {
|
|
173
180
|
return defaultColorScheme;
|
|
@@ -208,7 +215,7 @@ function createCssVarsProvider(options) {
|
|
|
208
215
|
return () => {
|
|
209
216
|
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
210
217
|
};
|
|
211
|
-
}, [mode, systemMode]);
|
|
218
|
+
}, [mode, systemMode, enableColorScheme]);
|
|
212
219
|
React.useEffect(() => {
|
|
213
220
|
let timer;
|
|
214
221
|
|
|
@@ -228,7 +235,7 @@ function createCssVarsProvider(options) {
|
|
|
228
235
|
return () => {
|
|
229
236
|
clearTimeout(timer);
|
|
230
237
|
};
|
|
231
|
-
}, [colorScheme]);
|
|
238
|
+
}, [colorScheme, disableTransitionOnChange]);
|
|
232
239
|
React.useEffect(() => {
|
|
233
240
|
hasMounted.current = true;
|
|
234
241
|
return () => {
|
|
@@ -252,7 +259,7 @@ function createCssVarsProvider(options) {
|
|
|
252
259
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
253
260
|
styles: styleSheet
|
|
254
261
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
|
|
255
|
-
theme: mergedTheme,
|
|
262
|
+
theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
|
|
256
263
|
children: children
|
|
257
264
|
})]
|
|
258
265
|
});
|
|
@@ -279,6 +286,16 @@ function createCssVarsProvider(options) {
|
|
|
279
286
|
*/
|
|
280
287
|
defaultMode: _propTypes.default.string,
|
|
281
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Disable CSS transitions when switching between modes or color schemes
|
|
291
|
+
*/
|
|
292
|
+
disableTransitionOnChange: _propTypes.default.bool,
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
296
|
+
*/
|
|
297
|
+
enableColorScheme: _propTypes.default.bool,
|
|
298
|
+
|
|
282
299
|
/**
|
|
283
300
|
* The key in the local storage used to store current color scheme.
|
|
284
301
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
-
* and they does not need to remember the prefix (defined once).
|
|
4
|
-
*/
|
|
5
|
-
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
|
|
1
|
+
/**
|
|
2
|
+
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
+
* and they does not need to remember the prefix (defined once).
|
|
4
|
+
*/
|
|
5
|
+
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
|
|
@@ -15,7 +15,13 @@ function createGetCssVar(prefix = '') {
|
|
|
15
15
|
return '';
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const value = vars[0];
|
|
19
|
+
|
|
20
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
21
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return `, ${value}`;
|
|
19
25
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
20
26
|
|
|
21
27
|
|
|
@@ -1,68 +1,70 @@
|
|
|
1
|
-
declare type NestedRecord<V = any> = {
|
|
2
|
-
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* This function create an object from keys, value and then assign to target
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} obj : the target object to be assigned
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
* @param {string | number} value
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const source = {}
|
|
13
|
-
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
-
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
-
*/
|
|
21
|
-
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} obj : source object
|
|
25
|
-
* @param {Function} callback : a function that will be called when
|
|
26
|
-
* - the deepest key in source object is reached
|
|
27
|
-
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
-
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
-
*/
|
|
33
|
-
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
-
/**
|
|
35
|
-
* a function that parse theme and return { css, vars }
|
|
36
|
-
*
|
|
37
|
-
* @param {Object} theme
|
|
38
|
-
* @param {{
|
|
39
|
-
* prefix?: string,
|
|
40
|
-
* basePrefix?: string,
|
|
41
|
-
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
|
-
* }} options.
|
|
43
|
-
* `basePrefix`: defined by design system.
|
|
44
|
-
* `prefix`: defined by application
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* const { css, vars } = parser({
|
|
52
|
-
* fontSize: 12,
|
|
53
|
-
* lineHeight: 1.2,
|
|
54
|
-
* palette: { primary: { 500: '
|
|
55
|
-
* })
|
|
56
|
-
*
|
|
57
|
-
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '
|
|
58
|
-
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
1
|
+
declare type NestedRecord<V = any> = {
|
|
2
|
+
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function create an object from keys, value and then assign to target
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} obj : the target object to be assigned
|
|
8
|
+
* @param {string[]} keys
|
|
9
|
+
* @param {string | number} value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const source = {}
|
|
13
|
+
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
+
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
+
*/
|
|
21
|
+
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} obj : source object
|
|
25
|
+
* @param {Function} callback : a function that will be called when
|
|
26
|
+
* - the deepest key in source object is reached
|
|
27
|
+
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
+
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
+
*/
|
|
33
|
+
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
+
/**
|
|
35
|
+
* a function that parse theme and return { css, vars }
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} theme
|
|
38
|
+
* @param {{
|
|
39
|
+
* prefix?: string,
|
|
40
|
+
* basePrefix?: string,
|
|
41
|
+
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
|
+
* }} options.
|
|
43
|
+
* `basePrefix`: defined by design system.
|
|
44
|
+
* `prefix`: defined by application
|
|
45
|
+
*
|
|
46
|
+
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
47
|
+
*
|
|
48
|
+
* @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.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const { css, vars, parsedTheme } = parser({
|
|
52
|
+
* fontSize: 12,
|
|
53
|
+
* lineHeight: 1.2,
|
|
54
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
55
|
+
* }, { prefix: 'foo' })
|
|
56
|
+
*
|
|
57
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
58
|
+
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
59
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
60
|
+
*/
|
|
61
|
+
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
62
|
+
prefix?: string;
|
|
63
|
+
basePrefix?: string;
|
|
64
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
65
|
+
}): {
|
|
66
|
+
css: NestedRecord<string>;
|
|
67
|
+
vars: NestedRecord<string>;
|
|
68
|
+
parsedTheme: T;
|
|
69
|
+
};
|
|
70
|
+
export {};
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -99,19 +99,20 @@ const getCssValue = (keys, value) => {
|
|
|
99
99
|
* `basePrefix`: defined by design system.
|
|
100
100
|
* `prefix`: defined by application
|
|
101
101
|
*
|
|
102
|
-
*
|
|
102
|
+
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
103
103
|
*
|
|
104
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
104
|
+
* @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.
|
|
105
105
|
*
|
|
106
106
|
* @example
|
|
107
|
-
* const { css, vars } = parser({
|
|
107
|
+
* const { css, vars, parsedTheme } = parser({
|
|
108
108
|
* fontSize: 12,
|
|
109
109
|
* lineHeight: 1.2,
|
|
110
|
-
* palette: { primary: { 500: '
|
|
111
|
-
* })
|
|
110
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
111
|
+
* }, { prefix: 'foo' })
|
|
112
112
|
*
|
|
113
|
-
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '
|
|
114
|
-
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
113
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
114
|
+
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
115
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
115
116
|
*/
|
|
116
117
|
|
|
117
118
|
|
|
@@ -123,20 +124,17 @@ function cssVarsParser(theme, options) {
|
|
|
123
124
|
} = options || {};
|
|
124
125
|
const css = {};
|
|
125
126
|
const vars = {};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
127
|
+
const parsedTheme = {};
|
|
128
|
+
walkObjectDeep(theme, (keys, value) => {
|
|
129
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
130
|
+
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
131
|
+
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
132
132
|
if (!basePrefix && prefix) {
|
|
133
|
-
value = value.replace(/var\(
|
|
133
|
+
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
134
134
|
} else {
|
|
135
|
-
value = prefix ? value.replace(new RegExp(basePrefix
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
scope[keys.slice(-1)[0]] = value;
|
|
135
|
+
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
136
|
+
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
137
|
+
}
|
|
140
138
|
}
|
|
141
139
|
|
|
142
140
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -148,10 +146,13 @@ function cssVarsParser(theme, options) {
|
|
|
148
146
|
assignNestedKeys(vars, keys, `var(${cssVar})`);
|
|
149
147
|
}
|
|
150
148
|
}
|
|
149
|
+
|
|
150
|
+
assignNestedKeys(parsedTheme, keys, value);
|
|
151
151
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
152
152
|
);
|
|
153
153
|
return {
|
|
154
154
|
css,
|
|
155
|
-
vars
|
|
155
|
+
vars,
|
|
156
|
+
parsedTheme
|
|
156
157
|
};
|
|
157
158
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const DEFAULT_MODE_STORAGE_KEY = "mui-mode";
|
|
3
|
-
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "mui-color-scheme";
|
|
4
|
-
export declare const DEFAULT_ATTRIBUTE = "data-mui-color-scheme";
|
|
5
|
-
export default function getInitColorSchemeScript(options?: {
|
|
6
|
-
enableSystem?: boolean;
|
|
7
|
-
defaultLightColorScheme?: string;
|
|
8
|
-
defaultDarkColorScheme?: string;
|
|
9
|
-
modeStorageKey?: string;
|
|
10
|
-
colorSchemeStorageKey?: string;
|
|
11
|
-
attribute?: string;
|
|
12
|
-
}): JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const DEFAULT_MODE_STORAGE_KEY = "mui-mode";
|
|
3
|
+
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "mui-color-scheme";
|
|
4
|
+
export declare const DEFAULT_ATTRIBUTE = "data-mui-color-scheme";
|
|
5
|
+
export default function getInitColorSchemeScript(options?: {
|
|
6
|
+
enableSystem?: boolean;
|
|
7
|
+
defaultLightColorScheme?: string;
|
|
8
|
+
defaultDarkColorScheme?: string;
|
|
9
|
+
modeStorageKey?: string;
|
|
10
|
+
colorSchemeStorageKey?: string;
|
|
11
|
+
attribute?: string;
|
|
12
|
+
}): JSX.Element;
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { BuildCssVarsTheme } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
export declare type Mode = 'light' | 'dark' | 'system';
|
|
2
|
-
export declare type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
-
export interface State<SupportedColorScheme extends string> {
|
|
4
|
-
/**
|
|
5
|
-
* User selected mode.
|
|
6
|
-
* Note: on the server, mode is always undefined
|
|
7
|
-
*/
|
|
8
|
-
mode: Mode | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
-
*/
|
|
12
|
-
systemMode: SystemMode | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* The color scheme for the light mode.
|
|
15
|
-
*/
|
|
16
|
-
lightColorScheme: SupportedColorScheme;
|
|
17
|
-
/**
|
|
18
|
-
* The color scheme for the dark mode.
|
|
19
|
-
*/
|
|
20
|
-
darkColorScheme: SupportedColorScheme;
|
|
21
|
-
}
|
|
22
|
-
export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
-
/**
|
|
24
|
-
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
-
*/
|
|
26
|
-
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* `mode` is saved to internal state and localStorage
|
|
29
|
-
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
-
*/
|
|
31
|
-
setMode: (mode: Mode | null) => void;
|
|
32
|
-
/**
|
|
33
|
-
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
-
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
-
*/
|
|
36
|
-
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
-
light: SupportedColorScheme | null;
|
|
38
|
-
dark: SupportedColorScheme | null;
|
|
39
|
-
}> | null) => void;
|
|
40
|
-
};
|
|
41
|
-
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
-
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
-
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
|
|
44
|
-
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
-
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
-
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
-
defaultMode?: Mode;
|
|
48
|
-
modeStorageKey?: string;
|
|
49
|
-
colorSchemeStorageKey?: string;
|
|
50
|
-
}): Result<SupportedColorScheme>;
|
|
1
|
+
export declare type Mode = 'light' | 'dark' | 'system';
|
|
2
|
+
export declare type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
+
export interface State<SupportedColorScheme extends string> {
|
|
4
|
+
/**
|
|
5
|
+
* User selected mode.
|
|
6
|
+
* Note: on the server, mode is always undefined
|
|
7
|
+
*/
|
|
8
|
+
mode: Mode | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
+
*/
|
|
12
|
+
systemMode: SystemMode | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The color scheme for the light mode.
|
|
15
|
+
*/
|
|
16
|
+
lightColorScheme: SupportedColorScheme;
|
|
17
|
+
/**
|
|
18
|
+
* The color scheme for the dark mode.
|
|
19
|
+
*/
|
|
20
|
+
darkColorScheme: SupportedColorScheme;
|
|
21
|
+
}
|
|
22
|
+
export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
+
/**
|
|
24
|
+
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
+
*/
|
|
26
|
+
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* `mode` is saved to internal state and localStorage
|
|
29
|
+
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
+
*/
|
|
31
|
+
setMode: (mode: Mode | null) => void;
|
|
32
|
+
/**
|
|
33
|
+
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
+
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
+
*/
|
|
36
|
+
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
+
light: SupportedColorScheme | null;
|
|
38
|
+
dark: SupportedColorScheme | null;
|
|
39
|
+
}> | null) => void;
|
|
40
|
+
};
|
|
41
|
+
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
+
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
+
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
|
|
44
|
+
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
+
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
+
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
+
defaultMode?: Mode;
|
|
48
|
+
modeStorageKey?: string;
|
|
49
|
+
colorSchemeStorageKey?: string;
|
|
50
|
+
}): Result<SupportedColorScheme>;
|
package/esm/createBox.js
CHANGED
|
@@ -5,14 +5,15 @@ import * as React from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import styled from '@mui/styled-engine';
|
|
8
|
-
import
|
|
8
|
+
import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
|
|
9
9
|
import useTheme from './useTheme';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
export default function createBox(options = {}) {
|
|
12
12
|
const {
|
|
13
13
|
defaultTheme,
|
|
14
14
|
defaultClassName = 'MuiBox-root',
|
|
15
|
-
generateClassName
|
|
15
|
+
generateClassName,
|
|
16
|
+
styleFunctionSx = defaultStyleFunctionSx
|
|
16
17
|
} = options;
|
|
17
18
|
const BoxRoot = styled('div')(styleFunctionSx);
|
|
18
19
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
package/esm/createStyled.js
CHANGED
|
@@ -6,8 +6,8 @@ const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesR
|
|
|
6
6
|
import styledEngineStyled from '@mui/styled-engine';
|
|
7
7
|
import { getDisplayName } from '@mui/utils';
|
|
8
8
|
import createTheme from './createTheme';
|
|
9
|
-
import styleFunctionSx from './styleFunctionSx';
|
|
10
9
|
import propsToClassKey from './propsToClassKey';
|
|
10
|
+
import defaultStyleFunctionSx from './styleFunctionSx';
|
|
11
11
|
|
|
12
12
|
function isEmpty(obj) {
|
|
13
13
|
return Object.keys(obj).length === 0;
|
|
@@ -61,7 +61,8 @@ const variantsResolver = (props, styles, theme, name) => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
return variantsStyles;
|
|
64
|
-
};
|
|
64
|
+
}; // Update /system/styled/#api in case if this changes
|
|
65
|
+
|
|
65
66
|
|
|
66
67
|
export function shouldForwardProp(prop) {
|
|
67
68
|
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
@@ -76,7 +77,8 @@ export default function createStyled(input = {}) {
|
|
|
76
77
|
const {
|
|
77
78
|
defaultTheme = systemDefaultTheme,
|
|
78
79
|
rootShouldForwardProp = shouldForwardProp,
|
|
79
|
-
slotShouldForwardProp = shouldForwardProp
|
|
80
|
+
slotShouldForwardProp = shouldForwardProp,
|
|
81
|
+
styleFunctionSx = defaultStyleFunctionSx
|
|
80
82
|
} = input;
|
|
81
83
|
return (tag, inputOptions = {}) => {
|
|
82
84
|
const {
|
|
@@ -172,7 +174,11 @@ export default function createStyled(input = {}) {
|
|
|
172
174
|
|
|
173
175
|
transformedStyleArg = [...styleArg, ...placeholders];
|
|
174
176
|
transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
|
|
175
|
-
} else if (typeof styleArg === 'function'
|
|
177
|
+
} else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
|
|
178
|
+
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
179
|
+
// which are basically components used as a selectors.
|
|
180
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
181
|
+
styleArg.__emotion_real !== styleArg) {
|
|
176
182
|
// If the type is function, we need to define the default theme.
|
|
177
183
|
transformedStyleArg = _ref2 => {
|
|
178
184
|
let {
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
const _excluded = ["values", "unit", "step"];
|
|
4
4
|
// Sorted ASC by size. That's important.
|
|
5
5
|
// It can't be configured as it's used statically for propTypes.
|
|
6
|
-
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
6
|
+
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
7
|
+
|
|
8
|
+
const sortBreakpointsValues = values => {
|
|
9
|
+
const breakpointsAsArray = Object.keys(values).map(key => ({
|
|
10
|
+
key,
|
|
11
|
+
val: values[key]
|
|
12
|
+
})) || []; // Sort in ascending order
|
|
13
|
+
|
|
14
|
+
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
15
|
+
return breakpointsAsArray.reduce((acc, obj) => {
|
|
16
|
+
return _extends({}, acc, {
|
|
17
|
+
[obj.key]: obj.val
|
|
18
|
+
});
|
|
19
|
+
}, {});
|
|
20
|
+
}; // Keep in mind that @media is inclusive by the CSS specification.
|
|
21
|
+
|
|
7
22
|
|
|
8
23
|
export default function createBreakpoints(breakpoints) {
|
|
9
24
|
const {
|
|
@@ -26,7 +41,8 @@ export default function createBreakpoints(breakpoints) {
|
|
|
26
41
|
} = breakpoints,
|
|
27
42
|
other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
|
|
28
43
|
|
|
29
|
-
const
|
|
44
|
+
const sortedValues = sortBreakpointsValues(values);
|
|
45
|
+
const keys = Object.keys(sortedValues);
|
|
30
46
|
|
|
31
47
|
function up(key) {
|
|
32
48
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
@@ -68,7 +84,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
68
84
|
|
|
69
85
|
return _extends({
|
|
70
86
|
keys,
|
|
71
|
-
values,
|
|
87
|
+
values: sortedValues,
|
|
72
88
|
up,
|
|
73
89
|
down,
|
|
74
90
|
between,
|