Skip to content

BasicComponent

BasicComponent is a foundational standard component in Miuix. It provides customizable content areas on the start and end 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 */ }
)

With Start Icon

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

With End Actions

kotlin
var isFlightMode by remember { mutableStateOf(false) }

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

Custom Content Variant

In addition to the title and summary variant, BasicComponent also provides an overload that accepts custom content. This is useful when you want full control over the layout inside the component while still reusing the container and interactions:

kotlin
BasicComponent(
    startAction = {
        Icon(
            modifier = Modifier.padding(end = 16.dp),
            imageVector = MiuixIcons.Contacts,
            contentDescription = "Avatar Icon",
            tint = MiuixTheme.colorScheme.onBackground
        )
    },
    endActions = {
        Text("Details")
    }
) {
    Text(
        text = "Custom Title",
        style = MiuixTheme.textStyles.headline1
    )
    Text(
        text = "Custom content description",
        style = MiuixTheme.textStyles.body2
    )
}

Component States

Disabled State

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

Properties

BasicComponent Properties (title and summary variant)

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier for the componentModifierNo
titleString?Title of the componentnullNo
titleColorBasicComponentColorsTitle color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary of the componentnullNo
summaryColorBasicComponentColorsSummary color configurationBasicComponentDefaults.summaryColor()No
startAction@Composable (() -> Unit)?Composable content on the start side of the componentnullNo
endActions@Composable (RowScope.() -> Unit)?Composable content on the end side of the componentnullNo
bottomAction@Composable (() -> Unit)?Composable content at the bottom of the componentnullNo
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
interactionSourceMutableInteractionSource?Interaction source of the componentnullNo

BasicComponent Properties (custom content variant)

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier for the componentModifierNo
startAction@Composable (() -> Unit)?Composable content on the start side of the componentnullNo
endActions@Composable (RowScope.() -> Unit)?Composable content on the end side of the componentnullNo
bottomAction@Composable (() -> Unit)?Composable content at the bottom of the componentnullNo
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
interactionSourceMutableInteractionSource?Interaction source of the componentnullNo
content@Composable ColumnScope.() -> UnitComposable content of the component-Yes

BasicComponentDefaults Object

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

BasicComponentDefaults Constants

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

BasicComponentDefaults 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%",
    startAction = {
        Icon(
            modifier = Modifier.padding(end = 16.dp),
            imageVector = MiuixIcons.Play,
            contentDescription = "Volume Icon",
            tint = MiuixTheme.colorScheme.onBackground
        )
    },
    endActions = {
        IconButton(onClick = { /* Decrease volume */ }) {
            Icon(
                imageVector = MiuixIcons.Remove,
                contentDescription = "Decrease Volume",
                tint = MiuixTheme.colorScheme.onBackground
            )
        }
        Text("70%")
        IconButton(onClick = { /* Increase volume */ }) {
            Icon(
                imageVector = MiuixIcons.Add,
                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 */ }
        )
    }
}

Changelog

Released under the Apache-2.0 License