-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
color_selector.js
51 lines (42 loc) · 1.26 KB
/
color_selector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export class ColorSelector {
/**
*
* @param {string} selectorContainerId
*/
constructor(selectorContainerId) {
this.okayCallback = null;
this.cancelCallback = null;
this.selectorContainer = document.getElementById(selectorContainerId);
this.input = document.getElementById("colorSelectorInput");
this.okButton = document.getElementById("colorSelectorOK");
this.cancelButton = document.getElementById("colorSelectorCancel");
this.okButton.onclick = () => {
this.hide();
if (this.okayCallback) {
this.okayCallback(this.input.value);
}
}
this.cancelButton.onclick = () => {
this.hide();
if (this.cancelCallback) {
this.cancelCallback();
}
}
this.hide();
}
hide() {
this.selectorContainer.style.display = "none";
}
/**
*
* @param {string} value
* @param {(col: string) => null} okay
* @param {() => null} cancel
*/
show(value, okay, cancel) {
this.selectorContainer.style.display = "flex";
this.input.value = value;
this.okayCallback = okay;
this.cancelCallback = cancel;
}
}