Files
nebula/pkg/wa/dialog.templ

224 lines
6.3 KiB
Plaintext

// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-dialog
package wa
import (
"github.com/a-h/templ"
)
// Dialogs, sometimes called "modals", appear above the page and require the user's immediate attention.
//
// Web Awesome component: <wa-dialog>
// DialogProps holds all properties for the wa-dialog component
type DialogProps struct {
// Indicates whether or not the dialog is open. Toggle this attribute to show and hide the dialog.
Open bool `attr:"open"`
// The dialog's label as displayed in the header. You should always include a relevant label, as it is required for
Label string `attr:"label"`
// Disables the header. This will also remove the default close button.
WithoutHeader bool `attr:"without-header"`
// When enabled, the dialog will be closed when the user clicks outside of it.
LightDismiss bool `attr:"light-dismiss"`
// Events
// Emitted when the dialog opens.
OnShow string `attr:"x-on:wa-show"`
// Emitted after the dialog opens and all animations are complete.
OnAfterShow string `attr:"x-on:wa-after-show"`
// Emitted when the dialog is requested to close. Calling event.preventDefault() will prevent the dialog from closing. Y...
OnHide string `attr:"x-on:wa-hide"`
// Emitted after the dialog closes and all animations are complete.
OnAfterHide string `attr:"x-on:wa-after-hide"`
// Slots contains named slot content
Slots DialogSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// DialogSlots holds named slot content for the component
type DialogSlots struct {
// The dialog's label. Alternatively, you can use the label attribute.
Label templ.Component
// Optional actions to add to the header. Works best with <wa-button>.
HeaderActions templ.Component
// The dialog's footer, usually one or more buttons representing various options.
Footer templ.Component
}
// DialogBuilder provides a fluent API for constructing DialogProps
type DialogBuilder struct {
props DialogProps
}
// NewDialog creates a new builder for wa-dialog
func NewDialog() *DialogBuilder {
return &DialogBuilder{}
}
// Open sets the open attribute
// Indicates whether or not the dialog is open. Toggle this attribute to show and hide the dialog.
func (b *DialogBuilder) Open(v bool) *DialogBuilder {
b.props.Open = v
return b
}
// Label sets the label attribute
// The dialog's label as displayed in the header. You should always include a relevant label, as it is required for
func (b *DialogBuilder) Label(v string) *DialogBuilder {
b.props.Label = v
return b
}
// WithoutHeader sets the without-header attribute
// Disables the header. This will also remove the default close button.
func (b *DialogBuilder) WithoutHeader(v bool) *DialogBuilder {
b.props.WithoutHeader = v
return b
}
// LightDismiss sets the light-dismiss attribute
// When enabled, the dialog will be closed when the user clicks outside of it.
func (b *DialogBuilder) LightDismiss(v bool) *DialogBuilder {
b.props.LightDismiss = v
return b
}
// OnShow sets the handler for wa-show event
// Emitted when the dialog opens.
func (b *DialogBuilder) OnShow(handler string) *DialogBuilder {
b.props.OnShow = handler
return b
}
// OnAfterShow sets the handler for wa-after-show event
// Emitted after the dialog opens and all animations are complete.
func (b *DialogBuilder) OnAfterShow(handler string) *DialogBuilder {
b.props.OnAfterShow = handler
return b
}
// OnHide sets the handler for wa-hide event
// Emitted when the dialog is requested to close. Calling event.preventDefault() will prevent the dialog from closing. Y...
func (b *DialogBuilder) OnHide(handler string) *DialogBuilder {
b.props.OnHide = handler
return b
}
// OnAfterHide sets the handler for wa-after-hide event
// Emitted after the dialog closes and all animations are complete.
func (b *DialogBuilder) OnAfterHide(handler string) *DialogBuilder {
b.props.OnAfterHide = handler
return b
}
// LabelSlot sets the label slot content
// The dialog's label. Alternatively, you can use the label attribute.
func (b *DialogBuilder) LabelSlot(c templ.Component) *DialogBuilder {
b.props.Slots.Label = c
return b
}
// HeaderActionsSlot sets the header-actions slot content
// Optional actions to add to the header. Works best with <wa-button>.
func (b *DialogBuilder) HeaderActionsSlot(c templ.Component) *DialogBuilder {
b.props.Slots.HeaderActions = c
return b
}
// FooterSlot sets the footer slot content
// The dialog's footer, usually one or more buttons representing various options.
func (b *DialogBuilder) FooterSlot(c templ.Component) *DialogBuilder {
b.props.Slots.Footer = c
return b
}
// Attr adds a custom HTML attribute
func (b *DialogBuilder) Attr(name, value string) *DialogBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *DialogBuilder) Attrs(attrs templ.Attributes) *DialogBuilder {
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 *DialogBuilder) Props() DialogProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *DialogBuilder) Build() DialogProps {
return b.props
}
// Dialog renders the wa-dialog component
templ Dialog(props DialogProps) {
<wa-dialog
if props.Open {
open
}
if props.Label != "" {
label={ props.Label }
}
if props.WithoutHeader {
without-header
}
if props.LightDismiss {
light-dismiss
}
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 }
}
{ props.Attrs... }
>
if props.Slots.Label != nil {
<div slot="label">
@props.Slots.Label
</div>
}
if props.Slots.HeaderActions != nil {
<div slot="header-actions">
@props.Slots.HeaderActions
</div>
}
if props.Slots.Footer != nil {
<div slot="footer">
@props.Slots.Footer
</div>
}
{ children... }
</wa-dialog>
}
// DialogFunc renders with a builder function for inline configuration
templ DialogFunc(fn func(*DialogBuilder)) {
{{ b := NewDialog(); fn(b) }}
@Dialog(b.Props()) {
{ children... }
}
}