@mui/system 5.2.2 → 5.2.6

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 (38) hide show
  1. package/CHANGELOG.md +271 -0
  2. package/createBox.d.ts +3 -3
  3. package/createBox.spec.d.ts +1 -0
  4. package/createTheme/createBreakpoints.d.ts +6 -0
  5. package/createTheme/createBreakpoints.js +16 -0
  6. package/cssVars/createCssVarsProvider.d.ts +13 -9
  7. package/cssVars/createCssVarsProvider.js +26 -6
  8. package/cssVars/createGetThemeVar.d.ts +1 -0
  9. package/cssVars/createGetThemeVar.js +22 -0
  10. package/cssVars/cssVarsParser.d.ts +1 -1
  11. package/cssVars/cssVarsParser.js +17 -16
  12. package/cssVars/getInitColorSchemeScript.js +1 -1
  13. package/esm/createTheme/createBreakpoints.js +16 -0
  14. package/esm/cssVars/createCssVarsProvider.js +25 -7
  15. package/esm/cssVars/createGetThemeVar.js +15 -0
  16. package/esm/cssVars/cssVarsParser.js +17 -15
  17. package/esm/cssVars/getInitColorSchemeScript.js +1 -1
  18. package/esm/index.js +2 -1
  19. package/esm/useThemeProps/getThemeProps.js +2 -17
  20. package/index.d.ts +1 -0
  21. package/index.js +11 -2
  22. package/legacy/createTheme/createBreakpoints.js +16 -0
  23. package/legacy/cssVars/createCssVarsProvider.js +27 -8
  24. package/legacy/cssVars/createGetThemeVar.js +26 -0
  25. package/legacy/cssVars/cssVarsParser.js +19 -13
  26. package/legacy/cssVars/getInitColorSchemeScript.js +1 -1
  27. package/legacy/index.js +3 -2
  28. package/legacy/useThemeProps/getThemeProps.js +2 -17
  29. package/modern/createTheme/createBreakpoints.js +16 -0
  30. package/modern/cssVars/createCssVarsProvider.js +23 -7
  31. package/modern/cssVars/createGetThemeVar.js +15 -0
  32. package/modern/cssVars/cssVarsParser.js +17 -15
  33. package/modern/cssVars/getInitColorSchemeScript.js +1 -1
  34. package/modern/index.js +3 -2
  35. package/modern/useThemeProps/getThemeProps.js +2 -17
  36. package/package.json +5 -5
  37. package/styleFunctionSx/styleFunctionSx.d.ts +1 -1
  38. package/useThemeProps/getThemeProps.js +2 -17
package/CHANGELOG.md CHANGED
@@ -1,5 +1,276 @@
1
1
  ### [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 5.2.6
