Skip to content

Commit

Permalink
[system] Remove getInitColorSchemeScript leading spaces (mui#38794)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored and xcode-it committed Sep 11, 2023
1 parent 7e8e1a2 commit 4fd7797
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions packages/mui-system/src/cssVars/getInitColorSchemeScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,32 @@ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScr
key="mui-color-scheme-init"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `(function() { try {
var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
var cssColorScheme = mode;
var colorScheme = '';
if (mode === 'system') {
// handle system mode
var mql = window.matchMedia('(prefers-color-scheme: dark)');
if (mql.matches) {
cssColorScheme = 'dark';
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
} else {
cssColorScheme = 'light';
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
}
}
if (mode === 'light') {
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
}
if (mode === 'dark') {
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
}
if (colorScheme) {
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
}
} catch (e) {} })();`,
__html: `(function() {
try {
var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
var cssColorScheme = mode;
var colorScheme = '';
if (mode === 'system') {
// handle system mode
var mql = window.matchMedia('(prefers-color-scheme: dark)');
if (mql.matches) {
cssColorScheme = 'dark';
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
} else {
cssColorScheme = 'light';
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
}
}
if (mode === 'light') {
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
}
if (mode === 'dark') {
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
}
if (colorScheme) {
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
}
} catch (e) {} })();`,
}}
/>
);
Expand Down

0 comments on commit 4fd7797

Please sign in to comment.