@mui/system 5.10.2 → 5.10.3

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 (36) hide show
  1. package/Box/Box.d.ts +10 -10
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/CHANGELOG.md +62 -0
  4. package/Container/Container.d.ts +13 -13
  5. package/Container/ContainerProps.d.ts +40 -40
  6. package/Container/containerClasses.d.ts +22 -22
  7. package/Container/createContainer.d.ts +18 -18
  8. package/Stack/Stack.d.ts +12 -12
  9. package/Stack/StackProps.d.ts +42 -42
  10. package/Stack/createStack.d.ts +21 -21
  11. package/Stack/index.d.ts +5 -5
  12. package/Stack/stackClasses.d.ts +8 -8
  13. package/Unstable_Grid/Grid.d.ts +12 -12
  14. package/Unstable_Grid/GridProps.d.ts +162 -162
  15. package/Unstable_Grid/createGrid.d.ts +11 -11
  16. package/Unstable_Grid/gridClasses.d.ts +20 -20
  17. package/Unstable_Grid/gridGenerator.d.ts +26 -26
  18. package/Unstable_Grid/index.d.ts +5 -5
  19. package/createBox.spec.d.ts +1 -1
  20. package/createTheme/createSpacing.d.ts +10 -10
  21. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  22. package/cssVars/createGetCssVar.d.ts +5 -5
  23. package/cssVars/cssVarsParser.d.ts +65 -65
  24. package/cssVars/getInitColorSchemeScript.d.ts +45 -45
  25. package/cssVars/index.d.ts +3 -3
  26. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  27. package/cssVars/useCurrentColorScheme.js +53 -52
  28. package/esm/cssVars/useCurrentColorScheme.js +54 -51
  29. package/index.js +1 -1
  30. package/index.spec.d.ts +1 -1
  31. package/legacy/cssVars/useCurrentColorScheme.js +54 -51
  32. package/legacy/index.js +1 -1
  33. package/modern/cssVars/useCurrentColorScheme.js +54 -51
  34. package/modern/index.js +1 -1
  35. package/package.json +6 -6
  36. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -1,45 +1,45 @@
