From 2e44d495769421423921bfcb06ebfc53f8370dd3 Mon Sep 17 00:00:00 2001
From: Ken Powers
Date: Fri, 25 Oct 2024 14:34:35 -0400
Subject: Add web component elements and slot attribute (#235)

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---
 html/attributes.go      | 4 ++++
 html/attributes_test.go | 1 +
 html/elements.go        | 8 ++++++++
 html/elements_test.go   | 2 ++
 4 files changed, 15 insertions(+)

(limited to 'html')

diff --git a/html/attributes.go b/html/attributes.go
index 2e9a05a..be8393e 100644
--- a/html/attributes.go
+++ b/html/attributes.go
@@ -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)
 }
diff --git a/html/attributes_test.go b/html/attributes_test.go
index e5ea3f4..67b98f4 100644
--- a/html/attributes_test.go
+++ b/html/attributes_test.go
@@ -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},
diff --git a/html/elements.go b/html/elements.go
index efc83df..bf747a1 100644
--- a/html/elements.go
+++ b/html/elements.go
@@ -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...)
 }
@@ -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...)
 }
diff --git a/html/elements_test.go b/html/elements_test.go
index 0b9dd02..5fe6268 100644
--- a/html/elements_test.go
+++ b/html/elements_test.go
@@ -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},
@@ -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},
-- 
cgit 1.4.1