some fixes for childlist
This commit is contained in:
parent
ec30a4e7e8
commit
fd0d72362f
3 changed files with 16 additions and 7 deletions
|
|
@ -37,7 +37,13 @@ func NewTextContent(content string) *TextContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChildList(children ...Ren) *ChildList {
|
func NewChildList(children ...Ren) *ChildList {
|
||||||
return &ChildList{
|
cl := &ChildList{
|
||||||
Children: children,
|
Children: Filter(children, func(item Ren) bool {
|
||||||
|
return item != nil
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
if len(children) == 0 || children == nil {
|
||||||
|
cl.Children = make([]Ren, 0)
|
||||||
|
}
|
||||||
|
return cl
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,15 +90,17 @@ func (node *Element) Render(context *RenderContext) {
|
||||||
if shouldFlatten {
|
if shouldFlatten {
|
||||||
// first pass, flatten the children
|
// first pass, flatten the children
|
||||||
flatChildren := make([]Ren, totalChildren)
|
flatChildren := make([]Ren, totalChildren)
|
||||||
for i, child := range node.children {
|
index := 0
|
||||||
|
for _, child := range node.children {
|
||||||
switch c := child.(type) {
|
switch c := child.(type) {
|
||||||
case *ChildList:
|
case *ChildList:
|
||||||
for _, ren := range c.Children {
|
for _, ren := range c.Children {
|
||||||
flatChildren[i] = ren
|
flatChildren[index] = ren
|
||||||
i++
|
index++
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
flatChildren[i] = child
|
flatChildren[index] = child
|
||||||
|
index++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,9 @@ func SubmitButton() *h.Element {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Spinner() *h.Element {
|
func Spinner(children ...h.Ren) *h.Element {
|
||||||
return h.Div(
|
return h.Div(
|
||||||
|
h.Children(children...),
|
||||||
h.Class("absolute left-1 spinner spinner-border animate-spin inline-block w-6 h-6 border-4 rounded-full border-slate-200 border-t-transparent"),
|
h.Class("absolute left-1 spinner spinner-border animate-spin inline-block w-6 h-6 border-4 rounded-full border-slate-200 border-t-transparent"),
|
||||||
h.Attribute("role", "status"),
|
h.Attribute("role", "status"),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue