generate elem with go

This commit is contained in:
Ettore Di Giacinto
2024-04-14 00:31:24 +02:00
parent 7c0f615952
commit 80508001c7
7 changed files with 75 additions and 59 deletions

View File

@@ -3,24 +3,33 @@ package main
import (
"fmt"
"strings"
elem "github.com/chasefleming/elem-go"
"github.com/chasefleming/elem-go/attrs"
)
// TODO: switch to https://github.com/chasefleming/elem-go
func chatDiv(content string, color string) string {
return fmt.Sprintf(`<div class="p-2 my-2 rounded bg-%s-600">%s</div>`, color, htmlIfy(content))
div := elem.Div(attrs.Props{
// attrs.ID: "container",
attrs.Class: fmt.Sprintf("p-2 my-2 rounded bg-%s-600", color),
},
elem.Raw(htmlIfy(content)),
)
return div.Render()
}
func loader() string {
return `<div class="loader"></div>`
return elem.Div(attrs.Props{
attrs.Class: "loader",
}).Render()
}
func disabledElement(id string, disabled bool) string {
if disabled {
return `<script> document.getElementById('` + id + `').disabled = true;</script>`
}
return `<script> document.getElementById('` + id + `').disabled = false;</script>`
return elem.Script(nil,
elem.If(disabled,
elem.Raw(`document.getElementById('`+id+`').disabled = true`),
elem.Raw(`document.getElementById('`+id+`').disabled = false`),
)).Render()
}
func htmlIfy(s string) string {