dees-domtools/ts/domtools.classes.thememanager.ts

44 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-11-24 19:18:59 +00:00
import { LitElement } from 'lit-element';
2020-11-23 20:41:26 +00:00
import { DomTools } from './domtools.classes.domtools';
import * as plugins from './domtools.plugins';
export class ThemeManager {
public domtoolsRef: DomTools;
2020-11-24 19:18:59 +00:00
2020-11-24 19:48:14 +00:00
public goBrightBoolean = false;
2020-11-23 20:41:26 +00:00
constructor(domtoolsRefArg: DomTools) {
this.domtoolsRef = domtoolsRefArg;
2020-11-24 19:18:59 +00:00
this.domtoolsRef.elementInstrumenter.connectedElements.eventSubject.subscribe(async eventData => {
await this.setThemeStatusForElement(eventData.payload, this.goBrightBoolean);
});
}
private async setThemeStatusForElement (elementArg: LitElement, goBrightBool: boolean) {
const goBright = (elementArg as any).goBright;
if (typeof goBright === 'boolean') {
(elementArg as any).goBright = goBrightBool;
}
2020-11-23 20:41:26 +00:00
}
2020-11-24 19:23:06 +00:00
private async updateAllConnectedElements() {
2020-11-23 20:41:26 +00:00
this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => {
2020-11-24 19:23:06 +00:00
await this.setThemeStatusForElement(elementArg, this.goBrightBoolean);
2020-11-23 20:41:26 +00:00
});
}
2020-11-24 19:23:06 +00:00
public goBright() {
this.goBrightBoolean = true;
this.updateAllConnectedElements();
}
2020-11-23 20:41:26 +00:00
public goDark() {
2020-11-24 19:23:06 +00:00
this.goBrightBoolean = false;
this.updateAllConnectedElements();
}
public toggleDarkBright() {
this.goBrightBoolean = !this.goBrightBoolean;
this.updateAllConnectedElements();
2020-11-23 20:41:26 +00:00
}
}