forked from gbtami/pychess-variants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzen.ts
45 lines (33 loc) · 1.04 KB
/
zen.ts
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
import { h, VNode } from 'snabbdom';
import { _ } from './i18n';
import { StringSettings } from './settings';
import { radioList } from './view';
import { patch } from './document';
const zenModeOptions = {
off: _("Off"),
on: _("On"),
};
class ZenModeSettings extends StringSettings {
constructor() {
super('zen', 'off');
}
update(): void {
document.documentElement.setAttribute('data-zen', this.value);
}
view(): VNode {
return h('div#zen-selector', radioList(this, 'zen', zenModeOptions, (_, key) => this.value = key));
}
}
export const zenModeSettings = new ZenModeSettings();
function deactivateZenMode() {
zenModeSettings.value = 'off';
zenModeSettings.update();
const zenSettings = document.getElementById('zen-selector') as HTMLElement;
zenSettings.innerHTML = "";
patch(zenSettings, zenModeSettings.view());
}
export function zenButtonView() {
return h('a#zen-button', { on: { click: deactivateZenMode } }, [
h('div.icon.icon-check', _('ZEN MODE'))
]);
}