mapcomplete/UI/Input/ColorPicker.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
994 B
TypeScript
Raw Normal View History

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