Date and time
A calendar, a date picker and a time picker over one time.Time.
Loading the live example…
import (
"time"
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type meeting struct {
at time.Time
}
func (m *meeting) View(c *ui.Context) {
ui.Column(c).Gap(12).AlignItems(ui.Center).Children(func() {
ui.Row(c).Gap(8).Children(func() {
// Both edit the same time.Time: the date keeps the time of day,
// and the time keeps the date.
components.CalendarPicker(c, &m.at).Label("Date")
components.TimePicker(c, &m.at).Label("Time")
})
components.Text(c, m.at.Format("Mon, Jan 2 at 15:04")).TextColor(c.Theme().TextMuted)
})
}CalendarPicker shows a date and opens a calendar in a popover; TimePicker shows a 24-hour time and opens hour and minute columns. Choosing a date keeps the time of day, and choosing a time keeps the date, so both can edit the same value.
Calendar
components.Calendar is the six-week view on its own. Click its title to switch to months, then years. The first day of the week follows the user's regional formats.
Loading the live example…
import (
"time"
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type dueDate struct {
day time.Time
}
func (d *dueDate) View(c *ui.Context) {
ui.Column(c).Gap(12).AlignItems(ui.Center).Children(func() {
components.Calendar(c, &d.day)
components.Text(c, d.day.Format("Monday, January 2")).TextColor(c.Theme().TextMuted)
})
}API
CalendarPicker
func CalendarPicker(c *ui.Context, value *time.Time) *CalendarControlCalendarPicker displays a leading calendar icon and an ISO date. Click, Enter or Space opens Calendar in a dismissible Popover; choosing a date closes it and restores trigger focus, including when choosing the existing date. Escape/outside press cancel navigation. The application owns value; selection preserves its time of day and location. Changed excludes opening/navigation. Key or disable a parent before construction; Label names the trigger.
pkg.go.devTimePicker
func TimePicker(c *ui.Context, value *time.Time) *TimeControlTimePicker displays a leading clock icon and a 24-hour HH:mm value. Its fixed popup contains independently scrolling hour (left) and minute (right) columns without scrollbars. Choosing an hour moves focus to minutes; choosing a minute confirms without closing the popup. Up/Down and Home/End move the focused column's draft cursor; Left/Right switch columns; Enter/Space activates it. Escape/outside press discards the draft. Opening reveals the current hour and minute. External changes reset the draft. Confirmation preserves the date, seconds, nanoseconds and location, subject to time.Date's normalization of nonexistent/ambiguous local times at DST changes. Key or disable a parent before construction; Label names the trigger.
pkg.go.devCalendar
func Calendar(c *ui.Context, value *time.Time) *CalendarControlCalendar builds the fixed-size six-week view (Monday-first by default) used inside CalendarPicker. Arrows move its cursor; Page Up/Down change months with day clamping; Home/End move to month boundaries. Enter/Space or a day click selects a date, preserving its time and location. Navigation alone does not select. Click the title to switch from days to months, then to a twelve-year grid. Choose a year to open months, and a month to open days. In these grids, arrows move by cell and Page Up/Down changes pages. Today returns to today's day view without committing a value. All modes retain the same fixed size. Key or disable a parent before construction.
pkg.go.devCalendarControl
CalendarControl exposes layout and frame-local date changes. Keep this handle when applying Element layout methods, which return ui.Element.
Prop
Type
Methods
func (c *CalendarControl) Changed() boolChanged reports a selected date changed by input, not cursor navigation.
TimeControl
TimeControl exposes layout and a frame-local time change. Keep this handle when applying Element layout methods, which return ui.Element.
Prop
Type
Methods
func (t *TimeControl) Changed() boolChanged reports a confirmed time change, not opening or draft navigation.