Improve styles and compatibility

This commit is contained in:
Andras Schmelczer 2022-09-22 10:28:49 +02:00
parent d246dddbf5
commit 4ab6a5c5b0
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
10 changed files with 46 additions and 46 deletions

View file

@ -1,13 +1,4 @@
import { createElement } from '../../../helper/create-element';
import {
turnOffAnimations,
turnOnAnimations,
} from '../../../style/animations/animations';
import {
isSystemLevelDarkModeEnabled,
turnOnDarkMode,
turnOnLightMode,
} from '../../../style/dark-mode/dark-mode';
import { PageElement } from '../../page-element';
import { generate } from './theme-switcher.html';
@ -60,3 +51,18 @@ export class PageThemeSwitcher extends PageElement {
}
}
}
export const isSystemLevelDarkModeEnabled = (): boolean =>
matchMedia && matchMedia('(prefers-color-scheme: dark)').matches;
export const turnOnDarkMode = () =>
document.documentElement.setAttribute('theme', 'dark');
export const turnOnLightMode = () =>
document.documentElement.setAttribute('theme', 'light');
export const turnOnAnimations = () =>
document.documentElement.setAttribute('animations', 'on');
export const turnOffAnimations = () =>
document.documentElement.setAttribute('animations', 'off');