about summary refs log tree commit diff stats
path: root/internal/components/search.go
blob: 0a7c991476079494159c39ed1de69bd7827f6012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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")),
			),
		),
	)
}