Documentation
¶
Overview ¶
Package timepicker provides time selection components.
Available variants:
- New() creates a time picker (template: "lvt:timepicker:default:v1")
- NewDuration() creates a duration picker (template: "lvt:timepicker:duration:v1")
Open/close is handled client-side. Server actions handle time adjustments only.
Example usage:
// In your controller/state
StartTime: timepicker.New("start-time",
timepicker.WithPlaceholder("Select time"),
timepicker.WithFormat("3:04 PM"),
)
// In your template
{{template "lvt:timepicker:default:v1" .StartTime}}
Index ¶
- func Templates() *base.TemplateSet
- type DurationOption
- type DurationPicker
- func (dp *DurationPicker) Clear()
- func (dp *DurationPicker) DecrementHours()
- func (dp *DurationPicker) DecrementMinutes()
- func (dp *DurationPicker) DisplayValue() string
- func (dp *DurationPicker) DurationStyles() styles.TimepickerStyles
- func (dp *DurationPicker) FormatDuration() string
- func (dp *DurationPicker) IncrementHours()
- func (dp *DurationPicker) IncrementMinutes()
- func (dp *DurationPicker) SetDuration(hours, minutes int)
- func (dp *DurationPicker) SetDurationWithSeconds(hours, minutes, seconds int)
- func (dp *DurationPicker) SetHours(hours int)
- func (dp *DurationPicker) SetMinutes(minutes int)
- func (dp *DurationPicker) SetSeconds(seconds int)
- func (dp *DurationPicker) TotalMinutes() int
- func (dp *DurationPicker) TotalSeconds() int
- type Option
- func With24Hour(use24 bool) Option
- func WithFormat(format string) Option
- func WithMaxTime(maxTime string) Option
- func WithMinTime(minTime string) Option
- func WithMinuteStep(step int) Option
- func WithOpen(_ bool) Option
- func WithPlaceholder(placeholder string) Option
- func WithShowSeconds(show bool) Option
- func WithStyled(styled bool) Option
- func WithTime(hour, minute int) Option
- type TimePicker
- func (tp *TimePicker) Clear()
- func (tp *TimePicker) DecrementHour()
- func (tp *TimePicker) DecrementMinute()
- func (tp *TimePicker) DisplayValue() string
- func (tp *TimePicker) FormatTime() string
- func (tp *TimePicker) Get24Hour() int
- func (tp *TimePicker) HourOptions() []int
- func (tp *TimePicker) IncrementHour()
- func (tp *TimePicker) IncrementMinute()
- func (tp *TimePicker) MinuteOptions() []int
- func (tp *TimePicker) SecondOptions() []int
- func (tp *TimePicker) SetHour(hour int)
- func (tp *TimePicker) SetMinute(minute int)
- func (tp *TimePicker) SetNow()
- func (tp *TimePicker) SetPeriod(period string)
- func (tp *TimePicker) SetSecond(second int)
- func (tp *TimePicker) SetTime(hour, minute int)
- func (tp *TimePicker) SetTimeWithSeconds(hour, minute, second int)
- func (tp *TimePicker) Styles() styles.TimepickerStyles
- func (tp *TimePicker) TogglePeriod()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Templates ¶
func Templates() *base.TemplateSet
Templates returns the timepicker component's template set for registration with the LiveTemplate framework.
Example usage in main.go:
import "github.com/livetemplate/lvt/components/timepicker"
tmpl, err := livetemplate.New("app",
livetemplate.WithComponentTemplates(timepicker.Templates()),
)
Available templates:
- "lvt:timepicker:default:v1" - Time picker
- "lvt:timepicker:duration:v1" - Duration picker
Types ¶
type DurationOption ¶
type DurationOption func(*DurationPicker)
DurationOption is a functional option for configuring duration pickers.
func WithDuration ¶
func WithDuration(hours, minutes int) DurationOption
WithDuration sets the initial duration.
func WithDurationPlaceholder ¶
func WithDurationPlaceholder(placeholder string) DurationOption
WithDurationPlaceholder sets the placeholder text.
func WithDurationShowSeconds ¶
func WithDurationShowSeconds(show bool) DurationOption
WithDurationShowSeconds enables second selection.
func WithDurationStyled ¶
func WithDurationStyled(styled bool) DurationOption
WithDurationStyled enables Tailwind CSS styling.
type DurationPicker ¶
type DurationPicker struct {
base.Base
// Hours in the duration
Hours int
// Minutes in the duration
Minutes int
// Seconds in the duration (only if ShowSeconds)
Seconds int
// HasValue indicates if a duration has been set
HasValue bool
// Placeholder text
Placeholder string
// ShowSeconds includes seconds
ShowSeconds bool
// MaxHours limits the maximum hours
MaxHours int
}
DurationPicker is a component for selecting a duration. Use template "lvt:timepicker:duration:v1" to render.
func NewDuration ¶
func NewDuration(id string, opts ...DurationOption) *DurationPicker
NewDuration creates a duration picker.
func (*DurationPicker) DecrementHours ¶
func (dp *DurationPicker) DecrementHours()
DecrementHours decrements hours.
func (*DurationPicker) DecrementMinutes ¶
func (dp *DurationPicker) DecrementMinutes()
DecrementMinutes decrements minutes.
func (*DurationPicker) DisplayValue ¶
func (dp *DurationPicker) DisplayValue() string
DisplayValue returns the formatted duration or placeholder.
func (*DurationPicker) DurationStyles ¶
func (dp *DurationPicker) DurationStyles() styles.TimepickerStyles
DurationStyles returns the resolved TimepickerStyles for the duration picker.
func (*DurationPicker) FormatDuration ¶
func (dp *DurationPicker) FormatDuration() string
FormatDuration returns the formatted duration string.
func (*DurationPicker) IncrementHours ¶
func (dp *DurationPicker) IncrementHours()
IncrementHours increments hours.
func (*DurationPicker) IncrementMinutes ¶
func (dp *DurationPicker) IncrementMinutes()
IncrementMinutes increments minutes.
func (*DurationPicker) SetDuration ¶
func (dp *DurationPicker) SetDuration(hours, minutes int)
SetDuration sets the duration.
func (*DurationPicker) SetDurationWithSeconds ¶
func (dp *DurationPicker) SetDurationWithSeconds(hours, minutes, seconds int)
SetDurationWithSeconds sets the duration including seconds.
func (*DurationPicker) SetHours ¶
func (dp *DurationPicker) SetHours(hours int)
SetHours sets the hours.
func (*DurationPicker) SetMinutes ¶
func (dp *DurationPicker) SetMinutes(minutes int)
SetMinutes sets the minutes.
func (*DurationPicker) SetSeconds ¶
func (dp *DurationPicker) SetSeconds(seconds int)
SetSeconds sets the seconds.
func (*DurationPicker) TotalMinutes ¶
func (dp *DurationPicker) TotalMinutes() int
TotalMinutes returns the total duration in minutes.
func (*DurationPicker) TotalSeconds ¶
func (dp *DurationPicker) TotalSeconds() int
TotalSeconds returns the total duration in seconds.
type Option ¶
type Option func(*TimePicker)
Option is a functional option for configuring time pickers.
func WithMaxTime ¶
WithMaxTime sets the maximum selectable time.
func WithMinTime ¶
WithMinTime sets the minimum selectable time.
func WithMinuteStep ¶
WithMinuteStep sets the minute increment.
func WithOpen ¶
WithOpen is a no-op. Open/close is now handled client-side via CSS classes. Deprecated: This option has no effect.
func WithPlaceholder ¶
WithPlaceholder sets the placeholder text.
func WithShowSeconds ¶
WithShowSeconds enables second selection.
type TimePicker ¶
type TimePicker struct {
base.Base
// Hour is the selected hour (0-23 or 1-12 depending on Use24Hour)
Hour int
// Minute is the selected minute (0-59)
Minute int
// Second is the selected second (0-59, only used if ShowSeconds)
Second int
// Period is "AM" or "PM" (only used if not Use24Hour)
Period string
// HasValue indicates if a time has been selected
HasValue bool
// Placeholder text shown when no time is selected
Placeholder string
// Format for displaying the time
Format string
// Use24Hour uses 24-hour format instead of 12-hour
Use24Hour bool
// ShowSeconds shows second selection
ShowSeconds bool
// MinuteStep is the minute increment (default 1, common: 5, 15, 30)
MinuteStep int
// MinTime is the earliest selectable time (HH:MM)
MinTime string
// MaxTime is the latest selectable time (HH:MM)
MaxTime string
}
TimePicker is a component for selecting time. Use template "lvt:timepicker:default:v1" to render.
func New ¶
func New(id string, opts ...Option) *TimePicker
New creates a time picker.
Example:
tp := timepicker.New("meeting-time",
timepicker.WithPlaceholder("Select time"),
timepicker.WithMinuteStep(15),
)
func (*TimePicker) DecrementHour ¶
func (tp *TimePicker) DecrementHour()
DecrementHour decrements the hour.
func (*TimePicker) DecrementMinute ¶
func (tp *TimePicker) DecrementMinute()
DecrementMinute decrements the minute by MinuteStep.
func (*TimePicker) DisplayValue ¶
func (tp *TimePicker) DisplayValue() string
DisplayValue returns the formatted time or placeholder.
func (*TimePicker) FormatTime ¶
func (tp *TimePicker) FormatTime() string
FormatTime returns the formatted time string.
func (*TimePicker) Get24Hour ¶
func (tp *TimePicker) Get24Hour() int
Get24Hour returns the hour in 24-hour format.
func (*TimePicker) HourOptions ¶
func (tp *TimePicker) HourOptions() []int
HourOptions returns available hour options.
func (*TimePicker) IncrementHour ¶
func (tp *TimePicker) IncrementHour()
IncrementHour increments the hour.
func (*TimePicker) IncrementMinute ¶
func (tp *TimePicker) IncrementMinute()
IncrementMinute increments the minute by MinuteStep.
func (*TimePicker) MinuteOptions ¶
func (tp *TimePicker) MinuteOptions() []int
MinuteOptions returns available minute options.
func (*TimePicker) SecondOptions ¶
func (tp *TimePicker) SecondOptions() []int
SecondOptions returns available second options.
func (*TimePicker) SetMinute ¶
func (tp *TimePicker) SetMinute(minute int)
SetMinute sets the minute.
func (*TimePicker) SetNow ¶
func (tp *TimePicker) SetNow()
SetNow sets the time to the current time.
func (*TimePicker) SetSecond ¶
func (tp *TimePicker) SetSecond(second int)
SetSecond sets the second.
func (*TimePicker) SetTimeWithSeconds ¶
func (tp *TimePicker) SetTimeWithSeconds(hour, minute, second int)
SetTimeWithSeconds sets the time including seconds.
func (*TimePicker) Styles ¶
func (tp *TimePicker) Styles() styles.TimepickerStyles
Styles returns the resolved TimepickerStyles for this component.
func (*TimePicker) TogglePeriod ¶
func (tp *TimePicker) TogglePeriod()
TogglePeriod toggles between AM and PM.