mapcomplete/UI/Input/ColorPicker.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

import {InputElement} from "./InputElement";
import {UIEventSource} from "../../Logic/UIEventSource";
export default class ColorPicker extends InputElement<string> {
private readonly value: UIEventSource<string>
2021-06-11 22:51:45 +02:00
private readonly _element : HTMLElement
constructor(
2021-06-11 22:51:45 +02:00
value: UIEventSource<string> = new UIEventSource<string>(undefined)
) {
super();
2021-06-11 22:51:45 +02:00
this.value = value ;
const el = document.createElement("input")
this._element = el;
el.type = "color"
this.value.addCallbackAndRun(v => {
if(v === undefined){
return;
}
2021-06-11 22:51:45 +02:00
el.value =v
});
2021-06-11 22:51:45 +02:00
el.oninput = () => {
const hex = el.value;
value.setData(hex);
}
}
2021-06-11 22:51:45 +02:00
protected InnerConstructElement(): HTMLElement {
return this._element;
}
GetValue(): UIEventSource<string> {
return this.value;
}
IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false);
IsValid(t: string): boolean {
return false;
}
}