D3vugu-components/components/input/button.go

34 lines
794 B
Go
Raw Permalink Normal View History

2023-05-08 18:43:07 +00:00
package input
import "github.com/vugu/vugu"
type Button struct {
AttrMap vugu.AttrMap
IconSlot vugu.Builder `vugu:"data"` // Slot for the symbol.
DefaultSlot vugu.Builder `vugu:"data"`
Bind *bool `vugu:"data"` // A data binding with some bool variable. If this contains a reference, the button can be toggled.
Click ClickHandler // External handler that is called upon an event.
classes string // Additional computed classes that are added to the component.
}
func (c *Button) Compute(ctx vugu.ComputeCtx) {
if c.Bind != nil && *c.Bind {
c.classes = "d3c-color-accent"
} else {
c.classes = ""
}
}
func (c *Button) HandleClick(event vugu.DOMEvent) {
if c.Bind != nil {
*c.Bind = !*c.Bind
}
if c.Click != nil {
c.Click.ClickHandle(ClickEvent{DOMEvent: event})
}
2023-05-08 18:43:07 +00:00
}