Skip to content

Commit

Permalink
[system] Remove getInitColorSchemeScript leading spaces (#38794)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Sep 10, 2023
1 parent 19fd760 commit 8dd133f
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 8dd133f

Please sign in to comment.