Files
romm/frontend/src/plugins/vuetify.ts
Georges-Antoine Assi cca2702ce3 get app working again
2024-01-02 21:03:37 -05:00

42 lines
910 B
TypeScript

import { createVuetify } from "vuetify";
import { themes, dark, light, autoThemeKey } from "@/styles/themes";
import { isKeyof } from "@/types";
import "vuetify/styles";
import "@mdi/font/css/materialdesignicons.css";
const mediaMatch = window.matchMedia("(prefers-color-scheme: dark)");
function getTheme() {
const storedTheme = parseInt(localStorage.getItem("settings.theme") ?? "");
if (
!isNaN(storedTheme) &&
storedTheme !== autoThemeKey &&
isKeyof(storedTheme, themes)
) {
return themes[storedTheme];
}
return mediaMatch.matches ? "dark" : "light";
}
const instance = createVuetify({
icons: {
defaultSet: "mdi",
},
theme: {
defaultTheme: getTheme(),
themes: {
dark,
light,
},
},
});
mediaMatch.addEventListener("change", (event) => {
instance.theme.global.name.value = event.matches ? "dark" : "light";
});
export default instance;