4
+
5
+ <!-- generated comparing v5.2.5..master -->
6
+
7
+ _Dec 27, 2021_
8
+
9
+ A big thanks to the 14 contributors who made this release possible. Here are some highlights ✨:
10
+
11
+ - 📓 The Norwegian Bokmål (nb-NO) locale was added (#27520) @wogsland
12
+ - 🛠 Introduced a new `useBadge` hook in the `@mui/base` package (#30246) @mnajdova
13
+ - And more 🐛 bug fixes and 📚 documentation improvements.
14
+
15
+ ### `@mui/material@5.2.6`
16
+
17
+ - &#8203;<!-- 24 -->[ButtonGroup] Fix typo in ButtonGroupContext's interface (#30376) @kealjones-wk
18
+ - &#8203;<!-- 03 -->[l10n] Add Norwegian Bokmål (nb-NO) locale (#27520) @wogsland
19
+
20
+ ### `@mui/base@5.0.0-alpha.62`
21
+
22
+ - &#8203;<!-- 26 -->[BadgeUnstyled] Add useBadge hook (#30246) @mnajdova
23
+
24
+ ### `@mui/joy@5.0.0-alpha.8`
25
+
26
+ - &#8203;<!-- 04 -->[Joy] Button API (#29962) @siriwatknp
27
+
28
+ ### Docs
29
+
30
+ - &#8203;<!-- 27 -->[docs] Fix color coercion (#30319) @Janpot
31
+ - &#8203;<!-- 25 -->[blog] Fix file import conflict resolution (#30391) @oliviertassinari
32
+ - &#8203;<!-- 21 -->[docs] Fix crash on Safari because of unsupported lookahead feature (#30345) @cherniavskii
33
+ - &#8203;<!-- 20 -->[docs] Update to new website domain (#30396) @ryota-murakami
34
+ - &#8203;<!-- 19 -->[docs] Fix text from material-ui to @mui to reflect v5 name changes (#30393) @pupudu
35
+ - &#8203;<!-- 18 -->[docs] Fix a11y in Menu demos (#30378) @ZeeshanTamboli
36
+ - &#8203;<!-- 17 -->[docs] Document how to unmount transition child (#30382) @oliviertassinari
37
+ - &#8203;<!-- 16 -->[docs] The current standard for quotes is QUOTATION MARK @oliviertassinari
38
+ - &#8203;<!-- 15 -->[docs] Fix 404 links (#30380) @oliviertassinari
39
+ - &#8203;<!-- 14 -->[docs] Fix Breadcrumb description (#30307) @jamesmelzer
40
+ - &#8203;<!-- 13 -->[docs] Modify injection order for Gatsby and SSR examples (#30358) @ShuPink
41
+ - &#8203;<!-- 12 -->[docs] Improve the translation experience (#30373) @oliviertassinari
42
+ - &#8203;<!-- 11 -->[docs] Sync translations with Crowdin (#30176) @l10nbot
43
+ - &#8203;<!-- 10 -->[docs] Fix link to /size-snapshot (#30363) @oliviertassinari
44
+ - &#8203;<!-- 09 -->[docs] Fix incorrect aria label in SpeedDial demo (#30354) @chwallen
45
+ - &#8203;<!-- 08 -->[docs] Fix incorrect number of breakpoint helpers (#30353) @chwallen
46
+ - &#8203;<!-- 07 -->[docs] Update outdated links (#30260) @oliviertassinari
47
+ - &#8203;<!-- 06 -->[docs] Support redirects from old urls to /material/\* (#30286) @siriwatknp
48
+ - &#8203;<!-- 05 -->[examples] Fix CSS modules integration (#30381) @oliviertassinari
49
+ - &#8203;<!-- 02 -->[website] Fix SEO issues (#30372) @oliviertassinari
50
+ - &#8203;<!-- 01 -->[website] Sync sponsors (#30259) @oliviertassinari
51
+
52
+ ### Core
53
+
54
+ - &#8203;<!-- 28 -->[core] Rename Material-UI to MUI (#30338) @ZeeshanTamboli
55
+ - &#8203;<!-- 23 -->[core] Fix warning in dev mode (#30368) @oliviertassinari
56
+ - &#8203;<!-- 22 -->[core] Update `buildApi` script to support new structure (#30245) @siriwatknp
57
+
58
+ All contributors of this release in alphabetical order: @cherniavskii, @chwallen, @jamesmelzer, @Janpot, @kealjones-wk, @l10nbot, @mnajdova, @oliviertassinari, @pupudu, @ryota-murakami, @ShuPink, @siriwatknp, @wogsland, @ZeeshanTamboli
59
+
60
+ ## 5.2.5
61
+
62
+ <!-- generated comparing v5.2.4..master -->
63
+
64
+ _Dec 20, 2021_
65
+
66
+ A big thanks to the 16 contributors who made this release possible. Here are some highlights ✨:
67
+
68
+ - 🛠 This release mostly improves what's behind the scenes: infrastructure and tests
69
+ - 📓 Danish (da-DK) locale was added (#29485) @mikk5829
70
+ - 🖌 Polished the design of Base components (#30149) and the docs in general (#29994) @danilo-leal
71
+ - 📚 Many additions and improvements to the documentation were made
72
+
73
+ ### `@mui/material@5.2.5`
74
+
75
+ - [l10n] Add Danish (da-DK) locale (#29485) @mikk5829
76
+ - [LoadingButton] Label progressbar by the LoadingButton (#30002) @eps1lon
77
+ - [Tabs] Remove unnecessary `Partial<>` type around TabIndicatorProps type (#30254) @ZeeshanTamboli
78
+
79
+ ### `@mui/system@5.2.5`
80
+
81
+ - [system] Use `useEnhancedEffect` to prevent flicker (#30216) @hbjORbj
82
+
83
+ ### `@mui/lab@5.0.0-alpha.61`
84
+
85
+ - [pickers] Fix the wrong MuiClockPicker's ArrowSwitcher slot name (#30226) @rejetto
86
+
87
+ ### Docs
88
+
89
+ - [docs] Run JS compiler on markdown output (#29732) @Janpot
90
+ - [Badge] Add tests for `anchorOrigin` prop (#30147) @daniel-sachs
91
+ - [docs] Add cssmodule injection order comments to Nextjs example (#30213) @ShuPink
92
+ - [docs] Remove extra word in Select component code example comments (#30281) @KThompso
93
+ - [docs] Improve the description of the Accordion (#30253) @jamesmelzer
94
+ - [docs] Heading capitalization convention @oliviertassinari
95
+ - [docs] Rename remaining 'unstyled' references to 'base' (#30206) @michaldudak
96
+ - [docs] Add to migration doc about ref type specificity (#30114) @hbjORbj
97
+ - [docs] Add script to clone pages (#30107) @siriwatknp
98
+ - [docs] Correct colors in breakpoints documentation (#30219) @michaldudak
99
+ - [docs] Sync icon search UI state with the url (#30075) @Janpot
100
+ - [docs] Base components demos design polish (#30149) @danilo-leal
101
+ - [docs] General documentation polish (#29994) @danilo-leal
102
+ - [examples] Fix typo in the remix example's README (#30289) @lemol
103
+ - [website] Remove expired gold sponsor (#30222) @oliviertassinari
104
+ - [website] Remove broken showcase links (#30217) @mnajdova
105
+
106
+ ### Core
107
+
108
+ - [test] Reduce bundle size comparison memory consumption (#30195) @Janpot
109
+ - [core] make snapshot comparison more resilient (#30183) @Janpot
110
+ - [core] update formatted ts demo to support new structure (#30248) @siriwatknp
111
+ - [core] cache dependencies in github actions (#30211) @siriwatknp
112
+ - [core] fix root package version (#30204) @siriwatknp
113
+ - [core] Fail the build when the dangerjs script errors (#30186) @Janpot
114
+ - [test] Add E2E website tests (#30128) @siriwatknp
115
+
116
+ All contributors of this release in alphabetical order: @daniel-sachs, @danilo-leal, @eps1lon, @hbjORbj, @jamesmelzer, @Janpot, @KThompso, @lemol, @michaldudak, @mikk5829, @mnajdova, @oliviertassinari, @rejetto, @ShuPink, @siriwatknp, @ZeeshanTamboli
117
+
118
+ ## 5.2.4
119
+
120
+ <!-- generated comparing v5.2.3..master -->
121
+
122
+ _Dec 14, 2021_
123
+
124
+ A big thanks to the 16 contributors who made this release possible. Here are some highlights ✨:
125
+
126
+ - ✨ Add `not` operator to `theme.breakpoints` (#29311) @Philipp000
127
+
128
+ ```js
129
+ const styles = (theme) => ({
130
+ root: {
131
+ backgroundColor: 'blue',
132
+ // Match [xs, md) and [md + 1, ∞)
133
+ // [xs, md) and [lg, ∞)
134
+ // [0px, 900px) and [1200px, ∞)
135
+ [theme.breakpoints.not('md')]: {
136
+ backgroundColor: 'red',
137
+ },
138
+ },
139
+ });
140
+ ```
141
+
142
+ - And many more 🐛 bug fixes and 📚 improvements.
143
+
144
+ ### `@mui/material@5.2.4`
145
+
146
+ - &#8203;<!-- 14 -->[esm] Correct a styles imports (#29976) @Janpot
147
+ - &#8203;<!-- 12 -->[GlobalStyles] Fix `theme` type (#30072) @mnajdova
148
+ - &#8203;<!-- 11 -->[Grid] Fix grid items to respond to the container's responsive columns (#29715) @kkorach
149
+ - &#8203;<!-- 04 -->[TextField] Fix missing space before asterisk in `OutlinedInput`'s label (#29630) @alisasanib
150
+ - &#8203;<!-- 03 -->[Transition] Allow any valid HTML attribute to be passed (#29888) @Janpot
151
+ - &#8203;<!-- 02 -->[types] Fix discrepancy between core and system `ThemeOptions` (#30095) @fmeum
152
+ - &#8203;<!-- 09 -->[InputBase] Add prop for disabling global styles (#29213) @bryan-hunter
153
+ - &#8203;<!-- 08 -->[Select] Improve multiple logic (#30135) @ladygo93
154
+
155
+ ### `@mui/system@5.2.4`
156
+
157
+ - &#8203;<!-- 06 -->[system] Don't transition when re-appearing (#30108) @eps1lon
158
+ - &#8203;<!-- 05 -->[system] Add `not` operator to `breakpoints` (#29311) @Philipp000
159
+
160
+ ### `@mui/base@5.0.0-alpha.60`
161
+
162
+ - &#8203;<!-- 25 -->[BadgeUnstyled] Make it conformant with other base components (#30141) @mnajdova
163
+
164
+ ### `@mui/icons-material@5.2.4`
165
+
166
+ - &#8203;<!-- 10 -->[icons] Correct location of icon download folder (#29839) @yaboi
167
+
168
+ ### Docs
169
+
170
+ - &#8203;<!-- 22 -->[docs] Explain the use of Select's label in FormControl (#30189) @michaldudak
171
+ - &#8203;<!-- 21 -->[docs] Don't run nprogress on shallow routing (#30087) @Janpot
172
+ - &#8203;<!-- 20 -->[docs] Add Data Driven Forms to related projects (#30078) @rvsia
173
+ - &#8203;<!-- 19 -->[docs] Sync translations with Crowdin (#30067) @l10nbot
174
+ - &#8203;<!-- 18 -->[docs] Fix link on "Custom variables" section in the Theming page #30100 @danilo-leal
175
+ - &#8203;<!-- 17 -->[docs] Fix justifyContent option in the Grid interactive demo (#30117) @danilo-leal
176
+ - &#8203;<!-- 16 -->[docs] Add tip to help access the docs of a previous version when finding answers in StackOverflow (#30101) @danilo-leal
177
+ - &#8203;<!-- 15 -->[docs] Fix import example inside Unstyled Backdrop section (#30098) @TheodosiouTh
178
+ - &#8203;<!-- 01 -->[website] Column pinning and Tree data are out (#30136) @oliviertassinari
179
+ - &#8203;<!-- 07 -->[survey] Remove survey promotion items (#30122) @danilo-leal
180
+
181
+ ### Core
182
+
183
+ - &#8203;<!-- 23 -->[core] Fix link to Open Collective @oliviertassinari
184
+ - &#8203;<!-- 26 -->[core] Update snapshots and s3 fallback (#30134) @Janpot
185
+ - &#8203;<!-- 24 -->[ci] Update CI bucket (#30080) @Janpot
186
+ - &#8203;<!-- 13 -->[fix] size:snapshot for mui-material-next and mui-joy components (#30106) @Janpot
187
+
188
+ All contributors of this release in alphabetical order: @alisasanib, @bryan-hunter, @danilo-leal, @eps1lon, @fmeum, @Janpot, @kkorach, @l10nbot, @ladygo93, @michaldudak, @mnajdova, @oliviertassinari, @Philipp000, @rvsia, @TheodosiouTh, @yaboi
189
+
190
+ ## 5.2.3
191
+
192
+ <!-- generated comparing v5.2.2..master -->
193
+
194
+ _Dec 6, 2021_
195
+
196
+ A big thanks to the 25 contributors who made this release possible. Here are some highlights ✨:
197
+
198
+ - ✨ We have introduced a new unstyled component in `@mui/base`: `TablePagination` (#29759) @mnajdova
199
+
200
+ <a href="https://mui.com/components/tables/#unstyled-table"><img width="800" alt="unstyled table" src="https://user-images.githubusercontent.com/4512430/144862194-584356ef-7d9d-462c-a631-186a7e716193.png"></a>
201
+
202
+ You can follow our progress with unstyled components at https://github.com/mui-org/material-ui/issues/27170.
203
+
204
+ - 🎉 We have added an example of how to use MUI with [Remix](https://remix.run/) (#29952) @mnajdova
205
+
206
+ - And many more 🐛 bug fixes and 📚 improvements.
207
+
208
+ ### `@mui/material@5.2.3`
209
+
210
+ - &#8203;<!-- 33 -->[Accordion] Add a test for handling `square` prop (#29972) @daniel-sachs
211
+ - &#8203;<!-- 32 -->[Alert] Fix `square` Paper prop (#30027) @ZeeshanTamboli
212
+ - &#8203;<!-- 31 -->[AvatarGroup] Allow specifying total number of avatars (#29898) @eduardomcv
213
+ - &#8203;<!-- 29 -->[Button] Fix regression from context API (#29982) @siriwatknp
214
+ - &#8203;<!-- 13 -->[Grid] Fix generated classes for `spacing` prop when the value is object (#29880) @jayeclark
215
+ - &#8203;<!-- 10 -->[Select] Should not crash when an empty array is passed with `multiple` enabled (#29957) @Domino987
216
+
217
+ ### `@mui/system@5.2.3`
218
+
219
+ - &#8203;<!-- 06 -->[system] Fix return type of `createBox` (#29989) @mnajdova
220
+ - &#8203;<!-- 05 -->[system] Support boolean values in typescript for the `sx` prop when used as array (#29911) @tasugi
221
+
222
+ ### `@mui/utils@5.2.3`
223
+
224
+ - &#8203;<!-- 03 -->[utils] Add typings for `@mui-material/styles/cssUtils` (#29621) @Semigradsky
225
+
226
+ ### `@mui/icons-material@5.2.1`
227
+
228
+ - &#8203;<!-- 12 -->[icons] Consolidate ignored icons into one list (#29843) @chao813
229
+
230
+ ### `@mui/base@5.0.0-alpha.59`
231
+
232
+ - &#8203;<!-- 30 -->[base] Fix missing ClickAwayListener barrel index export (#30000) @oliviertassinari
233
+ - &#8203;<!-- 04 -->[TablePaginationUnstyled] Introduce new component (#29759) @mnajdova
234
+
235
+ ### `@mui/lab@5.0.0-alpha.59`
236
+
237
+ - &#8203;<!-- 27 -->[DateRangePicker] Fix `DateRangePickerDayProps` interface (#29067) @jonathanrtuck
238
+ - &#8203;<!-- 10 -->[Pickers] Remove propagation of custom props to the `MonthPicker` component's DOM element (#30021) @ZeeshanTamboli
239
+ - &#8203;<!-- 08 -->[StaticDatePicker] Add className and slot to PickerStaticWrapper (#29619) @kkorach
240
+
241
+ ### `@mui/joy@5.0.0-alpha.5`
242
+
243
+ - &#8203;<!-- 11 -->[Joy] Theme setup (#29846) @siriwatknp
244
+
245
+ ### Docs
246
+
247
+ - &#8203;<!-- 34 -->[docs] Fix link in TypeScript doc page (#30044) @genzyy
248
+ - &#8203;<!-- 26 -->[docs] Remove the 'WIP' icon from the 'Group & Pivot' page title (#30077) @flaviendelangle
249
+ - &#8203;<!-- 25 -->[docs] Add warning that `@mui/styled-engine-sc` does not work in SSR (#30026) @mnajdova
250
+ - &#8203;<!-- 24 -->[docs] Add section for CSS specificity in the migration guide (#30008) @hbjORbj
251
+ - &#8203;<!-- 28 -->[docs] Clarify comment in migration doc (#30076) @hbjORbj
252
+ - &#8203;<!-- 23 -->[docs] Sync translations with Crowdin (#30041) @l10nbot
253
+ - &#8203;<!-- 22 -->[docs] Explain how Paper changes shade in dark mode (#30003) @michaldudak
254
+ - &#8203;<!-- 21 -->[docs] Update nextjs-typescript-example (#29974) @huydhoang
255
+ - &#8203;<!-- 20 -->[docs] Add missing global state classes to API docs generator (#29945) @michaldudak
256
+ - &#8203;<!-- 19 -->[docs] Fix benchmarks folder link (#29981) @fourjr
257
+ - &#8203;<!-- 18 -->[docs] Improve wording in StackOverflow section of support page (#29956) @ronwarner
258
+ - &#8203;<!-- 17 -->[docs] Remove Black Friday sale notification (#29936) @mbrookes
259
+ - &#8203;<!-- 16 -->[examples] Fix typos in the Remix example (#30071) @MichaelDeBoey
260
+ - &#8203;<!-- 15 -->[examples] Add Remix example (#29952) @mnajdova
261
+ - &#8203;<!-- 14 -->[examples] Fix lint issue for displayName missing in the Next.js examples (#29985) @ZeeshanTamboli
262
+ - &#8203;<!-- 09 -->[Stack] Document system props in Stack API (#30069) @ThewBear
263
+ - &#8203;<!-- 07 -->[survey] Add a banner and card for promoting the 2021 survey (#29950) @danilo-leal
264
+ - &#8203;<!-- 02 -->[website] Correct the Careers page description (#30073) @michaldudak
265
+ - &#8203;<!-- 01 -->[website] Fix 301 links (#30040) @oliviertassinari
266
+
267
+ ### Core
268
+
269
+ - &#8203;<!-- 31 -->[core] Batch small changes (#30042) @oliviertassinari
270
+ - &#8203;<!-- 28 -->[core] Transition to a new StackOverflow tag (#29967) @oliviertassinari
271
+
272
+ All contributors of this release in alphabetical order: @chao813, @daniel-sachs, @danilo-leal, @Domino987, @eduardomcv, @flaviendelangle, @fourjr, @genzyy, @hbjORbj, @huydhoang, @jayeclark, @jonathanrtuck, @kkorach, @l10nbot, @mbrookes, @MichaelDeBoey, @michaldudak, @mnajdova, @oliviertassinari, @ronwarner, @Semigradsky, @siriwatknp, @tasugi, @ThewBear, @ZeeshanTamboli
273
+
3
274
  ## 5.2.2
4
275
 
5
276
  <!-- generated comparing v5.2.1..master -->
package/createBox.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
1
+ import Box from './Box';
2
2
 
3
3
  export default function createBox(options?: {
4
4
  defaultTheme: object;
5
5
  defaultClassName?: string;
6
- generateClassName?: () => string;
7
- }): React.ElementType;
6
+ generateClassName?: (componentName: string) => string;
7
+ }): typeof Box;
@@ -0,0 +1 @@
1
+ export {};
@@ -55,6 +55,12 @@ export interface Breakpoints {
55
55
  * @see [API documentation](https://mui.com/customization/breakpoints/#theme-breakpoints-only-key-media-query)
56
56
  */
57
57
  only: (key: Breakpoint) => string;
58
+ /**
59
+ * @param key - A breakpoint key (`xs`, `sm`, etc.).
60
+ * @returns A media query string ready to be used with most styling solutions, which matches screen widths stopping at
61
+ * the screen size given by the breakpoint key (exclusive) and starting at the screen size given by the next breakpoint key (inclusive).
62
+ */
63
+ not: (key: Breakpoint) => string;
58
64
  }
59
65
 
60
66
  export interface BreakpointsOptions extends Partial<Breakpoints> {
@@ -64,6 +64,21 @@ function createBreakpoints(breakpoints) {
64
64
  return up(key);
65
65
  }
66
66
 
67
+ function not(key) {
68
+ // handle first and last key separately, for better readability
69
+ const keyIndex = keys.indexOf(key);
70
+
71
+ if (keyIndex === 0) {
72
+ return up(keys[1]);
73
+ }
74
+
75
+ if (keyIndex === keys.length - 1) {
76
+ return down(keys[keyIndex]);
77
+ }
78
+
79
+ return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
80
+ }
81
+
67
82
  return (0, _extends2.default)({
68
83
  keys,
69
84
  values,
@@ -71,6 +86,7 @@ function createBreakpoints(breakpoints) {
71
86
  down,
72
87
  between,
73
88
  only,
89
+ not,
74
90
  unit
75
91
  }, other);
76
92
  }
@@ -1,10 +1,7 @@
1
1
  import * as React from 'react';
2
+ import getInitColorSchemeScript from './getInitColorSchemeScript';
2
3
  import { Mode, Result } from './useCurrentColorScheme';
3
4
 
4
- type RequiredDeep<T> = {
5
- [K in keyof T]-?: RequiredDeep<T[K]>;
6
- };
7
-
8
5
  export type BuildCssVarsTheme<ThemeInput> = ThemeInput extends {
9
6
  colorSchemes: Record<string, infer ColorSystems>;
10
7
  }
@@ -25,7 +22,16 @@ type DecideTheme<
25
22
  ApplicationTheme extends { colorSchemes: Record<ApplicationColorScheme, any> },
26
23
  ApplicationColorScheme extends string | never,
27
24
  > = [ApplicationColorScheme] extends [never]
28
- ? { theme?: DesignSystemTheme }
25
+ ? {
26
+ theme?: Omit<DesignSystemTheme, 'colorSchemes'> & {
27
+ colorSchemes?: Partial<
28
+ Record<
29
+ DesignSystemColorScheme,
30
+ DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
31
+ >
32
+ >;
33
+ };
34
+ }
29
35
  : {
30
36
  theme: Omit<ApplicationTheme, 'colorSchemes'> & {
31
37
  colorSchemes: Partial<
@@ -34,9 +40,7 @@ type DecideTheme<
34
40
  DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
35
41
  >
36
42
  > &
37
- RequiredDeep<
38
- Record<ApplicationColorScheme, ApplicationTheme['colorSchemes'][ApplicationColorScheme]>
39
- >;
43
+ Record<ApplicationColorScheme, ApplicationTheme['colorSchemes'][ApplicationColorScheme]>;
40
44
  };
41
45
  };
42
46
 
@@ -134,7 +138,7 @@ export default function createCssVarsProvider<
134
138
  >,
135
139
  ) => React.ReactElement;
136
140
  useColorScheme: () => ColorSchemeContextValue<DesignSystemColorScheme | ApplicationColorScheme>;
137
- getInitColorSchemeScript: () => React.ReactElement;
141
+ getInitColorSchemeScript: typeof getInitColorSchemeScript;
138
142
  };
139
143
 
140
144
  // disable automatic export
@@ -20,6 +20,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
20
20
 
21
21
  var _styledEngine = require("@mui/styled-engine");
22
22
 
23
+ var _createSpacing = _interopRequireDefault(require("../createTheme/createSpacing"));
24
+
25
+ var _createBreakpoints = _interopRequireDefault(require("../createTheme/createBreakpoints"));
26
+
23
27
  var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
24
28
 
25
29
  var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
@@ -28,6 +32,8 @@ var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorS
28
32
 
29
33
  var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
30
34
 
35
+ var _createGetThemeVar = _interopRequireDefault(require("./createGetThemeVar"));
36
+
31
37
  var _jsxRuntime = require("react/jsx-runtime");
32
38
 
33
39
  const _excluded = ["colorSchemes"],
@@ -42,6 +48,8 @@ const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transit
42
48
  exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
43
49
 
44
50
  function createCssVarsProvider(options) {
51
+ var _baseTheme$breakpoint;
52
+
45
53
  const {
46
54
  theme: baseTheme = {},
47
55
  defaultMode: desisgnSystemMode = 'light',
@@ -51,6 +59,8 @@ function createCssVarsProvider(options) {
51
59
  prefix: designSystemPrefix = '',
52
60
  shouldSkipGeneratingVar
53
61
  } = options;
62
+ const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
63
+ const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
54
64
 
55
65
  if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
56
66
  console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
@@ -77,15 +87,18 @@ function createCssVarsProvider(options) {
77
87
  defaultMode = desisgnSystemMode,
78
88
  defaultColorScheme = designSystemColorScheme
79
89
  }) {
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)), []);
80
93
  const {
81
94
  colorSchemes: baseColorSchemes = {}
82
- } = baseTheme,
83
- restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
95
+ } = clonedBaseTheme,
96
+ restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(clonedBaseTheme, _excluded);
84
97
  const {
85
98
  colorSchemes: colorSchemesProp = {}
86
99
  } = themeProp,
87
100
  restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded2);
88
- const hasMounted = React.useRef(null); // eslint-disable-next-line prefer-const
101
+ const hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
89
102
 
90
103
  let _deepmerge = (0, _utils.deepmerge)(restBaseTheme, restThemeProp),
91
104
  {
@@ -138,7 +151,10 @@ function createCssVarsProvider(options) {
138
151
  mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
139
152
  components,
140
153
  colorSchemes,
141
- vars: rootVars
154
+ vars: rootVars,
155
+ spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
156
+ breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints,
157
+ getThemeVar: (0, _createGetThemeVar.default)(prefix)
142
158
  });
143
159
  const styleSheet = {};
144
160
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -172,10 +188,11 @@ function createCssVarsProvider(options) {
172
188
  });
173
189
  React.useEffect(() => {
174
190
  if (colorScheme) {
175
- document.body.setAttribute(attribute, colorScheme);
191
+ // attaches attribute to <html> because the css variables are attached to :root (html)
192
+ document.documentElement.setAttribute(attribute, colorScheme);
176
193
  }
177
194
  }, [colorScheme, attribute]);
178
- React.useEffect(() => {
195
+ (0, _utils.unstable_useEnhancedEffect)(() => {
179
196
  if (!mode || !enableColorScheme) {
180
197
  return undefined;
181
198
  }
@@ -214,6 +231,9 @@ function createCssVarsProvider(options) {
214
231
  }, [colorScheme]);
215
232
  React.useEffect(() => {
216
233
  hasMounted.current = true;
234
+ return () => {
235
+ hasMounted.current = false;
236
+ };
217
237
  }, []);
218
238
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ColorSchemeContext.Provider, {
219
239
  value: {
@@ -0,0 +1 @@
1
+ export default function createGetThemeVar<T extends string = string>(prefix?: string): (field: T, ...vars: T[]) => string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = createGetThemeVar;
7
+
8
+ function createGetThemeVar(prefix = '') {
9
+ function appendVar(...vars) {
10
+ if (!vars.length) {
11
+ return '';
12
+ }
13
+
14
+ return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
15
+ }
16
+
17
+ const getThemeVar = (field, ...vars) => {
18
+ return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...vars)})`;
19
+ };
20
+
21
+ return getThemeVar;
22
+ }
@@ -30,7 +30,7 @@ export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = an
30
30
  * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
31
  * // ['palette', 'primary', 'main'] '#000000'
32
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) => void;
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
34
  /**
35
35
  * a function that parse theme and return { css, vars }
36
36
  *
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -9,8 +7,6 @@ exports.assignNestedKeys = void 0;
9
7
  exports.default = cssVarsParser;
10
8
  exports.walkObjectDeep = void 0;
11
9
 
12
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
10
  /**
15
11
  * This function create an object from keys, value and then assign to target
16
12
  *
@@ -59,14 +55,16 @@ const assignNestedKeys = (obj, keys, value) => {
59
55
 
60
56
  exports.assignNestedKeys = assignNestedKeys;
61
57
 
62
- const walkObjectDeep = (obj, callback) => {
58
+ const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
63
59
  function recurse(object, parentKeys = []) {
64
60
  Object.entries(object).forEach(([key, value]) => {
65
- if (value !== undefined && value !== null) {
66
- if (typeof value === 'object' && Object.keys(value).length > 0) {
67
- recurse(value, [...parentKeys, key]);
68
- } else {
69
- callback([...parentKeys, key], value, object);
61
+ if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
62
+ if (value !== undefined && value !== null) {
63
+ if (typeof value === 'object' && Object.keys(value).length > 0) {
64
+ recurse(value, [...parentKeys, key]);
65
+ } else {
66
+ callback([...parentKeys, key], value, object);
67
+ }
70
68
  }
71
69
  }
72
70
  });
@@ -118,9 +116,6 @@ const getCssValue = (keys, value) => {
118
116
 
119
117
 
120
118
  function cssVarsParser(theme, options) {
121
- const clonedTheme = (0, _extends2.default)({}, theme);
122
- delete clonedTheme.vars; // remove 'vars' from the structure
123
-
124
119
  const {
125
120
  prefix,
126
121
  basePrefix = '',
@@ -128,13 +123,18 @@ function cssVarsParser(theme, options) {
128
123
  } = options || {};
129
124
  const css = {};
130
125
  const vars = {};
131
- walkObjectDeep(clonedTheme, (keys, val, scope) => {
126
+ walkObjectDeep(theme, (keys, val, scope) => {
132
127
  if (typeof val === 'string' || typeof val === 'number') {
133
128
  let value = val;
134
129
 
135
130
  if (typeof value === 'string' && value.startsWith('var')) {
136
131
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
137
- value = prefix ? value.replace(basePrefix, prefix) : value.replace(`${basePrefix}-`, ''); // scope is the deepest object in the tree, keys is the theme path keys
132
+ if (!basePrefix && prefix) {
133
+ value = value.replace(/var\(--/g, `var(--${prefix}-`);
134
+ } else {
135
+ value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
136
+ } // scope is the deepest object in the tree, keys is the theme path keys
137
+
138
138
 
139
139
  scope[keys.slice(-1)[0]] = value;
140
140
  }
@@ -148,7 +148,8 @@ function cssVarsParser(theme, options) {
148
148
  assignNestedKeys(vars, keys, `var(${cssVar})`);
149
149
  }
150
150
  }
151
- });
151
+ }, keys => keys[0] === 'vars' // skip 'vars/*' paths
152
+ );
152
153
  return {
153
154
  css,
154
155
  vars
@@ -52,7 +52,7 @@ function getInitColorSchemeScript(options) {
52
52
  colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
53
53
  }
54
54
  if (colorScheme) {
55
- document.body.setAttribute('${attribute}', colorScheme);
55
+ document.documentElement.setAttribute('${attribute}', colorScheme);
56
56
  }
57
57
  } catch (e) {} })();`
58
58
  }
@@ -51,6 +51,21 @@ export default function createBreakpoints(breakpoints) {
51
51
  return up(key);
52
52
  }
53
53
 
54
+ function not(key) {
55
+ // handle first and last key separately, for better readability
56
+ const keyIndex = keys.indexOf(key);
57
+
58
+ if (keyIndex === 0) {
59
+ return up(keys[1]);
60
+ }
61
+
62
+ if (keyIndex === keys.length - 1) {
63
+ return down(keys[keyIndex]);
64
+ }
65
+
66
+ return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
67
+ }
68
+
54
69
  return _extends({
55
70
  keys,
56
71
  values,
@@ -58,6 +73,7 @@ export default function createBreakpoints(breakpoints) {
58
73
  down,
59
74
  between,
60
75
  only,
76
+ not,
61
77
  unit
62
78
  }, other);
63
79
  }