-
Notifications
You must be signed in to change notification settings - Fork 6
/
span.go
64 lines (53 loc) · 1.35 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
59
60
61
62
63
64
package control
import (
"context"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/html5tag"
)
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.Self = p
p.Init(parent, id)
return p
}
func (c *Span) Init(parent page.ControlI, id string) {
c.Panel.Init(parent, id)
c.Tag = "span"
}
func (c *Span) DrawingAttributes(ctx context.Context) html5tag.Attributes {
a := c.ControlBase.DrawingAttributes(ctx)
a.SetData("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(ctx, 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)
}
func init() {
page.RegisterControl(&Span{})
}