585 lines
30 KiB
Go
585 lines
30 KiB
Go
// Code generated by templ - DO NOT EDIT.
|
|
|
|
// templ: version: v0.3.865
|
|
// templui component rating - version: main installed by templui v0.71.0
|
|
|
|
package rating
|
|
|
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
|
|
|
import "github.com/a-h/templ"
|
|
import templruntime "github.com/a-h/templ/runtime"
|
|
|
|
import (
|
|
"fmt"
|
|
"git.jmbit.de/jmb/scanfile/server/web/templui/components/icon"
|
|
"git.jmbit.de/jmb/scanfile/server/web/templui/utils"
|
|
"strconv"
|
|
)
|
|
|
|
type Style string
|
|
|
|
const (
|
|
StyleStar Style = "star"
|
|
StyleHeart Style = "heart"
|
|
StyleEmoji Style = "emoji"
|
|
)
|
|
|
|
type Props struct {
|
|
ID string
|
|
Class string
|
|
Attributes templ.Attributes
|
|
Value float64
|
|
ReadOnly bool
|
|
Precision float64
|
|
Name string
|
|
OnlyInteger bool
|
|
}
|
|
|
|
type GroupProps struct {
|
|
ID string
|
|
Class string
|
|
Attributes templ.Attributes
|
|
}
|
|
|
|
type ItemProps struct {
|
|
ID string
|
|
Class string
|
|
Attributes templ.Attributes
|
|
Value int
|
|
Style Style
|
|
}
|
|
|
|
func Rating(props ...Props) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var1 == nil {
|
|
templ_7745c5c3_Var1 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
templ_7745c5c3_Err = Script().Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var p Props
|
|
if len(props) > 0 {
|
|
p = props[0]
|
|
}
|
|
p.setDefaults()
|
|
var templ_7745c5c3_Var2 = []any{
|
|
utils.TwMerge(
|
|
"flex flex-col items-start gap-1",
|
|
p.Class,
|
|
),
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.ID != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " id=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var3 string
|
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(p.ID)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 53, Col: 12}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " data-rating-component data-initial-value=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var4 string
|
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", p.Value))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 56, Col: 51}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\" data-precision=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var5 string
|
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", p.Precision))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 57, Col: 51}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" data-readonly=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var6 string
|
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatBool(p.ReadOnly))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 58, Col: 48}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.Name != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " data-name=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var7 string
|
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 60, Col: 21}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, " data-onlyinteger=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var8 string
|
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatBool(p.OnlyInteger))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 62, Col: 54}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "\" class=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var9 string
|
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var2).String())
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 1, Col: 0}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, p.Attributes)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, ">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.Name != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<input type=\"hidden\" name=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var10 string
|
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 75, Col: 17}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\" value=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var11 string
|
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", p.Value))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 76, Col: 40}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\" data-rating-input>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</div>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func Group(props ...GroupProps) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var12 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var12 == nil {
|
|
templ_7745c5c3_Var12 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
var p GroupProps
|
|
if len(props) > 0 {
|
|
p = props[0]
|
|
}
|
|
var templ_7745c5c3_Var13 = []any{utils.TwMerge("flex flex-row items-center gap-1", p.Class)}
|
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var13...)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<div")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.ID != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " id=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var14 string
|
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(p.ID)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 90, Col: 12}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, " class=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var15 string
|
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var13).String())
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 1, Col: 0}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, p.Attributes)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, ">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ_7745c5c3_Var12.Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</div>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func Item(props ...ItemProps) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var16 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var16 == nil {
|
|
templ_7745c5c3_Var16 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
var p ItemProps
|
|
if len(props) > 0 {
|
|
p = props[0]
|
|
}
|
|
p.setDefaults()
|
|
var templ_7745c5c3_Var17 = []any{
|
|
utils.TwMerge(
|
|
"relative",
|
|
colorClass(p.Style),
|
|
"transition-opacity",
|
|
"cursor-pointer", // Default cursor
|
|
p.Class,
|
|
),
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var17...)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<div")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.ID != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, " id=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var18 string
|
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(p.ID)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 107, Col: 12}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " data-rating-item data-rating-value=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var19 string
|
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(p.Value))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 110, Col: 43}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\" class=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var20 string
|
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var17).String())
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 1, Col: 0}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, p.Attributes)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "><div class=\"opacity-30\">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = ratingIcon(p.Style, false, float64(p.Value)).Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "</div><div class=\"absolute inset-0 overflow-hidden w-0\" data-rating-item-foreground>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = ratingIcon(p.Style, true, float64(p.Value)).Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</div></div>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func colorClass(style Style) string {
|
|
switch style {
|
|
case StyleHeart:
|
|
return "text-destructive"
|
|
case StyleEmoji:
|
|
return "text-yellow-500"
|
|
default:
|
|
return "text-yellow-400"
|
|
}
|
|
}
|
|
|
|
func ratingIcon(style Style, filled bool, value float64) templ.Component {
|
|
if style == StyleEmoji {
|
|
if filled {
|
|
switch {
|
|
case value <= 1:
|
|
return icon.Angry()
|
|
case value <= 2:
|
|
return icon.Frown()
|
|
case value <= 3:
|
|
return icon.Meh()
|
|
case value <= 4:
|
|
return icon.Smile()
|
|
default:
|
|
return icon.Laugh()
|
|
}
|
|
}
|
|
return icon.Meh()
|
|
}
|
|
iconProps := icon.Props{}
|
|
if filled {
|
|
iconProps.Fill = "currentColor"
|
|
}
|
|
switch style {
|
|
case StyleHeart:
|
|
return icon.Heart(iconProps)
|
|
default:
|
|
return icon.Star(iconProps)
|
|
}
|
|
}
|
|
|
|
func (p *ItemProps) setDefaults() {
|
|
if p.Style == "" {
|
|
p.Style = StyleStar
|
|
}
|
|
}
|
|
|
|
func (p *Props) setDefaults() {
|
|
if p.Precision <= 0 {
|
|
p.Precision = 1.0
|
|
}
|
|
}
|
|
|
|
var handle = templ.NewOnceHandle()
|
|
|
|
func Script() templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var21 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var21 == nil {
|
|
templ_7745c5c3_Var21 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
templ_7745c5c3_Var22 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<script nonce=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var23 string
|
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(templ.GetNonce(ctx))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/rating/rating.templ`, Line: 191, Col: 37}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "\">\n\t\t\tif (typeof window.ratingState === 'undefined') {\n\t\t\t\twindow.ratingState = new WeakMap();\n\t\t\t}\n\t\t\t\n\t\t\t(function() { // IIFE\n\t\t\t\tfunction initRating(ratingElement) {\n\t\t\t\t\tif (!ratingElement) return;\n\t\t\t\t\t\n\t\t\t\t\tconst existingState = window.ratingState.get(ratingElement);\n\t\t\t\t\tif (existingState) {\n\t\t\t\t\t\tcleanupRating(ratingElement, existingState);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tratingElement.dataset.ratingInitialized = 'true';\n\t\t\t\t\t\n\t\t\t\t\tconst config = {\n\t\t\t\t\t\tvalue: parseFloat(ratingElement.dataset.initialValue) || 0,\n\t\t\t\t\t\tprecision: parseFloat(ratingElement.dataset.precision) || 1,\n\t\t\t\t\t\treadonly: ratingElement.dataset.readonly === 'true',\n\t\t\t\t\t\tname: ratingElement.dataset.name || '',\n\t\t\t\t\t\tonlyInteger: ratingElement.dataset.onlyinteger === 'true',\n\t\t\t\t\t\tmaxValue: 0\n\t\t\t\t\t};\n\n\t\t\t\t\tconst hiddenInput = ratingElement.querySelector('[data-rating-input]');\n\t\t\t\t\tlet items = Array.from(ratingElement.querySelectorAll('[data-rating-item]'));\n\n\t\t\t\t\tlet currentValue = config.value;\n\t\t\t\t\tlet previewValue = 0;\n\t\t\t\t\t\n\t\t\t\t\tconst handlers = {\n\t\t\t\t\t\tclick: handleClick,\n\t\t\t\t\t\tmouseover: handleMouseOver,\n\t\t\t\t\t\tmouseleave: handleMouseLeave\n\t\t\t\t\t};\n\t\t\t\t\t\n\t\t\t\t\tfunction calculateMaxValue() {\n\t\t\t\t\t\tlet highestValue = 0;\n\t\t\t\t\t\tfor (const item of items) {\n\t\t\t\t\t\t\tconst value = parseInt(item.dataset.ratingValue, 10);\n\t\t\t\t\t\t\tif (!isNaN(value) && value > highestValue) {\n\t\t\t\t\t\t\t\thighestValue = value;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconfig.maxValue = Math.max(1, highestValue);\n\t\t\t\t\t\tcurrentValue = Math.max(0, Math.min(config.maxValue, currentValue));\n\t\t\t\t\t\tcurrentValue = Math.round(currentValue / config.precision) * config.precision;\n\t\t\t\t\t\tupdateHiddenInput();\n\t\t\t\t\t}\n\n\t\t\t\t\tfunction updateHiddenInput() {\n\t\t\t\t\t\tif (hiddenInput) {\n\t\t\t\t\t\t\thiddenInput.value = currentValue.toFixed(2);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tfunction updateItemStyles(displayValue) {\n\t\t\t\t\t\tfor (const item of items) {\n\t\t\t\t\t\t\tconst itemValue = parseInt(item.dataset.ratingValue, 10);\n\t\t\t\t\t\t\tif (isNaN(itemValue)) continue;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tconst foreground = item.querySelector('[data-rating-item-foreground]');\n\t\t\t\t\t\t\tif (!foreground) continue;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tconst valueToCompare = displayValue > 0 ? displayValue : currentValue;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tconst filled = itemValue <= Math.floor(valueToCompare);\n\t\t\t\t\t\t\tconst partial = !filled && (itemValue - 1 < valueToCompare && valueToCompare < itemValue);\n\t\t\t\t\t\t\tconst percentage = partial ? (valueToCompare - Math.floor(valueToCompare)) * 100 : 0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tforeground.style.width = filled ? '100%' : (partial ? `${percentage}%` : '0%');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tfunction setValue(itemValue) {\n\t\t\t\t\t\tif (config.readonly) return;\n\t\t\t\t\t\t\n\t\t\t\t\t\tlet newValue = itemValue;\n\t\t\t\t\t\tif (config.onlyInteger) {\n\t\t\t\t\t\t\tnewValue = Math.round(newValue);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (currentValue === newValue && newValue % 1 === 0) {\n\t\t\t\t\t\t\t\tnewValue = Math.max(0, newValue - config.precision);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tnewValue = Math.round(newValue / config.precision) * config.precision;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tcurrentValue = Math.max(0, Math.min(config.maxValue, newValue));\n\t\t\t\t\t\tpreviewValue = 0;\n\t\t\t\t\t\tupdateHiddenInput();\n\t\t\t\t\t\tupdateItemStyles(0);\n\t\t\t\t\t\t\n\t\t\t\t\t\tratingElement.dispatchEvent(new CustomEvent('rating-change', {\n\t\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\t\tdetail: { \n\t\t\t\t\t\t\t\tname: config.name, \n\t\t\t\t\t\t\t\tvalue: currentValue, \n\t\t\t\t\t\t\t\tmaxValue: config.maxValue \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}));\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (hiddenInput) {\n\t\t\t\t\t\t\thiddenInput.dispatchEvent(new Event('input', { bubbles: true }));\n\t\t\t\t\t\t\thiddenInput.dispatchEvent(new Event('change', { bubbles: true }));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfunction handleMouseOver(event) {\n\t\t\t\t\t\tif (config.readonly) return;\n\t\t\t\t\t\tconst item = event.target.closest('[data-rating-item]');\n\t\t\t\t\t\tif (!item) return;\n\t\t\t\t\t\t\n\t\t\t\t\t\tpreviewValue = parseInt(item.dataset.ratingValue, 10);\n\t\t\t\t\t\tif (!isNaN(previewValue)) {\n\t\t\t\t\t\t\tupdateItemStyles(previewValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfunction handleMouseLeave() {\n\t\t\t\t\t\tif (config.readonly) return;\n\t\t\t\t\t\tpreviewValue = 0;\n\t\t\t\t\t\tupdateItemStyles(0);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfunction handleClick(event) {\n\t\t\t\t\t\tif (config.readonly) return;\n\t\t\t\t\t\tconst item = event.target.closest('[data-rating-item]');\n\t\t\t\t\t\tif (!item) return;\n\t\t\t\t\t\t\n\t\t\t\t\t\tconst itemValue = parseInt(item.dataset.ratingValue, 10);\n\t\t\t\t\t\tif (!isNaN(itemValue)) {\n\t\t\t\t\t\t\tsetValue(itemValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tcalculateMaxValue();\n\t\t\t\t\tupdateItemStyles(0);\n\t\t\t\t\t\n\t\t\t\t\tif (config.readonly) {\n\t\t\t\t\t\tratingElement.style.cursor = 'default';\n\t\t\t\t\t\tfor (const item of items) {\n\t\t\t\t\t\t\titem.style.cursor = 'default';\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tratingElement.addEventListener('click', handlers.click);\n\t\t\t\t\t\tratingElement.addEventListener('mouseover', handlers.mouseover);\n\t\t\t\t\t\tratingElement.addEventListener('mouseleave', handlers.mouseleave);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tconst observer = new MutationObserver(() => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst currentItemCount = ratingElement.querySelectorAll('[data-rating-item]').length;\n\t\t\t\t\t\t\tif (currentItemCount !== items.length) {\n\t\t\t\t\t\t\t\titems = Array.from(ratingElement.querySelectorAll('[data-rating-item]'));\n\t\t\t\t\t\t\t\tcalculateMaxValue();\n\t\t\t\t\t\t\t\tupdateItemStyles(previewValue > 0 ? previewValue : 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\tconsole.error('Error in rating MutationObserver:', err);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\tobserver.observe(ratingElement, { childList: true, subtree: true });\n\t\t\t\t\t\n\t\t\t\t\tconst state = {\n\t\t\t\t\t\thandlers,\n\t\t\t\t\t\tobserver,\n\t\t\t\t\t\titems\n\t\t\t\t\t};\n\t\t\t\t\t\n\t\t\t\t\twindow.ratingState.set(ratingElement, state);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfunction cleanupRating(ratingElement, state) {\n\t\t\t\t\tif (!ratingElement || !state) return;\n\t\t\t\t\t\n\t\t\t\t\tif (!ratingElement.dataset.readonly === 'true') {\n\t\t\t\t\t\tratingElement.removeEventListener('click', state.handlers.click);\n\t\t\t\t\t\tratingElement.removeEventListener('mouseover', state.handlers.mouseover);\n\t\t\t\t\t\tratingElement.removeEventListener('mouseleave', state.handlers.mouseleave);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (state.observer) {\n\t\t\t\t\t\tstate.observer.disconnect();\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\twindow.ratingState.delete(ratingElement);\n\t\t\t\t\tratingElement.removeAttribute('data-rating-initialized');\n\t\t\t\t}\n\n\t\t\t\tfunction initAllComponents(root = document) {\n\t\t\t\t\tif (root instanceof Element && root.matches('[data-rating-component]')) {\n\t\t\t\t\t\tinitRating(root); // initRating handles already initialized check internally\n\t\t\t\t\t}\n\t\t\t\t\tif (root && typeof root.querySelectorAll === 'function') {\n\t\t\t\t\t\troot.querySelectorAll('[data-rating-component]').forEach(initRating);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst handleHtmxSwap = (event) => {\n\t\t\t\t\tconst target = event.detail.target || event.detail.elt;\n\t\t\t\t\tif (target instanceof Element) {\n\t\t\t\t\t\trequestAnimationFrame(() => initAllComponents(target));\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tinitAllComponents();\n\t\t\t\t\n\t\t\t\tdocument.addEventListener('DOMContentLoaded', () => initAllComponents());\n\n\t\t\t\tdocument.body.addEventListener('htmx:beforeCleanup', event => {\n\t\t\t\t\tconst containerToRemove = event.detail.target || event.detail.elt;; // Use elt for beforeCleanup\n\t\t\t\t\tif (containerToRemove instanceof Element) {\n\t\t\t\t\t\t// Cleanup target itself\n\t\t\t\t\t\tif (containerToRemove.matches && containerToRemove.matches('[data-rating-component][data-rating-initialized]')) {\n\t\t\t\t\t\t\tconst state = window.ratingState.get(containerToRemove);\n\t\t\t\t\t\t\tif (state) cleanupRating(containerToRemove, state);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Cleanup descendants\n\t\t\t\t\t\tif (containerToRemove.querySelectorAll) {\n\t\t\t\t\t\t\tfor (const ratingEl of containerToRemove.querySelectorAll('[data-rating-component][data-rating-initialized]')) {\n\t\t\t\t\t\t\t\tconst state = window.ratingState.get(ratingEl);\n\t\t\t\t\t\t\t\tif (state) cleanupRating(ratingEl, state);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tdocument.body.addEventListener('htmx:afterSwap', handleHtmxSwap);\n\t\t\t\tdocument.body.addEventListener('htmx:oobAfterSwap', handleHtmxSwap);\n\t\t\t})(); // End of IIFE\n\t\t</script>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
templ_7745c5c3_Err = handle.Once().Render(templ.WithChildren(ctx, templ_7745c5c3_Var22), templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
var _ = templruntime.GeneratedTemplate
|