-
Notifications
You must be signed in to change notification settings - Fork 0
/
appbar.go
114 lines (90 loc) · 1.96 KB
/
appbar.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 mdc
// https://material.io/components/app-bars-top/web#using-the-top-app-bar
import (
"fmt"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
const (
AppBarMainClass = "mdc-top-app-bar--fixed-adjust"
AppBarNavigationClass = "mdc-top-app-bar__navigation-item"
AppBarActionClass = "mdc-top-app-bar__action-item"
)
type appBarTop struct {
app.Compo
id string
mdcComponent app.Value
InavButton app.UI
Ititle string
IactionButtons []app.UI
IonClick app.EventHandler
}
type IAppBar interface {
app.UI
ID(string) IAppBar
NavIcon(app.UI) IAppBar
Title(string) IAppBar
Actions(...app.UI) IAppBar
}
func (a *appBarTop) ID(id string) IAppBar {
a.id = id
return a
}
func (a *appBarTop) NavIcon(icon app.UI) IAppBar {
a.InavButton = icon
return a
}
func (a *appBarTop) Title(t string) IAppBar {
a.Ititle = t
return a
}
func (a *appBarTop) Actions(v ...app.UI) IAppBar {
a.IactionButtons = app.FilterUIElems(v...)
return a
}
func (a *appBarTop) OnMount(ctx app.Context) {
if a.id == "" {
a.id = fmt.Sprintf("appbar-%d", allocID())
}
a.mdcComponent = app.Window().
Get("mdc").
Get("topAppBar").
Get("MDCTopAppBar").
Call("attachTo", ctx.JSSrc())
app.Log("mounted", a.id, a.mdcComponent)
}
func (a *appBarTop) OnDismount(ctx app.Context) {
a.mdcComponent.Call("destroy")
}
func (a *appBarTop) Render() app.UI {
appBarTop := app.Header().
Class("mdc-top-app-bar").
ID(a.id)
sectionStart := app.Section().
Class("mdc-top-app-bar__section").
Class("mdc-top-app-bar__section--align-start").
Body(
a.InavButton,
app.Span().
Class("mdc-top-app-bar__title").
Text(a.Ititle),
)
sectionEnd := app.Section().
Class("mdc-top-app-bar__section").
Class("mdc-top-app-bar__section--align-end").
Role("toolbar").
Body(
a.IactionButtons...,
)
row := app.Div().
Class("mdc-top-app-bar__row").
Body(
sectionStart,
sectionEnd,
)
return appBarTop.Body(
row,
)
}
func AppBarTop() IAppBar {
return &appBarTop{}
}