godash/components/application.templ

40 lines
1.1 KiB
Text

package components
import (
"gitlab.unjx.de/flohoss/godash/services"
"html/template"
)
var ImageTemplate = template.Must(template.New("bar").Parse("<div class=\"{{ .Background }}img rounded w-8 h-8 bg-contain bg-center bg-origin-content bg-no-repeat opacity-90\" style=\"background-image: url({{ .Icon }})\"></div>"))
type Image struct {
Background string
Icon string
}
func backgroundColor(config string) string {
result := "p-[0.05rem] "
switch config {
case "dark":
return result + "bg-black "
case "light":
return result + "bg-white "
case "base":
return result + "bg-base-300 "
default:
return ""
}
}
templ Application(application services.Application) {
<a href={ templ.URL(application.URL) } class="flex items-center hover-effect">
@templ.FromGoHTML(ImageTemplate, Image{Background: backgroundColor(application.Background), Icon: application.Icon})
<div class="uppercase truncate ml-2">{ application.Name }</div>
</a>
}
templ Link(link services.Link) {
<a href={ templ.URL(link.URL) } class="hover-effect">
<div class="truncate">{ link.Name }</div>
</a>
}