Default classes for implemented elements.

This commit is contained in:
2020-03-21 22:16:30 +05:00
parent cc5c1a3e20
commit 5d2d29a61d
5 changed files with 47 additions and 3 deletions

View File

@@ -1,12 +1,18 @@
package elements
import (
"strings"
"github.com/gopherjs/gopherjs/js"
"go.dev.pztrn.name/bulpherjs/common"
"go.dev.pztrn.name/bulpherjs/metas"
)
const (
buttonDefaultClass = "button"
)
// ButtonOptions is a "button" HTML element configuration structure.
type ButtonOptions struct {
Class string
@@ -35,9 +41,17 @@ func (b *Button) Build() *js.Object {
b.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementButton)
if b.options == nil {
b.AddClassesFromString(buttonDefaultClass)
b.BuildChilds(b.Object)
return b.Object
}
// Button should always have "button" class.
if !strings.Contains(b.options.Class, "button") {
b.options.Class += " button"
}
if b.options.Class != "" {
b.AddClassesFromString(b.options.Class)
}

View File

@@ -1,12 +1,18 @@
package elements
import (
"strings"
"github.com/gopherjs/gopherjs/js"
"go.dev.pztrn.name/bulpherjs/common"
"go.dev.pztrn.name/bulpherjs/metas"
)
const (
navDefaultClass = "navbar"
)
// NavOptions is a "nav" HTML element configuration structure.
type NavOptions struct {
Class string
@@ -33,9 +39,16 @@ func (n *Nav) Build() *js.Object {
n.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementNav)
if n.options == nil {
n.AddClassesFromString(navDefaultClass)
n.BuildChilds(n.Object)
return n.Object
}
if !strings.Contains(n.options.Class, "navbar") {
n.options.Class += " navbar"
}
if n.options.Class != "" {
n.AddClassesFromString(n.options.Class)
}

View File

@@ -1,12 +1,18 @@
package elements
import (
"strings"
"github.com/gopherjs/gopherjs/js"
"go.dev.pztrn.name/bulpherjs/common"
"go.dev.pztrn.name/bulpherjs/metas"
)
const (
sectionDefaultClass = "section"
)
// SectionOptions is a "section" HTML element configuration structure.
type SectionOptions struct {
Class string
@@ -31,6 +37,17 @@ func NewSection(sectionOptions *SectionOptions) *Section {
func (s *Section) Build() *js.Object {
s.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementSection)
if s.options == nil {
s.AddClassesFromString(sectionDefaultClass)
s.BuildChilds(s.Object)
return s.Object
}
if !strings.Contains(s.options.Class, "section") {
s.options.Class += " section"
}
if s.options.Class != "" {
s.AddClassesFromString(s.options.Class)
}