-
-
Notifications
You must be signed in to change notification settings - Fork 489
/
button_icon.ts
57 lines (46 loc) · 1.38 KB
/
button_icon.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
import {ClickableIcon, ClickableIconView} from "./icon"
import type * as p from "@bokehjs/core/properties"
export class ButtonIconView extends ClickableIconView {
declare model: ButtonIcon
_click_listener: any
public override *controls() {}
override update_cursor(): void {
this.icon_view.el.style.cursor = this.model.disabled ? "default" : "pointer"
}
override click(): void {
if (this.model.disabled) {
return
}
super.click()
const updateState = (value: boolean, disabled: boolean) => {
this.model.value = value
this.model.disabled = disabled
}
updateState(true, true)
new Promise(resolve => setTimeout(resolve, this.model.toggle_duration))
.then(() => {
updateState(false, false)
})
}
}
export namespace ButtonIcon {
export type Attrs = p.AttrsOf<Props>
export type Props = ClickableIcon.Props & {
toggle_duration: p.Property<number>
}
}
export interface ButtonIcon extends ButtonIcon.Attrs { }
export class ButtonIcon extends ClickableIcon {
declare properties: ButtonIcon.Props
declare __view_type__: ButtonIconView
static override __module__ = "panel.models.icon"
constructor(attrs?: Partial<ButtonIcon.Attrs>) {
super(attrs)
}
static {
this.prototype.default_view = ButtonIconView
this.define<ButtonIcon.Props>(({Int}) => ({
toggle_duration: [Int, 75],
}))
}
}