From a76262652b227c95ce140f3698c46f59b79354ac Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Thu, 10 Dec 2020 13:00:23 +0100 Subject: Move elements and attributes into html package (#52) This makes it easier to use dot-imports. Also updated the readme and examples with new usage, and move the `Classes` helper into the `components` package.--- el/elements.go | 68 ---------------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 el/elements.go (limited to 'el/elements.go') diff --git a/el/elements.go b/el/elements.go deleted file mode 100644 index 0841ff8..0000000 --- a/el/elements.go +++ /dev/null @@ -1,68 +0,0 @@ -// Package el provides shortcuts and helpers to common HTML elements. -// See https://developer.mozilla.org/en-US/docs/Web/HTML/Element for a list of elements. -package el - -import ( - "fmt" - "io" - - g "github.com/maragudk/gomponents" -) - -func A(href string, children ...g.Node) g.NodeFunc { - return g.El("a", g.Attr("href", href), g.Group(children)) -} - -// Document returns an special kind of Node that prefixes its child with the string "". -func Document(child g.Node) g.NodeFunc { - return func(w io.Writer) error { - if _, err := w.Write([]byte("")); err != nil { - return err - } - return child.Render(w) - } -} - -// Form returns an element with name "form", the given action and method attributes, and the given children. -func Form(action, method string, children ...g.Node) g.NodeFunc { - return g.El("form", g.Attr("action", action), g.Attr("method", method), g.Group(children)) -} - -func Img(src, alt string, children ...g.Node) g.NodeFunc { - return g.El("img", g.Attr("src", src), g.Attr("alt", alt), g.Group(children)) -} - -// Input returns an element with name "input", the given type and name attributes, and the given children. -// Note that "type" is a keyword in Go, so the parameter is called typ. -func Input(typ, name string, children ...g.Node) g.NodeFunc { - return g.El("input", g.Attr("type", typ), g.Attr("name", name), g.Group(children)) -} - -// Label returns an element with name "label", the given for attribute, and the given children. -// Note that "for" is a keyword in Go, so the parameter is called forr. -func Label(forr string, children ...g.Node) g.NodeFunc { - return g.El("label", g.Attr("for", forr), g.Group(children)) -} - -// Option returns an element with name "option", the given text content and value attribute, and the given children. -func Option(text, value string, children ...g.Node) g.NodeFunc { - return g.El("option", g.Attr("value", value), g.Text(text), g.Group(children)) -} - -// Progress returns an element with name "progress", the given value and max attributes, and the given children. -func Progress(value, max float64, children ...g.Node) g.NodeFunc { - return g.El("progress", - g.Attr("value", fmt.Sprintf("%v", value)), - g.Attr("max", fmt.Sprintf("%v", max)), - g.Group(children)) -} - -// Select returns an element with name "select", the given name attribute, and the given children. -func Select(name string, children ...g.Node) g.NodeFunc { - return g.El("select", g.Attr("name", name), g.Group(children)) -} - -// Textarea returns an element with name "textarea", the given name attribute, and the given children. -func Textarea(name string, children ...g.Node) g.NodeFunc { - return g.El("textarea", g.Attr("name", name), g.Group(children)) -} -- cgit 1.4.1