2021-05-11 02:39:51 +02:00
|
|
|
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
|
2021-05-11 02:39:51 +02:00
|
|
|
constructor(
|
2021-06-11 22:51:45 +02:00
|
|
|
value: UIEventSource<string> = new UIEventSource<string>(undefined)
|
2021-05-11 02:39:51 +02:00
|
|
|
) {
|
|
|
|
super();
|
2021-06-11 22:51:45 +02:00
|
|
|
this.value = value ;
|
|
|
|
|
|
|
|
const el = document.createElement("input")
|
|
|
|
this._element = el;
|
|
|
|
|
|
|
|
el.type = "color"
|
|
|
|
|
2021-05-11 02:39:51 +02:00
|
|
|
this.value.addCallbackAndRun(v => {
|
|
|
|
if(v === undefined){
|
|
|
|
return;
|
|
|
|
}
|
2021-06-11 22:51:45 +02:00
|
|
|
el.value =v
|
2021-05-11 02:39:51 +02:00
|
|
|
});
|
2021-06-11 22:51:45 +02:00
|
|
|
|
|
|
|
el.oninput = () => {
|
|
|
|
const hex = el.value;
|
|
|
|
value.setData(hex);
|
2021-05-11 02:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 22:51:45 +02:00
|
|
|
protected InnerConstructElement(): HTMLElement {
|
|
|
|
return this._element;
|
2021-05-11 02:39:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GetValue(): UIEventSource<string> {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false);
|
|
|
|
|
|
|
|
IsValid(t: string): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|