12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package element
- import (
- "golang.org/x/net/html/atom"
- "html"
- )
- 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 renderTag(atom.A.String(), Attrs{
- "class": "button",
- "href": element.Url,
- "style": element.Style.String(),
- }, html.EscapeString(element.Text))
- }
- func NewButton(label, link string, opts ...ButtonOption) *Button {
- btn := &Button{Text: label, Url: link}
- for _, cb := range opts {
- cb(btn)
- }
- return btn
- }
|