forked from MapComplete/MapComplete
Fix input elements
This commit is contained in:
parent
48f66bd17e
commit
910970e4a4
6 changed files with 78 additions and 81 deletions
|
@ -4,32 +4,41 @@ import {UIEventSource} from "../../Logic/UIEventSource";
|
|||
|
||||
|
||||
export default class Link extends BaseUIElement {
|
||||
private readonly _element: HTMLElement;
|
||||
private readonly _href: string | UIEventSource<string>;
|
||||
private readonly _embeddedShow: BaseUIElement;
|
||||
private readonly _newTab: boolean;
|
||||
|
||||
constructor(embeddedShow: BaseUIElement | string, href: string | UIEventSource<string>, newTab: boolean = false) {
|
||||
super();
|
||||
const _embeddedShow = Translations.W(embeddedShow);
|
||||
this._embeddedShow =Translations.W(embeddedShow);
|
||||
this._href = href;
|
||||
this._newTab = newTab;
|
||||
|
||||
|
||||
const el = document.createElement("a")
|
||||
|
||||
if(typeof href === "string"){
|
||||
el.href = href
|
||||
}else{
|
||||
href.addCallbackAndRun(href => {
|
||||
el.href = href;
|
||||
})
|
||||
}
|
||||
if (newTab) {
|
||||
el.target = "_blank"
|
||||
}
|
||||
el.appendChild(_embeddedShow.ConstructElement())
|
||||
this._element = el
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const embeddedShow = this._embeddedShow?.ConstructElement();
|
||||
if(embeddedShow === undefined){
|
||||
return undefined;
|
||||
}
|
||||
const el = document.createElement("a")
|
||||
if(typeof this._href === "string"){
|
||||
el.href = this._href
|
||||
}else{
|
||||
this._href.addCallbackAndRun(href => {
|
||||
el.href = href;
|
||||
})
|
||||
}
|
||||
if (this._newTab) {
|
||||
el.target = "_blank"
|
||||
}
|
||||
el.appendChild(embeddedShow)
|
||||
return el;
|
||||
}
|
||||
|
||||
return this._element;
|
||||
AsMarkdown(): string {
|
||||
// @ts-ignore
|
||||
return `[${this._embeddedShow.AsMarkdown()}](${this._href.data ?? this._href})`;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue