D3vugu-components/components/input/button.go
David Vogel cd35a61dc8 Support button to bind to boolean variables
- Bring back d3c-color-accent
- Reduce number of CSS color variables
2023-05-25 16:37:46 +02:00

34 lines
794 B
Go

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})
}
}