datepicker

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 datepicker provides date selection components with calendar UI.

Available variants:

  • New() creates a single date picker (template: "lvt:datepicker:single:v1")
  • NewRange() creates a date range picker (template: "lvt:datepicker:range:v1")
  • NewInline() creates an inline calendar (template: "lvt:datepicker:inline:v1")

Required lvt-* attributes: name, lvt-el:removeClass:on:click-away

Example usage:

// In your controller/state
BirthDate: datepicker.New("birthdate",
    datepicker.WithPlaceholder("Select date"),
)

// In your template
{{template "lvt:datepicker:single:v1" .BirthDate}}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Templates

func Templates() *base.TemplateSet

Templates returns the datepicker component's template set for registration with the LiveTemplate framework.

Example usage in main.go:

import "github.com/livetemplate/lvt/components/datepicker"

tmpl, err := livetemplate.New("app",
    livetemplate.WithComponentTemplates(datepicker.Templates()),
)

Available templates:

  • "lvt:datepicker:single:v1" - Single date picker
  • "lvt:datepicker:range:v1" - Date range picker
  • "lvt:datepicker:inline:v1" - Inline calendar (always visible)

Types

type CalendarDay

type CalendarDay struct {
	Date       time.Time
	Day        int
	InMonth    bool
	IsToday    bool
	IsSelected bool
	IsDisabled bool
}

CalendarDay represents a day in the calendar view.

func (CalendarDay) DateString

func (d CalendarDay) DateString() string

DateString returns the date as a string (for lvt-data attributes).

type DatePicker

type DatePicker struct {
	base.Base

	// Selected is the currently selected date (nil if none)
	Selected *time.Time

	// ViewDate is the date currently being viewed (for navigation)
	ViewDate time.Time

	// Placeholder text shown when no date is selected
	Placeholder string

	// MinDate is the earliest selectable date (nil for no limit)
	MinDate *time.Time

	// MaxDate is the latest selectable date (nil for no limit)
	MaxDate *time.Time

	// DisabledDates are specific dates that cannot be selected
	DisabledDates []time.Time

	// DisabledWeekdays are days of the week that cannot be selected (0=Sunday, 6=Saturday)
	DisabledWeekdays []time.Weekday

	// Format for displaying the date
	Format string

	// FirstDayOfWeek (0=Sunday, 1=Monday, etc.)
	FirstDayOfWeek int
}

DatePicker is a component for selecting a single date. Use template "lvt:datepicker:single:v1" to render.

func New

func New(id string, opts ...Option) *DatePicker

New creates a single date picker.

Example:

dp := datepicker.New("birthdate",
    datepicker.WithPlaceholder("Select date"),
    datepicker.WithFormat("Jan 2, 2006"),
)

func NewInline

func NewInline(id string, opts ...Option) *DatePicker

NewInline creates an inline calendar. The consuming template should add the "open" class to the root element to make the calendar panel always visible.

func (*DatePicker) CalendarWeeks

func (dp *DatePicker) CalendarWeeks() [][]CalendarDay

CalendarWeeks returns the weeks for the current view month.

func (*DatePicker) Clear

func (dp *DatePicker) Clear()

Clear clears the selected date.

func (*DatePicker) DisplayValue

func (dp *DatePicker) DisplayValue() string

DisplayValue returns the formatted selected date or placeholder.

func (*DatePicker) GoToToday

func (dp *DatePicker) GoToToday()

GoToToday navigates to and selects today.

func (*DatePicker) IsDateSelectable

func (dp *DatePicker) IsDateSelectable(date time.Time) bool

IsDateSelectable checks if a date can be selected.

func (*DatePicker) IsSelected

func (dp *DatePicker) IsSelected(date time.Time) bool

IsSelected checks if a date is the selected date.

func (*DatePicker) IsToday

func (dp *DatePicker) IsToday(date time.Time) bool

IsToday checks if a date is today.

func (*DatePicker) NextMonth

func (dp *DatePicker) NextMonth()

NextMonth navigates to the next month.

func (*DatePicker) NextYear

func (dp *DatePicker) NextYear()

NextYear navigates to the next year.

func (*DatePicker) PreviousMonth

func (dp *DatePicker) PreviousMonth()

PreviousMonth navigates to the previous month.

func (*DatePicker) PreviousYear

func (dp *DatePicker) PreviousYear()

PreviousYear navigates to the previous year.

func (*DatePicker) SelectDate

func (dp *DatePicker) SelectDate(date time.Time) bool

SelectDate selects a date.

func (*DatePicker) Styles

func (dp *DatePicker) Styles() styles.DatepickerStyles

Styles returns the resolved DatepickerStyles for this component.

func (*DatePicker) ViewMonth

func (dp *DatePicker) ViewMonth() string

ViewMonth returns the month being viewed.

func (*DatePicker) ViewYear

func (dp *DatePicker) ViewYear() int

ViewYear returns the year being viewed.

func (*DatePicker) WeekdayNames

func (dp *DatePicker) WeekdayNames() []string

WeekdayNames returns the names of weekdays starting from FirstDayOfWeek.

type Option

type Option func(*DatePicker)

Option is a functional option for configuring date pickers.

func WithDisabledDates

func WithDisabledDates(dates ...time.Time) Option

WithDisabledDates sets specific dates that cannot be selected.

func WithDisabledWeekdays

func WithDisabledWeekdays(weekdays ...time.Weekday) Option

WithDisabledWeekdays sets days of the week that cannot be selected.

func WithFirstDayOfWeek

func WithFirstDayOfWeek(day int) Option

WithFirstDayOfWeek sets the first day of the week (0=Sunday, 1=Monday, etc.).

func WithFormat

func WithFormat(format string) Option

WithFormat sets the date display format.

func WithMaxDate

func WithMaxDate(date time.Time) Option

WithMaxDate sets the maximum selectable date.

func WithMinDate

func WithMinDate(date time.Time) Option

WithMinDate sets the minimum selectable date.

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 WithSelected

func WithSelected(date time.Time) Option

WithSelected sets the initially selected date.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling for the component.

type RangePicker

type RangePicker struct {
	DatePicker

	// StartDate is the beginning of the selected range
	StartDate *time.Time

	// EndDate is the end of the selected range
	EndDate *time.Time

	// SelectingEnd indicates we're selecting the end date
	SelectingEnd bool
}

RangePicker is a component for selecting a date range. Use template "lvt:datepicker:range:v1" to render.

func NewRange

func NewRange(id string, opts ...Option) *RangePicker

NewRange creates a date range picker.

func (*RangePicker) ClearRange

func (rp *RangePicker) ClearRange()

ClearRange clears both dates.

func (*RangePicker) DisplayRangeValue

func (rp *RangePicker) DisplayRangeValue() string

DisplayRangeValue returns the formatted range or placeholder.

func (*RangePicker) IsInRange

func (rp *RangePicker) IsInRange(date time.Time) bool

IsInRange checks if a date is within the selected range.

func (*RangePicker) SelectRangeDate

func (rp *RangePicker) SelectRangeDate(date time.Time) bool

SelectRangeDate handles date selection for range picker.

Jump to

Keyboard shortcuts

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