@mui/system 5.11.11 → 5.11.13

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +187 -2
  2. package/cssVars/createCssVarsProvider.d.ts +0 -50
  3. package/cssVars/createCssVarsProvider.js +8 -16
  4. package/cssVars/createCssVarsTheme.d.ts +13 -0
  5. package/cssVars/createCssVarsTheme.js +24 -0
  6. package/cssVars/createGetCssVar.js +1 -1
  7. package/cssVars/cssVarsParser.d.ts +3 -2
  8. package/cssVars/cssVarsParser.js +4 -1
  9. package/cssVars/index.d.ts +2 -0
  10. package/cssVars/index.js +15 -1
  11. package/cssVars/prepareCssVars.d.ts +14 -0
  12. package/cssVars/prepareCssVars.js +70 -0
  13. package/esm/cssVars/createCssVarsProvider.js +8 -16
  14. package/esm/cssVars/createCssVarsTheme.js +16 -0
  15. package/esm/cssVars/createGetCssVar.js +1 -1
  16. package/esm/cssVars/cssVarsParser.js +4 -1
  17. package/esm/cssVars/index.js +3 -1
  18. package/esm/cssVars/prepareCssVars.js +62 -0
  19. package/esm/index.js +3 -0
  20. package/esm/styleFunctionSx/defaultSxConfig.js +30 -3
  21. package/index.d.ts +3 -0
  22. package/index.js +25 -1
  23. package/legacy/cssVars/createCssVarsProvider.js +15 -21
  24. package/legacy/cssVars/createCssVarsTheme.js +13 -0
  25. package/legacy/cssVars/createGetCssVar.js +1 -1
  26. package/legacy/cssVars/cssVarsParser.js +4 -1
  27. package/legacy/cssVars/index.js +3 -1
  28. package/legacy/cssVars/prepareCssVars.js +59 -0
  29. package/legacy/index.js +4 -1
  30. package/legacy/styleFunctionSx/defaultSxConfig.js +29 -3
  31. package/modern/cssVars/createCssVarsProvider.js +8 -16
  32. package/modern/cssVars/createCssVarsTheme.js +16 -0
  33. package/modern/cssVars/createGetCssVar.js +1 -1
  34. package/modern/cssVars/cssVarsParser.js +4 -1
  35. package/modern/cssVars/index.js +3 -1
  36. package/modern/cssVars/prepareCssVars.js +62 -0
  37. package/modern/index.js +4 -1
  38. package/modern/styleFunctionSx/defaultSxConfig.js +28 -3
  39. package/package.json +3 -3
  40. package/styleFunctionSx/defaultSxConfig.js +30 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,190 @@
1
1
  # [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 5.11.13
