139 lines
3.6 KiB
Plaintext
139 lines
3.6 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-tree
|
|
|
|
package wa
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Trees allow you to display a hierarchical list of selectable tree items. Items with children can be expanded and coll...
|
|
//
|
|
// Web Awesome component: <wa-tree>
|
|
|
|
// TreeProps holds all properties for the wa-tree component
|
|
type TreeProps struct {
|
|
// The selection behavior of the tree. Single selection allows only one node to be selected at a time. Multiple
|
|
// Valid values: "single", "multiple", "leaf"
|
|
Selection string `attr:"selection"`
|
|
|
|
// Events
|
|
// Emitted when a tree item is selected or deselected.
|
|
OnSelectionChange string `attr:"x-on:wa-selection-change"`
|
|
|
|
// Slots contains named slot content
|
|
Slots TreeSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// TreeSlots holds named slot content for the component
|
|
type TreeSlots struct {
|
|
// The icon to show when the tree item is expanded. Works best with <wa-icon>.
|
|
ExpandIcon templ.Component
|
|
// The icon to show when the tree item is collapsed. Works best with <wa-icon>.
|
|
CollapseIcon templ.Component
|
|
}
|
|
|
|
// TreeBuilder provides a fluent API for constructing TreeProps
|
|
type TreeBuilder struct {
|
|
props TreeProps
|
|
}
|
|
|
|
// NewTree creates a new builder for wa-tree
|
|
func NewTree() *TreeBuilder {
|
|
return &TreeBuilder{}
|
|
}
|
|
|
|
// Selection sets the selection attribute
|
|
// The selection behavior of the tree. Single selection allows only one node to be selected at a time. Multiple
|
|
func (b *TreeBuilder) Selection(v string) *TreeBuilder {
|
|
b.props.Selection = v
|
|
return b
|
|
}
|
|
|
|
// OnSelectionChange sets the handler for wa-selection-change event
|
|
// Emitted when a tree item is selected or deselected.
|
|
func (b *TreeBuilder) OnSelectionChange(handler string) *TreeBuilder {
|
|
b.props.OnSelectionChange = handler
|
|
return b
|
|
}
|
|
|
|
// ExpandIconSlot sets the expand-icon slot content
|
|
// The icon to show when the tree item is expanded. Works best with <wa-icon>.
|
|
func (b *TreeBuilder) ExpandIconSlot(c templ.Component) *TreeBuilder {
|
|
b.props.Slots.ExpandIcon = c
|
|
return b
|
|
}
|
|
|
|
// CollapseIconSlot sets the collapse-icon slot content
|
|
// The icon to show when the tree item is collapsed. Works best with <wa-icon>.
|
|
func (b *TreeBuilder) CollapseIconSlot(c templ.Component) *TreeBuilder {
|
|
b.props.Slots.CollapseIcon = c
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *TreeBuilder) Attr(name, value string) *TreeBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *TreeBuilder) Attrs(attrs templ.Attributes) *TreeBuilder {
|
|
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 *TreeBuilder) Props() TreeProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *TreeBuilder) Build() TreeProps {
|
|
return b.props
|
|
}
|
|
|
|
// Tree renders the wa-tree component
|
|
templ Tree(props TreeProps) {
|
|
<wa-tree
|
|
if props.Selection != "" {
|
|
selection={ props.Selection }
|
|
}
|
|
if props.OnSelectionChange != "" {
|
|
x-on:wa-selection-change={ props.OnSelectionChange }
|
|
}
|
|
{ props.Attrs... }
|
|
>
|
|
if props.Slots.ExpandIcon != nil {
|
|
<div slot="expand-icon">
|
|
@props.Slots.ExpandIcon
|
|
</div>
|
|
}
|
|
if props.Slots.CollapseIcon != nil {
|
|
<div slot="collapse-icon">
|
|
@props.Slots.CollapseIcon
|
|
</div>
|
|
}
|
|
{ children... }
|
|
</wa-tree>
|
|
}
|
|
|
|
// TreeFunc renders with a builder function for inline configuration
|
|
templ TreeFunc(fn func(*TreeBuilder)) {
|
|
{{ b := NewTree(); fn(b) }}
|
|
@Tree(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|