@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
|
@@ -25,10 +25,11 @@ export default function createCssVarsProvider(options) {
|
|
|
25
25
|
theme: baseTheme = {},
|
|
26
26
|
defaultMode: desisgnSystemMode = 'light',
|
|
27
27
|
defaultColorScheme: designSystemColorScheme,
|
|
28
|
-
disableTransitionOnChange = false,
|
|
29
|
-
enableColorScheme = true,
|
|
28
|
+
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
29
|
+
enableColorScheme: designSystemEnableColorScheme = true,
|
|
30
30
|
prefix: designSystemPrefix = '',
|
|
31
|
-
shouldSkipGeneratingVar
|
|
31
|
+
shouldSkipGeneratingVar,
|
|
32
|
+
resolveTheme
|
|
32
33
|
} = options;
|
|
33
34
|
const systemSpacing = createSpacing(baseTheme.spacing);
|
|
34
35
|
const systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
@@ -56,16 +57,14 @@ export default function createCssVarsProvider(options) {
|
|
|
56
57
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
57
58
|
attribute = DEFAULT_ATTRIBUTE,
|
|
58
59
|
defaultMode = desisgnSystemMode,
|
|
59
|
-
defaultColorScheme = designSystemColorScheme
|
|
60
|
+
defaultColorScheme = designSystemColorScheme,
|
|
61
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
62
|
+
enableColorScheme = designSystemEnableColorScheme
|
|
60
63
|
}) {
|
|
61
|
-
// make sure that baseTheme is always independent of each <CssVarsProvider /> call.
|
|
62
|
-
// JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
|
|
63
|
-
const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
|
|
64
|
-
|
|
65
64
|
const {
|
|
66
65
|
colorSchemes: baseColorSchemes = {}
|
|
67
|
-
} =
|
|
68
|
-
restBaseTheme = _objectWithoutPropertiesLoose(
|
|
66
|
+
} = baseTheme,
|
|
67
|
+
restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
|
|
69
68
|
|
|
70
69
|
const {
|
|
71
70
|
colorSchemes: colorSchemesProp = {}
|
|
@@ -116,15 +115,17 @@ export default function createCssVarsProvider(options) {
|
|
|
116
115
|
|
|
117
116
|
const {
|
|
118
117
|
css: rootCss,
|
|
119
|
-
vars: rootVars
|
|
118
|
+
vars: rootVars,
|
|
119
|
+
parsedTheme
|
|
120
120
|
} = cssVarsParser(mergedTheme, {
|
|
121
121
|
prefix,
|
|
122
122
|
basePrefix: designSystemPrefix,
|
|
123
123
|
shouldSkipGeneratingVar
|
|
124
124
|
});
|
|
125
|
-
mergedTheme = _extends({},
|
|
125
|
+
mergedTheme = _extends({}, parsedTheme, {
|
|
126
126
|
components,
|
|
127
127
|
colorSchemes,
|
|
128
|
+
prefix,
|
|
128
129
|
vars: rootVars,
|
|
129
130
|
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
130
131
|
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
@@ -134,7 +135,8 @@ export default function createCssVarsProvider(options) {
|
|
|
134
135
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
135
136
|
const {
|
|
136
137
|
css,
|
|
137
|
-
vars
|
|
138
|
+
vars,
|
|
139
|
+
parsedTheme: parsedScheme
|
|
138
140
|
} = cssVarsParser(scheme, {
|
|
139
141
|
prefix,
|
|
140
142
|
basePrefix: designSystemPrefix,
|
|
@@ -142,6 +144,10 @@ export default function createCssVarsProvider(options) {
|
|
|
142
144
|
});
|
|
143
145
|
mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
|
|
144
146
|
|
|
147
|
+
if (key === resolvedColorScheme) {
|
|
148
|
+
mergedTheme = _extends({}, mergedTheme, parsedScheme);
|
|
149
|
+
}
|
|
150
|
+
|
|
145
151
|
const resolvedDefaultColorScheme = (() => {
|
|
146
152
|
if (typeof defaultColorScheme === 'string') {
|
|
147
153
|
return defaultColorScheme;
|
|
@@ -182,7 +188,7 @@ export default function createCssVarsProvider(options) {
|
|
|
182
188
|
return () => {
|
|
183
189
|
document.documentElement.style.setProperty('color-scheme', priorColorScheme);
|
|
184
190
|
};
|
|
185
|
-
}, [mode, systemMode]);
|
|
191
|
+
}, [mode, systemMode, enableColorScheme]);
|
|
186
192
|
React.useEffect(() => {
|
|
187
193
|
let timer;
|
|
188
194
|
|
|
@@ -202,7 +208,7 @@ export default function createCssVarsProvider(options) {
|
|
|
202
208
|
return () => {
|
|
203
209
|
clearTimeout(timer);
|
|
204
210
|
};
|
|
205
|
-
}, [colorScheme]);
|
|
211
|
+
}, [colorScheme, disableTransitionOnChange]);
|
|
206
212
|
React.useEffect(() => {
|
|
207
213
|
hasMounted.current = true;
|
|
208
214
|
return () => {
|
|
@@ -226,7 +232,7 @@ export default function createCssVarsProvider(options) {
|
|
|
226
232
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
227
233
|
styles: styleSheet
|
|
228
234
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
229
|
-
theme: mergedTheme,
|
|
235
|
+
theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
|
|
230
236
|
children: children
|
|
231
237
|
})]
|
|
232
238
|
});
|
|
@@ -253,6 +259,16 @@ export default function createCssVarsProvider(options) {
|
|
|
253
259
|
*/
|
|
254
260
|
defaultMode: PropTypes.string,
|
|
255
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Disable CSS transitions when switching between modes or color schemes
|
|
264
|
+
*/
|
|
265
|
+
disableTransitionOnChange: PropTypes.bool,
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
269
|
+
*/
|
|
270
|
+
enableColorScheme: PropTypes.bool,
|
|
271
|
+
|
|
256
272
|
/**
|
|
257
273
|
* The key in the local storage used to store current color scheme.
|
|
258
274
|
*/
|
|
@@ -8,7 +8,13 @@ export default function createGetCssVar(prefix = '') {
|
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const value = vars[0];
|
|
12
|
+
|
|
13
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
14
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return `, ${value}`;
|
|
12
18
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
13
19
|
|
|
14
20
|
|
|
@@ -85,19 +85,20 @@ const getCssValue = (keys, value) => {
|
|
|
85
85
|
* `basePrefix`: defined by design system.
|
|
86
86
|
* `prefix`: defined by application
|
|
87
87
|
*
|
|
88
|
-
*
|
|
88
|
+
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
89
89
|
*
|
|
90
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
90
|
+
* @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.
|
|
91
91
|
*
|
|
92
92
|
* @example
|
|
93
|
-
* const { css, vars } = parser({
|
|
93
|
+
* const { css, vars, parsedTheme } = parser({
|
|
94
94
|
* fontSize: 12,
|
|
95
95
|
* lineHeight: 1.2,
|
|
96
|
-
* palette: { primary: { 500: '
|
|
97
|
-
* })
|
|
96
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
97
|
+
* }, { prefix: 'foo' })
|
|
98
98
|
*
|
|
99
|
-
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '
|
|
100
|
-
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
99
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
100
|
+
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
101
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
101
102
|
*/
|
|
102
103
|
|
|
103
104
|
|
|
@@ -109,20 +110,17 @@ export default function cssVarsParser(theme, options) {
|
|
|
109
110
|
} = options || {};
|
|
110
111
|
const css = {};
|
|
111
112
|
const vars = {};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
113
|
+
const parsedTheme = {};
|
|
114
|
+
walkObjectDeep(theme, (keys, value) => {
|
|
115
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
116
|
+
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
117
|
+
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
118
118
|
if (!basePrefix && prefix) {
|
|
119
|
-
value = value.replace(/var\(
|
|
119
|
+
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
120
120
|
} else {
|
|
121
|
-
value = prefix ? value.replace(new RegExp(basePrefix
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
scope[keys.slice(-1)[0]] = value;
|
|
121
|
+
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
122
|
+
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
123
|
+
}
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -134,10 +132,13 @@ export default function cssVarsParser(theme, options) {
|
|
|
134
132
|
assignNestedKeys(vars, keys, `var(${cssVar})`);
|
|
135
133
|
}
|
|
136
134
|
}
|
|
135
|
+
|
|
136
|
+
assignNestedKeys(parsedTheme, keys, value);
|
|
137
137
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
138
138
|
);
|
|
139
139
|
return {
|
|
140
140
|
css,
|
|
141
|
-
vars
|
|
141
|
+
vars,
|
|
142
|
+
parsedTheme
|
|
142
143
|
};
|
|
143
144
|
}
|
package/esm/getThemeValue.js
CHANGED
package/esm/index.js
CHANGED
|
@@ -21,7 +21,7 @@ export * from './spacing';
|
|
|
21
21
|
export { default as style, getPath } from './style';
|
|
22
22
|
export { default as typography } from './typography';
|
|
23
23
|
export * from './typography';
|
|
24
|
-
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
24
|
+
export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
25
25
|
export { default as experimental_sx } from './sx';
|
|
26
26
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
27
27
|
export { default as Box } from './Box';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import merge from '../merge';
|
|
2
|
-
import
|
|
2
|
+
import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
|
|
3
3
|
import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
|
|
4
4
|
|
|
5
5
|
function objectsHaveSameKeys(...objects) {
|
|
@@ -10,70 +10,97 @@ function objectsHaveSameKeys(...objects) {
|
|
|
10
10
|
|
|
11
11
|
function callIfFn(maybeFn, arg) {
|
|
12
12
|
return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
|
|
13
|
-
}
|
|
13
|
+
} // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14
14
|
|
|
15
|
-
function styleFunctionSx(props) {
|
|
16
|
-
const {
|
|
17
|
-
sx,
|
|
18
|
-
theme = {}
|
|
19
|
-
} = props || {};
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
16
|
+
export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultStyleFunctionMapping) {
|
|
17
|
+
const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
|
|
18
|
+
styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
|
|
19
|
+
acc[propName] = styleFunctionMapping[styleFnName];
|
|
20
|
+
});
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
29
23
|
|
|
24
|
+
function getThemeValue(prop, value, theme) {
|
|
25
|
+
const inputProps = {
|
|
26
|
+
[prop]: value,
|
|
27
|
+
theme
|
|
28
|
+
};
|
|
29
|
+
const styleFunction = propToStyleFunction[prop];
|
|
30
|
+
return styleFunction ? styleFunction(inputProps) : {
|
|
31
|
+
[prop]: value
|
|
32
|
+
};
|
|
33
|
+
}
|
|
30
34
|
|
|
31
|
-
function
|
|
32
|
-
|
|
35
|
+
function styleFunctionSx(props) {
|
|
36
|
+
const {
|
|
37
|
+
sx,
|
|
38
|
+
theme = {}
|
|
39
|
+
} = props || {};
|
|
33
40
|
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
} else if (typeof sxInput !== 'object') {
|
|
37
|
-
// value
|
|
38
|
-
return sxInput;
|
|
41
|
+
if (!sx) {
|
|
42
|
+
return null; // emotion & styled-components will neglect null
|
|
39
43
|
}
|
|
44
|
+
/*
|
|
45
|
+
* Receive `sxInput` as object or callback
|
|
46
|
+
* and then recursively check keys & values to create media query object styles.
|
|
47
|
+
* (the result will be used in `styled`)
|
|
48
|
+
*/
|
|
40
49
|
|
|
41
|
-
const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
42
|
-
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
43
|
-
let css = emptyBreakpoints;
|
|
44
|
-
Object.keys(sxObject).forEach(styleKey => {
|
|
45
|
-
const value = callIfFn(sxObject[styleKey], theme);
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
function traverse(sxInput) {
|
|
52
|
+
let sxObject = sxInput;
|
|
53
|
+
|
|
54
|
+
if (typeof sxInput === 'function') {
|
|
55
|
+
sxObject = sxInput(theme);
|
|
56
|
+
} else if (typeof sxInput !== 'object') {
|
|
57
|
+
// value
|
|
58
|
+
return sxInput;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!sxObject) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
66
|
+
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
67
|
+
let css = emptyBreakpoints;
|
|
68
|
+
Object.keys(sxObject).forEach(styleKey => {
|
|
69
|
+
const value = callIfFn(sxObject[styleKey], theme);
|
|
70
|
+
|
|
71
|
+
if (value !== null && value !== undefined) {
|
|
72
|
+
if (typeof value === 'object') {
|
|
73
|
+
if (propToStyleFunction[styleKey]) {
|
|
74
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
63
75
|
} else {
|
|
64
|
-
|
|
76
|
+
const breakpointsValues = handleBreakpoints({
|
|
77
|
+
theme
|
|
78
|
+
}, value, x => ({
|
|
79
|
+
[styleKey]: x
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
83
|
+
css[styleKey] = styleFunctionSx({
|
|
84
|
+
sx: value,
|
|
85
|
+
theme
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
css = merge(css, breakpointsValues);
|
|
89
|
+
}
|
|
65
90
|
}
|
|
91
|
+
} else {
|
|
92
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
66
93
|
}
|
|
67
|
-
} else {
|
|
68
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
69
94
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
95
|
+
});
|
|
96
|
+
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
73
100
|
}
|
|
74
101
|
|
|
75
|
-
return
|
|
102
|
+
return styleFunctionSx;
|
|
76
103
|
}
|
|
77
|
-
|
|
104
|
+
const styleFunctionSx = unstable_createStyleFunctionSx();
|
|
78
105
|
styleFunctionSx.filterProps = ['sx'];
|
|
79
106
|
export default styleFunctionSx;
|
package/getThemeValue.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.propToStyleFunction = exports.default = void 0;
|
|
8
|
+
exports.styleFunctionMapping = exports.propToStyleFunction = exports.default = void 0;
|
|
9
9
|
|
|
10
10
|
var _borders = _interopRequireDefault(require("./borders"));
|
|
11
11
|
|
|
@@ -51,6 +51,7 @@ const styleFunctionMapping = {
|
|
|
51
51
|
spacing: _spacing.default,
|
|
52
52
|
typography: _typography.default
|
|
53
53
|
};
|
|
54
|
+
exports.styleFunctionMapping = styleFunctionMapping;
|
|
54
55
|
const propToStyleFunction = Object.keys(filterPropsMapping).reduce((acc, styleFnName) => {
|
|
55
56
|
filterPropsMapping[styleFnName].forEach(propName => {
|
|
56
57
|
acc[propName] = styleFunctionMapping[styleFnName];
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.4.
|
|
1
|
+
/** @license MUI v5.4.4
|
|
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.
|
|
@@ -33,6 +33,7 @@ var _exportNames = {
|
|
|
33
33
|
getPath: true,
|
|
34
34
|
typography: true,
|
|
35
35
|
unstable_styleFunctionSx: true,
|
|
36
|
+
unstable_createStyleFunctionSx: true,
|
|
36
37
|
unstable_extendSxProp: true,
|
|
37
38
|
experimental_sx: true,
|
|
38
39
|
unstable_getThemeValue: true,
|
|
@@ -250,6 +251,12 @@ Object.defineProperty(exports, "unstable_createGetCssVar", {
|
|
|
250
251
|
return _createGetCssVar.default;
|
|
251
252
|
}
|
|
252
253
|
});
|
|
254
|
+
Object.defineProperty(exports, "unstable_createStyleFunctionSx", {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () {
|
|
257
|
+
return _styleFunctionSx.unstable_createStyleFunctionSx;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
253
260
|
Object.defineProperty(exports, "unstable_extendSxProp", {
|
|
254
261
|
enumerable: true,
|
|
255
262
|
get: function () {
|
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/legacy/createBox.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import styled from '@mui/styled-engine';
|
|
7
|
-
import
|
|
7
|
+
import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
|
|
8
8
|
import useTheme from './useTheme';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
export default function createBox() {
|
|
@@ -12,7 +12,9 @@ export default function createBox() {
|
|
|
12
12
|
var defaultTheme = options.defaultTheme,
|
|
13
13
|
_options$defaultClass = options.defaultClassName,
|
|
14
14
|
defaultClassName = _options$defaultClass === void 0 ? 'MuiBox-root' : _options$defaultClass,
|
|
15
|
-
generateClassName = options.generateClassName
|
|
15
|
+
generateClassName = options.generateClassName,
|
|
16
|
+
_options$styleFunctio = options.styleFunctionSx,
|
|
17
|
+
styleFunctionSx = _options$styleFunctio === void 0 ? defaultStyleFunctionSx : _options$styleFunctio;
|
|
16
18
|
var BoxRoot = styled('div')(styleFunctionSx);
|
|
17
19
|
var Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
|
18
20
|
var theme = useTheme(defaultTheme);
|
package/legacy/createStyled.js
CHANGED
|
@@ -5,8 +5,8 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
5
5
|
import styledEngineStyled from '@mui/styled-engine';
|
|
6
6
|
import { getDisplayName } from '@mui/utils';
|
|
7
7
|
import createTheme from './createTheme';
|
|
8
|
-
import styleFunctionSx from './styleFunctionSx';
|
|
9
8
|
import propsToClassKey from './propsToClassKey';
|
|
9
|
+
import defaultStyleFunctionSx from './styleFunctionSx';
|
|
10
10
|
|
|
11
11
|
function isEmpty(obj) {
|
|
12
12
|
return Object.keys(obj).length === 0;
|
|
@@ -59,7 +59,8 @@ var variantsResolver = function variantsResolver(props, styles, theme, name) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return variantsStyles;
|
|
62
|
-
};
|
|
62
|
+
}; // Update /system/styled/#api in case if this changes
|
|
63
|
+
|
|
63
64
|
|
|
64
65
|
export function shouldForwardProp(prop) {
|
|
65
66
|
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
@@ -77,7 +78,9 @@ export default function createStyled() {
|
|
|
77
78
|
_input$rootShouldForw = input.rootShouldForwardProp,
|
|
78
79
|
rootShouldForwardProp = _input$rootShouldForw === void 0 ? shouldForwardProp : _input$rootShouldForw,
|
|
79
80
|
_input$slotShouldForw = input.slotShouldForwardProp,
|
|
80
|
-
slotShouldForwardProp = _input$slotShouldForw === void 0 ? shouldForwardProp : _input$slotShouldForw
|
|
81
|
+
slotShouldForwardProp = _input$slotShouldForw === void 0 ? shouldForwardProp : _input$slotShouldForw,
|
|
82
|
+
_input$styleFunctionS = input.styleFunctionSx,
|
|
83
|
+
styleFunctionSx = _input$styleFunctionS === void 0 ? defaultStyleFunctionSx : _input$styleFunctionS;
|
|
81
84
|
return function (tag) {
|
|
82
85
|
var inputOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
83
86
|
|
|
@@ -178,7 +181,11 @@ export default function createStyled() {
|
|
|
178
181
|
|
|
179
182
|
transformedStyleArg = [].concat(_toConsumableArray(styleArg), _toConsumableArray(placeholders));
|
|
180
183
|
transformedStyleArg.raw = [].concat(_toConsumableArray(styleArg.raw), _toConsumableArray(placeholders));
|
|
181
|
-
} else if (typeof styleArg === 'function'
|
|
184
|
+
} else if (typeof styleArg === 'function' && // On the server emotion doesn't use React.forwardRef for creating components, so the created
|
|
185
|
+
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
186
|
+
// which are basically components used as a selectors.
|
|
187
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
188
|
+
styleArg.__emotion_real !== styleArg) {
|
|
182
189
|
// If the type is function, we need to define the default theme.
|
|
183
190
|
transformedStyleArg = function transformedStyleArg(_ref4) {
|
|
184
191
|
var themeInput = _ref4.theme,
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
// Sorted ASC by size. That's important.
|
|
4
5
|
// It can't be configured as it's used statically for propTypes.
|
|
5
|
-
export var breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
6
|
+
export var breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
7
|
+
|
|
8
|
+
var sortBreakpointsValues = function sortBreakpointsValues(values) {
|
|
9
|
+
var breakpointsAsArray = Object.keys(values).map(function (key) {
|
|
10
|
+
return {
|
|
11
|
+
key: key,
|
|
12
|
+
val: values[key]
|
|
13
|
+
};
|
|
14
|
+
}) || []; // Sort in ascending order
|
|
15
|
+
|
|
16
|
+
breakpointsAsArray.sort(function (breakpoint1, breakpoint2) {
|
|
17
|
+
return breakpoint1.val - breakpoint2.val;
|
|
18
|
+
});
|
|
19
|
+
return breakpointsAsArray.reduce(function (acc, obj) {
|
|
20
|
+
return _extends({}, acc, _defineProperty({}, obj.key, obj.val));
|
|
21
|
+
}, {});
|
|
22
|
+
}; // Keep in mind that @media is inclusive by the CSS specification.
|
|
23
|
+
|
|
6
24
|
|
|
7
25
|
export default function createBreakpoints(breakpoints) {
|
|
8
26
|
var _breakpoints$values = breakpoints.values,
|
|
@@ -24,7 +42,8 @@ export default function createBreakpoints(breakpoints) {
|
|
|
24
42
|
step = _breakpoints$step === void 0 ? 5 : _breakpoints$step,
|
|
25
43
|
other = _objectWithoutProperties(breakpoints, ["values", "unit", "step"]);
|
|
26
44
|
|
|
27
|
-
var
|
|
45
|
+
var sortedValues = sortBreakpointsValues(values);
|
|
46
|
+
var keys = Object.keys(sortedValues);
|
|
28
47
|
|
|
29
48
|
function up(key) {
|
|
30
49
|
var value = typeof values[key] === 'number' ? values[key] : key;
|
|
@@ -66,7 +85,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
66
85
|
|
|
67
86
|
return _extends({
|
|
68
87
|
keys: keys,
|
|
69
|
-
values:
|
|
88
|
+
values: sortedValues,
|
|
70
89
|
up: up,
|
|
71
90
|
down: down,
|
|
72
91
|
between: between,
|