@mui/system 7.0.0-beta.2 → 7.0.0-beta.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/borders/borders.d.ts +3 -2
  3. package/cssGrid/cssGrid.d.ts +15 -2
  4. package/cssVars/createCssVarsProvider.d.ts +12 -0
  5. package/cssVars/createCssVarsProvider.js +21 -4
  6. package/cssVars/index.d.ts +2 -1
  7. package/cssVars/localStorageManager.d.ts +34 -0
  8. package/cssVars/localStorageManager.js +57 -0
  9. package/cssVars/useCurrentColorScheme.d.ts +2 -0
  10. package/cssVars/useCurrentColorScheme.js +50 -69
  11. package/display/display.d.ts +2 -1
  12. package/esm/borders/borders.d.ts +3 -2
  13. package/esm/cssGrid/cssGrid.d.ts +15 -2
  14. package/esm/cssVars/createCssVarsProvider.d.ts +12 -0
  15. package/esm/cssVars/createCssVarsProvider.js +21 -4
  16. package/esm/cssVars/index.d.ts +2 -1
  17. package/esm/cssVars/localStorageManager.d.ts +34 -0
  18. package/esm/cssVars/localStorageManager.js +51 -0
  19. package/esm/cssVars/useCurrentColorScheme.d.ts +2 -0
  20. package/esm/cssVars/useCurrentColorScheme.js +49 -69
  21. package/esm/display/display.d.ts +2 -1
  22. package/esm/flexbox/flexbox.d.ts +2 -1
  23. package/esm/index.d.ts +1 -0
  24. package/esm/index.js +1 -1
  25. package/esm/palette/palette.d.ts +2 -1
  26. package/esm/positions/positions.d.ts +2 -1
  27. package/esm/shadows/shadows.d.ts +2 -1
  28. package/esm/sizing/sizing.d.ts +2 -1
  29. package/esm/spacing/spacing.d.ts +2 -1
  30. package/esm/spacing/spacing.js +9 -0
  31. package/esm/style/style.d.ts +4 -4
  32. package/esm/typography/typography.d.ts +2 -1
  33. package/esm/version/index.js +2 -2
  34. package/flexbox/flexbox.d.ts +2 -1
  35. package/index.d.ts +1 -0
  36. package/index.js +1 -1
  37. package/modern/borders/borders.d.ts +3 -2
  38. package/modern/cssGrid/cssGrid.d.ts +15 -2
  39. package/modern/cssVars/createCssVarsProvider.d.ts +12 -0
  40. package/modern/cssVars/createCssVarsProvider.js +21 -4
  41. package/modern/cssVars/index.d.ts +2 -1
  42. package/modern/cssVars/localStorageManager.d.ts +34 -0
  43. package/modern/cssVars/localStorageManager.js +51 -0
  44. package/modern/cssVars/useCurrentColorScheme.d.ts +2 -0
  45. package/modern/cssVars/useCurrentColorScheme.js +49 -69
  46. package/modern/display/display.d.ts +2 -1
  47. package/modern/flexbox/flexbox.d.ts +2 -1
  48. package/modern/index.d.ts +1 -0
  49. package/modern/index.js +1 -1
  50. package/modern/palette/palette.d.ts +2 -1
  51. package/modern/positions/positions.d.ts +2 -1
  52. package/modern/shadows/shadows.d.ts +2 -1
  53. package/modern/sizing/sizing.d.ts +2 -1
  54. package/modern/spacing/spacing.d.ts +2 -1
  55. package/modern/spacing/spacing.js +9 -0
  56. package/modern/style/style.d.ts +4 -4
  57. package/modern/typography/typography.d.ts +2 -1
  58. package/modern/version/index.js +2 -2
  59. package/package.json +5 -5
  60. package/palette/palette.d.ts +2 -1
  61. package/positions/positions.d.ts +2 -1
  62. package/shadows/shadows.d.ts +2 -1
  63. package/sizing/sizing.d.ts +2 -1
  64. package/spacing/spacing.d.ts +2 -1
  65. package/spacing/spacing.js +9 -0
  66. package/style/style.d.ts +4 -4
  67. package/tsconfig.build.tsbuildinfo +1 -1
  68. package/typography/typography.d.ts +2 -1
  69. package/version/index.js +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,85 @@
