Files
nebula/pkg/wa/radio.templ

156 lines
3.7 KiB
Plaintext
Raw Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-radio
package wa
import (
"github.com/a-h/templ"
)
// Radios allow the user to select a single option from a group.
//
// Web Awesome component: <wa-radio>
// RadioProps holds all properties for the wa-radio component
type RadioProps struct {
// The radio's value. When selected, the radio group will receive this value.
Value string `attr:"value"`
// The radio's visual appearance.
// Valid values: "default", "button"
Appearance string `attr:"appearance"`
// The radio's size. When used inside a radio group, the size will be determined by the radio group's size so this
// Valid values: "small", "medium", "large"
Size string `attr:"size"`
// Disables the radio.
Disabled bool `attr:"disabled"`
// Events
// Emitted when the control loses focus.
OnBlur string `attr:"x-on:blur"`
// Emitted when the control gains focus.
OnFocus string `attr:"x-on:focus"`
// Slots contains named slot content
Slots RadioSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// RadioBuilder provides a fluent API for constructing RadioProps
type RadioBuilder struct {
props RadioProps
}
// NewRadio creates a new builder for wa-radio
func NewRadio() *RadioBuilder {
return &RadioBuilder{}
}
// Value sets the value attribute
// The radio's value. When selected, the radio group will receive this value.
func (b *RadioBuilder) Value(v string) *RadioBuilder {
b.props.Value = v
return b
}
// Appearance sets the appearance attribute
// The radio's visual appearance.
func (b *RadioBuilder) Appearance(v string) *RadioBuilder {
b.props.Appearance = v
return b
}
// Size sets the size attribute
// The radio's size. When used inside a radio group, the size will be determined by the radio group's size so this
func (b *RadioBuilder) Size(v string) *RadioBuilder {
b.props.Size = v
return b
}
// Disabled sets the disabled attribute
// Disables the radio.
func (b *RadioBuilder) Disabled(v bool) *RadioBuilder {
b.props.Disabled = v
return b
}
// OnBlur sets the handler for blur event
// Emitted when the control loses focus.
func (b *RadioBuilder) OnBlur(handler string) *RadioBuilder {
b.props.OnBlur = handler
return b
}
// OnFocus sets the handler for focus event
// Emitted when the control gains focus.
func (b *RadioBuilder) OnFocus(handler string) *RadioBuilder {
b.props.OnFocus = handler
return b
}
// Attr adds a custom HTML attribute
func (b *RadioBuilder) Attr(name, value string) *RadioBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *RadioBuilder) Attrs(attrs templ.Attributes) *RadioBuilder {
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 *RadioBuilder) Props() RadioProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *RadioBuilder) Build() RadioProps {
return b.props
}
// Radio renders the wa-radio component
templ Radio(props RadioProps) {
<wa-radio
if props.Value != "" {
value={ props.Value }
}
if props.Appearance != "" {
appearance={ props.Appearance }
}
if props.Size != "" {
size={ props.Size }
}
if props.Disabled {
disabled
}
if props.OnBlur != "" {
x-on:blur={ props.OnBlur }
}
if props.OnFocus != "" {
x-on:focus={ props.OnFocus }
}
{ props.Attrs... }
>
{ children... }
</wa-radio>
}
// RadioFunc renders with a builder function for inline configuration
templ RadioFunc(fn func(*RadioBuilder)) {
{{ b := NewRadio(); fn(b) }}
@Radio(b.Props()) {
{ children... }
}
}