Skip to content

IconButton

IconButton is a button component in Miuix used for providing auxiliary interaction points. They are typically used in scenarios that require compact buttons, such as toolbars or image lists.

Import

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

Basic Usage

The IconButton component can be used to trigger actions or events:

kotlin
IconButton(
    onClick = { /* Handle click event */ }
) {
    Icon(
        imageVector = MiuixIcons.Useful.Like,
        contentDescription = "Like"
    )
}

Component States

Disabled State

kotlin
IconButton(
    onClick = { /* Handle click event */ },
    enabled = false
) {
    Icon(
        imageVector = MiuixIcons.Useful.Like,
        contentDescription = "Like"
    )
}

Hold Down State

IconButton supports controlling the hold down state through the holdDownState parameter, typically used for visual feedback when displaying pop-up dialogs:

kotlin
var showDialog = remember { mutableStateOf(false) }

Scaffold {
    IconButton(
        onClick = { showDialog.value = true },
        holdDownState = showDialog.value
    ) {
        Icon(
            imageVector = MiuixIcons.Useful.Like,
            contentDescription = "Like"
        )
    }
    // Define dialog elsewhere
    SuperDialog(
        title = "Dialog",
        show = showDialog,
        onDismissRequest = { showDialog.value = false }
    ) {
        // Dialog content
    }
}

Properties

IconButton Properties

Property NameTypeDescriptionDefault ValueRequired
onClick() -> UnitCallback triggered on button click-Yes
modifierModifierModifier applied to the buttonModifierNo
enabledBooleanWhether button is clickabletrueNo
holdDownStateBooleanWhether button is held downfalseNo
backgroundColorColorButton background colorColor.UnspecifiedNo
cornerRadiusDpButton corner radiusIconButtonDefaults.CornerRadiusNo
minHeightDpButton minimum heightIconButtonDefaults.MinHeightNo
minWidthDpButton minimum widthIconButtonDefaults.MinWidthNo
content@Composable () -> UnitButton content, typically an Icon-Yes

IconButtonDefaults Object

The IconButtonDefaults object provides default values for the icon button component.

Constants

Constant NameTypeDescriptionDefault Value
MinWidthDpMinimum button width40.dp
MinHeightDpMinimum button height40.dp
CornerRadiusDpButton corner radius40.dp

Advanced Usage

Custom Background Color

kotlin
IconButton(
    onClick = { /* Handle click event */ },
    backgroundColor = Color.LightGray.copy(alpha = 0.3f)
) {
    Icon(
        imageVector = MiuixIcons.Useful.Like,
        contentDescription = "Like"
    )
}

Custom Size and Corner Radius

kotlin
IconButton(
    onClick = { /* Handle click event */ },
    minWidth = 48.dp,
    minHeight = 48.dp,
    cornerRadius = 12.dp
) {
    Icon(
        imageVector = MiuixIcons.Useful.Like,
        contentDescription = "Like"
    )
}

Using with Other Components

kotlin
Surface {
    Row(
        verticalAlignment = Alignment.CenterVertically
    ) {
        IconButton(
            onClick = { /* Handle click event */ }
        ) {
            Icon(
                imageVector = MiuixIcons.Useful.New,
                tint = MiuixTheme.colorScheme.onBackground,
                contentDescription = "Add"
            )
        }
        Text("Add New Item")
    }
}

Dynamic Icon Button

kotlin
var isLiked by remember { mutableStateOf(false) }

IconButton(
    onClick = { isLiked = !isLiked }
) {
    Icon(
        imageVector = if (isLiked) MiuixIcons.Useful.Like else MiuixIcons.Useful.Unlike,
        contentDescription = if (isLiked) "Liked" else "Like",
        tint = if (isLiked) Color.Red else MiuixTheme.colorScheme.onBackground
    )
}

Released under the Apache-2.0 License