timepicker

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 4 Imported by: 0

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

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.

func WithMaxHours

func WithMaxHours(max int) DurationOption

WithMaxHours sets the maximum hours.

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) Clear

func (dp *DurationPicker) Clear()

Clear clears the duration.

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 With24Hour

func With24Hour(use24 bool) Option

With24Hour enables 24-hour format.

func WithFormat

func WithFormat(format string) Option

WithFormat sets the time format.

func WithMaxTime

func WithMaxTime(maxTime string) Option

WithMaxTime sets the maximum selectable time.

func WithMinTime

func WithMinTime(minTime string) Option

WithMinTime sets the minimum selectable time.

func WithMinuteStep

func WithMinuteStep(step int) Option

WithMinuteStep sets the minute increment.

func WithOpen

func WithOpen(_ bool) Option

WithOpen is a no-op. Open/close is now handled client-side via CSS classes. Deprecated: This option has no effect.

func WithPlaceholder

func WithPlaceholder(placeholder string) Option

WithPlaceholder sets the placeholder text.

func WithShowSeconds

func WithShowSeconds(show bool) Option

WithShowSeconds enables second selection.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling.

func WithTime

func WithTime(hour, minute int) Option

WithTime sets the initial time.

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) Clear

func (tp *TimePicker) Clear()

Clear clears the selected time.

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) SetHour

func (tp *TimePicker) SetHour(hour int)

SetHour sets the hour.

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) SetPeriod

func (tp *TimePicker) SetPeriod(period string)

SetPeriod sets AM/PM.

func (*TimePicker) SetSecond

func (tp *TimePicker) SetSecond(second int)

SetSecond sets the second.

func (*TimePicker) SetTime

func (tp *TimePicker) SetTime(hour, minute int)

SetTime sets the time.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL