Skip to content

Commit

Permalink
Add web component elements and slot attribute (#235)
Browse files Browse the repository at this point in the history
The slot attribute is a standard attribute for use with web components:
https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots
  • Loading branch information
knpwrs authored Oct 25, 2024
1 parent 87bb2f3 commit 2e44d49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions html/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func DataAttr(name, v string) g.Node {
return Data(name, v)
}

func SlotAttr(v string) g.Node {
return g.Attr("slot", v)
}

func For(v string) g.Node {
return g.Attr("for", v)
}
Expand Down
1 change: 1 addition & 0 deletions html/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestSimpleAttributes(t *testing.T) {
{Name: "role", Func: Role},
{Name: "rows", Func: Rows},
{Name: "rowspan", Func: RowSpan},
{Name: "slot", Func: SlotAttr},
{Name: "src", Func: Src},
{Name: "srcset", Func: SrcSet},
{Name: "step", Func: Step},
Expand Down
8 changes: 8 additions & 0 deletions html/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ func Select(children ...g.Node) g.Node {
return g.El("select", children...)
}

func SlotEl(children ...g.Node) g.Node {
return g.El("slot", children...)
}

func Source(children ...g.Node) g.Node {
return g.El("source", children...)
}
Expand Down Expand Up @@ -296,6 +300,10 @@ func Td(children ...g.Node) g.Node {
return g.El("td", children...)
}

func Template(children ...g.Node) g.Node {
return g.El("template", children...)
}

func Textarea(children ...g.Node) g.Node {
return g.El("textarea", children...)
}
Expand Down
2 changes: 2 additions & 0 deletions html/elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestSimpleElements(t *testing.T) {
{Name: "script", Func: Script},
{Name: "section", Func: Section},
{Name: "select", Func: Select},
{Name: "slot", Func: SlotEl},
{Name: "small", Func: Small},
{Name: "span", Func: Span},
{Name: "strong", Func: Strong},
Expand All @@ -114,6 +115,7 @@ func TestSimpleElements(t *testing.T) {
{Name: "table", Func: Table},
{Name: "tbody", Func: TBody},
{Name: "td", Func: Td},
{Name: "template", Func: Template},
{Name: "textarea", Func: Textarea},
{Name: "tfoot", Func: TFoot},
{Name: "th", Func: Th},
Expand Down

0 comments on commit 2e44d49

Please sign in to comment.