KDatePicker - farimarwat/KrossUi GitHub Wiki
KDatePicker
Component Documentation
📅 A customizable, cross-platform date picker component for Kotlin Multiplatform apps, designed to work seamlessly on Android and iOS.
🔹 Overview
Element | Type | Description |
---|---|---|
KDatePicker |
Composable | Shows a modal date picker dialog. |
KDatePickerColors |
Data Class | Holds color settings for the date picker. |
KDatePickerDefaults |
Object | Provides default color configurations. |
🧩 KDatePicker
Definition:
A composable function that displays a platform-specific date picker dialog.
Parameters
Parameter | Type | Description |
---|---|---|
show |
Boolean |
Whether the date picker dialog is currently visible. |
initialDate |
Long |
The initial date to display, in milliseconds since epoch. |
colors |
KDatePickerColors |
Color configuration for dialog container, content, and footer. |
onDismiss |
() -> Unit |
Callback when the dialog is dismissed. |
onDateSelected |
(Long) -> Unit |
Callback with the selected date in milliseconds. |
🎨 KDatePickerColors
Defines the color styling of the date picker dialog.
Properties
Property | Type | Description |
---|---|---|
containerColor |
Color |
Color of the dialog's main background. |
contentColor |
Color |
Color used for text and date content. |
footerContainerColor |
Color |
Background color of the footer area. |
footerContentColor |
Color |
Text/icon color used in the footer actions. |
⚙️ KDatePickerDefaults
Provides default styling options.
🎛️ colors(...)
Returns a KDatePickerColors
instance with optional overrides.
Parameter | Type | Default Value | Description |
---|---|---|---|
containerColor |
Color |
PlatformColors.systemBackground |
Background color of the picker dialog. |
contentColor |
Color |
PlatformColors.systemBlue |
Text/date highlight color. |
footerContainerColor |
Color |
PlatformColors.systemGray.copy(alpha = 0.5f) |
Footer background. |
footerContentColor |
Color |
PlatformColors.systemBlue |
Footer action text/icon color. |
✅ Usage Example
var showDatePicker by remember { mutableStateOf(false) }
var currentDate by remember { mutableStateOf("") }
KButton(
modifier = Modifier.fillMaxWidth(),
text = "Show Date Picker",
onClick = {
showDatePicker = true
}
)
var showDatePicker by remember { mutableStateOf(false) }
var currentDate by remember { mutableStateOf("") }
KButton(
modifier = Modifier.fillMaxWidth(),
text = "Show Date Picker",
onClick = {
showDatePicker = true
}
)
KDatePicker(
show = showDatePicker,
initialDate = Clock.System.now().toEpochMilliseconds(),
colors = KDatePickerDefaults.colors(
containerColor = PlatformColors.systemBackground
),
onDismiss = {
showDatePicker = false
},
onDateSelected = {
showDatePicker = false
currentDate = formatDateFromMillis(it)
}
)