-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.ts
59 lines (51 loc) · 1.4 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { View, html } from 'rune-ts';
import { SwitchView } from '../lib/SwitchView';
import { ListView } from '../lib/ListView';
import { CheckAllController } from '../lib/CheckAllController';
interface Setting {
title: string;
on: boolean;
}
class SettingItemView extends View<Setting> {
switchView = new SwitchView(this.data);
override template() {
return html`
<div>
<span class="title">${this.data.title}</span>
${this.switchView}
</div>
`;
}
}
class SettingListView extends ListView<Setting, SettingItemView> {
createItemView(itemData: Setting) {
return new SettingItemView(itemData);
}
}
class SettingPage extends View<Setting[]> {
private _checkAllController = new CheckAllController(
new SwitchView(),
new SettingListView(this.data),
(itemView) => itemView.data.on,
(itemView, bool) => itemView.switchView.setOn(bool),
);
override template() {
return html`
<div>
<div class="header">
<h2>Setting</h2>
${this._checkAllController.checkAllView}
</div>
<div class="body">${this._checkAllController.listView}</div>
</div>
`;
}
}
export function main() {
const settings: Setting[] = [
{ title: 'WiFi', on: true },
{ title: 'Bluetooth', on: false },
{ title: 'AirDrop', on: true },
];
document.querySelector('#body')!.append(new SettingPage(settings).render());
}