forked from MapComplete/MapComplete
More refactoring, still very broken
This commit is contained in:
parent
d5d90afc74
commit
62f471df1e
23 changed files with 428 additions and 356 deletions
|
@ -2,6 +2,7 @@ import {InputElement} from "./InputElement";
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {Utils} from "../../Utils";
|
||||
import {UIElement} from "../UIElement";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
|
||||
/**
|
||||
* Supports multi-input
|
||||
|
@ -10,15 +11,24 @@ export default class CheckBoxes extends InputElement<number[]> {
|
|||
IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false);
|
||||
|
||||
private readonly value: UIEventSource<number[]>;
|
||||
private readonly _elements: UIElement[]
|
||||
private readonly _elements: BaseUIElement[]
|
||||
|
||||
|
||||
private readonly _element : HTMLElement
|
||||
|
||||
|
||||
constructor(elements: UIElement[]) {
|
||||
super(undefined);
|
||||
constructor(elements: BaseUIElement[]) {
|
||||
super();
|
||||
this._elements = Utils.NoNull(elements);
|
||||
|
||||
this.value = new UIEventSource<number[]>([])
|
||||
this.ListenTo(this.value);
|
||||
|
||||
|
||||
const el = document.createElement()
|
||||
this._element = el;
|
||||
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
return this._element
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,46 +4,33 @@ import {UIEventSource} from "../../Logic/UIEventSource";
|
|||
export default class ColorPicker extends InputElement<string> {
|
||||
|
||||
private readonly value: UIEventSource<string>
|
||||
|
||||
private readonly _element : HTMLElement
|
||||
constructor(
|
||||
value?: UIEventSource<string>
|
||||
value: UIEventSource<string> = new UIEventSource<string>(undefined)
|
||||
) {
|
||||
super();
|
||||
this.value = value ?? new UIEventSource<string>(undefined);
|
||||
const self = this;
|
||||
this.value = value ;
|
||||
|
||||
const el = document.createElement("input")
|
||||
this._element = el;
|
||||
|
||||
el.type = "color"
|
||||
|
||||
this.value.addCallbackAndRun(v => {
|
||||
if(v === undefined){
|
||||
return;
|
||||
}
|
||||
self.SetValue(v);
|
||||
el.value =v
|
||||
});
|
||||
|
||||
el.oninput = () => {
|
||||
const hex = el.value;
|
||||
value.setData(hex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InnerRender(): string {
|
||||
return `<span id="${this.id}"><input type='color' id='color-${this.id}'></span>`;
|
||||
}
|
||||
|
||||
private SetValue(color: string){
|
||||
const field = document.getElementById("color-" + this.id);
|
||||
if (field === undefined || field === null) {
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
field.value = color;
|
||||
}
|
||||
|
||||
protected InnerUpdate() {
|
||||
const field = document.getElementById("color-" + this.id);
|
||||
if (field === undefined || field === null) {
|
||||
return;
|
||||
}
|
||||
const self = this;
|
||||
field.oninput = () => {
|
||||
const hex = field["value"];
|
||||
self.value.setData(hex);
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
return this._element;
|
||||
}
|
||||
|
||||
GetValue(): UIEventSource<string> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue