-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_button.go
71 lines (63 loc) · 1.47 KB
/
component_button.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
package components
import (
"github.com/hexops/vecty"
"github.com/hexops/vecty/elem"
"github.com/hexops/vecty/event"
"github.com/hexops/vecty/prop"
"github.com/stas-makutin/howeve/page/core"
)
type MdcButton struct {
vecty.Core
core.Classes
core.Keyable
ID string `vecty:"prop"`
Text string `vecty:"prop"`
Disabled bool `vecty:"prop"`
clickFn func()
}
func NewMdcButton(id string, text string, disabled bool, clickFn func()) (r *MdcButton) {
r = &MdcButton{ID: id, Text: text, Disabled: disabled, clickFn: clickFn}
return
}
func (ch *MdcButton) onClick(event *vecty.Event) {
ch.clickFn()
}
func (ch *MdcButton) WithKey(key interface{}) *MdcButton {
ch.Keyable.WithKey(key)
return ch
}
func (ch *MdcButton) WithClasses(classes ...string) *MdcButton {
ch.Classes.WithClasses(classes...)
return ch
}
func (ch *MdcButton) Copy() vecty.Component {
cpy := *ch
return &cpy
}
func (ch *MdcButton) Render() vecty.ComponentOrHTML {
return elem.Button(
vecty.Markup(
prop.ID(ch.ID),
vecty.Class("mdc-button", "mdc-button--outlined"),
ch.ApplyClasses(),
prop.Disabled(ch.Disabled),
event.Click(ch.onClick),
),
elem.Span(
vecty.Markup(
vecty.Class("mdc-button__ripple"),
),
),
elem.Span(
vecty.Markup(
vecty.Class("mdc-button__focus-ring"),
),
),
elem.Span(
vecty.Markup(
vecty.Class("mdc-button__label"),
),
vecty.Text(ch.Text),
),
)
}