Files
nebula/pkg/wa/avatar.templ

174 lines
4.4 KiB
Plaintext

// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-avatar
package wa
import (
"github.com/a-h/templ"
)
// Avatars are used to represent a person or object.
//
// Web Awesome component: <wa-avatar>
// AvatarProps holds all properties for the wa-avatar component
type AvatarProps struct {
// The image source to use for the avatar.
Image string `attr:"image"`
// A label to use to describe the avatar to assistive devices.
Label string `attr:"label"`
// Initials to use as a fallback when no image is available (1-2 characters max recommended).
Initials string `attr:"initials"`
// Indicates how the browser should load the image.
// Valid values: "eager", "lazy"
Loading string `attr:"loading"`
// The shape of the avatar.
// Valid values: "circle", "square", "rounded"
Shape string `attr:"shape"`
// Events
// The image could not be loaded. This may because of an invalid URL, a temporary network condition, or some unknown cause.
OnError string `attr:"x-on:wa-error"`
// Slots contains named slot content
Slots AvatarSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// AvatarSlots holds named slot content for the component
type AvatarSlots struct {
// The default icon to use when no image or initials are present. Works best with <wa-icon>.
Icon templ.Component
}
// AvatarBuilder provides a fluent API for constructing AvatarProps
type AvatarBuilder struct {
props AvatarProps
}
// NewAvatar creates a new builder for wa-avatar
func NewAvatar() *AvatarBuilder {
return &AvatarBuilder{}
}
// Image sets the image attribute
// The image source to use for the avatar.
func (b *AvatarBuilder) Image(v string) *AvatarBuilder {
b.props.Image = v
return b
}
// Label sets the label attribute
// A label to use to describe the avatar to assistive devices.
func (b *AvatarBuilder) Label(v string) *AvatarBuilder {
b.props.Label = v
return b
}
// Initials sets the initials attribute
// Initials to use as a fallback when no image is available (1-2 characters max recommended).
func (b *AvatarBuilder) Initials(v string) *AvatarBuilder {
b.props.Initials = v
return b
}
// Loading sets the loading attribute
// Indicates how the browser should load the image.
func (b *AvatarBuilder) Loading(v string) *AvatarBuilder {
b.props.Loading = v
return b
}
// Shape sets the shape attribute
// The shape of the avatar.
func (b *AvatarBuilder) Shape(v string) *AvatarBuilder {
b.props.Shape = v
return b
}
// OnError sets the handler for wa-error event
// The image could not be loaded. This may because of an invalid URL, a temporary network condition, or some unknown cause.
func (b *AvatarBuilder) OnError(handler string) *AvatarBuilder {
b.props.OnError = handler
return b
}
// IconSlot sets the icon slot content
// The default icon to use when no image or initials are present. Works best with <wa-icon>.
func (b *AvatarBuilder) IconSlot(c templ.Component) *AvatarBuilder {
b.props.Slots.Icon = c
return b
}
// Attr adds a custom HTML attribute
func (b *AvatarBuilder) Attr(name, value string) *AvatarBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *AvatarBuilder) Attrs(attrs templ.Attributes) *AvatarBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
for k, v := range attrs {
b.props.Attrs[k] = v
}
return b
}
// Props returns the built properties
func (b *AvatarBuilder) Props() AvatarProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *AvatarBuilder) Build() AvatarProps {
return b.props
}
// Avatar renders the wa-avatar component
templ Avatar(props AvatarProps) {
<wa-avatar
if props.Image != "" {
image={ props.Image }
}
if props.Label != "" {
label={ props.Label }
}
if props.Initials != "" {
initials={ props.Initials }
}
if props.Loading != "" {
loading={ props.Loading }
}
if props.Shape != "" {
shape={ props.Shape }
}
if props.OnError != "" {
x-on:wa-error={ props.OnError }
}
{ props.Attrs... }
>
if props.Slots.Icon != nil {
<div slot="icon">
@props.Slots.Icon
</div>
}
{ children... }
</wa-avatar>
}
// AvatarFunc renders with a builder function for inline configuration
templ AvatarFunc(fn func(*AvatarBuilder)) {
{{ b := NewAvatar(); fn(b) }}
@Avatar(b.Props()) {
{ children... }
}
}