package element import ( "golang.org/x/net/html/atom" ) type ( ButtonOption func(btn *Button) Button struct { Url string Text string Color string Style Style } ) func (element *Button) Html() string { return element.String() } func (element *Button) String() string { if element.Style == nil { element.Style = make(map[string]string) } if element.Color != "" { element.Style["color"] = element.Color } return NewElement(atom.A, element.Text, WithAttribute("class", "button"), WithAttribute("href", element.Url), WithAttribute("style", element.Style.String()), ).String() } func NewButton(label, link string, opts ...ButtonOption) *Button { btn := &Button{Text: label, Url: link} for _, cb := range opts { cb(btn) } return btn }