@paperbits/core
Version:
Paperbits core components.
49 lines (38 loc) • 1.41 kB
text/typescript
import * as ko from "knockout";
import template from "./hyperlinkInput.html";
import { HyperlinkModel } from "@paperbits/common/permalinks";
import { Component, Event, Param, OnMounted } from "@paperbits/common/ko/decorators";
export class HyperlinkInput {
private selectedHyperlink: ko.Observable<HyperlinkModel>;
public hyperlinkTitle: ko.Computed<string>;
constructor() {
this.hyperlink = ko.observable();
this.selectedHyperlink = ko.observable();
this.hyperlinkTitle = ko.pureComputed<string>(() => {
const hyperlink = this.selectedHyperlink();
if (hyperlink) {
return `${hyperlink.title}`;
}
return "Click to select a link...";
});
}
public hyperlink: ko.Observable<HyperlinkModel>;
public onChange: (hyperlink: HyperlinkModel) => void;
public async onMounted(): Promise<void> {
this.selectedHyperlink(this.hyperlink());
this.hyperlink.subscribe(hyperlink => this.selectedHyperlink(hyperlink));
}
public onHyperlinkChange(hyperlink: HyperlinkModel): void {
this.selectedHyperlink(hyperlink);
if (this.onChange) {
this.onChange(hyperlink)
}
}
}