forked from hyoo-ru/mam_mol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.view.ts
76 lines (55 loc) · 1.25 KB
/
button.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
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
namespace $.$$ {
/**
* Simple button.
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_button_demo
*/
export class $mol_button extends $.$mol_button {
@ $mol_mem
status( next = [ null as any ] ) { return next }
disabled() {
return !this.enabled()
}
event_activate( next : Event ) {
if( !next ) return
if( !this.enabled() ) return
try {
this.event_click( next )
this.click( next )
this.status([ null ])
} catch( error: any ) {
Promise.resolve().then( ()=> this.status([ error ]) )
$mol_fail_hidden( error )
}
}
event_key_press ( event: KeyboardEvent ) {
if( event.keyCode === $mol_keyboard_code.enter ) {
return this.event_activate( event )
}
}
tab_index() {
return this.enabled() ? super.tab_index() : -1
}
error() {
const [ error ] = this.status()
if( !error ) return ''
if( error instanceof Promise ) {
return $mol_fail_hidden( error )
}
return String( error.message ?? error )
}
hint_safe() {
try {
return this.hint()
} catch( error ) {
$mol_fail_log( error )
return ''
}
}
sub_visible() {
return [
... this.error() ? [ this.Speck() ] : [] ,
... this.sub() ,
]
}
}
}