Skip to content

BasicComponent

BasicComponent is a foundational standard component in Miuix. It provides customizable content areas on the left and right sides, along with a title and summary, making it suitable for building list items, settings items, and other UI elements.

This project builds upon it to provide some extended components, enabling developers to quickly create UI components that conform to design specifications. See the usage of Extended Components for details.

Import

kotlin
import top.yukonga.miuix.kmp.basic.BasicComponent

Basic Usage

The BasicComponent can be used to display title and summary information:

kotlin
BasicComponent(
    title = "Setting Item Title",
    summary = "This is the description text for the setting item"
)

Component Variants

Clickable Component

kotlin
BasicComponent(
    title = "Wi-Fi",
    summary = "Connected to MIUI-WiFi",
    onClick = { /* Handle click event */ }
)

Component with Left Icon

kotlin
BasicComponent(
    title = "Nickname",
    summary = "A brief introduction",
    leftAction = {
        Icon(
            modifier = Modifier.padding(end = 16.dp),
            imageVector = MiuixIcons.Useful.Personal,
            contentDescription = "Avatar Icon",
            tint = MiuixTheme.colorScheme.onBackground
        )
    },
    onClick = { /* Handle click event */ }
)

Component with Right Actions

kotlin
var isFlightMode by remember { mutableStateOf(false) }

BasicComponent(
    title = "Flight Mode",
    rightActions = {
        Switch(
            checked = isFlightMode,
            onCheckedChange = { isFlightMode = it }
        )
    }
)

Component States

Disabled State

kotlin
BasicComponent(
    title = "Mobile Network",
    summary = "SIM card not inserted",
    enabled = false
)

Properties

BasicComponent Properties

Property NameTypeDescriptionDefault ValueRequired
titleString?Title of the componentnullNo
titleColorBasicComponentColorsTitle color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary of the componentnullNo
summaryColorBasicComponentColorsSummary color configurationBasicComponentDefaults.summaryColor()No
leftAction@Composable (() -> Unit?)?Composable content on the left side of the componentnullNo
rightActions@Composable RowScope.() -> UnitComposable content on the right side of the component{}No
modifierModifierModifier for the componentModifierNo
insideMarginPaddingValuesInternal padding of the componentBasicComponentDefaults.InsideMarginNo
onClick(() -> Unit)?Callback triggered when the component is clickednullNo
holdDownStateBooleanWhether the component is in the pressed statefalseNo
enabledBooleanWhether the component is enabledtrueNo
interactionSourceMutableInteractionSourceInteraction source of the componentremember { MutableInteractionSource() }No

BasicComponentDefaults Object

The BasicComponentDefaults object provides default values and color configurations for the BasicComponent.

Constants

Constant NameTypeDescriptionDefault Value
InsideMarginPaddingValuesInternal padding of the componentPaddingValues(16.dp)

Methods

Method NameTypeDescription
titleColor()BasicComponentColorsCreates title color configuration
summaryColor()BasicComponentColorsCreates summary color configuration

BasicComponentColors Class

Used to configure the color states of the component.

Property NameTypeDescription
colorColorColor in normal state
disabledColorColorColor in disabled state

Advanced Usage

Complex Layout Component

kotlin
BasicComponent(
    title = "Volume",
    summary = "Media Volume: 70%",
    leftAction = {
        Icon(
            modifier = Modifier.padding(end = 16.dp),
            imageVector = MiuixIcons.Useful.Play,
            contentDescription = "Volume Icon",
            tint = MiuixTheme.colorScheme.onBackground
        )
    },
    rightActions = {
        IconButton(onClick = { /* Decrease volume */ }) {
            Icon(
                imageVector = MiuixIcons.Useful.Remove,
                contentDescription = "Decrease Volume",
                tint = MiuixTheme.colorScheme.onBackground
            )
        }
        Text("70%")
        IconButton(onClick = { /* Increase volume */ }) {
            Icon(
                imageVector = MiuixIcons.Useful.New,
                contentDescription = "Increase Volume",
                tint = MiuixTheme.colorScheme.onBackground
            )
        }
    }
)

Custom Style Component

kotlin
BasicComponent(
    title = "Custom Component",
    summary = "Using custom colors",
    titleColor = BasicComponentColors(
        color = Color.Blue,
        disabledColor = Color.Gray
    ),
    summaryColor = BasicComponentColors(
        color = Color.DarkGray,
        disabledColor = Color.LightGray
    ),
    insideMargin = PaddingValues(horizontal = 24.dp, vertical = 12.dp),
    onClick = { /* Handle option click */ }
)

Usage in a List

kotlin
val options = listOf("Option 1", "Option 2", "Option 3", "Option 4")

Column {
    options.forEach { option ->
        BasicComponent(
            title = option,
            onClick = { /* Handle option click */ }
        )
    }
}

Released under the Apache-2.0 License