Skip to content

DatePicker

DatePicker in <huxerui/view.h> edits std::chrono::year_month_day. It represents a calendar date, not a timestamp or timezone conversion.

#include <huxerui/huxerui.h>
#include <chrono>
using namespace huxerui;
[[huxerui::composable]]
View DeliveryDate() {
using namespace std::chrono;
auto date = UseState(year{2026} / September / 7);
return DatePicker(date)
.Label("Delivery date")
.Range(year{2026} / January / 1, year{2026} / December / 31)
.OnChanged([date](year_month_day next) { date = next; });
}

Construct with a date or State<year_month_day>. The date must be valid and within the configured inclusive interval. .Range(minimum, maximum), .Minimum(date), and .Maximum(date) configure that interval; invalid dates or contradictory bounds are caller errors.

.DisabledDates(predicate) rejects particular user choices, for example holidays. It does not automatically rewrite an already-controlled value; the application decides how to handle previously accepted dates that later become unavailable.

.OnChanged(handler) proposes a date. Write it back to keep the calendar selection in agreement. Use .Validation(result) for domain feedback independently of date availability.

.Label(StringVariant) accepts literal or resource text. Locale controls date presentation; DatePickerStyle controls the calendar surface. Do not encode an application’s display format as a different underlying date type.

Use TimePicker for time-of-day, and combine both controlled values explicitly when a scheduling workflow needs them.

DatePicker is inline calendar content. Put it in a Dialog or BottomSheet yourself when the workflow needs an explicit opening action. For Cancel/Apply behavior, edit a draft date in the presentation’s scope and copy it to the saved date only on Apply. Direct OnChanged write-back instead makes every accepted calendar choice immediate.

Range, Minimum, and Maximum take valid year_month_day values, and use inclusive bounds. DisabledDates takes bool(year_month_day); true means unavailable. Keep this predicate synchronous and inexpensive because calendar cells consult it during UI work. Store downloaded availability in State and let a recomposition use that snapshot.

Fields Effect
background, border, corner_radii, padding Whole calendar surface.
foreground, secondary_foreground, disabled_foreground Main, supporting, and disabled text.
selected_background, selected_foreground, hover_background, selection_corner_radius Day state visuals.
title_style, weekday_style, day_style, label_style Typography by calendar role.
cell_size, column_spacing, row_spacing, header_height Calendar grid geometry.
label_spacing, validation_error, validation_text_style, validation_spacing External label/error layout.

Theme choice changes these values, not the calendar’s data type or availability policy. Allow enough width for seven day columns; an arbitrarily narrow Frame is not a compact-month mode.