2020-07-20 15:54:50 +02:00
|
|
|
import {InputElement} from "./InputElement";
|
2020-07-20 13:28:45 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
2020-07-20 15:54:50 +02:00
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2020-07-20 13:28:45 +02:00
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
export class FixedInputElement<T> extends InputElement<T> {
|
2020-08-31 02:59:47 +02:00
|
|
|
private readonly rendering: UIElement;
|
|
|
|
private readonly value: UIEventSource<T>;
|
|
|
|
public readonly IsSelected : UIEventSource<boolean> = new UIEventSource<boolean>(false);
|
2020-09-09 18:42:13 +02:00
|
|
|
private readonly _comparator: (t0: T, t1: T) => boolean;
|
2020-07-20 13:28:45 +02:00
|
|
|
|
2020-09-09 18:42:13 +02:00
|
|
|
constructor(rendering: UIElement | string,
|
|
|
|
value: T,
|
|
|
|
comparator: ((t0: T, t1: T) => boolean ) = undefined) {
|
2020-07-20 13:28:45 +02:00
|
|
|
super(undefined);
|
2020-09-09 18:42:13 +02:00
|
|
|
this._comparator = comparator ?? ((t0, t1) => t0 == t1);
|
2020-07-20 13:28:45 +02:00
|
|
|
this.value = new UIEventSource<T>(value);
|
|
|
|
this.rendering = typeof (rendering) === 'string' ? new FixedUiElement(rendering) : rendering;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetValue(): UIEventSource<T> {
|
|
|
|
return this.value;
|
|
|
|
}
|
2020-07-20 21:03:55 +02:00
|
|
|
InnerRender(): string {
|
2020-07-20 13:28:45 +02:00
|
|
|
return this.rendering.Render();
|
|
|
|
}
|
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
IsValid(t: T): boolean {
|
2020-09-09 18:42:13 +02:00
|
|
|
return this._comparator(t, this.value.data);
|
2020-07-20 15:54:50 +02:00
|
|
|
}
|
2020-08-31 02:59:47 +02:00
|
|
|
|
|
|
|
protected InnerUpdate(htmlElement: HTMLElement) {
|
|
|
|
super.InnerUpdate(htmlElement);
|
|
|
|
const self = this;
|
|
|
|
htmlElement.addEventListener("mouseenter", () => self.IsSelected.setData(true));
|
|
|
|
htmlElement.addEventListener("mouseout", () => self.IsSelected.setData(false))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
|
2020-07-20 13:28:45 +02:00
|
|
|
}
|