-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.tsx
125 lines (117 loc) · 3.56 KB
/
progress.tsx
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { ComponentContext, ObservableEvent, jsx } from 'butterfloat'
import { FastForward, Pause, Play, Rewind, SkipForward } from 'lucide'
import { map } from 'rxjs'
import { Icon } from './icon'
import { ProgVm } from './progvm'
export interface ProgressProps {
item: ProgVm
}
interface ProgressEvents {
finish: ObservableEvent<MouseEvent>
pause: ObservableEvent<MouseEvent>
slowDown: ObservableEvent<MouseEvent>
speedUp: ObservableEvent<MouseEvent>
unpause: ObservableEvent<MouseEvent>
}
export function Progress(
{ item }: ProgressProps,
{ bindImmediateEffect, events }: ComponentContext<ProgressEvents>,
) {
const { finish, pause, slowDown, speedUp, unpause } = events
const pauseDisplay = item.paused.pipe(
map((paused) => (paused ? `none` : `block`)),
)
const unpauseDisplay = item.paused.pipe(
map((paused) => (paused ? `block` : `none`)),
)
const notPaused = item.paused.pipe(map((paused) => !paused))
bindImmediateEffect(finish, () => item.finish())
bindImmediateEffect(pause, () => item.pause())
bindImmediateEffect(slowDown, () => item.slowDown())
bindImmediateEffect(speedUp, () => item.speedUp())
bindImmediateEffect(unpause, () => item.unpause())
return (
<div className="card">
<div className="level">
<div className="level-item">
<div className="buttons has-addons">
<button
type="button"
title="Pause"
className="button"
styleBind={{ display: pauseDisplay }}
events={{ click: pause }}
>
<span className="icon">
<Icon icon={Pause} />
</span>
</button>
<button
type="button"
title="Unpause"
className="button"
styleBind={{ display: unpauseDisplay }}
events={{ click: unpause }}
>
<span className="icon">
<Icon icon={Play} />
</span>
</button>
<button
type="button"
title="Slow Down"
className="button"
events={{ click: slowDown }}
>
<span className="icon">
<Icon icon={Rewind} />
</span>
</button>
<button
type="button"
title="Speed Up"
className="button"
events={{ click: speedUp }}
>
<span className="icon">
<Icon icon={FastForward} />
</span>
</button>
<button
type="button"
title="Finish"
className="button"
events={{ click: finish }}
>
<span className="icon">
<Icon icon={SkipForward} />
</span>
</button>
</div>
</div>
<div className="level-item">
<div>
<div className="heading is-capitalized">Item Progress</div>
<div
className="title"
bind={{ innerText: item.roundPercent }}
></div>
</div>
</div>
<div className="level-item is-flex-grow-5">
<progress
className="progress"
bind={{
innerText: item.roundPercent,
bfDelayValue: item.percent,
}}
classBind={{
'is-info': notPaused,
'is-warning': item.paused,
}}
></progress>
</div>
</div>
</div>
)
}