Default classes for implemented elements.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user