2021-02-28 14:12:48 +01:00
|
|
|
import { bridgeCommand } from "./lib";
|
|
|
|
|
2021-03-01 15:20:31 +01:00
|
|
|
|
|
|
|
function removeHoverIcon(evt: Event): void {
|
|
|
|
const icon = evt.currentTarget as HTMLElement;
|
|
|
|
icon.classList.remove("icon--hover")
|
|
|
|
}
|
|
|
|
|
|
|
|
function hoverIcon(evt: Event): void {
|
|
|
|
const icon = evt.currentTarget as HTMLElement;
|
|
|
|
icon.classList.add("icon--hover");
|
|
|
|
}
|
|
|
|
|
2021-02-28 14:12:48 +01:00
|
|
|
export class LabelContainer extends HTMLDivElement {
|
|
|
|
sticky: HTMLSpanElement;
|
|
|
|
label: HTMLSpanElement;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2021-03-01 13:06:07 +01:00
|
|
|
this.className = "d-flex justify-content-between";
|
|
|
|
|
|
|
|
this.label = document.createElement("span");
|
|
|
|
this.label.className = "fieldname";
|
|
|
|
this.appendChild(this.label);
|
2021-02-28 14:12:48 +01:00
|
|
|
|
|
|
|
this.sticky = document.createElement("span");
|
2021-03-01 15:20:31 +01:00
|
|
|
this.sticky.className = "bi me-1 bi-sticky icon";
|
2021-02-28 14:12:48 +01:00
|
|
|
this.sticky.hidden = true;
|
|
|
|
this.appendChild(this.sticky);
|
|
|
|
|
|
|
|
this.toggleSticky = this.toggleSticky.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback(): void {
|
|
|
|
this.sticky.addEventListener("click", this.toggleSticky);
|
2021-03-01 15:20:31 +01:00
|
|
|
this.sticky.addEventListener("mouseenter", hoverIcon);
|
|
|
|
this.sticky.addEventListener("mouseleave", removeHoverIcon);
|
2021-02-28 14:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
disconnectedCallback(): void {
|
|
|
|
this.sticky.removeEventListener("click", this.toggleSticky);
|
2021-03-01 15:20:31 +01:00
|
|
|
this.sticky.removeEventListener("mouseenter", hoverIcon);
|
|
|
|
this.sticky.removeEventListener("mouseleave", removeHoverIcon);
|
2021-02-28 14:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initialize(labelName: string): void {
|
|
|
|
this.label.innerText = labelName;
|
|
|
|
}
|
|
|
|
|
2021-02-28 18:46:43 +01:00
|
|
|
setSticky(state: boolean): void {
|
2021-03-01 15:20:31 +01:00
|
|
|
this.sticky.classList.toggle("is-inactive", state);
|
2021-02-28 18:46:43 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 14:12:48 +01:00
|
|
|
activateSticky(initialState: boolean): void {
|
2021-02-28 18:46:43 +01:00
|
|
|
this.setSticky(initialState);
|
2021-02-28 14:12:48 +01:00
|
|
|
this.sticky.hidden = false;
|
|
|
|
}
|
|
|
|
|
2021-03-01 15:20:31 +01:00
|
|
|
toggleSticky(evt: Event): void {
|
2021-02-28 18:46:43 +01:00
|
|
|
bridgeCommand(
|
|
|
|
`toggleSticky:${this.getAttribute("ord")}`,
|
|
|
|
(newState: boolean): void => {
|
|
|
|
this.setSticky(newState);
|
|
|
|
}
|
|
|
|
);
|
2021-03-01 15:20:31 +01:00
|
|
|
removeHoverIcon(evt);
|
2021-02-28 14:12:48 +01:00
|
|
|
}
|
|
|
|
}
|