add some more attributes

This commit is contained in:
maddalax 2024-09-29 01:05:22 -05:00
parent c045e880a7
commit 66fa5c2cf0
3 changed files with 131 additions and 14 deletions

View file

@ -51,11 +51,12 @@ func Input(list []*ent.Task) *h.Element {
h.Class("border border-b-slate-100 relative"),
h.Input(
"text",
h.Attribute("required", "true"),
h.Attribute("maxlength", "150"),
h.Attribute("autocomplete", "off"),
h.Attribute("autofocus", "true"),
h.Attribute("name", "name"),
h.Required(),
h.Disabled(),
h.MaxLength(150),
h.AutoComplete("off"),
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.Placeholder("What needs to be done?"),
h.Post(h.GetPartialPath(Create)),
@ -145,8 +146,8 @@ func Task(task *ent.Task, editing bool) *h.Element {
h.Form(
h.Class("h-full"),
h.Input("text",
h.Attribute("name", "task"),
h.Attribute("value", task.ID.String()),
h.Name("task"),
h.Value(task.ID.String()),
h.Class("hidden"),
),
h.Input(

View file

@ -58,7 +58,7 @@ func AttributePairs(pairs ...string) *AttributeMap {
}
func Checked() Ren {
return Attribute("checked", "true")
return Attribute("checked", "")
}
func Id(value string) Ren {
@ -68,7 +68,7 @@ func Id(value string) Ren {
return Attribute("id", value)
}
func Disabled() Ren {
func Disabled() *AttributeR {
return Attribute("disabled", "")
}
@ -182,3 +182,115 @@ func Boost() Ren {
func IfQueryParam(key string, node *Element) Ren {
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))
}

View file

@ -3,7 +3,7 @@ package h
import (
"fmt"
"github.com/maddalax/htmgo/framework/hx"
"golang.org/x/net/html"
"html"
"html/template"
"strings"
)
@ -161,10 +161,14 @@ func renderScripts(context *RenderContext) {
func (a *AttributeR) Render(context *RenderContext) {
context.builder.WriteString(a.Name)
if a.Value != "" {
context.builder.WriteString(`=`)
context.builder.WriteString(`"`)
context.builder.WriteString(html.EscapeString(a.Value))
context.builder.WriteString(`"`)
} else {
context.builder.WriteString(" ")
}
}
func (t *TextContent) Render(context *RenderContext) {