forked from jummbus/jummbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemePrompt.ts
More file actions
97 lines (87 loc) · 3.7 KB
/
ThemePrompt.ts
File metadata and controls
97 lines (87 loc) · 3.7 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (C) 2020 John Nesky, distributed under the MIT license.
import { HTML } from "imperative-html/dist/esm/elements-strict";
import { Prompt } from "./Prompt";
import { SongDocument } from "./SongDocument";
import { ColorConfig } from "./ColorConfig";
//namespace beepbox {
const { button, div, h2, select, option } = HTML;
export class ThemePrompt implements Prompt {
private readonly _themeSelect: HTMLSelectElement = select({ style: "width: 100%;" },
option({ value: "dark classic" }, "BeepBox Dark"),
option({ value: "light classic" }, "BeepBox Light"),
option({ value: "dark competition" }, "BeepBox Competition Dark"),
option({ value: "jummbox classic" }, "JummBox Dark"),
// option({ value: "jummbox light" }, "JummBox Light"), // It's not ready to see the world yet...
option({ value: "forest" }, "Forest"),
option({ value: "canyon" }, "Canyon"),
option({ value: "midnight" }, "Midnight"),
option({ value: "beachcombing" }, "Beachcombing"),
option({ value: "violet verdant" }, "Violet Verdant"),
option({ value: "sunset" }, "Sunset"),
option({ value: "autumn" }, "Autumn"),
option({ value: "fruit" }, "Shadowfruit"),
option({ value: "toxic" }, "Toxic"),
option({ value: "roe" }, "Roe"),
option({ value: "moonlight" }, "Moonlight"),
option({ value: "portal" }, "Portal"),
option({ value: "fusion" }, "Fusion"),
option({ value: "inverse" }, "Inverse"),
option({ value: "nebula" }, "Nebula"),
option({ value: "roe light" }, "Roe Light"),
option({ value: "energized" }, "Energized"),
option({ value: "neapolitan" }, "Neapolitan"),
option({ value: "poly" }, "Poly"),
option({ value: "blutonium" }, "Blutonium"),
);
private readonly _cancelButton: HTMLButtonElement = button({ class: "cancelButton" });
private readonly _okayButton: HTMLButtonElement = button({ class: "okayButton", style: "width:45%;" }, "Okay");
public readonly container: HTMLDivElement = div({ class: "prompt noSelection", style: "width: 220px;" },
h2("Set Theme"),
div({ style: "display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;" },
div({ class: "selectContainer", style: "width: 100%;" }, this._themeSelect),
),
div({ style: "display: flex; flex-direction: row-reverse; justify-content: space-between;" },
this._okayButton,
),
this._cancelButton,
);
private readonly lastTheme: string | null = window.localStorage.getItem("colorTheme")
constructor(private _doc: SongDocument) {
if (this.lastTheme != null) {
this._themeSelect.value = this.lastTheme;
}
this._okayButton.addEventListener("click", this._saveChanges);
this._cancelButton.addEventListener("click", this._close);
this.container.addEventListener("keydown", this._whenKeyPressed);
this._themeSelect.addEventListener("change", this._previewTheme);
}
private _close = (): void => {
if (this.lastTheme != null) {
ColorConfig.setTheme(this.lastTheme);
} else {
ColorConfig.setTheme("jummbox classic");
}
this._doc.undo();
}
public cleanUp = (): void => {
this._okayButton.removeEventListener("click", this._saveChanges);
this._cancelButton.removeEventListener("click", this._close);
this.container.removeEventListener("keydown", this._whenKeyPressed);
}
private _whenKeyPressed = (event: KeyboardEvent): void => {
if ((<Element>event.target).tagName != "BUTTON" && event.keyCode == 13) { // Enter key
this._saveChanges();
}
}
private _saveChanges = (): void => {
window.localStorage.setItem("colorTheme", this._themeSelect.value);
this._doc.prompt = null;
this._doc.prefs.colorTheme = this._themeSelect.value;
this._doc.undo();
}
private _previewTheme = (): void => {
ColorConfig.setTheme(this._themeSelect.value);
this._doc.notifier.changed();
}
}
//}