1
- /// <reference types="react" />
2
- export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
3
- export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
4
- export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
5
- export interface GetInitColorSchemeScriptOptions {
6
- /**
7
- * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
8
- * @default true
9
- */
10
- enableColorScheme?: boolean;
11
- /**
12
- * If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
13
- * @default false
14
- */
15
- enableSystem?: boolean;
16
- /**
17
- * The default color scheme to be used on the light mode
18
- */
19
- defaultLightColorScheme?: string;
20
- /**
21
- * The default color scheme to be used on the dark mode
22
- */
23
- defaultDarkColorScheme?: string;
24
- /**
25
- * The node (provided as string) used to attach the color-scheme attribute
26
- * @default 'document.documentElement'
27
- */
28
- colorSchemeNode?: string;
29
- /**
30
- * localStorage key used to store `mode`
31
- * @default 'mode'
32
- */
33
- modeStorageKey?: string;
34
- /**
35
- * localStorage key used to store `colorScheme`
36
- * @default 'color-scheme'
37
- */
38
- colorSchemeStorageKey?: string;
39
- /**
40
- * DOM attribute for applying color scheme
41
- * @default 'data-color-scheme'
42
- */
43
- attribute?: string;
44
- }
45
- export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
3
+ export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
4
+ export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
5
+ export interface GetInitColorSchemeScriptOptions {
6
+ /**
7
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
8
+ * @default true
9
+ */
10
+ enableColorScheme?: boolean;
11
+ /**
12
+ * If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
13
+ * @default false
14
+ */
15
+ enableSystem?: boolean;
16
+ /**
17
+ * The default color scheme to be used on the light mode
18
+ */
19
+ defaultLightColorScheme?: string;
20
+ /**
21
+ * The default color scheme to be used on the dark mode
22
+ */
23
+ defaultDarkColorScheme?: string;
24
+ /**
25
+ * The node (provided as string) used to attach the color-scheme attribute
26
+ * @default 'document.documentElement'
27
+ */
28
+ colorSchemeNode?: string;
29
+ /**
30
+ * localStorage key used to store `mode`
31
+ * @default 'mode'
32
+ */
33
+ modeStorageKey?: string;
34
+ /**
35
+ * localStorage key used to store `colorScheme`
36
+ * @default 'color-scheme'
37
+ */
38
+ colorSchemeStorageKey?: string;
39
+ /**
40
+ * DOM attribute for applying color scheme
41
+ * @default 'data-color-scheme'
42
+ */
43
+ attribute?: string;
44
+ }
45
+ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
@@ -1,3 +1,3 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
- export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
1
+ export { default } from './createCssVarsProvider';
2
+ export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
+ export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
@@ -1,53 +1,53 @@
1
- export declare type Mode = 'light' | 'dark' | 'system';
2
- export declare type SystemMode = Exclude<Mode, 'system'>;
3
- export interface State<SupportedColorScheme extends string> {
4
- /**
5
- * User selected mode.
6
- * Note: on the server, mode is always undefined
7
- */
8
- mode: Mode | undefined;
9
- /**
10
- * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
- */
12
- systemMode: SystemMode | undefined;
13
- /**
14
- * The color scheme for the light mode.
15
- */
16
- lightColorScheme: SupportedColorScheme;
17
- /**
18
- * The color scheme for the dark mode.
19
- */
20
- darkColorScheme: SupportedColorScheme;
21
- }
22
- export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
- /**
24
- * The current application color scheme. It is always `undefined` on the server.
25
- */
26
- colorScheme: SupportedColorScheme | undefined;
27
- /**
28
- * `mode` is saved to internal state and localStorage
29
- * If `mode` is null, it will be reset to the defaultMode
30
- */
31
- setMode: (mode: Mode | null) => void;
32
- /**
33
- * `colorScheme` is saved to internal state and localStorage
34
- * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
- */
36
- setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
- light: SupportedColorScheme | null;
38
- dark: SupportedColorScheme | null;
39
- }> | null) => void;
40
- };
41
- export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
- export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
- interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
44
- defaultLightColorScheme: SupportedColorScheme;
45
- defaultDarkColorScheme: SupportedColorScheme;
46
- supportedColorSchemes: Array<SupportedColorScheme>;
47
- defaultMode?: Mode;
48
- modeStorageKey?: string;
49
- colorSchemeStorageKey?: string;
50
- storageWindow?: Window | null;
51
- }
52
- export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
53
- export {};
1
+ export declare type Mode = 'light' | 'dark' | 'system';
2
+ export declare type SystemMode = Exclude<Mode, 'system'>;
3
+ export interface State<SupportedColorScheme extends string> {
4
+ /**
5
+ * User selected mode.
6
+ * Note: on the server, mode is always undefined
7
+ */
8
+ mode: Mode | undefined;
9
+ /**
10
+ * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
+ */
12
+ systemMode: SystemMode | undefined;
13
+ /**
14
+ * The color scheme for the light mode.
15
+ */
16
+ lightColorScheme: SupportedColorScheme;
17
+ /**
18
+ * The color scheme for the dark mode.
19
+ */
20
+ darkColorScheme: SupportedColorScheme;
21
+ }
22
+ export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
+ /**
24
+ * The current application color scheme. It is always `undefined` on the server.
25
+ */
26
+ colorScheme: SupportedColorScheme | undefined;
27
+ /**
28
+ * `mode` is saved to internal state and localStorage
29
+ * If `mode` is null, it will be reset to the defaultMode
30
+ */
31
+ setMode: (mode: Mode | null) => void;
32
+ /**
33
+ * `colorScheme` is saved to internal state and localStorage
34
+ * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
+ */
36
+ setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
+ light: SupportedColorScheme | null;
38
+ dark: SupportedColorScheme | null;
39
+ }> | null) => void;
40
+ };
41
+ export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
+ export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
+ interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
44
+ defaultLightColorScheme: SupportedColorScheme;
45
+ defaultDarkColorScheme: SupportedColorScheme;
46
+ supportedColorSchemes: Array<SupportedColorScheme>;
47
+ defaultMode?: Mode;
48
+ modeStorageKey?: string;
49
+ colorSchemeStorageKey?: string;
50
+ storageWindow?: Window | null;
51
+ }
52
+ export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
53
+ export {};
@@ -59,7 +59,7 @@ function getColorScheme(state) {
59
59
  });
