KDialog - farimarwat/KrossUi GitHub Wiki

🗨️ KDialog Component Documentation

A platform-aware dialog component for Kotlin Multiplatform apps, providing a standard alert dialog interface with customizable title, message, and actions.


🔹 Overview

Element Type Description
KDialog Composable Shows a modal dialog with confirm/cancel.

🧩 KDialog

Definition:
Displays a modal alert dialog with a title, message, and optional confirm/cancel buttons.

Parameters

Parameter Type Default Description
show Boolean Whether the dialog is visible.
title String Title text displayed at the top of the dialog.
message String Main message body of the dialog.
confirmText String "OK" Text for the confirm action button.
cancelText String? null Optional text for the cancel button (null = no cancel).
onConfirm () -> Unit Callback invoked when the confirm button is clicked.
onCancel () -> Unit {} Callback for cancel button click (if provided).
onDismiss () -> Unit {} Callback when the dialog is dismissed (outside tap, etc).

✅ Usage Example

var showDialog by remember { mutableStateOf(false) }
var textValue by remember { mutableStateOf("This is the dialog message.") }

KButton(
    modifier = Modifier.fillMaxWidth(),
    text = "Show Dialog",
    onClick = {
        showDialog = true
    }
)

KDialog(
    show = showDialog,
    title = "My Dialog",
    message = textValue,
    confirmText = "OK",
    cancelText = "Close",
    onConfirm = {
        showDialog = false
    },
    onCancel = {
        showDialog = false
    }
)