12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package element
- import (
- "git.nspix.com/golang/pgenr/internal/pool"
- "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 {
- br := pool.Get()
- defer pool.Put(br)
- if element.Style == nil {
- element.Style = make(map[string]string)
- }
- if element.Color != "" {
- element.Style["color"] = element.Color
- }
- br.WriteString(renderTag(atom.A.String(), Attrs{"class": "button", "href": element.Url, "style": element.Style.String()}, html.EscapeString(element.Text)))
- return br.String()
- }
- func NewButton(label, link string, opts ...ButtonOption) *Button {
- btn := &Button{Text: label, Url: link}
- for _, cb := range opts {
- cb(btn)
- }
- return btn
- }
|