Files
nebula/pkg/wa/option.templ

162 lines
3.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-option
package wa
import (
"github.com/a-h/templ"
)
// Options define the selectable items within a select component.
//
// Web Awesome component: <wa-option>
// OptionProps holds all properties for the wa-option component
type OptionProps struct {
// The option's value. When selected, the containing form control will receive this value. The value must be unique
Value string `attr:"value"`
// Draws the option in a disabled state, preventing selection.
Disabled bool `attr:"disabled"`
// Selects an option initially.
Selected bool `attr:"selected"`
// The options plain text label.
Label string `attr:"label"`
// Events
// Slots contains named slot content
Slots OptionSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// OptionSlots holds named slot content for the component
type OptionSlots struct {
// An element, such as <wa-icon>, placed before the label.
Start templ.Component
// An element, such as <wa-icon>, placed after the label.
End templ.Component
}
// OptionBuilder provides a fluent API for constructing OptionProps
type OptionBuilder struct {
props OptionProps
}
// NewOption creates a new builder for wa-option
func NewOption() *OptionBuilder {
return &OptionBuilder{}
}
// Value sets the value attribute
// The option's value. When selected, the containing form control will receive this value. The value must be unique
func (b *OptionBuilder) Value(v string) *OptionBuilder {
b.props.Value = v
return b
}
// Disabled sets the disabled attribute
// Draws the option in a disabled state, preventing selection.
func (b *OptionBuilder) Disabled(v bool) *OptionBuilder {
b.props.Disabled = v
return b
}
// Selected sets the selected attribute
// Selects an option initially.
func (b *OptionBuilder) Selected(v bool) *OptionBuilder {
b.props.Selected = v
return b
}
// Label sets the label attribute
// The options plain text label.
func (b *OptionBuilder) Label(v string) *OptionBuilder {
b.props.Label = v
return b
}
// StartSlot sets the start slot content
// An element, such as <wa-icon>, placed before the label.
func (b *OptionBuilder) StartSlot(c templ.Component) *OptionBuilder {
b.props.Slots.Start = c
return b
}
// EndSlot sets the end slot content
// An element, such as <wa-icon>, placed after the label.
func (b *OptionBuilder) EndSlot(c templ.Component) *OptionBuilder {
b.props.Slots.End = c
return b
}
// Attr adds a custom HTML attribute
func (b *OptionBuilder) Attr(name, value string) *OptionBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *OptionBuilder) Attrs(attrs templ.Attributes) *OptionBuilder {
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 *OptionBuilder) Props() OptionProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *OptionBuilder) Build() OptionProps {
return b.props
}
// Option renders the wa-option component
templ Option(props OptionProps) {
<wa-option
if props.Value != "" {
value={ props.Value }
}
if props.Disabled {
disabled
}
if props.Selected {
selected
}
if props.Label != "" {
label={ props.Label }
}
{ props.Attrs... }
>
if props.Slots.Start != nil {
<div slot="start">
@props.Slots.Start
</div>
}
if props.Slots.End != nil {
<div slot="end">
@props.Slots.End
</div>
}
{ children... }
</wa-option>
}
// OptionFunc renders with a builder function for inline configuration
templ OptionFunc(fn func(*OptionBuilder)) {
{{ b := NewOption(); fn(b) }}
@Option(b.Props()) {
{ children... }
}
}