-
Notifications
You must be signed in to change notification settings - Fork 6
/
span.go
58 lines (49 loc) · 1.3 KB
/
span.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package control
import (
"context"
"github.com/goradd/goradd/pkg/html"
"github.com/goradd/goradd/pkg/page"
)
type SpanI interface {
PanelI
}
// Span is a Goradd control that is a basic "span" wrapper. Use it to style and listen to events on a span. It
// can also be used as the basis for more advanced javascript controls.
type Span struct {
Panel
}
func NewSpan(parent page.ControlI, id string) *Span {
p := &Span{}
p.Init(p, parent, id)
return p
}
func (c *Span) Init(self SpanI, parent page.ControlI, id string) {
c.Panel.Init(self, parent, id)
c.Tag = "span"
}
func (c *Span) ΩDrawingAttributes(ctx context.Context) html.Attributes {
a := c.Control.ΩDrawingAttributes(ctx)
a.SetDataAttribute("grctl", "span")
return a
}
type SpanCreator struct {
ID string
Text string
TextIsHtml bool
Children []page.Creator
page.ControlOptions
}
func (c SpanCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI {
ctrl := NewSpan(parent, c.ID)
if c.Text != "" {
ctrl.SetText(c.Text)
}
ctrl.SetTextIsHtml(c.TextIsHtml)
ctrl.ApplyOptions(c.ControlOptions)
ctrl.AddControls(ctx, c.Children...)
return ctrl
}
// GetSpan is a convenience method to return the button with the given id from the page.
func GetSpan(c page.ControlI, id string) *Span {
return c.Page().GetControl(id).(*Span)
}