add some more attributes
This commit is contained in:
parent
c045e880a7
commit
66fa5c2cf0
3 changed files with 131 additions and 14 deletions
|
|
@ -51,11 +51,12 @@ func Input(list []*ent.Task) *h.Element {
|
||||||
h.Class("border border-b-slate-100 relative"),
|
h.Class("border border-b-slate-100 relative"),
|
||||||
h.Input(
|
h.Input(
|
||||||
"text",
|
"text",
|
||||||
h.Attribute("required", "true"),
|
h.Required(),
|
||||||
h.Attribute("maxlength", "150"),
|
h.Disabled(),
|
||||||
h.Attribute("autocomplete", "off"),
|
h.MaxLength(150),
|
||||||
h.Attribute("autofocus", "true"),
|
h.AutoComplete("off"),
|
||||||
h.Attribute("name", "name"),
|
h.AutoFocus(),
|
||||||
|
h.Name("name"),
|
||||||
h.Class("pl-12 text-xl p-4 w-full outline-none focus:outline-2 focus:outline-rose-400"),
|
h.Class("pl-12 text-xl p-4 w-full outline-none focus:outline-2 focus:outline-rose-400"),
|
||||||
h.Placeholder("What needs to be done?"),
|
h.Placeholder("What needs to be done?"),
|
||||||
h.Post(h.GetPartialPath(Create)),
|
h.Post(h.GetPartialPath(Create)),
|
||||||
|
|
@ -145,8 +146,8 @@ func Task(task *ent.Task, editing bool) *h.Element {
|
||||||
h.Form(
|
h.Form(
|
||||||
h.Class("h-full"),
|
h.Class("h-full"),
|
||||||
h.Input("text",
|
h.Input("text",
|
||||||
h.Attribute("name", "task"),
|
h.Name("task"),
|
||||||
h.Attribute("value", task.ID.String()),
|
h.Value(task.ID.String()),
|
||||||
h.Class("hidden"),
|
h.Class("hidden"),
|
||||||
),
|
),
|
||||||
h.Input(
|
h.Input(
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func AttributePairs(pairs ...string) *AttributeMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Checked() Ren {
|
func Checked() Ren {
|
||||||
return Attribute("checked", "true")
|
return Attribute("checked", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Id(value string) Ren {
|
func Id(value string) Ren {
|
||||||
|
|
@ -68,7 +68,7 @@ func Id(value string) Ren {
|
||||||
return Attribute("id", value)
|
return Attribute("id", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Disabled() Ren {
|
func Disabled() *AttributeR {
|
||||||
return Attribute("disabled", "")
|
return Attribute("disabled", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,3 +182,115 @@ func Boost() Ren {
|
||||||
func IfQueryParam(key string, node *Element) Ren {
|
func IfQueryParam(key string, node *Element) Ren {
|
||||||
return Fragment(Attribute("hx-if-qp:"+key, "true"), node)
|
return Fragment(Attribute("hx-if-qp:"+key, "true"), node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadOnly() *AttributeR {
|
||||||
|
return Attribute("readonly", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Required() *AttributeR {
|
||||||
|
return Attribute("required", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Multiple() *AttributeR {
|
||||||
|
return Attribute("multiple", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Selected() *AttributeR {
|
||||||
|
return Attribute("selected", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func MaxLength(value int) *AttributeR {
|
||||||
|
return Attribute("maxlength", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func MinLength(value int) *AttributeR {
|
||||||
|
return Attribute("minlength", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Size(value int) *AttributeR {
|
||||||
|
return Attribute("size", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Width(value int) *AttributeR {
|
||||||
|
return Attribute("width", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Height(value int) *AttributeR {
|
||||||
|
return Attribute("height", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Download(value bool) *AttributeR {
|
||||||
|
return Attribute("download", fmt.Sprintf("%t", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Rel(value string) *AttributeR {
|
||||||
|
return Attribute("rel", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Pattern(value string) *AttributeR {
|
||||||
|
return Attribute("pattern", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Action(value string) *AttributeR {
|
||||||
|
return Attribute("action", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Method(value string) *AttributeR {
|
||||||
|
return Attribute("method", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Enctype(value string) *AttributeR {
|
||||||
|
return Attribute("enctype", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AutoComplete(value string) *AttributeR {
|
||||||
|
return Attribute("autocomplete", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AutoFocus() *AttributeR {
|
||||||
|
return Attribute("autofocus", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NoValidate() *AttributeR {
|
||||||
|
return Attribute("novalidate", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Step(value string) *AttributeR {
|
||||||
|
return Attribute("step", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Max(value string) *AttributeR {
|
||||||
|
return Attribute("max", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Min(value string) *AttributeR {
|
||||||
|
return Attribute("min", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Cols(value int) *AttributeR {
|
||||||
|
return Attribute("cols", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Rows(value int) *AttributeR {
|
||||||
|
return Attribute("rows", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Wrap(value string) *AttributeR {
|
||||||
|
return Attribute("wrap", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Role(value string) *AttributeR {
|
||||||
|
return Attribute("role", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AriaLabel(value string) *AttributeR {
|
||||||
|
return Attribute("aria-label", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AriaHidden(value bool) *AttributeR {
|
||||||
|
return Attribute("aria-hidden", fmt.Sprintf("%t", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TabIndex(value int) *AttributeR {
|
||||||
|
return Attribute("tabindex", fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package h
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/maddalax/htmgo/framework/hx"
|
"github.com/maddalax/htmgo/framework/hx"
|
||||||
"golang.org/x/net/html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
@ -161,10 +161,14 @@ func renderScripts(context *RenderContext) {
|
||||||
|
|
||||||
func (a *AttributeR) Render(context *RenderContext) {
|
func (a *AttributeR) Render(context *RenderContext) {
|
||||||
context.builder.WriteString(a.Name)
|
context.builder.WriteString(a.Name)
|
||||||
|
if a.Value != "" {
|
||||||
context.builder.WriteString(`=`)
|
context.builder.WriteString(`=`)
|
||||||
context.builder.WriteString(`"`)
|
context.builder.WriteString(`"`)
|
||||||
context.builder.WriteString(html.EscapeString(a.Value))
|
context.builder.WriteString(html.EscapeString(a.Value))
|
||||||
context.builder.WriteString(`"`)
|
context.builder.WriteString(`"`)
|
||||||
|
} else {
|
||||||
|
context.builder.WriteString(" ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TextContent) Render(context *RenderContext) {
|
func (t *TextContent) Render(context *RenderContext) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue