-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear.go
More file actions
86 lines (72 loc) · 1.87 KB
/
linear.go
File metadata and controls
86 lines (72 loc) · 1.87 KB
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
package progress
import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
"github.com/mlctrez/goapp-mdc/pkg/base"
)
type Linear struct {
app.Compo
base.JsUtil
id string
label string
progress float64
onmount func(ctx app.Context)
target app.Value
}
func NewLinear(id string) *Linear {
return &Linear{id: id, target: app.Undefined()}
}
func (b *Linear) Label(label string) *Linear {
b.label = label
return b
}
func (b *Linear) WithOnMount(cb func(ctx app.Context)) *Linear {
b.onmount = cb
return b
}
func (b *Linear) Render() app.UI {
root := app.Div().ID(b.id).Class("mdc-linear-progress", "mdc-linear-progress--closed").Aria("hidden", "true")
root.Aria("valuemin", "0").Aria("valuemax", "1").Aria("valuenow", "0")
if b.label != "" {
root.Aria("label", b.label)
}
root.Body(
app.Div().Class("mdc-linear-progress__buffer").Body(
app.Div().Class("mdc-linear-progress__buffer-bar"),
app.Div().Class("mdc-linear-progress__buffer-dots"),
),
app.Div().Class("mdc-linear-progress__bar", "mdc-linear-progress__primary-bar").Body(
app.Span().Class("mdc-linear-progress__bar-inner"),
),
app.Div().Class("mdc-linear-progress__bar", "mdc-linear-progress__secondary-bar").Body(
app.Span().Class("mdc-linear-progress__bar-inner"),
),
)
return root
}
func (b *Linear) OnMount(ctx app.Context) {
b.target = b.JsNewAtPath("mdc.linearProgress.MDCLinearProgress", app.Window().GetElementByID(b.id))
if b.onmount != nil {
b.onmount(ctx)
}
}
func (b *Linear) Open() {
if !b.target.IsUndefined() {
b.target.Call("open")
}
}
func (b *Linear) Determinate(d bool) {
if !b.target.IsUndefined() {
b.target.Set("determinate", d)
}
}
func (b *Linear) SetProgress(f float64) {
b.progress = f
if !b.target.IsUndefined() {
b.target.Set("progress", b.progress)
}
}
func (b *Linear) Close() {
if !b.target.IsUndefined() {
b.target.Call("close")
}
}