Skip to content

DatePicker

DatePicker is a basic interactive component in COUI used for selecting a calendar date with three vertical scroll wheels (year / month / day), mirroring ColorOS's COUIDatePicker. The day range automatically follows the selected year and month (leap years included), and the day is clamped when a shorter month is selected. All columns support infinite scrolling.

Dates are represented by the plain DateValue data class, so no date/time library dependency is required.

Import

kotlin
import io.github.suqi8.coui.kmp.basic.DatePicker
import io.github.suqi8.coui.kmp.basic.DatePickerDefaults
import io.github.suqi8.coui.kmp.basic.DateValue
import io.github.suqi8.coui.kmp.basic.NumberPickerDefaults

Basic Usage

kotlin
var date by remember { mutableStateOf(DateValue(year = 2026, month = 7, day = 26)) }

DatePicker(
    value = date,
    onValueChange = { date = it }
)

Component States

Disabled State

kotlin
DatePicker(
    value = date,
    onValueChange = { date = it },
    enabled = false
)

Properties

DatePicker Properties

Property NameTypeDescriptionDefault ValueRequired
valueDateValueCurrently selected date. Out-of-range fields coerced-Yes
onValueChange(DateValue) -> UnitCallback invoked when the selected date changes-Yes
modifierModifierModifier applied to the pickerModifierNo
enabledBooleanWhether the picker is enabled for user interactiontrueNo
yearRangeIntRangeThe selectable year rangeDatePickerDefaults.YearRangeNo
yearLabel(Int) -> StringConverts a year to its display stringDatePickerDefaults.YearLabelNo
monthLabel(Int) -> StringConverts a month (1..12) to its display stringDatePickerDefaults.MonthLabelNo
dayLabel(Int) -> StringConverts a day of month to its display stringDatePickerDefaults.DayLabelNo
yearColumnWidthDpWidth of the year columnDatePickerDefaults.YearColumnWidthNo
monthColumnWidthDpWidth of the month columnDatePickerDefaults.MonthColumnWidthNo
dayColumnWidthDpWidth of the day columnDatePickerDefaults.DayColumnWidthNo
colorsNumberPickerColorsColor configuration of the wheelsNumberPickerDefaults.colors()No
textStyleTextStyleText style for the wheel itemsCOUITheme.textStyles.title3No
itemHeightDpThe height of each wheel itemNumberPickerDefaults.ItemHeightNo
insideMarginPaddingValuesPadding around the wheel columnsDatePickerDefaults.InsideMarginNo

DateValue Class

Property NameTypeDescription
yearIntThe calendar year (e.g. 2026)
monthIntThe month of the year, 1-based (1 = January)
dayIntThe day of the month, 1-based

DatePickerDefaults Object

Property NameTypeDescriptionDefault Value
YearRangeIntRangeDefault selectable year range1900..2100
YearColumnWidthDpDefault width of the year column76.dp
MonthColumnWidthDpDefault width of the month column96.dp
DayColumnWidthDpDefault width of the day column62.dp
InsideMarginPaddingValuesDefault padding around the wheel columnsPaddingValues(vertical = 12.dp)
YearLabel(Int) -> StringPlain year number
MonthLabel(Int) -> StringAbbreviated English month names"Jan".."Dec"
DayLabel(Int) -> StringZero-padded two digits"01".."31"

Advanced Usage

Custom Year Range

kotlin
DatePicker(
    value = date,
    onValueChange = { date = it },
    yearRange = 2000..2030
)

Localized Labels

Pass custom label functions to localize the wheel items. For example, the Chinese COUI style embeds the unit into each item:

kotlin
DatePicker(
    value = date,
    onValueChange = { date = it },
    yearLabel = { "${it}年" },
    monthLabel = { "${it}月" },
    dayLabel = { "${it}日" }
)

Custom Colors

kotlin
DatePicker(
    value = date,
    onValueChange = { date = it },
    colors = NumberPickerDefaults.colors(
        selectedTextColor = Color.Red,
        unselectedTextColor = Color.Gray
    )
)

Changelog

Released under the Apache-2.0 License