202 lines
5.6 KiB
Plaintext
202 lines
5.6 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-icon
|
|
|
|
package wa
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Icons are symbols that can be used to represent various options within an application.
|
|
//
|
|
// Web Awesome component: <wa-icon>
|
|
|
|
// IconProps holds all properties for the wa-icon component
|
|
type IconProps struct {
|
|
// The name of the icon to draw. Available names depend on the icon library being used.
|
|
Name string `attr:"name"`
|
|
// The family of icons to choose from. For Font Awesome Free, valid options include classic and brands. For
|
|
Family string `attr:"family"`
|
|
// The name of the icon's variant. For Font Awesome, valid options include thin, light, regular, and solid for
|
|
Variant string `attr:"variant"`
|
|
// Sets the width of the icon to match the cropped SVG viewBox. This operates like the Font fa-width-auto class.
|
|
AutoWidth bool `attr:"auto-width"`
|
|
// Swaps the opacity of duotone icons.
|
|
SwapOpacity bool `attr:"swap-opacity"`
|
|
// An external URL of an SVG file. Be sure you trust the content you are including, as it will be executed as code and
|
|
Src string `attr:"src"`
|
|
// An alternate description to use for assistive devices. If omitted, the icon will be considered presentational and
|
|
Label string `attr:"label"`
|
|
// The name of a registered custom icon library.
|
|
Library string `attr:"library"`
|
|
|
|
// Events
|
|
// Emitted when the icon has loaded. When using spriteSheet: true this will not emit.
|
|
OnLoad string `attr:"x-on:wa-load"`
|
|
// Emitted when the icon fails to load due to an error. When using spriteSheet: true this will not emit.
|
|
OnError string `attr:"x-on:wa-error"`
|
|
|
|
// Slots contains named slot content
|
|
Slots IconSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// IconBuilder provides a fluent API for constructing IconProps
|
|
type IconBuilder struct {
|
|
props IconProps
|
|
}
|
|
|
|
// NewIcon creates a new builder for wa-icon
|
|
func NewIcon() *IconBuilder {
|
|
return &IconBuilder{}
|
|
}
|
|
|
|
// Name sets the name attribute
|
|
// The name of the icon to draw. Available names depend on the icon library being used.
|
|
func (b *IconBuilder) Name(v string) *IconBuilder {
|
|
b.props.Name = v
|
|
return b
|
|
}
|
|
|
|
// Family sets the family attribute
|
|
// The family of icons to choose from. For Font Awesome Free, valid options include classic and brands. For
|
|
func (b *IconBuilder) Family(v string) *IconBuilder {
|
|
b.props.Family = v
|
|
return b
|
|
}
|
|
|
|
// Variant sets the variant attribute
|
|
// The name of the icon's variant. For Font Awesome, valid options include thin, light, regular, and solid for
|
|
func (b *IconBuilder) Variant(v string) *IconBuilder {
|
|
b.props.Variant = v
|
|
return b
|
|
}
|
|
|
|
// AutoWidth sets the auto-width attribute
|
|
// Sets the width of the icon to match the cropped SVG viewBox. This operates like the Font fa-width-auto class.
|
|
func (b *IconBuilder) AutoWidth(v bool) *IconBuilder {
|
|
b.props.AutoWidth = v
|
|
return b
|
|
}
|
|
|
|
// SwapOpacity sets the swap-opacity attribute
|
|
// Swaps the opacity of duotone icons.
|
|
func (b *IconBuilder) SwapOpacity(v bool) *IconBuilder {
|
|
b.props.SwapOpacity = v
|
|
return b
|
|
}
|
|
|
|
// Src sets the src attribute
|
|
// An external URL of an SVG file. Be sure you trust the content you are including, as it will be executed as code and
|
|
func (b *IconBuilder) Src(v string) *IconBuilder {
|
|
b.props.Src = v
|
|
return b
|
|
}
|
|
|
|
// Label sets the label attribute
|
|
// An alternate description to use for assistive devices. If omitted, the icon will be considered presentational and
|
|
func (b *IconBuilder) Label(v string) *IconBuilder {
|
|
b.props.Label = v
|
|
return b
|
|
}
|
|
|
|
// Library sets the library attribute
|
|
// The name of a registered custom icon library.
|
|
func (b *IconBuilder) Library(v string) *IconBuilder {
|
|
b.props.Library = v
|
|
return b
|
|
}
|
|
|
|
// OnLoad sets the handler for wa-load event
|
|
// Emitted when the icon has loaded. When using spriteSheet: true this will not emit.
|
|
func (b *IconBuilder) OnLoad(handler string) *IconBuilder {
|
|
b.props.OnLoad = handler
|
|
return b
|
|
}
|
|
|
|
// OnError sets the handler for wa-error event
|
|
// Emitted when the icon fails to load due to an error. When using spriteSheet: true this will not emit.
|
|
func (b *IconBuilder) OnError(handler string) *IconBuilder {
|
|
b.props.OnError = handler
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *IconBuilder) Attr(name, value string) *IconBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *IconBuilder) Attrs(attrs templ.Attributes) *IconBuilder {
|
|
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 *IconBuilder) Props() IconProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *IconBuilder) Build() IconProps {
|
|
return b.props
|
|
}
|
|
|
|
// Icon renders the wa-icon component
|
|
templ Icon(props IconProps) {
|
|
<wa-icon
|
|
if props.Name != "" {
|
|
name={ props.Name }
|
|
}
|
|
if props.Family != "" {
|
|
family={ props.Family }
|
|
}
|
|
if props.Variant != "" {
|
|
variant={ props.Variant }
|
|
}
|
|
if props.AutoWidth {
|
|
auto-width
|
|
}
|
|
if props.SwapOpacity {
|
|
swap-opacity
|
|
}
|
|
if props.Src != "" {
|
|
src={ props.Src }
|
|
}
|
|
if props.Label != "" {
|
|
label={ props.Label }
|
|
}
|
|
if props.Library != "" {
|
|
library={ props.Library }
|
|
}
|
|
if props.OnLoad != "" {
|
|
x-on:wa-load={ props.OnLoad }
|
|
}
|
|
if props.OnError != "" {
|
|
x-on:wa-error={ props.OnError }
|
|
}
|
|
{ props.Attrs... }
|
|
>
|
|
{ children... }
|
|
</wa-icon>
|
|
}
|
|
|
|
// IconFunc renders with a builder function for inline configuration
|
|
templ IconFunc(fn func(*IconBuilder)) {
|
|
{{ b := NewIcon(); fn(b) }}
|
|
@Icon(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|