Files
nebula/pkg/wa/relative-time.templ

132 lines
3.4 KiB
Plaintext
Raw Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-relative-time
package wa
import (
"github.com/a-h/templ"
)
// Outputs a localized time phrase relative to the current date and time.
//
// Web Awesome component: <wa-relative-time>
// RelativeTimeProps holds all properties for the wa-relative-time component
type RelativeTimeProps struct {
// The date from which to calculate time from. If not set, the current date and time will be used. When passing a
Date string `attr:"date"`
// The formatting style to use.
// Valid values: "long", "short", "narrow"
Format string `attr:"format"`
// When auto, values such as "yesterday" and "tomorrow" will be shown when possible. When always, values such as
// Valid values: "always", "auto"
Numeric string `attr:"numeric"`
// Keep the displayed value up to date as time passes.
Sync bool `attr:"sync"`
// Events
// Slots contains named slot content
Slots RelativeTimeSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// RelativeTimeBuilder provides a fluent API for constructing RelativeTimeProps
type RelativeTimeBuilder struct {
props RelativeTimeProps
}
// NewRelativeTime creates a new builder for wa-relative-time
func NewRelativeTime() *RelativeTimeBuilder {
return &RelativeTimeBuilder{}
}
// Date sets the date attribute
// The date from which to calculate time from. If not set, the current date and time will be used. When passing a
func (b *RelativeTimeBuilder) Date(v string) *RelativeTimeBuilder {
b.props.Date = v
return b
}
// Format sets the format attribute
// The formatting style to use.
func (b *RelativeTimeBuilder) Format(v string) *RelativeTimeBuilder {
b.props.Format = v
return b
}
// Numeric sets the numeric attribute
// When auto, values such as "yesterday" and "tomorrow" will be shown when possible. When always, values such as
func (b *RelativeTimeBuilder) Numeric(v string) *RelativeTimeBuilder {
b.props.Numeric = v
return b
}
// Sync sets the sync attribute
// Keep the displayed value up to date as time passes.
func (b *RelativeTimeBuilder) Sync(v bool) *RelativeTimeBuilder {
b.props.Sync = v
return b
}
// Attr adds a custom HTML attribute
func (b *RelativeTimeBuilder) Attr(name, value string) *RelativeTimeBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *RelativeTimeBuilder) Attrs(attrs templ.Attributes) *RelativeTimeBuilder {
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 *RelativeTimeBuilder) Props() RelativeTimeProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *RelativeTimeBuilder) Build() RelativeTimeProps {
return b.props
}
// RelativeTime renders the wa-relative-time component
templ RelativeTime(props RelativeTimeProps) {
<wa-relative-time
if props.Date != "" {
date={ props.Date }
}
if props.Format != "" {
format={ props.Format }
}
if props.Numeric != "" {
numeric={ props.Numeric }
}
if props.Sync {
sync
}
{ props.Attrs... }
>
{ children... }
</wa-relative-time>
}
// RelativeTimeFunc renders with a builder function for inline configuration
templ RelativeTimeFunc(fn func(*RelativeTimeBuilder)) {
{{ b := NewRelativeTime(); fn(b) }}
@RelativeTime(b.Props()) {
{ children... }
}
}