forked from maxence-charriere/go-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.go
114 lines (99 loc) · 1.81 KB
/
loader.go
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
package main
import (
"fmt"
"github.com/gabstv/go-app/v9/pkg/app"
)
type loader struct {
app.Compo
Iloading bool
Iclass string
Ititle string
Idescription string
Ierr error
Isize int
}
func newLoader() *loader {
return &loader{
Isize: 66,
}
}
func (l *loader) Class(v string) *loader {
if v == "" {
return l
}
if l.Iclass != "" {
l.Iclass += " "
}
l.Iclass += v
return l
}
func (l *loader) Title(v string) *loader {
l.Ititle = v
return l
}
func (l *loader) Description(v string) *loader {
l.Idescription = v
return l
}
func (l *loader) Loading(v bool) *loader {
l.Iloading = v
return l
}
func (l *loader) Err(err error) *loader {
l.Ierr = err
return l
}
func (l *loader) Size(v int) *loader {
l.Isize = v
return l
}
func (l *loader) Render() app.UI {
display := "hide"
if l.Iloading {
display = ""
}
title := l.Ititle
descriptionMsg := l.Idescription
descriptionColor := ""
state := "active"
if l.Ierr != nil {
title += " failed"
descriptionMsg = l.Ierr.Error()
descriptionColor = "error"
state = "inactive"
display = ""
}
return app.Aside().
Class("loader").
Class(display).
Class(l.Iclass).
Body(
app.Stack().
Class("hspace-out").
Class("vspace-in-stretch").
Center().
Middle().
Content(
app.Div().
Style("width", fmt.Sprintf("%vpx", l.Isize)).
Style("height", fmt.Sprintf("%vpx", l.Isize)).
Body(
app.Div().
Class("icon").
Class(state).
Style("width", fmt.Sprintf("%vpx", l.Isize-2)).
Style("height", fmt.Sprintf("%vpx", l.Isize-2)),
),
app.Div().
Class("hspace-in").
Body(
app.Header().
Class("h1").
Text(title),
app.P().
Class(descriptionColor).
Text(descriptionMsg),
),
),
)
}