Delete low-value helper components (#115) I'd rather reserve the package for components that have proven repeatedly useful, like `Classes` and `HTML5`.
1 file changed, 30 insertions(+), 0 deletions(-)
changed files
M components/documents_test.go → components/components_test.go
@@ -1,6 +1,7 @@ package components_test import ( + "os" "testing" g "github.com/maragudk/gomponents"@@ -30,3 +31,32 @@ assert.Equal(t, `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Hat</title></head><body></body></html>`, e) }) } + +func TestClasses(t *testing.T) { + t.Run("given a map, returns sorted keys from the map with value true", func(t *testing.T) { + assert.Equal(t, ` class="boheme-hat hat partyhat"`, Classes{ + "boheme-hat": true, + "hat": true, + "partyhat": true, + "turtlehat": false, + }) + }) + + t.Run("renders as attribute in an element", func(t *testing.T) { + e := g.El("div", Classes{"hat": true}) + assert.Equal(t, `<div class="hat"></div>`, e) + }) + + t.Run("also works with fmt", func(t *testing.T) { + a := Classes{"hat": true} + if a.String() != ` class="hat"` { + t.FailNow() + } + }) +} + +func ExampleClasses() { + e := g.El("div", Classes{"party-hat": true, "boring-hat": false}) + _ = e.Render(os.Stdout) + // Output: <div class="party-hat"></div> +}