CommandLink alias syntax

This commit is contained in:
Zef Hemel
2022-11-29 09:11:23 +01:00
parent 55791cc88e
commit 6a047e1ef4
8 changed files with 172 additions and 22 deletions
+23
View File
@@ -35,6 +35,29 @@ export class LinkWidget extends WidgetType {
}
}
export class ButtonWidget extends WidgetType {
constructor(
readonly text: string,
readonly title: string,
readonly cssClass: string,
readonly callback: (e: MouseEvent) => void,
) {
super();
}
toDOM(): HTMLElement {
const anchor = document.createElement("button");
anchor.className = this.cssClass;
anchor.textContent = this.text;
anchor.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
this.callback(e);
});
anchor.setAttribute("title", this.title);
return anchor;
}
}
/**
* Check if two ranges overlap
* Based on the visual diagram on https://stackoverflow.com/a/25369187