// templui component avatar - version: v0.84.0 installed by templui v0.84.0 package avatar import ( "fmt" "git.jmbit.de/jmb/scanfile/server/web/templui/utils" "strings" ) type Size string type GroupSpacing string const ( SizeSm Size = "sm" SizeMd Size = "md" SizeLg Size = "lg" ) const ( GroupSpacingSm GroupSpacing = "sm" GroupSpacingMd GroupSpacing = "medium" GroupSpacingLg GroupSpacing = "large" ) type Props struct { ID string Class string Attributes templ.Attributes Size Size InGroup bool } type ImageProps struct { ID string Class string Attributes templ.Attributes Alt string Src string } type FallbackProps struct { ID string Class string Attributes templ.Attributes } type GroupProps struct { ID string Class string Attributes templ.Attributes Spacing GroupSpacing } templ Avatar(props ...Props) { {{ var p Props }} if len(props) > 0 { {{ p = props[0] }} }
{ children... }
} templ Image(props ...ImageProps) { {{ var p ImageProps }} if len(props) > 0 { {{ p = props[0] }} } { } templ Fallback(props ...FallbackProps) { {{ var p FallbackProps }} if len(props) > 0 { {{ p = props[0] }} } { children... } } templ Group(props ...GroupProps) { {{ var p GroupProps }} if len(props) > 0 { {{ p = props[0] }} }
{ children... }
} templ GroupOverflow(count int, props ...Props) { {{ var p Props }} if len(props) > 0 { {{ p = props[0] }} }
+{ fmt.Sprint(count) }
} func SizeClasses(size Size) string { switch size { case SizeSm: return "w-8 h-8 text-xs" case SizeLg: return "w-16 h-16 text-xl" default: // SizeMd return "w-12 h-12 text-base" } } func Initials(name string) string { parts := strings.Fields(name) initials := "" for i, part := range parts { if i > 1 { break } if len(part) > 0 { initials += string([]rune(part)[0]) } } return strings.ToUpper(initials) } func groupSpacingClasses(spacing GroupSpacing) string { switch spacing { case GroupSpacingSm: return "-space-x-1" case GroupSpacingLg: return "-space-x-4" default: // GroupSpacingMd return "-space-x-2" } } func avatarAlt(p ImageProps) string { if p.Alt != "" { return p.Alt } if p.ID != "" { return fmt.Sprintf("Avatar of %s", p.ID) } if p.Src != "" { return "User avatar" } return "" } templ Script() { }