UX4G Logo
Components

Time Picker

Interactive time selection trigger field and scroll-wheel dialog modal supporting 12-hour AM/PM formats, custom minute intervals, and validation states

The UX4G Time Picker component provides a standardized time selection input for citizens scheduling public service appointments, grievance hearings, passport slots, and administrative verification visits.

Key Capabilities

  • Form Input Trigger: Clean outlined input container displaying the selected time formatted in 12-hour AM/PM notation with trailing clock icon (AccessTime).
  • Scroll-Wheel Modal Dialog: Integrated Ux4gTimePickerDialog featuring smooth snap-fling vertical wheels for hours (01 to 12) and minutes (00 to 59), plus an AM/PM toggle selector.
  • Custom Minute Intervals: Configurable step increments via minuteInterval (e.g., 1, 5, 15, or 30 minute slots).
  • Labels & Required Indicators: Form label support with mandatory asterisk (*) and descriptive helper captions.
  • Dual Type Support: Overloaded composables supporting both Ux4gTimeOfDay and standard java.time.LocalTime.

Import from com.ux4g.designsystemv1.components.Ux4gTimePicker.


Interactive Previews

1. Time Picker Input Field (Ux4gTimePicker)

Outlined time selection trigger field displaying placeholder or chosen time with trailing clock icon.

Ux4gTimePickerJetpack Compose
UX4G Time Picker Input Preview

2. Time Picker Dialog Modal (Auto-Opened on Click)

When a citizen clicks on the time picker input field, the interactive scroll-wheel time picker dialog modal opens automatically to allow hour, minute, and AM/PM selection:

UX4G Time Picker Dialog Modal

Modal dialog view with hour (HH) and minute (MM) scroll wheels, AM/PM selector toggle, and Done / Cancel action buttons.


Kotlin Usage

1. Appointment Scheduling with 12-Hour AM/PM Format

AppointmentTimePicker.kt
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.Ux4gTimeOfDay
import com.ux4g.designsystemv1.components.Ux4gTimePicker

@Composable
fun AppointmentSlotBooking() {
    var appointmentTime by remember { mutableStateOf<Ux4gTimeOfDay?>(Ux4gTimeOfDay(10, 30)) }

    Column(
        modifier = Modifier.padding(16.dp),
        verticalArrangement = Arrangement.spacedBy(16.dp)
    ) {
        Ux4gTimePicker(
            selectedTime = appointmentTime,
            onTimeSelected = { appointmentTime = it },
            label = "Appointment Time",
            isRequired = true,
            minuteInterval = 15,
            placeholder = "Choose a time slot",
            description = "Appointments are scheduled in 15-minute intervals"
        )
    }
}

2. Using Standard java.time.LocalTime

LocalTimePickerExample.kt
import androidx.compose.runtime.*
import com.ux4g.designsystemv1.components.Ux4gTimePicker
import java.time.LocalTime

@Composable
fun HearingSchedulePicker() {
    var selectedTime by remember { mutableStateOf<LocalTime?>(null) }

    Ux4gTimePicker(
        selectedTime = selectedTime,
        onTimeSelected = { time -> selectedTime = time },
        label = "Grievance Hearing Time",
        isRequired = true,
        placeholder = "Select hearing time"
    )
}

Parameters

Ux4gTimePicker Props

PropTypeDescriptionDefault
selectedTimeUx4gTimeOfDay? / LocalTime?Currently selected time value displayed in the input box.null
onTimeSelected *(Ux4gTimeOfDay) -> Unit / (LocalTime) -> UnitCallback triggered when the citizen confirms a time in the dialog modal.—
modifierModifierCompose layout modifier applied to the outer container.Modifier
placeholderStringPlaceholder text shown when no time is selected."Select time"
enabledBooleanControls interactive touch state and disabled opacity.true
minuteIntervalIntStep increment for the minute scroll wheel (1, 5, 10, 15, 30).1
labelString?Header title displayed above the time input box.null
descriptionString?Supplementary helper or validation message displayed below input.null
isRequiredBooleanWhen true, appends a red asterisk (*) to the label.false
colorsUx4gTimePickerColorsCustom color palette configuration for input and dialog wheel elements.Ux4gTimePickerDefaults.colors()

Ux4gTimeOfDay Data Class Reference

Property / MethodType / SignatureDescription
hour *Int24-hour format hour (0..23).
minute *IntMinute of the hour (0..59).
hourOfPeriodInt12-hour period hour (1..12).
isAmBooleanReturns true if before noon (hour < 12), false for PM.
format()(placeholder: String) -> StringReturns formatted string (e.g., "05:02 PM").
toLocalTime()() -> LocalTimeConverts to standard java.time.LocalTime.
now()() -> Ux4gTimeOfDayStatic constructor capturing system local current time.
fromLocalTime()(LocalTime) -> Ux4gTimeOfDayStatic helper converting LocalTime to Ux4gTimeOfDay.
of()(hour: Int, minute: Int, isAm: Boolean) -> Ux4gTimeOfDayStatic helper constructing instance from 12-hour values.

On this page