4
+
5
+ <!-- generated comparing v5.11.12..master -->
6
+
7
+ _Mar 14, 2023_
8
+
9
+ A big thanks to the 13 contributors who made this release possible. Here are some highlights ✨:
10
+
11
+ - @michaldudak added an option for [disabling the generation](https://mui.com/base/getting-started/customization/#disabling-default-css-classes) of the default classes in MUI Base (#35963)
12
+ - other 🐛 bug fixes and 📚 documentation improvements.
13
+
14
+ ### `@mui/material@5.11.13`
15
+
16
+ - &#8203;<!-- 13 -->[core] Bump MUI Base's version in Material UI (#36492) @hbjORbj
17
+ - &#8203;<!-- 17 -->[material] Export `shouldSkipGeneratingVar` from Material UI (#36489) @siriwatknp
18
+ - &#8203;<!-- 06 -->[Typography] Apply font properties to typography inherit variant (#33621) @oyar99
19
+
20
+ ### `@mui/base@5.0.0-alpha.121`
21
+
22
+ - &#8203;<!-- 16 -->[base] Disable classes generation via a context (#35963) @michaldudak
23
+ - &#8203;<!-- 15 -->[useMenu][base] Add return interface for useMenu hook (#36376) @HeVictor
24
+ - &#8203;<!-- 05 -->[useBadge] Add interface for the return value (#36042) @skevprog
25
+ - &#8203;<!-- 04 -->[useMenuItem] Add explicit return type (#36359) @rayrw
26
+ - &#8203;<!-- 03 -->[useTabs] Add explicit return type (#36047) @sai6855
27
+
28
+ ### Docs
29
+
30
+ - &#8203;<!-- 14 -->[blog] Update fields behavior on date pickers blog post (#36480) @joserodolfofreitas
31
+ - &#8203;<!-- 12 -->[docs] Info markdown not rendering in Contributing Guide README (#36487) @hbjORbj
32
+ - &#8203;<!-- 11 -->[docs] Remove 301 redirection to MUI X lab migration @oliviertassinari
33
+ - &#8203;<!-- 10 -->[docs] Fix a grammar error (#36486) @hbjORbj
34
+ - &#8203;<!-- 09 -->[docs] Add blog post notification for v6 release (#36446) @joserodolfofreitas
35
+ - &#8203;<!-- 08 -->[docs] Update link to v5 docs (#36421) @m4theushw
36
+ - &#8203;<!-- 07 -->[docs] Fix 404 in the API page links (#36419) @oliviertassinari
37
+ - &#8203;<!-- 08 -->[docs][joy] Error in the exemplary Codesandbox of using Material UI and Joy UI together (#36462) @hbjORbj
38
+ - &#8203;<!-- 06 -->[examples] Refactor to have better types in the Next.js + TypeScript examples (#36355) @erikian
39
+ - &#8203;<!-- 02 -->[website] Fix layout shift when loading /blog/mui-x-v6/ @oliviertassinari
40
+ - &#8203;<!-- 01 -->[website] Update stats (#36477) @hrutik7
41
+
42
+ All contributors of this release in alphabetical order: @erikian, @hbjORbj, @HeVictor, @hrutik7, @joserodolfofreitas, @m4theushw, @michaldudak, @oliviertassinari, @oyar99, @rayrw, @sai6855, @siriwatknp, @skevprog
43
+
44
+ ## 5.11.12
45
+
46
+ <!-- generated comparing v5.11.11..master -->
47
+
48
+ _Mar 6, 2023_
49
+
50
+ A big thanks to the 17 contributors who made this release possible. Here are some highlights ✨:
51
+
52
+ - @michaldudak added the multiselect functionality to SelectUnstyled (#36274)
53
+ - @mnajdova updated `extendTheme` so that it can generate CSS variables with default values. This means that the `CssVarsProvider` is no longer required for Joy UI when using the default theme (#35739)
54
+ - other 🐛 bug fixes and 📚 documentation improvements.
55
+
56
+ ### `@mui/material@5.11.12`
57
+
58
+ - &#8203;<!-- 30 -->[Autocomplete] Fix list scrolls to the top when new data is added on touch devices (#36231) @SaidMarar
59
+ - &#8203;<!-- 29 -->[Autocomplete] Add `Mui-expanded` class (#33312) @Osman-Sodefa
60
+ - &#8203;<!-- 24 -->[Dialog] Use the `id` prop provided to the `DialogTitle` component (#36353) @Kundan28
61
+ - &#8203;<!-- 07 -->[Menu] Fix Menu Paper styles overriding in the theme (#36316) @Paatus
62
+
63
+ ### `@mui/lab@5.0.0-alpha.122`
64
+
65
+ - &#8203;<!-- 05 -->[TreeView] Fix Tree View inside shadow root crashes (#36225) @NoFr1ends
66
+
67
+ ### `@mui/system@5.11.12`
68
+
69
+ #### Breaking changes
70
+
71
+ - &#8203;<!-- 26 -->[core] Generate vars in `extendTheme` (#35739) @mnajdova
72
+
73
+ The `shouldSkipGeneratingVar` prop was moved from the `createCssVarsProvider`'s option to the `theme`. If the default theme does not use `extendTheme` from Material UI or Joy UI, it needs to be wrapped inside `unstable_createCssVarsTheme` - a util exported from the MUI System. Below is an example of how the migration should look like:
74
+
75
+ ```diff
76
+ import {
77
+ unstable_createCssVarsProvider as createCssVarsProvider,
78
+ + unstable_createCssVarsTheme as createCssVarsTheme,
79
+ } from '@mui/system';
80
+
81
+ const { CssVarsProvider } = createCssVarsProvider({
82
+ - theme: {
83
+ + theme: createCssVarsTheme({
84
+ colorSchemes: {
85
+ light: {
86
+ typography: {
87
+ htmlFontSize: '16px',
88
+ h1: {
89
+ fontSize: '1rem',
90
+ fontWeight: 500,
91
+ },
92
+ },
93
+ },
94
+ },
95
+ + shouldSkipGeneratingVar: (keys) => keys[0] === 'typography' && keys[1] === 'h1',
96
+ - },
97
+ + }),
98
+ defaultColorScheme: 'light',
99
+ - shouldSkipGeneratingVar: (keys) => keys[0] === 'typography' && keys[1] === 'h1',
100
+ });
101
+ ```
102
+
103
+ Or you can define it directly in the theme prop:
104
+
105
+ ```diff
106
+ <CssVarsProvider
107
+ + theme={createCssVarsProvider({
108
+ + // other theme keys
109
+ + shouldSkipGeneratingVar: (keys) => keys[0] === 'typography' && keys[1] === 'h1'
110
+ + })} />
111
+ ```
112
+
113
+ This breaking change **only** affects experimental APIs
114
+
115
+ ### `@mui/base@5.0.0-alpha.120`
116
+
117
+ #### Breaking changes
118
+
119
+ - &#8203;<!-- 27 -->[Select][base] Add the multiselect functionality to SelectUnstyled (#36274) @michaldudak
120
+
121
+ The MultiSelectUnstyled was removed. The `SelectUnstyled` component with the `multiple` prop should be used instead. Additionally, the SelectUnstyledProps received a second generic parameter: `Multiple extends boolean`. If you deal with strictly single- or multi-select components, you can hard-code this parameter to `false` or `true`, respectively. Below is an example of how the migration should look like:
122
+
123
+ ```diff
124
+ -import MultiSelectUnstyled from '@mui/base/MultiSelectUnstyled';
125
+ +import SelectUnstyled from '@mui/base/SelectUnstyled';
126
+
127
+ export default App() {
128
+ -return <MultiSelectUnstyled />
129
+ +return <SelectUnstyled multiple />
130
+ }
131
+ ```
132
+
133
+ #### Changes
134
+
135
+ - &#8203;<!-- 34 -->[useSnackBar] Add explicit return type (#36052) @sai6855
136
+ - &#8203;<!-- 04 -->[useMenu] Fix `import type` syntax (#36411) @ZeeshanTamboli
137
+ - &#8203;<!-- 03 -->[useSwitch] Add explicit return type (#36050) @sai6855
138
+
139
+ ### `@mui/joy@5.0.0-alpha.70`
140
+
141
+ #### Breaking changes
142
+
143
+ - &#8203;<!-- 09 -->[Joy] Change CSS variables naming for components (#36282) @hbjORbj
144
+
145
+ Joy UI has new naming standards of the CSS variables for its components. Below is an example of how the migration should look like:
146
+
147
+ ```diff
148
+ -<List sx={{ py: 'var(--List-divider-gap)' }}>
149
+ +<List sx={{ py: 'var(--ListDivider-gap)' }}>
150
+ -<Switch sx={{ '--Switch-track-width': '40px' }}>
151
+ +<Switch sx={{ '--Switch-trackWidth': '40px' }}>
152
+ ```
153
+
154
+ #### Changes
155
+
156
+ - &#8203;<!-- 28 -->[Autocomplete][joy] Add disabled class to the popup indicator (#36397) @hbjORbj
157
+ - &#8203;<!-- 08 -->[Joy] Fix broken loading button in Safari (#36298) @Kuba429
158
+
159
+ ### Docs
160
+
161
+ - &#8203;<!-- 33 -->[docs][joy] Clarify when `CssVarsProvider` is required (#36410) @mnajdova
162
+ - &#8203;<!-- 32 -->MUI X v6 release announcement (#36398) @joserodolfofreitas
163
+ - &#8203;<!-- 23 -->[docs] Add instructions for deploying docs without a release (#36301) @cherniavskii
164
+ - &#8203;<!-- 22 -->[docs] Fix 301 redirections on the docs @oliviertassinari
165
+ - &#8203;<!-- 21 -->[docs] Update MUI X banner to reflect stable release (#36354) @MBilalShafi
166
+ - &#8203;<!-- 20 -->[docs] Clarify the future plan for integrating MUI Base in Material UI (#36365) @mnajdova
167
+ - &#8203;<!-- 19 -->[docs] Improve visual look of loose lists (#36190) @oliviertassinari
168
+ - &#8203;<!-- 18 -->[docs] Fix @mui/styles example links (#36331) @oliviertassinari
169
+ - &#8203;<!-- 17 -->[docs][joy] Build TS versions for List component demos (#36382) @sai6855
170
+ - &#8203;<!-- 16 -->[docs][joy] Build TS versions for Radio component demos (#36406) @sai6855
171
+ - &#8203;<!-- 15 -->[docs][joy] Build TS versions for Checkbox component demos (#36381) @sai6855
172
+ - &#8203;<!-- 14 -->[docs][joy] Build TS versions for Select component demos (#36380) @sai6855
173
+ - &#8203;<!-- 13 -->[docs][joy] Build TS versions for Typography component demos (#36378) @varunmulay22
174
+ - &#8203;<!-- 12 -->[docs][joy] Add typescript demos for `Divider` (#36374) @sai6855
175
+ - &#8203;<!-- 11 -->[docs][joy] Build TS versions for Textarea component demos (#36371) @varunmulay22
176
+ - &#8203;<!-- 10 -->[docs][joy] Build TS versions for Link component demos (#36366) @hbjORbj
177
+
178
+ ### Core
179
+
180
+ - &#8203;<!-- 31 -->Revert "Bump rimraf to ^4.1.3" (#36420) @mnajdova
181
+ - &#8203;<!-- 25 -->[core] Fix test utils types and external `buildApiUtils` usage issues (#36310) @LukasTy
182
+ - &#8203;<!-- 06 -->[test] Remove duplicate `combobox` role queries in Autocomplete tests (#36394) @ZeeshanTamboli
183
+ - &#8203;<!-- 02 -->[website] Clarify redistribution @oliviertassinari
184
+ - &#8203;<!-- 01 -->[website] Sync /about page (#36334) @oliviertassinari
185
+
186
+ All contributors of this release in alphabetical order: @cherniavskii, @hbjORbj, @joserodolfofreitas, @Kuba429, @Kundan28, @LukasTy, @MBilalShafi, @michaldudak, @mnajdova, @NoFr1ends, @oliviertassinari, @Osman-Sodefa, @Paatus, @sai6855, @SaidMarar, @varunmulay22, @ZeeshanTamboli
187
+
3
188
  ## 5.11.11
4
189
 
5
190
  <!-- generated comparing v5.11.10..master -->
@@ -2098,7 +2283,7 @@ A big thanks to the 19 contributors who made this release possible. Here are som
2098
2283
  - 🧪 Exported Grid v2 as `Unstable_Grid2` (#33479) @siriwatknp
2099
2284
  - 📖 Added a guide for using Joy UI and Material UI together (#33396) @siriwatknp
2100
2285
  - 🐛 Fixed a few bugs in Material UI components. Thanks to @ZeeshanTamboli, @ivan-ngchakming, and @joebingham-wk.
2101
- - ⚠️ **[BREAKING CHANGE]** Date pickers were removed from the lab. Learn how to migrate by visiting the [migration guide](https://mui.com/x/react-date-pickers/migration-lab/). (#33386) @flaviendelangle
2286
+ - ⚠️ **[BREAKING CHANGE]** Date pickers were removed from the lab. Learn how to migrate by visiting the [migration guide](https://mui.com/x/migration/migration-pickers-lab/). (#33386) @flaviendelangle
2102
2287
  - many other 🐛 bug fixes and 📚 documentation improvements
2103
2288
  - our documentation site is now running with React 18! (#33196) @mnajdova
2104
2289
 
@@ -2124,7 +2309,7 @@ A big thanks to the 19 contributors who made this release possible. Here are som
2124
2309
 
2125
2310
  - [lab] Remove the pickers (#33386) @flaviendelangle
2126
2311
 
2127
- The pickers are moved to MUI X, check out the [migration guide](https://mui.com/x/react-date-pickers/migration-lab/).
2312
+ The pickers are moved to MUI X, check out the [migration guide](https://mui.com/x/migration/migration-pickers-lab/).
2128
2313
 
2129
2314
  **Changes**
2130
2315
 
@@ -39,14 +39,6 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
39
39
  * @default false
40
40
  */
41
41
  disableTransitionOnChange?: boolean;
42
- /**
43
- * A function to determine if the key, value should be attached as CSS Variable
44
- * `keys` is an array that represents the object path keys.
45
- * Ex, if the theme is { foo: { bar: 'var(--test)' } }
46
- * then, keys = ['foo', 'bar']
47
- * value = 'var(--test)'
48
- */
49
- shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
50
42
  }
51
43
 
52
44
  export interface CreateCssVarsProviderResult<ColorScheme extends string> {
@@ -92,48 +84,6 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string> {
92
84
  >,
93
85
  ) => React.ReactElement;
94
86
  useColorScheme: () => ColorSchemeContextValue<ColorScheme>;
95
- generateCssThemeVars: (options?: {
96
- /**
97
- * Design system default color scheme.
98
- * - provides string if the design system has one default color scheme (either light or dark)
99
- * - provides object if the design system has default light & dark color schemes
100
- */
101
- defaultColorScheme?: ColorScheme | { light: ColorScheme; dark: ColorScheme };
102
- /**
103
- * @default 'light'
104
- */
105
- defaultMode?: 'light' | 'dark';
106
- /**
107
- * The selector for attaching CSS variables that are **outside** of `theme.colorSchemes.*`.
108
- * @default ':root'
109
- */
110
- rootSelector: string;
111
- /**
112
- * The selector for attaching CSS variables that are **outside** of `theme.colorSchemes.*`.
113
- * @default (key) => `[data-color-scheme="${key}"]`
114
- */
115
- colorSchemeSelector: (key: ColorScheme) => string;
116
- /**
117
- * A function to determine if the key, value should be attached as CSS Variable
118
- * `keys` is an array that represents the object path keys.
119
- * Ex, if the theme is { foo: { bar: 'var(--test)' } }
120
- * then, keys = ['foo', 'bar']
121
- * value = 'var(--test)'
122
- */
123
- shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
124
- /**
125
- * Controlled mode. If not provided, it will try to read the value from the upper CssVarsProvider.
126
- */
127
- mode?: Mode;
128
- /**
129
- * Controlled color scheme. If not provided, it will try to read the value from the upper CssVarsProvider.
130
- */
131
- colorScheme?: ColorScheme;
132
- theme?: {
133
- cssVarPrefix?: string;
134
- colorSchemes: Record<ColorScheme, Record<string, any>>;
135
- };
136
- }) => Record<string, any>;
137
87
  getInitColorSchemeScript: typeof getInitColorSchemeScript;
138
88
  }
139
89
 
@@ -13,12 +13,11 @@ var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styledEngine = require("@mui/styled-engine");
15
15
  var _privateTheming = require("@mui/private-theming");
16
- var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
17
16
  var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
18
17
  var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
19
18
  var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
20
19
  var _jsxRuntime = require("react/jsx-runtime");
21
- const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
20
+ const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
22
21
  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); }
23
22
  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; }
24
23
  const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
@@ -32,7 +31,6 @@ function createCssVarsProvider(options) {
32
31
  defaultMode: designSystemMode = 'light',
33
32
  defaultColorScheme: designSystemColorScheme,
34
33
  disableTransitionOnChange: designSystemTransitionOnChange = false,
35
- shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
36
34
  resolveTheme,
37
35
  excludeVariablesFromRoot
38
36
  } = options;
@@ -60,7 +58,6 @@ function createCssVarsProvider(options) {
60
58
  documentNode = typeof document === 'undefined' ? undefined : document,
61
59
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
62
60
  colorSchemeSelector = ':root',
63
- shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
64
61
  disableNestedContext = false,
65
62
  disableStyleSheetGeneration = false
66
63
  }) {
@@ -71,6 +68,10 @@ function createCssVarsProvider(options) {
71
68
  const {
72
69
  colorSchemes = {},
73
70
  components = {},
71
+ generateCssVars = () => ({
72
+ vars: {},
73
+ css: {}
74
+ }),
74
75
  cssVarPrefix
75
76
  } = themeProp,
76
77
  restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
@@ -128,10 +129,7 @@ function createCssVarsProvider(options) {
128
129
  const {
129
130
  css: rootCss,
130
131
  vars: rootVars
131
- } = (0, _cssVarsParser.default)(restThemeProp, {
132
- prefix: cssVarPrefix,
133
- shouldSkipGeneratingVar
134
- });
132
+ } = generateCssVars();
135
133
 
136
134
  // 3. Start composing the theme object
137
135
  const theme = (0, _extends2.default)({}, restThemeProp, {
@@ -151,10 +149,7 @@ function createCssVarsProvider(options) {
151
149
  const {
152
150
  css,
153
151
  vars
154
- } = (0, _cssVarsParser.default)(scheme, {
155
- prefix: cssVarPrefix,
156
- shouldSkipGeneratingVar
157
- });
152
+ } = generateCssVars(key);
158
153
  theme.vars = (0, _utils.deepmerge)(theme.vars, vars);
159
154
  if (key === calculatedColorScheme) {
160
155
  // 4.1 Merge the selected color scheme to the theme
@@ -193,6 +188,7 @@ function createCssVarsProvider(options) {
193
188
  otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
194
189
  }
195
190
  });
191
+ theme.vars = (0, _utils.deepmerge)(theme.vars, rootVars);
196
192
 
197
193
  // 5. Declaring effects
198
194
  // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
@@ -317,10 +313,6 @@ function createCssVarsProvider(options) {
317
313
  * The key in the local storage used to store current color scheme.
318
314
  */
319
315
  modeStorageKey: _propTypes.default.string,
320
- /**
321
- * A function to determine if the key, value should be attached as CSS Variable
322
- */
323
- shouldSkipGeneratingVar: _propTypes.default.func,
324
316
  /**
325
317
  * The window that attaches the 'storage' event listener
326
318
  * @default window
@@ -0,0 +1,13 @@
1
+ import { DefaultCssVarsTheme } from './prepareCssVars';
2
+ interface Theme extends DefaultCssVarsTheme {
3
+ cssVarPrefix?: string;
4
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
5
+ }
6
+ declare function createCssVarsTheme<T extends Theme, ThemeVars extends Record<string, any>>(theme: T): T & {
7
+ vars: ThemeVars;
8
+ generateCssVars: (colorScheme?: string | undefined) => {
9
+ css: Record<string, string | number>;
10
+ vars: ThemeVars;
11
+ };
12
+ };
13
+ export default createCssVarsTheme;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
11
+ const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
12
+ function createCssVarsTheme(theme) {
13
+ const {
14
+ cssVarPrefix,
15
+ shouldSkipGeneratingVar
16
+ } = theme,
17
+ otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
18
+ return (0, _extends2.default)({}, theme, (0, _prepareCssVars.default)(otherTheme, {
19
+ prefix: cssVarPrefix,
20
+ shouldSkipGeneratingVar
21
+ }));
22
+ }
23
+ var _default = createCssVarsTheme;
24
+ exports.default = _default;
@@ -14,7 +14,7 @@ function createGetCssVar(prefix = '') {
14
14
  return '';
15
15
  }
16
16
  const value = vars[0];
17
- if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
17
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
18
18
  return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
19
19
  }
20
20
  return `, ${value}`;
@@ -53,11 +53,12 @@ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, ca
53
53
  * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
54
54
  * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
55
55
  */
56
- export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
56
+ export default function cssVarsParser<T extends Record<string, any>>(theme: Record<string, any>, options?: {
57
57
  prefix?: string;
58
58
  shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
59
  }): {
60
60
  css: Record<string, string | number>;
61
- vars: NestedRecord<string>;
61
+ vars: T;
62
+ varsWithDefaults: {};
62
63
  };
63
64
  export {};
@@ -115,6 +115,7 @@ function cssVarsParser(theme, options) {
115
115
  } = options || {};
116
116
  const css = {};
117
117
  const vars = {};
118
+ const varsWithDefaults = {};
118
119
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
119
120
  if (typeof value === 'string' || typeof value === 'number') {
120
121
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
@@ -124,6 +125,7 @@ function cssVarsParser(theme, options) {
124
125
  [cssVar]: getCssValue(keys, value)
125
126
  });
126
127
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
128
+ assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
127
129
  }
128
130
  }
129
131
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
@@ -131,6 +133,7 @@ function cssVarsParser(theme, options) {
131
133
 
132
134
  return {
133
135
  css,
134
- vars
136
+ vars,
137
+ varsWithDefaults
135
138
  };
136
139
  }
@@ -1,3 +1,5 @@
1
1
  export { default } from './createCssVarsProvider';
2
2
  export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
3
  export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
4
+ export { default as prepareCssVars } from './prepareCssVars';
5
+ export { default as createCssVarsTheme } from './createCssVarsTheme';
package/cssVars/index.js CHANGED
@@ -4,6 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ Object.defineProperty(exports, "createCssVarsTheme", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _createCssVarsTheme.default;
11
+ }
12
+ });
7
13
  Object.defineProperty(exports, "default", {
8
14
  enumerable: true,
9
15
  get: function () {
@@ -16,5 +22,13 @@ Object.defineProperty(exports, "getInitColorSchemeScript", {
16
22
  return _getInitColorSchemeScript.default;
17
23
  }
18
24
  });
25
+ Object.defineProperty(exports, "prepareCssVars", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _prepareCssVars.default;
29
+ }
30
+ });
19
31
  var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
20
- var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
32
+ var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
33
+ var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
34
+ var _createCssVarsTheme = _interopRequireDefault(require("./createCssVarsTheme"));
@@ -0,0 +1,14 @@
1
+ export interface DefaultCssVarsTheme {
2
+ colorSchemes: Record<string, any>;
3
+ }
4
+ declare function prepareCssVars<T extends DefaultCssVarsTheme, ThemeVars extends Record<string, any>>(theme: T, parserConfig?: {
5
+ prefix?: string;
6
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
7
+ }): {
8
+ vars: ThemeVars;
9
+ generateCssVars: (colorScheme?: string) => {
10
+ css: Record<string, string | number>;
11
+ vars: ThemeVars;
12
+ };
13
+ };
14
+ export default prepareCssVars;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
+ var _utils = require("@mui/utils");
10
+ var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
11
+ const _excluded = ["colorSchemes", "components"],
12
+ _excluded2 = ["light"];
13
+ function prepareCssVars(theme, parserConfig) {
14
+ // @ts-ignore - ignore components do not exist
15
+ const {
16
+ colorSchemes = {}
17
+ } = theme,
18
+ otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
19
+ const {
20
+ vars: rootVars,
21
+ css: rootCss,
22
+ varsWithDefaults: rootVarsWithDefaults
23
+ } = (0, _cssVarsParser.default)(otherTheme, parserConfig);
24
+ let themeVars = rootVarsWithDefaults;
25
+ const colorSchemesMap = {};
26
+ const {
27
+ light
28
+ } = colorSchemes,
29
+ otherColorSchemes = (0, _objectWithoutPropertiesLoose2.default)(colorSchemes, _excluded2);
30
+ Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
31
+ const {
32
+ vars,
33
+ css,
34
+ varsWithDefaults
35
+ } = (0, _cssVarsParser.default)(scheme, parserConfig);
36
+ themeVars = (0, _utils.deepmerge)(themeVars, varsWithDefaults);
37
+ colorSchemesMap[key] = {
38
+ css,
39
+ vars
40
+ };
41
+ });
42
+ if (light) {
43
+ // light color scheme vars should be merged last to set as default
44
+ const {
45
+ css,
46
+ vars,
47
+ varsWithDefaults
48
+ } = (0, _cssVarsParser.default)(light, parserConfig);
49
+ themeVars = (0, _utils.deepmerge)(themeVars, varsWithDefaults);
50
+ colorSchemesMap.light = {
51
+ css,
52
+ vars
53
+ };
54
+ }
55
+ const generateCssVars = colorScheme => {
56
+ if (!colorScheme) {
57
+ return {
58
+ css: rootCss,
59
+ vars: rootVars
60
+ };
61
+ }
62
+ return colorSchemesMap[colorScheme];
63
+ };
64
+ return {
65
+ vars: themeVars,
66
+ generateCssVars
67
+ };
68
+ }
69
+ var _default = prepareCssVars;
70
+ exports.default = _default;
@@ -1,13 +1,12 @@
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", "cssVarPrefix"];
4
+ const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { deepmerge } from '@mui/utils';
8
8
  import { GlobalStyles } from '@mui/styled-engine';
9
9
  import { useTheme as muiUseTheme } from '@mui/private-theming';
10
- import cssVarsParser from './cssVarsParser';
11
10
  import ThemeProvider from '../ThemeProvider';
12
11
  import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
13
12
  import useCurrentColorScheme from './useCurrentColorScheme';
@@ -23,7 +22,6 @@ export default function createCssVarsProvider(options) {
23
22
  defaultMode: designSystemMode = 'light',
24
23
  defaultColorScheme: designSystemColorScheme,
25
24
  disableTransitionOnChange: designSystemTransitionOnChange = false,
26
- shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
27
25
  resolveTheme,
28
26
  excludeVariablesFromRoot
29
27
  } = options;
@@ -51,7 +49,6 @@ export default function createCssVarsProvider(options) {
51
49
  documentNode = typeof document === 'undefined' ? undefined : document,
52
50
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
53
51
  colorSchemeSelector = ':root',
54
- shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
55
52
  disableNestedContext = false,
56
53
  disableStyleSheetGeneration = false
57
54
  }) {
@@ -62,6 +59,10 @@ export default function createCssVarsProvider(options) {
62
59
  const {
63
60
  colorSchemes = {},
64
61
  components = {},
62
+ generateCssVars = () => ({
63
+ vars: {},
64
+ css: {}
65
+ }),
65
66
  cssVarPrefix
66
67
  } = themeProp,
67
68
  restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
@@ -119,10 +120,7 @@ export default function createCssVarsProvider(options) {
119
120
  const {
120
121
  css: rootCss,
121
122
  vars: rootVars
122
- } = cssVarsParser(restThemeProp, {
123
- prefix: cssVarPrefix,
124
- shouldSkipGeneratingVar
125
- });
123
+ } = generateCssVars();
126
124
 
127
125
  // 3. Start composing the theme object
128
126
  const theme = _extends({}, restThemeProp, {
@@ -142,10 +140,7 @@ export default function createCssVarsProvider(options) {
142
140
  const {
143
141
  css,
144
142
  vars
145
- } = cssVarsParser(scheme, {
146
- prefix: cssVarPrefix,
147
- shouldSkipGeneratingVar
148
- });
143
+ } = generateCssVars(key);
149
144
  theme.vars = deepmerge(theme.vars, vars);
150
145
  if (key === calculatedColorScheme) {
151
146
  // 4.1 Merge the selected color scheme to the theme
@@ -184,6 +179,7 @@ export default function createCssVarsProvider(options) {
184
179
  otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
185
180
  }
186
181
  });
182
+ theme.vars = deepmerge(theme.vars, rootVars);
187
183
 
188
184
  // 5. Declaring effects
189
185
  // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
@@ -308,10 +304,6 @@ export default function createCssVarsProvider(options) {
308
304
  * The key in the local storage used to store current color scheme.
309
305
  */
310
306
  modeStorageKey: PropTypes.string,
311
- /**
312
- * A function to determine if the key, value should be attached as CSS Variable
313
- */
314
- shouldSkipGeneratingVar: PropTypes.func,
315
307
  /**
316
308
  * The window that attaches the 'storage' event listener
317
309
  * @default window
@@ -0,0 +1,16 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
4
+ import prepareCssVars from './prepareCssVars';
5
+ function createCssVarsTheme(theme) {
6
+ const {
7
+ cssVarPrefix,
8
+ shouldSkipGeneratingVar
9
+ } = theme,
10
+ otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
11
+ return _extends({}, theme, prepareCssVars(otherTheme, {
12
+ prefix: cssVarPrefix,
13
+ shouldSkipGeneratingVar
14
+ }));
15
+ }
16
+ export default createCssVarsTheme;