// templui component progress - version: v0.84.0 installed by templui v0.84.0 package progress import ( "fmt" "git.jmbit.de/jmb/scanfile/server/web/templui/utils" ) type Size string type Variant string const ( SizeSm Size = "sm" SizeLg Size = "lg" ) const ( VariantDefault Variant = "default" VariantSuccess Variant = "success" VariantDanger Variant = "danger" VariantWarning Variant = "warning" ) type Props struct { ID string Class string Attributes templ.Attributes Max int Value int Label string ShowValue bool Size Size Variant Variant BarClass string } templ Progress(props ...Props) { {{ var p Props }} if len(props) > 0 { {{ p = props[0] }} } if p.ID == "" { {{ p.ID = utils.RandomID() }} }
if p.Label != "" || p.ShowValue {
if p.Label != "" { { p.Label } } if p.ShowValue { { fmt.Sprintf("%d%%", percentage(p.Value, p)) } }
}
} func maxValue(max int) int { if max <= 0 { return 100 } return max } func percentage(value int, props Props) int { max := maxValue(props.Max) if value < 0 { value = 0 } if value > max { value = max } return (value * 100) / max } func sizeClasses(size Size) string { switch size { case SizeSm: return "h-1" case SizeLg: return "h-4" default: return "h-2.5" } } func variantClasses(variant Variant) string { switch variant { case VariantSuccess: return "bg-green-500" case VariantDanger: return "bg-destructive" case VariantWarning: return "bg-yellow-500" default: return "bg-primary" } } templ Script() { }