1
0
Fork 0
VaultUI/src/ThemeLoader.tsx

34 lines
867 B
TypeScript
Raw Normal View History

2022-01-11 10:57:30 +00:00
import { Component } from "preact";
import { settings } from "./globalSettings";
// @ts-ignore
2022-01-11 12:45:35 +00:00
import style_dark from "./scss/main-dark.scss" assert { type: "css" };
2022-01-11 10:57:30 +00:00
// @ts-ignore
2022-01-11 12:45:35 +00:00
import style_light from "./scss/main-light.scss" assert { type: "css" };
2022-01-11 10:57:30 +00:00
export const default_theme = "dark";
const themes: { [key: string]: string } = {
2022-01-11 12:45:35 +00:00
dark: style_dark as string,
light: style_light as string,
};
2022-01-11 10:57:30 +00:00
2022-01-11 12:45:35 +00:00
export class ThemeLoader extends Component<unknown, { sheet: string }> {
componentDidMount() {
this.setCorrectStyle(settings.theme);
settings.registerListener((key: string) => {
if (key != "theme") return;
this.setCorrectStyle(settings.theme);
});
}
2022-01-11 10:57:30 +00:00
2022-01-11 12:45:35 +00:00
setCorrectStyle(theme: string) {
this.setState({ sheet: themes[theme] });
}
2022-01-11 10:57:30 +00:00
2022-01-11 12:45:35 +00:00
render() {
if (!this.state.sheet) return;
return <style>{this.state.sheet}</style>;
}
}