-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagination.go
78 lines (66 loc) · 1.33 KB
/
pagination.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
package beleine
//PAGINATION
import (
"errors"
"fmt"
)
type Pagination struct {
id string
size string
alignment string
components []Component
js string
}
//Pseudo-object creation function
func NewPagination() Pagination {
return Pagination{id: GetGlobalID()}
}
func (p *Pagination) GetID() string {
return p.id
}
func (p *Pagination) SetAlignment(alignment string) error {
switch alignment {
case "NONE":
p.alignment = ""
case "CENTER":
p.alignment = "justify-content-center"
case "END":
p.alignment = "justify-content-end"
default:
return errors.New("there is no such alignment")
}
return nil
}
///Size in 0-6 number, 0 - default 1-6 <Hx>
func (p *Pagination) SetSize(size int) error {
switch size {
case 0:
p.size = "pagination-sm"
case 1:
p.size = ""
case 2:
p.size = "pagination-lg"
default:
return errors.New("value must be in 0-2 range")
}
return nil
}
func (p *Pagination) AddItem(c interface{Component}) {
p.components = append(p.components, c)
}
func (p *Pagination) Render() string {
items := ""
for _, v := range p.components {
items += v.Render()
}
return fmt.Sprintf(`
<nav id="%s" aria-label="Page navigation example">
<ul class="pagination %s %s">
%s
</ul>
</nav>
`, p.id, p.size, p.alignment, items)
}
func (p *Pagination) RenderJS() string {
return p.js
}