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 ¶
- func Templates() *base.TemplateSet
- type CalendarDay
- type DatePicker
- func (dp *DatePicker) CalendarWeeks() [][]CalendarDay
- func (dp *DatePicker) Clear()
- func (dp *DatePicker) DisplayValue() string
- func (dp *DatePicker) GoToToday()
- func (dp *DatePicker) IsDateSelectable(date time.Time) bool
- func (dp *DatePicker) IsSelected(date time.Time) bool
- func (dp *DatePicker) IsToday(date time.Time) bool
- func (dp *DatePicker) NextMonth()
- func (dp *DatePicker) NextYear()
- func (dp *DatePicker) PreviousMonth()
- func (dp *DatePicker) PreviousYear()
- func (dp *DatePicker) SelectDate(date time.Time) bool
- func (dp *DatePicker) Styles() styles.DatepickerStyles
- func (dp *DatePicker) ViewMonth() string
- func (dp *DatePicker) ViewYear() int
- func (dp *DatePicker) WeekdayNames() []string
- type Option
- func WithDisabledDates(dates ...time.Time) Option
- func WithDisabledWeekdays(weekdays ...time.Weekday) Option
- func WithFirstDayOfWeek(day int) Option
- func WithFormat(format string) Option
- func WithMaxDate(date time.Time) Option
- func WithMinDate(date time.Time) Option
- func WithOpen(_ bool) Option
- func WithPlaceholder(placeholder string) Option
- func WithSelected(date time.Time) Option
- func WithStyled(styled bool) Option
- type RangePicker
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) 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) 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 ¶
WithDisabledDates sets specific dates that cannot be selected.
func WithDisabledWeekdays ¶
WithDisabledWeekdays sets days of the week that cannot be selected.
func WithFirstDayOfWeek ¶
WithFirstDayOfWeek sets the first day of the week (0=Sunday, 1=Monday, etc.).
func WithMaxDate ¶
WithMaxDate sets the maximum selectable date.
func WithMinDate ¶
WithMinDate sets the minimum selectable date.
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 WithSelected ¶
WithSelected sets the initially selected date.
func WithStyled ¶
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) 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.