Skip to content

Commit

Permalink
divclass, passwordinput
Browse files Browse the repository at this point in the history
  • Loading branch information
gsiehien committed Apr 26, 2023
1 parent 9bd2c74 commit 4ba80b3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (n *EmbNode) Div(id string, style string, text string) *EmbNode {
return n.add(&EmbNode{ID: id, HTMLTag: "div", Style: style, Text: text})
}

// DivClass generates <div> with custom id and class
func (n *EmbNode) DivClass(id string, class string, text string) *EmbNode {
return n.add(&EmbNode{ID: id, HTMLTag: "div", Class: class, Text: text})
}

// Box generates div-box element
func (n *EmbNode) Box() *EmbNode {
return n.add(&EmbNode{HTMLTag: "div", Class: "box"})
Expand Down Expand Up @@ -194,7 +199,7 @@ func (n *EmbNode) Form(action string, method string) *EmbNode {
// FormInput generates a text input inside form
func (n *EmbNode) FormInput(label string, hideLabel bool, name string, value string) *EmbNode {
fieldWrapper := n.add(&EmbNode{HTMLTag: "div", Class: "field"})
if hideLabel == false {
if !hideLabel {
fieldWrapper.add(&EmbNode{HTMLTag: "label", Class: "label", Text: label})
fieldWrapper.add(&EmbNode{HTMLTag: "div", Class: "control"}).
add(&EmbNode{HTMLTag: "input", Type: "text", Class: "input", Name: name, Value: value})
Expand All @@ -205,14 +210,23 @@ func (n *EmbNode) FormInput(label string, hideLabel bool, name string, value str
return fieldWrapper
}

// FormInput generates a text input inside form
func (n *EmbNode) FormPasswordInput(label string, name string) *EmbNode {
fieldWrapper := n.add(&EmbNode{HTMLTag: "div", Class: "field"})
fieldWrapper.add(&EmbNode{HTMLTag: "label", Class: "label", Text: label})
fieldWrapper.add(&EmbNode{HTMLTag: "div", Class: "control"}).
add(&EmbNode{HTMLTag: "input", Type: "password", Class: "input", Name: name})
return fieldWrapper
}

// FormCheckbox generates a checkbox inside form
func (n *EmbNode) FormCheckbox(label string, name string) *EmbNode {
fieldWrapper := n.add(&EmbNode{HTMLTag: "div", Class: "field"})
controlWrapper := fieldWrapper.add(&EmbNode{HTMLTag: "div", Class: "control"})
inputHTMLString := (&EmbNode{HTMLTag: "input", Type: "checkbox", Name: name}).render()

labelWrapper := controlWrapper.add(&EmbNode{HTMLTag: "label", Class: "checkbox", Text: inputHTMLString + " " + label, Unsafe: true})
// labelWrapper.add(&EmbNode{HTMLTag: "input", Type: "checkbox", Name: name})
// labelWrapper.add(&EmbNode{HTMLTag: "input", Type: "checkbox", Name: name})
return labelWrapper
}

Expand Down Expand Up @@ -246,7 +260,7 @@ func (n *EmbNode) FormRadio(label string, name string) *EmbNode {
func (n *EmbNode) FormRadioOption(label string, name string) *EmbNode {
inputHTMLString := (&EmbNode{HTMLTag: "input", Type: "radio", Name: name, Value: label}).render()
option := n.add(&EmbNode{HTMLTag: "label", Class: "radio", Text: inputHTMLString + " " + label, Unsafe: true})
// option.add(&EmbNode{HTMLTag: "input", Type: "radio", Name: name, Value: label})
// option.add(&EmbNode{HTMLTag: "input", Type: "radio", Name: name, Value: label})
return option
}

Expand Down

0 comments on commit 4ba80b3

Please sign in to comment.