@mui/system 5.4.2 → 5.5.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.
@@ -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
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
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: '#000000' } }
55
- * })
56
- *
57
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
58
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
59
- */
60
- export default function cssVarsParser(theme: Record<string, any>, options?: {
61
- prefix?: string;
62
- basePrefix?: string;
63
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
64
- }): {
65
- css: NestedRecord<string>;
66
- vars: NestedRecord<string>;
67
- };
68
- export {};
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 {};
@@ -99,19 +99,20 @@ const getCssValue = (keys, value) => {
99
99
  * `basePrefix`: defined by design system.
100
100
  * `prefix`: defined by application
101
101
  *
102
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
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: '#000000' } }
111
- * })
110
+ * palette: { primary: { 500: 'var(--color)' } }
111
+ * }, { prefix: 'foo' })
112
112
  *
113
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
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,21 +124,17 @@ function cssVarsParser(theme, options) {
123
124
  } = options || {};
124
125
  const css = {};
125
126
  const vars = {};
126
- walkObjectDeep(theme, (keys, val, scope) => {
127
- if (typeof val === 'string' || typeof val === 'number') {
128
- let value = val;
129
-
127
+ const parsedTheme = {};
128
+ walkObjectDeep(theme, (keys, value) => {
129
+ if (typeof value === 'string' || typeof value === 'number') {
130
130
  if (typeof value === 'string' && value.match(/var\(\s*--/)) {
131
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
131
+ // for CSS variable, apply prefix or remove basePrefix from the variable
132
132
  if (!basePrefix && prefix) {
133
133
  value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
134
134
  } else {
135
135
  value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
136
136
  : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
137
- } // scope is the deepest object in the tree, keys is the theme path keys
138
-
139
-
140
- scope[keys.slice(-1)[0]] = value;
137
+ }
141
138
  }
142
139
 
143
140
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -149,10 +146,13 @@ function cssVarsParser(theme, options) {
149
146
  assignNestedKeys(vars, keys, `var(${cssVar})`);
150
147
  }
151
148
  }
149
+
150
+ assignNestedKeys(parsedTheme, keys, value);
152
151
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
153
152
  );
154
153
  return {
155
154
  css,
156
- vars
155
+ vars,
156
+ parsedTheme
157
157
  };
158
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;
@@ -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>;
@@ -174,7 +174,11 @@ export default function createStyled(input = {}) {
174
174
 
175
175
  transformedStyleArg = [...styleArg, ...placeholders];
176
176
  transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
177
- } 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) {
178
182
  // If the type is function, we need to define the default theme.
179
183
  transformedStyleArg = _ref2 => {
180
184
  let {
@@ -25,8 +25,8 @@ 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
31
  shouldSkipGeneratingVar,
32
32
  resolveTheme
@@ -57,16 +57,14 @@ export default function createCssVarsProvider(options) {
57
57
  modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
58
58
  attribute = DEFAULT_ATTRIBUTE,
59
59
  defaultMode = desisgnSystemMode,
60
- defaultColorScheme = designSystemColorScheme
60
+ defaultColorScheme = designSystemColorScheme,
61
+ disableTransitionOnChange = designSystemTransitionOnChange,
62
+ enableColorScheme = designSystemEnableColorScheme
61
63
  }) {
62
- // make sure that baseTheme is always independent of each <CssVarsProvider /> call.
63
- // JSON.parse(JSON.stringify(...)) is okay to be used as long as the baseTheme is a plain object.
64
- const clonedBaseTheme = React.useMemo(() => JSON.parse(JSON.stringify(baseTheme)), []);
65
-
66
64
  const {
67
65
  colorSchemes: baseColorSchemes = {}
68
- } = clonedBaseTheme,
69
- restBaseTheme = _objectWithoutPropertiesLoose(clonedBaseTheme, _excluded);
66
+ } = baseTheme,
67
+ restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
70
68
 
71
69
  const {
72
70
  colorSchemes: colorSchemesProp = {}
@@ -117,13 +115,14 @@ export default function createCssVarsProvider(options) {
117
115
 
118
116
  const {
119
117
  css: rootCss,
120
- vars: rootVars
118
+ vars: rootVars,
119
+ parsedTheme
121
120
  } = cssVarsParser(mergedTheme, {
122
121
  prefix,
123
122
  basePrefix: designSystemPrefix,
124
123
  shouldSkipGeneratingVar
125
124
  });
126
- mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
125
+ mergedTheme = _extends({}, parsedTheme, {
127
126
  components,
128
127
  colorSchemes,
129
128
  prefix,
@@ -136,7 +135,8 @@ export default function createCssVarsProvider(options) {
136
135
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
137
136
  const {
138
137
  css,
139
- vars
138
+ vars,
139
+ parsedTheme: parsedScheme
140
140
  } = cssVarsParser(scheme, {
141
141
  prefix,
142
142
  basePrefix: designSystemPrefix,
@@ -144,6 +144,10 @@ export default function createCssVarsProvider(options) {
144
144
  });
145
145
  mergedTheme.vars = deepmerge(mergedTheme.vars, vars);
146
146
 
147
+ if (key === resolvedColorScheme) {
148
+ mergedTheme = _extends({}, mergedTheme, parsedScheme);
149
+ }
150
+
147
151
  const resolvedDefaultColorScheme = (() => {
148
152
  if (typeof defaultColorScheme === 'string') {
149
153
  return defaultColorScheme;
@@ -184,7 +188,7 @@ export default function createCssVarsProvider(options) {
184
188
  return () => {
185
189
  document.documentElement.style.setProperty('color-scheme', priorColorScheme);
186
190
  };
187
- }, [mode, systemMode]);
191
+ }, [mode, systemMode, enableColorScheme]);
188
192
  React.useEffect(() => {
189
193
  let timer;
190
194
 
@@ -204,7 +208,7 @@ export default function createCssVarsProvider(options) {
204
208
  return () => {
205
209
  clearTimeout(timer);
206
210
  };
207
- }, [colorScheme]);
211
+ }, [colorScheme, disableTransitionOnChange]);
208
212
  React.useEffect(() => {
209
213
  hasMounted.current = true;
210
214
  return () => {
@@ -255,6 +259,16 @@ export default function createCssVarsProvider(options) {
255
259
  */
256
260
  defaultMode: PropTypes.string,
257
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
+
258
272
  /**
259
273
  * The key in the local storage used to store current color scheme.
260
274
  */
@@ -85,19 +85,20 @@ const getCssValue = (keys, value) => {
85
85
  * `basePrefix`: defined by design system.
86
86
  * `prefix`: defined by application
87
87
  *
88
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
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: '#000000' } }
97
- * })
96
+ * palette: { primary: { 500: 'var(--color)' } }
97
+ * }, { prefix: 'foo' })
98
98
  *
99
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
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,21 +110,17 @@ export default function cssVarsParser(theme, options) {
109
110
  } = options || {};
110
111
  const css = {};
111
112
  const vars = {};
112
- walkObjectDeep(theme, (keys, val, scope) => {
113
- if (typeof val === 'string' || typeof val === 'number') {
114
- let value = val;
115
-
113
+ const parsedTheme = {};
114
+ walkObjectDeep(theme, (keys, value) => {
115
+ if (typeof value === 'string' || typeof value === 'number') {
116
116
  if (typeof value === 'string' && value.match(/var\(\s*--/)) {
117
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
117
+ // for CSS variable, apply prefix or remove basePrefix from the variable
118
118
  if (!basePrefix && prefix) {
119
119
  value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
120
120
  } else {
121
121
  value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
122
122
  : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
123
- } // scope is the deepest object in the tree, keys is the theme path keys
124
-
125
-
126
- scope[keys.slice(-1)[0]] = value;
123
+ }
127
124
  }
128
125
 
129
126
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -135,10 +132,13 @@ export default function cssVarsParser(theme, options) {
135
132
  assignNestedKeys(vars, keys, `var(${cssVar})`);
136
133
  }
137
134
  }
135
+
136
+ assignNestedKeys(parsedTheme, keys, value);
138
137
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
139
138
  );
140
139
  return {
141
140
  css,
142
- vars
141
+ vars,
142
+ parsedTheme
143
143
  };
144
144
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.2
1
+ /** @license MUI v5.5.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.
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -181,7 +181,11 @@ export default function createStyled() {
181
181
 
182
182
  transformedStyleArg = [].concat(_toConsumableArray(styleArg), _toConsumableArray(placeholders));
183
183
  transformedStyleArg.raw = [].concat(_toConsumableArray(styleArg.raw), _toConsumableArray(placeholders));
184
- } 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) {
185
189
  // If the type is function, we need to define the default theme.
186
190
  transformedStyleArg = function transformedStyleArg(_ref4) {
187
191
  var themeInput = _ref4.theme,