Charts: ensure light/dark mode color updates (#28645)
This commit is contained in:
parent
de5b93e29d
commit
88cc66a611
2 changed files with 3 additions and 6 deletions
|
|
@ -66,7 +66,7 @@ export const lighterColor = (color: string | null) => setAlpha(color, "aa");
|
|||
|
||||
export const fullColor = (color: string | null) => setAlpha(color, "ff");
|
||||
|
||||
function updateCssColors() {
|
||||
export function updateCssColors() {
|
||||
const style = window.getComputedStyle(document.documentElement);
|
||||
colors.text = style.getPropertyValue("--evcc-default-text");
|
||||
colors.muted = style.getPropertyValue("--bs-gray-medium");
|
||||
|
|
@ -81,11 +81,6 @@ function updateCssColors() {
|
|||
colors.light = style.getPropertyValue("--bs-gray-light");
|
||||
}
|
||||
|
||||
// update colors on theme change
|
||||
const darkModeMatcher = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)");
|
||||
if (darkModeMatcher && darkModeMatcher.addEventListener) {
|
||||
darkModeMatcher.addEventListener("change", updateCssColors);
|
||||
}
|
||||
// initialize colors
|
||||
updateCssColors();
|
||||
window.requestAnimationFrame(updateCssColors);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { updateCssColors } from "./colors";
|
||||
import settings from "./settings";
|
||||
import { THEME } from "./types/evcc";
|
||||
|
||||
|
|
@ -47,6 +48,7 @@ function updateTheme() {
|
|||
$html.classList.add("no-transitions");
|
||||
$html.classList.toggle("dark", theme === THEME.DARK);
|
||||
$html.setAttribute("data-bs-theme", theme!);
|
||||
requestAnimationFrame(updateCssColors);
|
||||
window.setTimeout(function () {
|
||||
$html.classList.remove("no-transitions");
|
||||
}, 100);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue