Add setter to the toggle

This commit is contained in:
a 2020-07-26 21:14:45 +02:00
parent 1eb88d524f
commit f63d03b87a

View file

@ -1,20 +1,28 @@
import { browser } from "webextension-polyfill-ts";
import "./popup.scss";
class ExtensionToggle extends HTMLButtonElement {
on: boolean = false;
isON: boolean = false;
innerHTML: string = "OFF";
constructor() {
super();
this.addEventListener("click", this.toggle);
}
toggle() {
this.on = !this.on;
public set on(v: boolean) {
if (this.isON == v) {
return;
}
this.isON = v;
this.innerHTML = this.on ? "ON" : "OFF";
const toggleEvent = new CustomEvent("extensionToggled", {
detail: this.on,
});
this.dispatchEvent(toggleEvent);
}
public get on(): boolean {
return this.isON;
}
constructor() {
super();
this.addEventListener("click", () => (this.on = !this.on));
}
}
customElements.define("extension-toggle", ExtensionToggle, {
extends: "button",