Skip to content

Card

Card is a basic container component in Miuix, used to hold related content and actions. It provides a card container with Miuix style, suitable for scenarios such as information display and content grouping. Supports both static display and interactive modes.

Import

kotlin
import top.yukonga.miuix.kmp.basic.Card
import top.yukonga.miuix.kmp.utils.PressFeedbackType // If using interactive card

Basic Usage

The Card component can be used to wrap and organize content (static card):

kotlin
Card {
    Text("This is card content")
}

Properties

Card Properties

Property NameTypeDescriptionDefault ValueRequiredApplies To
modifierModifierModifier applied to the cardModifierNoAll
cornerRadiusDpCard corner radiusCardDefaults.CornerRadiusNoAll
insideMarginPaddingValuesCard inner paddingCardDefaults.InsideMarginNoAll
colorColorCard background colorCardDefaults.DefaultColor()NoAll
pressFeedbackTypePressFeedbackTypeFeedback type when pressedPressFeedbackType.NoneNoInteractive
showIndicationBoolean?Show indication on interactionfalseNoInteractive
onClick(() -> Unit)?Callback when clickednullNoInteractive
onLongPress(() -> Unit)?Callback when long pressednullNoInteractive
content@Composable ColumnScope.() -> UnitComposable function for card content area-YesAll

WARNING

Some properties are only available when creating an interactive card!

CardDefaults Object

The CardDefaults object provides default values and color configurations for the card component.

Constants

Constant NameTypeDescriptionDefault Value
CornerRadiusDpCard corner radius16.dp
InsideMarginPaddingValuesCard inner paddingPaddingValues(0.dp)

Methods

Method NameTypeDescription
DefaultColor()ColorThe default background color for the card

Advanced Usage

Custom Style Card

kotlin
Card(
    cornerRadius = 8.dp,
    insideMargin = PaddingValues(16.dp),
    color = Color.LightGray.copy(alpha = 0.5f)
) {
    Text("Custom Style Card")
}

Content-Rich Card

kotlin
Card(
    modifier = Modifier.padding(16.dp),
    insideMargin = PaddingValues(16.dp)
) {
    Text(
        text = "Card Title",
        style = MiuixTheme.textStyles.title2
    )
    Spacer(modifier = Modifier.height(8.dp))
    Text(
        text = "This is a detailed description of the card, which can contain multiple lines of text."
    )
    Spacer(modifier = Modifier.height(16.dp))
    Row(
        modifier = Modifier.fillMaxWidth(),
        horizontalArrangement = Arrangement.End
    ) {
        TextButton(
            text = "Cancel",
            onClick = { /* Handle cancel event */ }
        )
        Spacer(modifier = Modifier.width(8.dp))
        TextButton(
            text = "Confirm",
            colors = ButtonDefaults.textButtonColorsPrimary(), // Use theme colors
            onClick = { /* Handle confirm event */ }
        )
    }
}

Cards in a List

kotlin
LazyColumn {
    items(5) { index ->
        Card(
            modifier = Modifier
                .fillMaxWidth()
                .padding(horizontal = 16.dp, vertical = 8.dp),
            insideMargin = PaddingValues(16.dp)
        ) {
            Text("List Item ${index + 1}")
        }
    }
}

Interactive Card

kotlin
Card(
    modifier = Modifier.padding(16.dp),
    pressFeedbackType = PressFeedbackType.Sink, // Set press feedback to sink effect
    showIndication = true, // Show indication on click
    onClick = {/* Handle click event */ },
    onLongPress = {/* Handle long press event */ }
) {
    Text("Interactive Card")
}

Released under the Apache-2.0 License