60
60
  }
61
61
 
62
- function resolveValue(key, defaultValue) {
62
+ function initializeValue(key, defaultValue) {
63
63
  if (typeof window === 'undefined') {
64
64
  return undefined;
65
65
  }
@@ -68,6 +68,11 @@ function resolveValue(key, defaultValue) {
68
68
 
69
69
  try {
70
70
  value = localStorage.getItem(key) || undefined;
71
+
72
+ if (!value) {
73
+ // the first time that user enters the site.
74
+ localStorage.setItem(key, defaultValue);
75
+ }
71
76
  } catch (e) {// Unsupported
72
77
  }
73
78
 
@@ -86,23 +91,26 @@ function useCurrentColorScheme(options) {
86
91
  } = options;
87
92
  const joinedColorSchemes = supportedColorSchemes.join(',');
88
93
  const [state, setState] = React.useState(() => {
89
- const initialMode = resolveValue(modeStorageKey, defaultMode);
94
+ const initialMode = initializeValue(modeStorageKey, defaultMode);
95
+ const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
96
+ const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
90
97
  return {
91
98
  mode: initialMode,
92
99
  systemMode: getSystemMode(initialMode),
93
- lightColorScheme: resolveValue(`${colorSchemeStorageKey}-light`) || defaultLightColorScheme,
94
- darkColorScheme: resolveValue(`${colorSchemeStorageKey}-dark`) || defaultDarkColorScheme
100
+ lightColorScheme,
101
+ darkColorScheme
95
102
  };
96
103
  });
97
104
  const colorScheme = getColorScheme(state);
98
105
  const setMode = React.useCallback(mode => {
99
106
  setState(currentState => {
100
- const newMode = !mode ? defaultMode : mode;
101
-
102
107
  if (mode === currentState.mode) {
108
+ // do nothing if mode does not change
103
109
  return currentState;
104
110
  }
105
111
 
112
+ const newMode = !mode ? defaultMode : mode;
113
+
106
114
  try {
107
115
  localStorage.setItem(modeStorageKey, newMode);
108
116
  } catch (e) {// Unsupported
@@ -115,20 +123,25 @@ function useCurrentColorScheme(options) {
115
123
  });
116
124
  }, [modeStorageKey, defaultMode]);
117
125
  const setColorScheme = React.useCallback(value => {
118
- if (!value || typeof value === 'string') {
126
+ if (!value) {
127
+ setState(currentState => {
128
+ try {
129
+ localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
130
+ localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
131
+ } catch (e) {// Unsupported
132
+ }
133
+
134
+ return (0, _extends2.default)({}, currentState, {
135
+ lightColorScheme: defaultLightColorScheme,
136
+ darkColorScheme: defaultDarkColorScheme
137
+ });
138
+ });
139
+ } else if (typeof value === 'string') {
119
140
  if (value && !joinedColorSchemes.includes(value)) {
120
141
  console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
121
142
  } else {
122
143
  setState(currentState => {
123
144
  const newState = (0, _extends2.default)({}, currentState);
124
-
125
- if (!value) {
126
- // reset to default color scheme
127
- newState.lightColorScheme = defaultLightColorScheme;
128
- newState.darkColorScheme = defaultDarkColorScheme;
129
- return newState;
130
- }
131
-
132
145
  processState(currentState, mode => {
133
146
  try {
134
147
  localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
@@ -146,33 +159,40 @@ function useCurrentColorScheme(options) {
146
159
  return newState;
147
160
  });
148
161
  }
149
- } else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
150
- console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
151
162
  } else {
152
163
  setState(currentState => {
153
164
  const newState = (0, _extends2.default)({}, currentState);
165
+ const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
166
+ const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
154
167
 
155
- if (value.light || value.light === null) {
156
- newState.lightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
157
- }
168
+ if (newLightColorScheme) {
169
+ if (!joinedColorSchemes.includes(newLightColorScheme)) {
170
+ console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
171
+ } else {
172
+ newState.lightColorScheme = newLightColorScheme;
158
173
 
159
- if (value.dark || value.dark === null) {
160
- newState.darkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
174
+ try {
175
+ localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
176
+ } catch (error) {// Unsupported
177
+ }
178
+ }
161
179
  }
162
180
 
163
- return newState;
164
- });
181
+ if (newDarkColorScheme) {
182
+ if (!joinedColorSchemes.includes(newDarkColorScheme)) {
183
+ console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
184
+ } else {
185
+ newState.darkColorScheme = newDarkColorScheme;
165
186
 
166
- try {
167
- if (value.light) {
168
- localStorage.setItem(`${colorSchemeStorageKey}-light`, value.light);
187
+ try {
188
+ localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
189
+ } catch (error) {// Unsupported
190
+ }
191
+ }
169
192
  }
170
193
 
171
- if (value.dark) {
172
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, value.dark);
173
- }
174
- } catch (e) {// Unsupported
175
- }
194
+ return newState;
195
+ });
176
196
  }
177
197
  }, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
178
198
  const handleMediaQuery = React.useCallback(e => {
@@ -194,26 +214,7 @@ function useCurrentColorScheme(options) {
194
214
  media.addListener(handler);
195
215
  handler(media);
196
216
  return () => media.removeListener(handler);
197
- }, []); // Save mode, lightColorScheme & darkColorScheme to localStorage
198
-
199
- React.useEffect(() => {
200
- try {
201
- if (state.mode) {
202
- localStorage.setItem(modeStorageKey, state.mode);
203
- }
204
-
205
- processState(state, mode => {
206
- if (mode === 'light') {
207
- localStorage.setItem(`${colorSchemeStorageKey}-light`, state.lightColorScheme);
208
- }
209
-
210
- if (mode === 'dark') {
211
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, state.darkColorScheme);
212
- }
213
- });
214
- } catch (e) {// Unsupported
215
- }
216
- }, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
217
+ }, []); // Handle when localStorage has changed
217
218
 
218
219
  React.useEffect(() => {
219
220
  const handleStorage = event => {
@@ -41,7 +41,7 @@ export function getColorScheme(state) {
41
41
  });
42
42
  }
43
43
 
44
- function resolveValue(key, defaultValue) {
44
+ function initializeValue(key, defaultValue) {
45
45
  if (typeof window === 'undefined') {
46
46
  return undefined;
47
47
  }
@@ -50,6 +50,11 @@ function resolveValue(key, defaultValue) {
50
50
 
51
51
  try {
52
52
  value = localStorage.getItem(key) || undefined;
53
+
54
+ if (!value) {
55
+ // the first time that user enters the site.
56
+ localStorage.setItem(key, defaultValue);
57
+ }
53
58
  } catch (e) {// Unsupported
54
59
  }
55
60
 
@@ -68,23 +73,26 @@ export default function useCurrentColorScheme(options) {
68
73
  } = options;
69
74
  const joinedColorSchemes = supportedColorSchemes.join(',');
70
75
  const [state, setState] = React.useState(() => {
71
- const initialMode = resolveValue(modeStorageKey, defaultMode);
76
+ const initialMode = initializeValue(modeStorageKey, defaultMode);
77
+ const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
78
+ const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
72
79
  return {
73
80
  mode: initialMode,
74
81
  systemMode: getSystemMode(initialMode),
75
- lightColorScheme: resolveValue(`${colorSchemeStorageKey}-light`) || defaultLightColorScheme,
76
- darkColorScheme: resolveValue(`${colorSchemeStorageKey}-dark`) || defaultDarkColorScheme
82
+ lightColorScheme,
83
+ darkColorScheme
77
84
  };
78
85
  });
79
86
  const colorScheme = getColorScheme(state);
80
87
  const setMode = React.useCallback(mode => {
81
88
  setState(currentState => {
82
- const newMode = !mode ? defaultMode : mode;
83
-
84
89
  if (mode === currentState.mode) {
90
+ // do nothing if mode does not change
85
91
  return currentState;
86
92
  }
87
93
 
94
+ const newMode = !mode ? defaultMode : mode;
95
+
88
96
  try {
89
97
  localStorage.setItem(modeStorageKey, newMode);
90
98
  } catch (e) {// Unsupported
@@ -97,20 +105,26 @@ export default function useCurrentColorScheme(options) {
97
105
  });
98
106
  }, [modeStorageKey, defaultMode]);
99
107
  const setColorScheme = React.useCallback(value => {
100
- if (!value || typeof value === 'string') {
108
+ if (!value) {
109
+ setState(currentState => {
110
+ try {
111
+ localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
112
+ localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
113
+ } catch (e) {// Unsupported
114
+ }
115
+
116
+ return _extends({}, currentState, {
117
+ lightColorScheme: defaultLightColorScheme,
118
+ darkColorScheme: defaultDarkColorScheme
119
+ });
120
+ });
121
+ } else if (typeof value === 'string') {
101
122
  if (value && !joinedColorSchemes.includes(value)) {
102
123
  console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
103
124
  } else {
104
125
  setState(currentState => {
105
126
  const newState = _extends({}, currentState);
106
127
 
107
- if (!value) {
108
- // reset to default color scheme
109
- newState.lightColorScheme = defaultLightColorScheme;
110
- newState.darkColorScheme = defaultDarkColorScheme;
111
- return newState;
112
- }
113
-
114
128
  processState(currentState, mode => {
115
129
  try {
116
130
  localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
@@ -128,33 +142,41 @@ export default function useCurrentColorScheme(options) {
128
142
  return newState;
129
143
  });
130
144
  }
131
- } else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
132
- console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
133
145
  } else {
134
146
  setState(currentState => {
135
147
  const newState = _extends({}, currentState);
136
148
 
137
- if (value.light || value.light === null) {
138
- newState.lightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
139
- }
149
+ const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
150
+ const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
151
+
152
+ if (newLightColorScheme) {
153
+ if (!joinedColorSchemes.includes(newLightColorScheme)) {
154
+ console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
155
+ } else {
156
+ newState.lightColorScheme = newLightColorScheme;
140
157
 
141
- if (value.dark || value.dark === null) {
142
- newState.darkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
158
+ try {
159
+ localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
160
+ } catch (error) {// Unsupported
161
+ }
162
+ }
143
163
  }
144
164
 
145
- return newState;
146
- });
165
+ if (newDarkColorScheme) {
166
+ if (!joinedColorSchemes.includes(newDarkColorScheme)) {
167
+ console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
168
+ } else {
169
+ newState.darkColorScheme = newDarkColorScheme;
147
170
 
148
- try {
149
- if (value.light) {
150
- localStorage.setItem(`${colorSchemeStorageKey}-light`, value.light);
171
+ try {
172
+ localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
173
+ } catch (error) {// Unsupported
174
+ }
175
+ }
151
176
  }
152
177
 
153
- if (value.dark) {
154
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, value.dark);
155
- }
156
- } catch (e) {// Unsupported
157
- }
178
+ return newState;
179
+ });
158
180
  }
159
181
  }, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
160
182
  const handleMediaQuery = React.useCallback(e => {
@@ -176,26 +198,7 @@ export default function useCurrentColorScheme(options) {
176
198
  media.addListener(handler);
177
199
  handler(media);
178
200
  return () => media.removeListener(handler);
179
- }, []); // Save mode, lightColorScheme & darkColorScheme to localStorage
180
-
181
- React.useEffect(() => {
182
- try {
183
- if (state.mode) {
184
- localStorage.setItem(modeStorageKey, state.mode);
185
- }
186
-
187
- processState(state, mode => {
188
- if (mode === 'light') {
189
- localStorage.setItem(`${colorSchemeStorageKey}-light`, state.lightColorScheme);
190
- }
191
-
192
- if (mode === 'dark') {
193
- localStorage.setItem(`${colorSchemeStorageKey}-dark`, state.darkColorScheme);
194
- }
195
- });
196
- } catch (e) {// Unsupported
197
- }
198
- }, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
201
+ }, []); // Handle when localStorage has changed
199
202
 
200
203
  React.useEffect(() => {
201
204
  const handleStorage = event => {
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.10.2
1
+ /** @license MUI v5.10.3
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};