Files
nebula/pkg/wa/dropdown.templ

222 lines
6.0 KiB
Plaintext
Raw Permalink Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-dropdown
package wa
import (
"github.com/a-h/templ"
)
// Dropdowns display a list of options that can be triggered by a button or other element. They support
//
// Web Awesome component: <wa-dropdown>
// DropdownProps holds all properties for the wa-dropdown component
type DropdownProps struct {
// Opens or closes the dropdown.
Open bool `attr:"open"`
// The dropdown's size.
// Valid values: "small", "medium", "large"
Size string `attr:"size"`
// The placement of the dropdown menu in reference to the trigger. The menu will shift to a more optimal location if
// Valid values: "top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "right", "right-start", "right-end", "left", "left-start", "left-end"
Placement string `attr:"placement"`
// The distance of the dropdown menu from its trigger.
Distance float64 `attr:"distance"`
// The offset of the dropdown menu along its trigger.
Skidding float64 `attr:"skidding"`
// Events
// Emitted when the dropdown is about to show.
OnShow string `attr:"x-on:wa-show"`
// Emitted after the dropdown has been shown.
OnAfterShow string `attr:"x-on:wa-after-show"`
// Emitted when the dropdown is about to hide.
OnHide string `attr:"x-on:wa-hide"`
// Emitted after the dropdown has been hidden.
OnAfterHide string `attr:"x-on:wa-after-hide"`
// Emitted when an item in the dropdown is selected.
OnSelect string `attr:"x-on:wa-select"`
// Slots contains named slot content
Slots DropdownSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// DropdownSlots holds named slot content for the component
type DropdownSlots struct {
// The element that triggers the dropdown, such as a <wa-button> or <button>.
Trigger templ.Component
}
// DropdownBuilder provides a fluent API for constructing DropdownProps
type DropdownBuilder struct {
props DropdownProps
}
// NewDropdown creates a new builder for wa-dropdown
func NewDropdown() *DropdownBuilder {
return &DropdownBuilder{}
}
// Open sets the open attribute
// Opens or closes the dropdown.
func (b *DropdownBuilder) Open(v bool) *DropdownBuilder {
b.props.Open = v
return b
}
// Size sets the size attribute
// The dropdown's size.
func (b *DropdownBuilder) Size(v string) *DropdownBuilder {
b.props.Size = v
return b
}
// Placement sets the placement attribute
// The placement of the dropdown menu in reference to the trigger. The menu will shift to a more optimal location if
func (b *DropdownBuilder) Placement(v string) *DropdownBuilder {
b.props.Placement = v
return b
}
// Distance sets the distance attribute
// The distance of the dropdown menu from its trigger.
func (b *DropdownBuilder) Distance(v float64) *DropdownBuilder {
b.props.Distance = v
return b
}
// Skidding sets the skidding attribute
// The offset of the dropdown menu along its trigger.
func (b *DropdownBuilder) Skidding(v float64) *DropdownBuilder {
b.props.Skidding = v
return b
}
// OnShow sets the handler for wa-show event
// Emitted when the dropdown is about to show.
func (b *DropdownBuilder) OnShow(handler string) *DropdownBuilder {
b.props.OnShow = handler
return b
}
// OnAfterShow sets the handler for wa-after-show event
// Emitted after the dropdown has been shown.
func (b *DropdownBuilder) OnAfterShow(handler string) *DropdownBuilder {
b.props.OnAfterShow = handler
return b
}
// OnHide sets the handler for wa-hide event
// Emitted when the dropdown is about to hide.
func (b *DropdownBuilder) OnHide(handler string) *DropdownBuilder {
b.props.OnHide = handler
return b
}
// OnAfterHide sets the handler for wa-after-hide event
// Emitted after the dropdown has been hidden.
func (b *DropdownBuilder) OnAfterHide(handler string) *DropdownBuilder {
b.props.OnAfterHide = handler
return b
}
// OnSelect sets the handler for wa-select event
// Emitted when an item in the dropdown is selected.
func (b *DropdownBuilder) OnSelect(handler string) *DropdownBuilder {
b.props.OnSelect = handler
return b
}
// TriggerSlot sets the trigger slot content
// The element that triggers the dropdown, such as a <wa-button> or <button>.
func (b *DropdownBuilder) TriggerSlot(c templ.Component) *DropdownBuilder {
b.props.Slots.Trigger = c
return b
}
// Attr adds a custom HTML attribute
func (b *DropdownBuilder) Attr(name, value string) *DropdownBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *DropdownBuilder) Attrs(attrs templ.Attributes) *DropdownBuilder {
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 *DropdownBuilder) Props() DropdownProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *DropdownBuilder) Build() DropdownProps {
return b.props
}
// Dropdown renders the wa-dropdown component
templ Dropdown(props DropdownProps) {
<wa-dropdown
if props.Open {
open
}
if props.Size != "" {
size={ props.Size }
}
if props.Placement != "" {
placement={ props.Placement }
}
if props.Distance != 0 {
distance={ templ.Sprintf("%v", props.Distance) }
}
if props.Skidding != 0 {
skidding={ templ.Sprintf("%v", props.Skidding) }
}
if props.OnShow != "" {
x-on:wa-show={ props.OnShow }
}
if props.OnAfterShow != "" {
x-on:wa-after-show={ props.OnAfterShow }
}
if props.OnHide != "" {
x-on:wa-hide={ props.OnHide }
}
if props.OnAfterHide != "" {
x-on:wa-after-hide={ props.OnAfterHide }
}
if props.OnSelect != "" {
x-on:wa-select={ props.OnSelect }
}
{ props.Attrs... }
>
if props.Slots.Trigger != nil {
<div slot="trigger">
@props.Slots.Trigger
</div>
}
{ children... }
</wa-dropdown>
}
// DropdownFunc renders with a builder function for inline configuration
templ DropdownFunc(fn func(*DropdownBuilder)) {
{{ b := NewDropdown(); fn(b) }}
@Dropdown(b.Props()) {
{ children... }
}
}