Files
nebula/pkg/wa/builders.go

147 lines
5.7 KiB
Go
Raw Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
package wa
import "github.com/a]h/templ"
// PropsBuilder is the interface all component builders implement
type PropsBuilder[T any] interface {
Attr(name, value string) PropsBuilder[T]
Attrs(attrs templ.Attributes) PropsBuilder[T]
Build() T
}
// BaseBuilder provides common builder functionality
type BaseBuilder struct {
attrs templ.Attributes
}
// SetAttr sets a single attribute
func (b *BaseBuilder) SetAttr(name, value string) {
if b.attrs == nil {
b.attrs = templ.Attributes{}
}
b.attrs[name] = value
}
// MergeAttrs merges attributes
func (b *BaseBuilder) MergeAttrs(attrs templ.Attributes) {
if b.attrs == nil {
b.attrs = templ.Attributes{}
}
for k, v := range attrs {
b.attrs[k] = v
}
}
// GetAttrs returns the attributes
func (b *BaseBuilder) GetAttrs() templ.Attributes {
if b.attrs == nil {
return templ.Attributes{}
}
return b.attrs
}
// Common builder method helpers
// WithClass is a helper to add CSS classes
func WithClass[B interface{ Attr(string, string) B }](b B, classes ...string) B {
return b.Attr("class", strings.Join(classes, " "))
}
// WithID is a helper to set element ID
func WithID[B interface{ Attr(string, string) B }](b B, id string) B {
return b.Attr("id", id)
}
// WithStyle is a helper to add inline styles
func WithStyle[B interface{ Attr(string, string) B }](b B, style string) B {
return b.Attr("style", style)
}
// WithData is a helper to add data attributes
func WithData[B interface{ Attr(string, string) B }](b B, key, value string) B {
return b.Attr("data-"+key, value)
}
// Component registry for dynamic component creation
var componentRegistry = map[string]func() interface{}{
"wa-animated-image": func() interface{} { return NewAnimatedImage() },
"wa-animation": func() interface{} { return NewAnimation() },
"wa-avatar": func() interface{} { return NewAvatar() },
"wa-badge": func() interface{} { return NewBadge() },
"wa-breadcrumb-item": func() interface{} { return NewBreadcrumbItem() },
"wa-breadcrumb": func() interface{} { return NewBreadcrumb() },
"wa-button-group": func() interface{} { return NewButtonGroup() },
"wa-button": func() interface{} { return NewButton() },
"wa-callout": func() interface{} { return NewCallout() },
"wa-card": func() interface{} { return NewCard() },
"wa-carousel": func() interface{} { return NewCarousel() },
"wa-carousel-item": func() interface{} { return NewCarouselItem() },
"wa-checkbox": func() interface{} { return NewCheckbox() },
"wa-color-picker": func() interface{} { return NewColorPicker() },
"wa-combobox": func() interface{} { return NewCombobox() },
"wa-comparison": func() interface{} { return NewComparison() },
"wa-copy-button": func() interface{} { return NewCopyButton() },
"wa-details": func() interface{} { return NewDetails() },
"wa-dialog": func() interface{} { return NewDialog() },
"wa-divider": func() interface{} { return NewDivider() },
"wa-drawer": func() interface{} { return NewDrawer() },
"wa-dropdown": func() interface{} { return NewDropdown() },
"wa-dropdown-item": func() interface{} { return NewDropdownItem() },
"wa-format-bytes": func() interface{} { return NewFormatBytes() },
"wa-format-date": func() interface{} { return NewFormatDate() },
"wa-format-number": func() interface{} { return NewFormatNumber() },
"wa-icon": func() interface{} { return NewIcon() },
"wa-include": func() interface{} { return NewInclude() },
"wa-input": func() interface{} { return NewInput() },
"wa-intersection-observer": func() interface{} { return NewIntersectionObserver() },
"wa-mutation-observer": func() interface{} { return NewMutationObserver() },
"wa-option": func() interface{} { return NewOption() },
"wa-page": func() interface{} { return NewPage() },
"wa-popover": func() interface{} { return NewPopover() },
"wa-popup": func() interface{} { return NewPopup() },
"wa-progress-bar": func() interface{} { return NewProgressBar() },
"wa-qr-code": func() interface{} { return NewQrCode() },
"wa-progress-ring": func() interface{} { return NewProgressRing() },
"wa-radio": func() interface{} { return NewRadio() },
"wa-radio-group": func() interface{} { return NewRadioGroup() },
"wa-rating": func() interface{} { return NewRating() },
"wa-relative-time": func() interface{} { return NewRelativeTime() },
"wa-resize-observer": func() interface{} { return NewResizeObserver() },
"wa-scroller": func() interface{} { return NewScroller() },
"wa-skeleton": func() interface{} { return NewSkeleton() },
"wa-select": func() interface{} { return NewSelect() },
"wa-slider": func() interface{} { return NewSlider() },
"wa-spinner": func() interface{} { return NewSpinner() },
"wa-split-panel": func() interface{} { return NewSplitPanel() },
"wa-switch": func() interface{} { return NewSwitch() },
"wa-tab": func() interface{} { return NewTab() },
"wa-tab-group": func() interface{} { return NewTabGroup() },
"wa-tab-panel": func() interface{} { return NewTabPanel() },
"wa-tag": func() interface{} { return NewTag() },
"wa-textarea": func() interface{} { return NewTextarea() },
"wa-tooltip": func() interface{} { return NewTooltip() },
"wa-tree": func() interface{} { return NewTree() },
"wa-tree-item": func() interface{} { return NewTreeItem() },
"wa-zoomable-frame": func() interface{} { return NewZoomableFrame() },
}
// GetBuilder returns a builder for the given component name
func GetBuilder(name string) interface{} {
if fn, ok := componentRegistry[name]; ok {
return fn()
}
return nil
}
// ComponentNames returns all available component names
func ComponentNames() []string {
names := make([]string, 0, len(componentRegistry))
for name := range componentRegistry {
names = append(names, name)
}
sort.Strings(names)
return names
}