diff options
author | Alan Pearce | 2025-03-18 22:40:46 +0100 |
---|---|---|
committer | Alan Pearce | 2025-03-19 17:33:58 +0100 |
commit | 896d844cac976afd0ee8aa73dd2fb28e15e7ac79 (patch) | |
tree | cc8d288d0039cb3d2084f43cafe8d4e0aea50e8b /internal/components/search.go | |
parent | 1183108baa44fde88944e9207fb7763668c2b448 (diff) | |
download | searchix-896d844cac976afd0ee8aa73dd2fb28e15e7ac79.tar.lz searchix-896d844cac976afd0ee8aa73dd2fb28e15e7ac79.tar.zst searchix-896d844cac976afd0ee8aa73dd2fb28e15e7ac79.zip |
feat: Convert templ components to gomponents
Diffstat (limited to 'internal/components/search.go')
-rw-r--r-- | internal/components/search.go | 63 |
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")), + ), + ), + ) +} |