Date and time

Time Field

Enter a time segment by segment.

Rust
1use herogpui::components::time_field::{TimeField, TimeState};

Usage

Rust
1use herogpui::prelude::{HourCycle, Time, TimeField, TimeState};
2
3TimeField::new(self.time.clone())
4    .label("Start time")
5    .hour_cycle(HourCycle::H24)
6    .description("Click a segment, then use the steppers.")
7    .on_change(opt_time_cb(
8        cx.listener(|_, _t: &Option<Time>, _, cx| cx.notify()),
9    ))

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

TimeField

Time Field is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Time Field uses.

Styling

Time Field styling
StyleDescription
flex_col + gap(px(4.))Four-pixel field stack with label, group and message.
validity.first() branchInvalid state replaces help text with the first error.
full_width(true)Full-width root and group stretch even in a non-stretching parent.
FIELD_HEIGHT + field_radius + field tokensShared base group geometry and primary field chrome; group text and slots use explicit 14px/20px metrics.
immediate hover/focus/invalid stylesReaches state endpoints without property interpolation.
group px(12px) + gap(2px)Segment row uses the correct padding with a 2px GPUI gap rather than CSS's 1px gap.
px(2px) + radius_md + ConsolasRadius and padding match; Consolas supplies tabular figures without independent text-end alignment.
focused segment accent.softFocused segments match accent-soft; invalid segment foreground is represented only by group error chrome.
prefix/suffix + flex_shrink_0 + 4px marginsContent is inert and placeholder-colored; spacing is expressed within the padded group.
FieldVariant::Secondary + colors.defaultSecondary uses the neutral default palette without a shadow.

API reference

Builders

Time Field builders
BuilderTypeDefaultDescription
content(render)AnyElement | Fn(values: TimeFieldRenderProps) -> AnyElementBuilt-in field composition or replacement content with complete field state.
full_width(bool)boolfalseExpands the root and group to the available width.
new(state)stateThe bound TimeState entity supplies internal identity rather than a caller element id.
value(Option<Time>, cx)Option<Time>, cxControlled plain-time value; calendar date-time and zoned types are not represented.
default_value(Time)TimeSeeds an uncontrolled plain-time value once.
on_change(callback)Fn(value: TimeValue | null) -> ()Reports a plain Time value or null.
placeholder_value(Time)Time12:00 AM / 00:00Seeds the first edit and defaults to midnight in the active hour cycle.
is_required(bool)boolfalseMarks the field required and blocks empty native submission.
is_invalid(bool)boolfalseForces invalid chrome and validation reporting.
min_value(Time)TimeInclusive minimum plain time.
max_value(Time)TimeInclusive maximum plain time.
validate(callback)Fn(value: TimeValue) -> ValidationError | true | nullCustom validation returns one optional GPUI message.
validation_behavior(ValidationBehavior)ValidationBehaviorValidationBehavior::NativeChooses blocking native or non-blocking allow behavior.
granularity(TimeGranularity)TimeGranularityTimeGranularity::MinuteControls the smallest visible and submitted unit.
hour_cycle(HourCycle)HourCycleHourCycle::LocaleDefaults to the system regional time format; an explicit cycle overrides it.
should_force_leading_zeros(bool)boollocaleForces a two-digit hour when true; otherwise numeric padding follows the system regional time pattern.
is_disabled(bool)boolfalseDims the whole field, removes interaction and omits form data.
is_read_only(bool)boolfalseKeeps segment navigation and focus while blocking edits.
name(value) + form_field(cx)value) + form_field(cxRegisters a live ISO time FormField.
auto_focus(bool)boolfalseFocuses the segmented input on first render, including replacement content.
variant(FieldVariant)FieldVariantFieldVariant::PrimaryThe monolithic group and input share one field variant.
segment(render)DateSegmentHands custom content each time segment and its system-regional generated text.
prefix(element)AnyElementInert content before the segments.
suffix(element)AnyElementInert content after the segments.

Parts

Time Field parts
PartDescription
TimeFieldField state, validation and form owner.
TimeFieldOptional label with required, invalid and disabled state.
TimeFieldFocusable field chrome around input, prefix and suffix.
TimeFieldBuilt-in segmented input rather than an independently composable part.
TimeFieldKeyboard-editable time segment with custom content support.
TimeFieldInert leading content.
TimeFieldInert trailing content.
TimeFieldOptional help text hidden when invalid.
TimeFieldResolved validation message; the built-in equivalent is ErrorMessage.

States

Time Field states
BuilderStateDescription
hover field backgroundHoveredInteractive group uses its variant hover fill outside focus.
focus_handle + ring_if_focusedFocus withinFocused segments ring the field and use focus chrome.
validation::resolve + invalid chromeInvalidDanger field styling replaces description with the resolved error.
is_disabled + disabled_opacityDisabledThe whole field is dimmed and inert.
is_read_only gates editsRead onlySegments remain navigable but cannot change.
is_required + FormFieldRequiredLabel marker and native form validation reflect required state.
TimeState::focused + accent.softSegment focusedActive segment uses accent-soft selection chrome.
TimeState cleared/display_valueSegment placeholderIncomplete segments use placeholder text.