Change setting dark mode to use Bootstrap's data-bs-theme attribute

This commit is contained in:
Dominik Mielcarek 2023-09-12 22:03:43 +02:00 committed by shamoon
parent d1292c59ea
commit 8e034ac42b
2 changed files with 8 additions and 11 deletions

View File

@ -105,20 +105,17 @@ export class SettingsService {
darkModeEnabled ??= this.get(SETTINGS_KEYS.DARK_MODE_ENABLED) darkModeEnabled ??= this.get(SETTINGS_KEYS.DARK_MODE_ENABLED)
themeColor ??= this.get(SETTINGS_KEYS.THEME_COLOR) themeColor ??= this.get(SETTINGS_KEYS.THEME_COLOR)
if (darkModeUseSystem) { const isSystemColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
this._renderer.addClass(this.document.body, 'color-scheme-system')
this._renderer.removeClass(this.document.body, 'color-scheme-dark')
} else {
this._renderer.removeClass(this.document.body, 'color-scheme-system')
darkModeEnabled
? this._renderer.addClass(this.document.body, 'color-scheme-dark')
: this._renderer.removeClass(this.document.body, 'color-scheme-dark')
}
// remove these in case they were there // clearing state.
this._renderer.removeAttribute(this.document.documentElement, 'data-bs-theme');
this._renderer.removeClass(this.document.body, 'primary-dark') this._renderer.removeClass(this.document.body, 'primary-dark')
this._renderer.removeClass(this.document.body, 'primary-light') this._renderer.removeClass(this.document.body, 'primary-light')
if ((darkModeUseSystem && isSystemColorSchemeDark) || darkModeEnabled) {
this._renderer.setAttribute(this.document.documentElement, 'data-bs-theme', 'dark');
}
if (themeColor) { if (themeColor) {
const hsl = hexToHsl(themeColor) const hsl = hexToHsl(themeColor)
const bgBrightnessEstimate = estimateBrightnessForColor(themeColor) const bgBrightnessEstimate = estimateBrightnessForColor(themeColor)

View File

@ -11,7 +11,7 @@
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="apple-touch-icon" href="apple-touch-icon.png"> <link rel="apple-touch-icon" href="apple-touch-icon.png">
</head> </head>
<body class="color-scheme-system"> <body>
<app-root></app-root> <app-root></app-root>
</body> </body>
</html> </html>