226 lines
6.0 KiB
Plaintext
226 lines
6.0 KiB
Plaintext
|
|
// Code generated by wa-generator. DO NOT EDIT.
|
||
|
|
// Source: Web Awesome wa-dropdown-item
|
||
|
|
|
||
|
|
package wa
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/a-h/templ"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Represents an individual item within a dropdown menu, supporting standard items, checkboxes, and submenus.
|
||
|
|
//
|
||
|
|
// Web Awesome component: <wa-dropdown-item>
|
||
|
|
|
||
|
|
// DropdownItemProps holds all properties for the wa-dropdown-item component
|
||
|
|
type DropdownItemProps struct {
|
||
|
|
// The type of menu item to render.
|
||
|
|
// Valid values: "danger", "default"
|
||
|
|
Variant string `attr:"variant"`
|
||
|
|
// An optional value for the menu item. This is useful for determining which item was selected when listening to the
|
||
|
|
Value string `attr:"value"`
|
||
|
|
// Set to checkbox to make the item a checkbox.
|
||
|
|
// Valid values: "normal", "checkbox"
|
||
|
|
Type string `attr:"type"`
|
||
|
|
// Set to true to check the dropdown item. Only valid when type is checkbox.
|
||
|
|
Checked bool `attr:"checked"`
|
||
|
|
// Disables the dropdown item.
|
||
|
|
Disabled bool `attr:"disabled"`
|
||
|
|
// Whether the submenu is currently open.
|
||
|
|
SubmenuOpen bool `attr:"submenuOpen"`
|
||
|
|
|
||
|
|
// Events
|
||
|
|
// Emitted when the dropdown item loses focus.
|
||
|
|
OnBlur string `attr:"x-on:blur"`
|
||
|
|
// Emitted when the dropdown item gains focus.
|
||
|
|
OnFocus string `attr:"x-on:focus"`
|
||
|
|
|
||
|
|
// Slots contains named slot content
|
||
|
|
Slots DropdownItemSlots
|
||
|
|
|
||
|
|
// Attrs contains additional HTML attributes
|
||
|
|
Attrs templ.Attributes
|
||
|
|
}
|
||
|
|
|
||
|
|
// DropdownItemSlots holds named slot content for the component
|
||
|
|
type DropdownItemSlots struct {
|
||
|
|
// An optional icon to display before the label.
|
||
|
|
Icon templ.Component
|
||
|
|
// Additional content or details to display after the label.
|
||
|
|
Details templ.Component
|
||
|
|
// Submenu items, typically <wa-dropdown-item> elements, to create a nested menu.
|
||
|
|
Submenu templ.Component
|
||
|
|
}
|
||
|
|
|
||
|
|
// DropdownItemBuilder provides a fluent API for constructing DropdownItemProps
|
||
|
|
type DropdownItemBuilder struct {
|
||
|
|
props DropdownItemProps
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewDropdownItem creates a new builder for wa-dropdown-item
|
||
|
|
func NewDropdownItem() *DropdownItemBuilder {
|
||
|
|
return &DropdownItemBuilder{}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Variant sets the variant attribute
|
||
|
|
// The type of menu item to render.
|
||
|
|
func (b *DropdownItemBuilder) Variant(v string) *DropdownItemBuilder {
|
||
|
|
b.props.Variant = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Value sets the value attribute
|
||
|
|
// An optional value for the menu item. This is useful for determining which item was selected when listening to the
|
||
|
|
func (b *DropdownItemBuilder) Value(v string) *DropdownItemBuilder {
|
||
|
|
b.props.Value = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Type sets the type attribute
|
||
|
|
// Set to checkbox to make the item a checkbox.
|
||
|
|
func (b *DropdownItemBuilder) Type(v string) *DropdownItemBuilder {
|
||
|
|
b.props.Type = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Checked sets the checked attribute
|
||
|
|
// Set to true to check the dropdown item. Only valid when type is checkbox.
|
||
|
|
func (b *DropdownItemBuilder) Checked(v bool) *DropdownItemBuilder {
|
||
|
|
b.props.Checked = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Disabled sets the disabled attribute
|
||
|
|
// Disables the dropdown item.
|
||
|
|
func (b *DropdownItemBuilder) Disabled(v bool) *DropdownItemBuilder {
|
||
|
|
b.props.Disabled = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// SubmenuOpen sets the submenuOpen attribute
|
||
|
|
// Whether the submenu is currently open.
|
||
|
|
func (b *DropdownItemBuilder) SubmenuOpen(v bool) *DropdownItemBuilder {
|
||
|
|
b.props.SubmenuOpen = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnBlur sets the handler for blur event
|
||
|
|
// Emitted when the dropdown item loses focus.
|
||
|
|
func (b *DropdownItemBuilder) OnBlur(handler string) *DropdownItemBuilder {
|
||
|
|
b.props.OnBlur = handler
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnFocus sets the handler for focus event
|
||
|
|
// Emitted when the dropdown item gains focus.
|
||
|
|
func (b *DropdownItemBuilder) OnFocus(handler string) *DropdownItemBuilder {
|
||
|
|
b.props.OnFocus = handler
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// IconSlot sets the icon slot content
|
||
|
|
// An optional icon to display before the label.
|
||
|
|
func (b *DropdownItemBuilder) IconSlot(c templ.Component) *DropdownItemBuilder {
|
||
|
|
b.props.Slots.Icon = c
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// DetailsSlot sets the details slot content
|
||
|
|
// Additional content or details to display after the label.
|
||
|
|
func (b *DropdownItemBuilder) DetailsSlot(c templ.Component) *DropdownItemBuilder {
|
||
|
|
b.props.Slots.Details = c
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// SubmenuSlot sets the submenu slot content
|
||
|
|
// Submenu items, typically <wa-dropdown-item> elements, to create a nested menu.
|
||
|
|
func (b *DropdownItemBuilder) SubmenuSlot(c templ.Component) *DropdownItemBuilder {
|
||
|
|
b.props.Slots.Submenu = c
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Attr adds a custom HTML attribute
|
||
|
|
func (b *DropdownItemBuilder) Attr(name, value string) *DropdownItemBuilder {
|
||
|
|
if b.props.Attrs == nil {
|
||
|
|
b.props.Attrs = templ.Attributes{}
|
||
|
|
}
|
||
|
|
b.props.Attrs[name] = value
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Attrs merges multiple attributes
|
||
|
|
func (b *DropdownItemBuilder) Attrs(attrs templ.Attributes) *DropdownItemBuilder {
|
||
|
|
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 *DropdownItemBuilder) Props() DropdownItemProps {
|
||
|
|
return b.props
|
||
|
|
}
|
||
|
|
|
||
|
|
// Build returns the props (alias for Props for semantic clarity)
|
||
|
|
func (b *DropdownItemBuilder) Build() DropdownItemProps {
|
||
|
|
return b.props
|
||
|
|
}
|
||
|
|
|
||
|
|
// DropdownItem renders the wa-dropdown-item component
|
||
|
|
templ DropdownItem(props DropdownItemProps) {
|
||
|
|
<wa-dropdown-item
|
||
|
|
if props.Variant != "" {
|
||
|
|
variant={ props.Variant }
|
||
|
|
}
|
||
|
|
if props.Value != "" {
|
||
|
|
value={ props.Value }
|
||
|
|
}
|
||
|
|
if props.Type != "" {
|
||
|
|
type={ props.Type }
|
||
|
|
}
|
||
|
|
if props.Checked {
|
||
|
|
checked
|
||
|
|
}
|
||
|
|
if props.Disabled {
|
||
|
|
disabled
|
||
|
|
}
|
||
|
|
if props.SubmenuOpen {
|
||
|
|
submenuOpen
|
||
|
|
}
|
||
|
|
if props.OnBlur != "" {
|
||
|
|
x-on:blur={ props.OnBlur }
|
||
|
|
}
|
||
|
|
if props.OnFocus != "" {
|
||
|
|
x-on:focus={ props.OnFocus }
|
||
|
|
}
|
||
|
|
{ props.Attrs... }
|
||
|
|
>
|
||
|
|
if props.Slots.Icon != nil {
|
||
|
|
<div slot="icon">
|
||
|
|
@props.Slots.Icon
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
if props.Slots.Details != nil {
|
||
|
|
<div slot="details">
|
||
|
|
@props.Slots.Details
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
if props.Slots.Submenu != nil {
|
||
|
|
<div slot="submenu">
|
||
|
|
@props.Slots.Submenu
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
{ children... }
|
||
|
|
</wa-dropdown-item>
|
||
|
|
}
|
||
|
|
|
||
|
|
// DropdownItemFunc renders with a builder function for inline configuration
|
||
|
|
templ DropdownItemFunc(fn func(*DropdownItemBuilder)) {
|
||
|
|
{{ b := NewDropdownItem(); fn(b) }}
|
||
|
|
@DropdownItem(b.Props()) {
|
||
|
|
{ children... }
|
||
|
|
}
|
||
|
|
}
|