1
1
  # [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 7.0.0-beta.4
4
+
5
+ <!-- generated comparing v7.0.0-beta.3..master -->
6
+
7
+ _Mar 13, 2025_
8
+
9
+ A big thanks to the 10 contributors who made this release possible.
10
+ This release contains bug fixes 🐛 and improvements to the new package layout 🏗️.
11
+
12
+ ### `@mui/material@7.0.0-beta.4`
13
+
14
+ - [Accordion] Add missing `root` slot (#45532) @sai6855
15
+ - [AccordionSummary] Add slots and slotProps (#45559) @sai6855
16
+ - [ListItemText] Add missing `root` slot (#45540) @sai6855
17
+ - [SpeedDial] Add missing `root` slot (#45541) @sai6855
18
+ - [Tooltip] Allow auto placement on tooltip (#45399) @Jtaks
19
+ - [useScrollTrigger] Do nothing if target is null (#45441) @vipierozan99
20
+ - [TextareaAutosize] Fix ResizeObserver causing infinite `selectionchange` loop (#45351) @mj12albert
21
+ - Fix negative input for CSS variables spacing array (#45550) @siriwatknp
22
+ - Add missing deprecations in deprecations-all file (#45505) @sai6855
23
+ - Rename some `@mui/material/styles/createTypography` exports (#45558) @Janpot
24
+
25
+ ### `@mui/icons-material@7.0.0-beta.4`
26
+
27
+ - Remove unused icon names from the download script (#45453) @yermartee
28
+
29
+ ### `@mui/system@7.0.0-beta.4`
30
+
31
+ - Prevent nested non-vars theme inheritance (#45545) @siriwatknp
32
+ - Disable theme recalculation as default behavior (#45405) @siriwatknp
33
+ - Fix package layout inconsistencies (#45491) @DiegoAndai
34
+
35
+ ### `@mui/styled-engine@7.0.0-beta.4`
36
+
37
+ - Add `enableCssLayer` prop to StyledEngineProvider (#45428) @siriwatknp
38
+
39
+ ### `@mui/types@7.3.0`
40
+
41
+ - [code-infra] Fix type resolution for @mui/types (#45513) @Janpot
42
+
43
+ ### `@mui/utils@7.0.0-beta.4`
44
+
45
+ - Fix package layout inconsistencies (#45491) @DiegoAndai
46
+ - Use correct iri-reference homepage format (#45472) @dahiro
47
+
48
+ ### Docs
49
+
50
+ - [Backdrop] Fix component name in migration guide (#45506) @sai6855
51
+ - [TextField] Add HTML input section to TextField page (#45439) @siriwatknp
52
+
53
+ ### Core
54
+
55
+ - [code-infra] Convert a few docs modules to ts (#45548) @Janpot
56
+ - [code-infra] Remove more CJS modules from the docs (#45557) @Janpot
57
+ - [code-infra] Remove nested imports from theme augmentation (#45514) @Janpot
58
+ - [docs-infra] Add @ts-ignore to avoid type checking for MUI X (#45555) @siriwatknp
59
+ - [blog] Fix author end-of-year updates (#45533) @oliviertassinari
60
+
61
+ All contributors of this release in alphabetical order: @dahiro, @DiegoAndai, @Janpot, @Jtaks, @mj12albert, @oliviertassinari, @sai6855, @siriwatknp, @vipierozan99, @yermartee
62
+
63
+ ## 7.0.0-beta.3
64
+
65
+ <!-- generated comparing v7.0.0-beta.2..master -->
66
+
67
+ _Mar 5, 2025_
68
+
69
+ A big thanks to the 3 contributors who made this release possible.
70
+
71
+ ### `@mui/material@7.0.0-beta.3`
72
+
73
+ - Fix moduleResolution:node for icons (#45444) @Janpot
74
+ - [ThemeProvider] Add `storageManager` prop to `ThemeProvider` (#45136) @siriwatknp
75
+ - [Radio] Fix `inputProps` not forwarded (#45471) @siriwatknp
76
+
77
+ ### `@mui/codemod@7.0.0-beta.3`
78
+
79
+ - [codemod] Fix codemods not found (#45473) @DiegoAndai
80
+
81
+ All contributors of this release in alphabetical order: @DiegoAndai, @Janpot, @siriwatknp
82
+
3
83
  ## 7.0.0-beta.2
4
84
 
5
85
  <!-- generated comparing v7.0.0-beta.1..master -->
@@ -1,4 +1,4 @@
1
- import { PropsFor, SimpleStyleFunction, borders } from "../Box/index.js";
1
+ import { PropsFor, borders, SimpleStyleFunction } from "../Box/index.js";
2
2
  export const border: SimpleStyleFunction<'border'>;
3
3
  export const borderTop: SimpleStyleFunction<'borderTop'>;
4
4
  export const borderRight: SimpleStyleFunction<'borderRight'>;
@@ -10,4 +10,5 @@ export const borderRightColor: SimpleStyleFunction<'borderRightColor'>;
10
10
  export const borderBottomColor: SimpleStyleFunction<'borderBottomColor'>;
11
11
  export const borderLeftColor: SimpleStyleFunction<'borderLeftColor'>;
12
12
  export const borderRadius: SimpleStyleFunction<'borderRadius'>;
13
- export type BordersProps = PropsFor<typeof borders>;
13
+ export type BordersProps = PropsFor<typeof borders>;
14
+ export default borders;
@@ -1,2 +1,15 @@
1
- import { PropsFor, grid } from "../Box/index.js";
2
- export type CssGridProps = PropsFor<typeof grid>;
1
+ import { PropsFor, grid, SimpleStyleFunction } from "../Box/index.js";
2
+ export const gap: SimpleStyleFunction<'gap'>;
3
+ export const columnGap: SimpleStyleFunction<'columnGap'>;
4
+ export const rowGap: SimpleStyleFunction<'rowGap'>;
5
+ export const gridColumn: SimpleStyleFunction<'gridColumn'>;
6
+ export const gridRow: SimpleStyleFunction<'gridRow'>;
7
+ export const gridAutoFlow: SimpleStyleFunction<'gridAutoFlow'>;
8
+ export const gridAutoColumns: SimpleStyleFunction<'gridAutoColumns'>;
9
+ export const gridAutoRows: SimpleStyleFunction<'gridAutoRows'>;
10
+ export const gridTemplateColumns: SimpleStyleFunction<'gridTemplateColumns'>;
11
+ export const gridTemplateRows: SimpleStyleFunction<'gridTemplateRows'>;
12
+ export const gridTemplateAreas: SimpleStyleFunction<'gridTemplateAreas'>;
13
+ export const gridArea: SimpleStyleFunction<'gridArea'>;
14
+ export type CssGridProps = PropsFor<typeof grid>;
15
+ export default grid;
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import InitColorSchemeScript from "../InitColorSchemeScript/index.js";
3
3
  import { Result } from "./useCurrentColorScheme.js";
4
+ import type { StorageManager } from "./localStorageManager.js";
4
5
  export interface ColorSchemeContextValue<SupportedColorScheme extends string> extends Result<SupportedColorScheme> {
5
6
  allColorSchemes: SupportedColorScheme[];
6
7
  }
@@ -34,6 +35,12 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
34
35
  * @default false
35
36
  */
36
37
  disableTransitionOnChange?: boolean;
38
+ /**
39
+ * If `true`, theme values are recalculated when the mode changes.
40
+ * The `theme.colorSchemes.{mode}.*` nodes will be shallow merged to the top-level of the theme.
41
+ * @default false
42
+ */
43
+ forceThemeRerender?: boolean;
37
44
  }
38
45
  type Identify<I extends string | undefined, T> = I extends string ? T | { [k in I]: T } : T;
39
46
  export interface CreateCssVarsProviderResult<ColorScheme extends string, Identifier extends string | undefined = undefined> {
@@ -60,6 +67,11 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string, Identif
60
67
  * @default document
61
68
  */
62
69
  colorSchemeNode?: Element | null;
70
+ /**
71
+ * The storage manager to be used for storing the mode and color scheme.
72
+ * @default using `window.localStorage`
73
+ */
74
+ storageManager?: StorageManager | null;
63
75
  /**
64
76
  * The window that attaches the 'storage' event listener
65
77
  * @default window
@@ -58,12 +58,14 @@ function createCssVarsProvider(options) {
58
58
  modeStorageKey = defaultModeStorageKey,
59
59
  colorSchemeStorageKey = defaultColorSchemeStorageKey,
60
60
  disableTransitionOnChange = designSystemTransitionOnChange,
61
+ storageManager,
61
62
  storageWindow = typeof window === 'undefined' ? undefined : window,
62
63
  documentNode = typeof document === 'undefined' ? undefined : document,
63
64
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
64
65
  disableNestedContext = false,
65
66
  disableStyleSheetGeneration = false,
66
67
  defaultMode: initialMode = 'system',
68
+ forceThemeRerender = false,
67
69
  noSsr
68
70
  } = props;
69
71
  const hasMounted = React.useRef(false);
@@ -105,6 +107,7 @@ function createCssVarsProvider(options) {
105
107
  modeStorageKey,
106
108
  colorSchemeStorageKey,
107
109
  defaultMode,
110
+ storageManager,
108
111
  storageWindow,
109
112
  noSsr
110
113
  });
@@ -114,10 +117,15 @@ function createCssVarsProvider(options) {
114
117
  mode = ctx.mode;
115
118
  colorScheme = ctx.colorScheme;
116
119
  }
120
+ if (process.env.NODE_ENV !== 'production') {
121
+ if (forceThemeRerender && !restThemeProp.vars) {
122
+ console.warn(['MUI: The `forceThemeRerender` prop should only be used with CSS theme variables.', 'Note that it will slow down the app when changing between modes, so only do this when you cannot find a better solution.'].join('\n'));
123
+ }
124
+ }
125
+ const calculatedColorScheme = forceThemeRerender && restThemeProp.vars ?
126
+ // `colorScheme` is undefined on the server and hydration phase
127
+ colorScheme || restThemeProp.defaultColorScheme : restThemeProp.defaultColorScheme;
117
128
  const memoTheme = React.useMemo(() => {
118
- // `colorScheme` is undefined on the server and hydration phase
119
- const calculatedColorScheme = colorScheme || restThemeProp.defaultColorScheme;
120
-
121
129
  // 2. get the `vars` object that refers to the CSS custom properties
122
130
  const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
123
131
 
@@ -152,7 +160,7 @@ function createCssVarsProvider(options) {
152
160
  }
153
161
  }
154
162
  return resolveTheme ? resolveTheme(theme) : theme;
155
- }, [restThemeProp, colorScheme, components, colorSchemes, cssVarPrefix]);
163
+ }, [restThemeProp, calculatedColorScheme, components, colorSchemes, cssVarPrefix]);
156
164
 
157
165
  // 5. Declaring effects
158
166
  // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
@@ -290,6 +298,10 @@ function createCssVarsProvider(options) {
290
298
  * The document to attach the attribute to.
291
299
  */
292
300
  documentNode: _propTypes.default.any,
301
+ /**
302
+ * If `true`, theme values are recalculated when the mode changes.
303
+ */
304
+ forceThemeRerender: _propTypes.default.bool,
293
305
  /**
294
306
  * The key in the local storage used to store current color scheme.
295
307
  */
@@ -299,6 +311,11 @@ function createCssVarsProvider(options) {
299
311
  * You should use this option in conjuction with `InitColorSchemeScript` component.
300
312
  */
301
313
  noSsr: _propTypes.default.bool,
314
+ /**
315
+ * The storage manager to be used for storing the mode and color scheme
316
+ * @default using `window.localStorage`
317
+ */
318
+ storageManager: _propTypes.default.func,
302
319
  /**
303
320
  * The window that attaches the 'storage' event listener.
304
321
  * @default window
@@ -4,4 +4,5 @@ export { default as prepareCssVars } from "./prepareCssVars.js";
4
4
  export { default as prepareTypographyVars } from "./prepareTypographyVars.js";
5
5
  export type { ExtractTypographyTokens } from "./prepareTypographyVars.js";
6
6
  export { default as createCssVarsTheme } from "./createCssVarsTheme.js";
7
- export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
7
+ export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
8
+ export type { StorageManager } from "./localStorageManager.js";
@@ -0,0 +1,34 @@
1
+ export interface StorageManager {
2
+ (options: {
3
+ key: string;
4
+ storageWindow?: Window | null;
5
+ }): {
6
+ /**
7
+ * Function to get the value from the storage
8
+ * @param defaultValue The default value to be returned if the key is not found
9
+ * @returns The value from the storage or the default value
10
+ */
11
+ get(defaultValue: any): any;
12
+ /**
13
+ * Function to set the value in the storage
14
+ * @param value The value to be set
15
+ * @returns void
16
+ */
17
+ set(value: any): void;
18
+ /**
19
+ * Function to subscribe to the value of the specified key triggered by external events
20
+ * @param handler The function to be called when the value changes
21
+ * @returns A function to unsubscribe the handler
22
+ * @example
23
+ * React.useEffect(() => {
24
+ * const unsubscribe = storageManager.subscribe((value) => {
25
+ * console.log(value);
26
+ * });
27
+ * return unsubscribe;
28
+ * }, []);
29
+ */
30
+ subscribe(handler: (value: any) => void): () => void;
31
+ };
32
+ }
33
+ declare const localStorageManager: StorageManager;
34
+ export default localStorageManager;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function noop() {}
8
+ const localStorageManager = ({
9
+ key,
10
+ storageWindow
11
+ }) => {
12
+ if (!storageWindow && typeof window !== 'undefined') {
13
+ storageWindow = window;
14
+ }
15
+ return {
16
+ get(defaultValue) {
17
+ if (typeof window === 'undefined') {
18
+ return undefined;
19
+ }
20
+ if (!storageWindow) {
21
+ return defaultValue;
22
+ }
23
+ let value;
24
+ try {
25
+ value = storageWindow.localStorage.getItem(key);
26
+ } catch {
27
+ // Unsupported
28
+ }
29
+ return value || defaultValue;
30
+ },
31
+ set: value => {
32
+ if (storageWindow) {
33
+ try {
34
+ storageWindow.localStorage.setItem(key, value);
35
+ } catch {
36
+ // Unsupported
37
+ }
38
+ }
39
+ },
40
+ subscribe: handler => {
41
+ if (!storageWindow) {
42
+ return noop;
43
+ }
44
+ const listener = event => {
45
+ const value = event.newValue;
46
+ if (event.key === key) {
47
+ handler(value);
48
+ }
49
+ };
50
+ storageWindow.addEventListener('storage', listener);
51
+ return () => {
52
+ storageWindow.removeEventListener('storage', listener);
53
+ };
54
+ }
55
+ };
56
+ };
57
+ var _default = exports.default = localStorageManager;
@@ -1,3 +1,4 @@
1
+ import type { StorageManager } from "./localStorageManager.js";
1
2
  export type Mode = 'light' | 'dark' | 'system';
2
3
  export type SystemMode = Exclude<Mode, 'system'>;
3
4
  export interface State<SupportedColorScheme extends string> {
@@ -48,6 +49,7 @@ interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
48
49
  modeStorageKey?: string;
49
50
  colorSchemeStorageKey?: string;
50
51
  storageWindow?: Window | null;
52
+ storageManager?: StorageManager | null;
51
53
  noSsr?: boolean;
52
54
  }
53
55
  export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
5
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
6
  Object.defineProperty(exports, "__esModule", {
6
7
  value: true
@@ -10,6 +11,8 @@ exports.getColorScheme = getColorScheme;
10
11
  exports.getSystemMode = getSystemMode;
11
12
  var React = _interopRequireWildcard(require("react"));
12
13
  var _InitColorSchemeScript = require("../InitColorSchemeScript/InitColorSchemeScript");
14
+ var _localStorageManager = _interopRequireDefault(require("./localStorageManager"));
15
+ function noop() {}
13
16
  function getSystemMode(mode) {
14
17
  if (typeof window !== 'undefined' && typeof window.matchMedia === 'function' && mode === 'system') {
15
18
  const mql = window.matchMedia('(prefers-color-scheme: dark)');
@@ -40,22 +43,6 @@ function getColorScheme(state) {
40
43
  return undefined;
41
44
  });
42
45
  }
43
- function initializeValue(key, defaultValue) {
44
- if (typeof window === 'undefined') {
45
- return undefined;
46
- }
47
- let value;
48
- try {
49
- value = localStorage.getItem(key) || undefined;
50
- if (!value) {
51
- // the first time that user enters the site.
52
- localStorage.setItem(key, defaultValue);
53
- }
54
- } catch {
55
- // Unsupported
56
- }
57
- return value || defaultValue;
58
- }
59
46
  function useCurrentColorScheme(options) {
60
47
  const {
61
48
  defaultMode = 'light',
@@ -65,14 +52,27 @@ function useCurrentColorScheme(options) {
65
52
  modeStorageKey = _InitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
66
53
  colorSchemeStorageKey = _InitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY,
67
54
  storageWindow = typeof window === 'undefined' ? undefined : window,
55
+ storageManager = _localStorageManager.default,
68
56
  noSsr = false
69
57
  } = options;
70
58
  const joinedColorSchemes = supportedColorSchemes.join(',');
71
59
  const isMultiSchemes = supportedColorSchemes.length > 1;
60
+ const modeStorage = React.useMemo(() => storageManager?.({
61
+ key: modeStorageKey,
62
+ storageWindow
63
+ }), [storageManager, modeStorageKey, storageWindow]);
64
+ const lightStorage = React.useMemo(() => storageManager?.({
65
+ key: `${colorSchemeStorageKey}-light`,
66
+ storageWindow
67
+ }), [storageManager, colorSchemeStorageKey, storageWindow]);
68
+ const darkStorage = React.useMemo(() => storageManager?.({
69
+ key: `${colorSchemeStorageKey}-dark`,
70
+ storageWindow
71
+ }), [storageManager, colorSchemeStorageKey, storageWindow]);
72
72
  const [state, setState] = React.useState(() => {
73
- const initialMode = initializeValue(modeStorageKey, defaultMode);
74
- const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
75
- const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
73
+ const initialMode = modeStorage?.get(defaultMode) || defaultMode;
74
+ const lightColorScheme = lightStorage?.get(defaultLightColorScheme) || defaultLightColorScheme;
75
+ const darkColorScheme = darkStorage?.get(defaultDarkColorScheme) || defaultDarkColorScheme;
76
76
  return {
77
77
  mode: initialMode,
78
78
  systemMode: getSystemMode(initialMode),
@@ -92,27 +92,19 @@ function useCurrentColorScheme(options) {
92
92
  return currentState;
93
93
  }
94
94
  const newMode = mode ?? defaultMode;
95
- try {
96
- localStorage.setItem(modeStorageKey, newMode);
97
- } catch {
98
- // Unsupported
99
- }
95
+ modeStorage?.set(newMode);
100
96
  return {
101
97
  ...currentState,
102
98
  mode: newMode,
103
99
  systemMode: getSystemMode(newMode)
104
100
  };
105
101
  });
106
- }, [modeStorageKey, defaultMode]);
102
+ }, [modeStorage, defaultMode]);
107
103
  const setColorScheme = React.useCallback(value => {
108
104
  if (!value) {
109
105
  setState(currentState => {
110
- try {
111
- localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
112
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
113
- } catch {
114
- // Unsupported
115
- }
106
+ lightStorage?.set(defaultLightColorScheme);
107
+ darkStorage?.set(defaultDarkColorScheme);
116
108
  return {
117
109
  ...currentState,
118
110
  lightColorScheme: defaultLightColorScheme,
@@ -128,15 +120,12 @@ function useCurrentColorScheme(options) {
128
120
  ...currentState
129
121
  };
130
122
  processState(currentState, mode => {
131
- try {
132
- localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
133
- } catch {
134
- // Unsupported
135
- }
136
123
  if (mode === 'light') {
124
+ lightStorage?.set(value);
137
125
  newState.lightColorScheme = value;
138
126
  }
139
127
  if (mode === 'dark') {
128
+ darkStorage?.set(value);
140
129
  newState.darkColorScheme = value;
141
130
  }
142
131
  });
@@ -155,11 +144,7 @@ function useCurrentColorScheme(options) {
155
144
  console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
156
145
  } else {
157
146
  newState.lightColorScheme = newLightColorScheme;
158
- try {
159
- localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
160
- } catch (error) {
161
- // Unsupported
162
- }
147
+ lightStorage?.set(newLightColorScheme);
163
148
  }
164
149
  }
165
150
  if (newDarkColorScheme) {
@@ -167,17 +152,13 @@ function useCurrentColorScheme(options) {
167
152
  console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
168
153
  } else {
169
154
  newState.darkColorScheme = newDarkColorScheme;
170
- try {
171
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
172
- } catch (error) {
173
- // Unsupported
174
- }
155
+ darkStorage?.set(newDarkColorScheme);
175
156
  }
176
157
  }
177
158
  return newState;
178
159
  });
179
160
  }
180
- }, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
161
+ }, [joinedColorSchemes, lightStorage, darkStorage, defaultLightColorScheme, defaultDarkColorScheme]);
181
162
  const handleMediaQuery = React.useCallback(event => {
182
163
  if (state.mode === 'system') {
183
164
  setState(currentState => {
@@ -217,34 +198,34 @@ function useCurrentColorScheme(options) {
217
198
 
218
199
  // Handle when localStorage has changed
219
200
  React.useEffect(() => {
220
- if (storageWindow && isMultiSchemes) {
221
- const handleStorage = event => {
222
- const value = event.newValue;
223
- if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
224
- // If the key is deleted, value will be null then reset color scheme to the default one.
225
- if (event.key.endsWith('light')) {
226
- setColorScheme({
227
- light: value
228
- });
229
- }
230
- if (event.key.endsWith('dark')) {
231
- setColorScheme({
232
- dark: value
233
- });
234
- }
235
- }
236
- if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
201
+ if (isMultiSchemes) {
202
+ const unsubscribeMode = modeStorage?.subscribe(value => {
203
+ if (!value || ['light', 'dark', 'system'].includes(value)) {
237
204
  setMode(value || defaultMode);
238
205
  }
239
- };
240
- // For syncing color-scheme changes between iframes
241
- storageWindow.addEventListener('storage', handleStorage);
206
+ }) || noop;
207
+ const unsubscribeLight = lightStorage?.subscribe(value => {
208
+ if (!value || joinedColorSchemes.match(value)) {
209
+ setColorScheme({
210
+ light: value
211
+ });
212
+ }
213
+ }) || noop;
214
+ const unsubscribeDark = darkStorage?.subscribe(value => {
215
+ if (!value || joinedColorSchemes.match(value)) {
216
+ setColorScheme({
217
+ dark: value
218
+ });
219
+ }
220
+ }) || noop;
242
221
  return () => {
243
- storageWindow.removeEventListener('storage', handleStorage);
222
+ unsubscribeMode();
223
+ unsubscribeLight();
224
+ unsubscribeDark();
244
225
  };
245
226
  }
246
227
  return undefined;
247
- }, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes]);
228
+ }, [setColorScheme, setMode, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes, modeStorage, lightStorage, darkStorage]);
248
229
  return {
249
230
  ...state,
250
231
  mode: isClient ? state.mode : undefined,
@@ -1,2 +1,3 @@
1
1
  import { PropsFor, display } from "../Box/index.js";
2
- export type DisplayProps = PropsFor<typeof display>;
2
+ export type DisplayProps = PropsFor<typeof display>;
3
+ export default display;
@@ -1,4 +1,4 @@
1
- import { PropsFor, SimpleStyleFunction, borders } from "../Box/index.js";
1
+ import { PropsFor, borders, SimpleStyleFunction } from "../Box/index.js";
2
2
  export const border: SimpleStyleFunction<'border'>;
3
3
  export const borderTop: SimpleStyleFunction<'borderTop'>;
4
4
  export const borderRight: SimpleStyleFunction<'borderRight'>;
@@ -10,4 +10,5 @@ export const borderRightColor: SimpleStyleFunction<'borderRightColor'>;
10
10
  export const borderBottomColor: SimpleStyleFunction<'borderBottomColor'>;
11
11
  export const borderLeftColor: SimpleStyleFunction<'borderLeftColor'>;
12
12
  export const borderRadius: SimpleStyleFunction<'borderRadius'>;
13
- export type BordersProps = PropsFor<typeof borders>;
13
+ export type BordersProps = PropsFor<typeof borders>;
14
+ export default borders;
@@ -1,2 +1,15 @@
1
- import { PropsFor, grid } from "../Box/index.js";
2
- export type CssGridProps = PropsFor<typeof grid>;
1
+ import { PropsFor, grid, SimpleStyleFunction } from "../Box/index.js";
2
+ export const gap: SimpleStyleFunction<'gap'>;
3
+ export const columnGap: SimpleStyleFunction<'columnGap'>;
4
+ export const rowGap: SimpleStyleFunction<'rowGap'>;
5
+ export const gridColumn: SimpleStyleFunction<'gridColumn'>;
6
+ export const gridRow: SimpleStyleFunction<'gridRow'>;
7
+ export const gridAutoFlow: SimpleStyleFunction<'gridAutoFlow'>;
8
+ export const gridAutoColumns: SimpleStyleFunction<'gridAutoColumns'>;
9
+ export const gridAutoRows: SimpleStyleFunction<'gridAutoRows'>;
10
+ export const gridTemplateColumns: SimpleStyleFunction<'gridTemplateColumns'>;
11
+ export const gridTemplateRows: SimpleStyleFunction<'gridTemplateRows'>;
12
+ export const gridTemplateAreas: SimpleStyleFunction<'gridTemplateAreas'>;
13
+ export const gridArea: SimpleStyleFunction<'gridArea'>;
14
+ export type CssGridProps = PropsFor<typeof grid>;
15
+ export default grid;
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import InitColorSchemeScript from "../InitColorSchemeScript/index.js";
3
3
  import { Result } from "./useCurrentColorScheme.js";
4
+ import type { StorageManager } from "./localStorageManager.js";
4
5
  export interface ColorSchemeContextValue<SupportedColorScheme extends string> extends Result<SupportedColorScheme> {
5
6
  allColorSchemes: SupportedColorScheme[];
6
7
  }
@@ -34,6 +35,12 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
34
35
  * @default false
35
36
  */
36
37
  disableTransitionOnChange?: boolean;
38
+ /**
39
+ * If `true`, theme values are recalculated when the mode changes.
40
+ * The `theme.colorSchemes.{mode}.*` nodes will be shallow merged to the top-level of the theme.
41
+ * @default false
42
+ */
43
+ forceThemeRerender?: boolean;
37
44
  }
38
45
  type Identify<I extends string | undefined, T> = I extends string ? T | { [k in I]: T } : T;
39
46
  export interface CreateCssVarsProviderResult<ColorScheme extends string, Identifier extends string | undefined = undefined> {
@@ -60,6 +67,11 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string, Identif
60
67
  * @default document
61
68
  */
62
69
  colorSchemeNode?: Element | null;
70
+ /**
71
+ * The storage manager to be used for storing the mode and color scheme.
72
+ * @default using `window.localStorage`
73
+ */
74
+ storageManager?: StorageManager | null;
63
75
  /**
64
76
  * The window that attaches the 'storage' event listener
65
77
  * @default window