Skip to content

Icon

Icon is a fundamental icon component in Miuix used to display various vector icons, bitmap icons, or custom drawn content in the interface. It provides multiple ways to render icons to accommodate different icon resource types.

To follow night mode or theme changes, you need to actively use the tint property of the Icon component to set the icon color, commonly using MiuixTheme.colorScheme.onBackground.

Import

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

Basic Usage

The Icon component can be used to display icons:

kotlin
Icon(
    imageVector = MiuixIcons.Useful.Like,
    contentDescription = "Like Icon"
)

Icon Types

Miuix Icon supports multiple types of icon resources:

Vector Icon

kotlin
Icon(
    imageVector = MiuixIcons.Useful.Settings,
    contentDescription = "Settings Icon"
)

Bitmap Icon

kotlin
val bitmap = ImageBitmap(...)
Icon(
    bitmap = bitmap,
    contentDescription = "Bitmap Icon"
)

Custom Painter

kotlin
val customPainter = remember { /* Custom Painter */ }

Icon(
    painter = customPainter,
    contentDescription = "Custom Icon"
)

Component States

Custom Color

kotlin
Icon(
    imageVector = MiuixIcons.Useful.Personal,
    contentDescription = "Personal Icon",
    tint = Color.Red
)

Original Color (No Tinting)

kotlin
Icon(
    imageVector = MiuixIcons.Useful.Like,
    contentDescription = "Like Icon",
    tint = Color.Unspecified // Default
)

Properties

Icon Properties (ImageVector Version)

Property NameTypeDescriptionDefault ValueRequired
imageVectorImageVectorVector icon to draw-Yes
contentDescriptionString?Accessibility description text-No
modifierModifierModifier applied to the iconModifierNo
tintColorColor tint applied to the iconIconDefaults.DefaultTint()No

Icon Properties (ImageBitmap Version)

Property NameTypeDescriptionDefault ValueRequired
bitmapImageBitmapBitmap icon to draw-Yes
contentDescriptionString?Accessibility description text-No
modifierModifierModifier applied to the iconModifierNo
tintColorColor tint applied to the iconIconDefaults.DefaultTint()No

Icon Properties (Painter Version)

Property NameTypeDescriptionDefault ValueRequired
painterPainterPainter to use-Yes
contentDescriptionString?Accessibility description text-No
modifierModifierModifier applied to the iconModifierNo
tintColorColor tint applied to the iconIconDefaults.DefaultTint()No

IconDefaults Object

The IconDefaults object provides default configurations for the Icon component.

Methods

Method NameReturn TypeDescription
DefaultTintColorReturns default tint color (Color.Unspecified)

Advanced Usage

Custom Size

kotlin
Icon(
    imageVector = MiuixIcons.Useful.Like,
    contentDescription = "Like Icon",
    modifier = Modifier.size(32.dp)
)

Using with Other Components

kotlin
Button(
    onClick = { /* Handle click event */ }
) {
    Icon(
        imageVector = MiuixIcons.Useful.Save,
        contentDescription = "Download Icon"
    )
    Spacer(modifier = Modifier.width(8.dp))
    Text("Download")
}

Custom Style

kotlin
Icon(
    imageVector = MiuixIcons.Useful.Info,
    contentDescription = "Warning Icon",
    tint = Color(0xFFFFA500),
    modifier = Modifier
        .size(48.dp)
        .background(
            color = Color.LightGray.copy(alpha = 0.3f),
            shape = CircleShape
        )
        .padding(8.dp)
)

Dynamic Icon

kotlin
var isSelected by remember { mutableStateOf(false) }

Icon(
    imageVector = if (isSelected) MiuixIcons.Useful.Like else MiuixIcons.Useful.Unlike,
    contentDescription = "Like Icon",
    modifier = Modifier.clickable { isSelected = !isSelected }
)

Released under the Apache-2.0 License