-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconbutton.go
93 lines (69 loc) · 1.6 KB
/
iconbutton.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
package mdc
// https://material.io/develop/web/components/buttons/icon-buttons
import (
"fmt"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
type iconButton struct {
app.Compo
id string
mdcComponent app.Value
Iicon string
IonClick app.EventHandler
Iclass []string
}
type IIconButton interface {
app.UI
ID(string) IIconButton
Icon(string) IIconButton
OnClick(app.EventHandler) IIconButton
Class(...string) IIconButton
}
func (b *iconButton) ID(id string) IIconButton {
b.id = id
return b
}
func (b *iconButton) Icon(icon string) IIconButton {
b.Iicon = icon
return b
}
func (b *iconButton) OnClick(handler app.EventHandler) IIconButton {
b.IonClick = handler
return b
}
func (b *iconButton) Class(c ...string) IIconButton {
b.Iclass = append(b.Iclass, c...)
return b
}
func (b *iconButton) OnMount(ctx app.Context) {
if b.id == "" {
b.id = fmt.Sprintf("iconbutton-%d", allocID())
}
// FIXME: For some reason this causes a spurious additional
// circle
// b.mdcComponent = app.Window().
// Get("mdc").
// Get("ripple").
// Get("MDCRipple").
// Call("attachTo", ctx.JSSrc())
app.Log("mounted", b.id, b.mdcComponent)
}
func (b *iconButton) OnDismount(ctx app.Context) {
// b.mdcComponent.Call("destroy")
}
func (b *iconButton) Render() app.UI {
iconButton := app.Button().
Class("mdc-icon-button", "material-icons").
Class(b.Iclass...).
ID(b.id)
if b.IonClick != nil {
iconButton = iconButton.OnClick(b.IonClick)
}
return iconButton.Body(
app.Div().Class("mdc-icon-button__ripple"),
app.Text(b.Iicon),
)
}
func IconButton() IIconButton {
return &iconButton{}
}