1
0
Fork 0
VaultUI/src/ThemeLoader.tsx

33 lines
889 B
TypeScript
Raw Normal View History

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