mapcomplete/UI/Input/FixedInputElement.ts

35 lines
858 B
TypeScript
Raw Normal View History

2020-07-20 15:54:50 +02:00
import {InputElement} from "./InputElement";
2020-07-20 13:28:45 +02:00
import {UIEventSource} from "../UIEventSource";
import {UIElement} from "../UIElement";
2020-07-20 15:54:50 +02:00
import {FixedUiElement} from "../Base/FixedUiElement";
2020-07-20 13:28:45 +02:00
2020-07-20 15:54:50 +02:00
export class FixedInputElement<T> extends InputElement<T> {
2020-07-20 13:28:45 +02:00
private rendering: UIElement;
private value: UIEventSource<T>;
constructor(rendering: UIElement | string, value: T) {
super(undefined);
this.value = new UIEventSource<T>(value);
this.rendering = typeof (rendering) === 'string' ? new FixedUiElement(rendering) : rendering;
}
GetValue(): UIEventSource<T> {
return this.value;
}
ShowValue(t: T): boolean {
return false;
}
2020-07-20 13:28:45 +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 {
return t == this.value.data;
2020-07-20 15:54:50 +02:00
}
2020-07-20 15:54:50 +02:00
2020-07-20 13:28:45 +02:00
}