about summary refs log tree commit diff stats
path: root/internal/components/search.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/components/search.go')
-rw-r--r--internal/components/search.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/components/search.go b/internal/components/search.go
new file mode 100644
index 0000000..0a7c991
--- /dev/null
+++ b/internal/components/search.go
@@ -0,0 +1,63 @@
+package components
+
+import (
+	g "go.alanpearce.eu/gomponents"
+	. "go.alanpearce.eu/gomponents/html"
+)
+
+func Search(tdata TemplateData, r ResultData) g.Node {
+	return Form(
+		ID("search"),
+		Role("search"),
+		FieldSet(
+			Legend(
+				ID("legend"),
+				H2(g.Textf("%s search", sourceNameAndType(tdata.Source))),
+			),
+			Input(
+				ID("query"),
+				Aria("labelledby", "legend"),
+				Name("query"),
+				Type("search"),
+				Value(r.Query),
+				AutoFocus(),
+				g.Attr("spellcheck", "false"),
+				g.Attr("autocapitalize", "none"),
+			),
+			Button(g.Text("Search")),
+		),
+	)
+}
+
+func SearchPage(tdata TemplateData, r ResultData, children ...g.Node) g.Node {
+	return Page(
+		tdata,
+		P(
+			g.Text("Search Nix packages and options from "),
+			A(Href("https://nixos.org"), g.Text("NixOS")),
+			g.Text(", "),
+			A(Href("https://github.com/LnL7/nix-darwin"), g.Text("nix-darwin")),
+			g.Text(" and "),
+			A(Href("https://github.com/nix-community/home-manager"), g.Text("home-manager")),
+		),
+		script(tdata.Assets.ByPath["/static/search.js"]),
+		Search(tdata, r),
+		Section(
+			ID("results"),
+			Role("list"),
+			Aria("label", "search results"),
+			g.Group(children),
+		),
+		Dialog(
+			ID("dialog"),
+			Button(AutoFocus(), g.Text("Close")),
+		),
+		NoScript(
+			P(
+				Class("notice"),
+				g.Text("Everything should work fine without JavaScript. If that is not the case, "),
+				A(Href("https://todo.sr.ht/~alanpearce/searchix"), g.Text("report an issue")),
+			),
+		),
+	)
+}