-
Notifications
You must be signed in to change notification settings - Fork 6
/
input_group.go
79 lines (68 loc) · 1.67 KB
/
input_group.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package control
import (
"context"
"github.com/goradd/goradd/pkg/bootstrap/config"
"github.com/goradd/goradd/pkg/page"
grctl "github.com/goradd/goradd/pkg/page/control"
)
type InputGroupI interface {
grctl.PanelI
}
type InputGroup struct {
grctl.Panel
}
// NewInputGroup creates a new input group
func NewInputGroup(parent page.ControlI, id string) *InputGroup {
b := new(InputGroup)
b.Init(b, parent, id)
return b
}
func (g *InputGroup) Init(self any, parent page.ControlI, id string) {
g.Panel.Init(self, parent, id)
config.LoadBootstrap(g.ParentForm())
}
func (g *InputGroup) this() InputGroupI {
return g.Self().(InputGroupI)
}
type InputGroupCreator struct {
// ID is the control id
ID string
Prepend []page.Creator
Child page.Creator
Append []page.Creator
page.ControlOptions
}
// Create is called by the framework to create a new control from the Creator. You
// do not normally need to call this.
func (c InputGroupCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI {
ctrl := NewInputGroup(parent, c.ID)
ctrl.AddClass("input-group")
var children []page.Creator
if c.Prepend != nil {
children = append(children,
grctl.PanelCreator{
Children: c.Prepend,
ControlOptions: page.ControlOptions{
Class: "input-group-prepend",
},
},
)
}
children = append(children, c.Child)
if c.Append != nil {
children = append(children,
grctl.PanelCreator{
Children: c.Append,
ControlOptions: page.ControlOptions{
Class: "input-group-append",
},
},
)
}
ctrl.ApplyOptions(ctx, c.ControlOptions)
ctrl.AddControls(ctx, children...)
return ctrl
}
func init() {
page.RegisterControl(new(InputGroup))
}