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.Favorites,
        contentDescription = "Favorites"
    )
}

Component States ​

Disabled State ​

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

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 by remember { mutableStateOf(false) }

Scaffold {
    IconButton(
        onClick = { showDialog = true },
        holdDownState = showDialog
    ) {
        Icon(
            imageVector = MiuixIcons.Favorites,
            contentDescription = "Favorites"
        )
    }
    // Define dialog elsewhere
    OverlayDialog(
        title = "Dialog",
        show = showDialog,
        onDismissRequest = { showDialog = 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.Favorites,
        contentDescription = "Favorites"
    )
}

Custom Size and Corner Radius ​

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

Using with Other Components ​

kotlin
Surface {
    Row(
        verticalAlignment = Alignment.CenterVertically
    ) {
        IconButton(
            onClick = { /* Handle click event */ }
        ) {
            Icon(
                imageVector = MiuixIcons.Add,
                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.FavoritesFill else MiuixIcons.Favorites,
        contentDescription = if (isLiked) "Like" else "Unlike",
        tint = if (isLiked) Color.Red else MiuixTheme.colorScheme.onBackground
    )
}

Changelog

Released under the Apache-2.0 License