-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
list.view.ts
43 lines (32 loc) · 902 Bytes
/
list.view.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
namespace $.$$ {
/**
* List of checkboxes
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_check_list_demo
*/
export class $mol_check_list extends $.$mol_check_list {
options() : { [ key : string ] : string } {
return {}
}
override dictionary(next?: Record<string, boolean>) {
return next ?? {}
}
override option_checked(id: string, next?: boolean | null) {
const prev = this.dictionary()
if (next === undefined) return prev[id] ?? null
const next_rec = { ... prev, [id]: next } as Record<string, boolean>
if (next === null) delete next_rec[id]
return this.dictionary(next_rec)[id] ?? null
}
@ $mol_mem
keys(): readonly string[] {
return Object.keys( this.options() )
}
@ $mol_mem
items() {
return this.keys().map( key => this.Option( key ) )
}
option_title( key : string ) {
return this.options()[key] || key
}
}
}