Skip to content

#! /usr/bin/env markdown

Badge

Badge is a small status element in Miuix that overlays dynamic information — such as a count of unread messages or pending requests — onto an anchor like an icon. Following Material 3, BadgedBox positions a Badge relative to its content; the badge can be a small dot (icon only) or contain short text.

Import

kotlin
import top.yukonga.miuix.kmp.basic.Badge
import top.yukonga.miuix.kmp.basic.BadgedBox
import top.yukonga.miuix.kmp.basic.BadgeDefaults

Basic Usage

Wrap an anchor with BadgedBox and supply a Badge in its badge slot. A Badge with no content renders as a small dot:

kotlin
BadgedBox(badge = { Badge() }) {
    Icon(imageVector = MiuixIcons.Settings, contentDescription = "Settings")
}

Pass content to show short text, such as an unread count:

kotlin
BadgedBox(badge = { Badge { Text("99+") } }) {
    Icon(imageVector = MiuixIcons.Settings, contentDescription = "Settings")
}

Badge

Badge draws the badge container. With no content it is a small dot; with content it grows to fit a short label.

kotlin
@Composable
fun Badge(
    modifier: Modifier = Modifier,
    containerColor: Color = BadgeDefaults.containerColor,
    contentColor: Color = BadgeDefaults.contentColor,
    content: @Composable (RowScope.() -> Unit)? = null,
)
Parameter NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to this badgeModifierNo
containerColorColorBackground color of the badgeBadgeDefaults.containerColorNo
contentColorColorPreferred color for content inside the badgeBadgeDefaults.contentColorNo
content@Composable (RowScope.() -> Unit)?Optional content rendered inside the badgenullNo

BadgedBox

BadgedBox is a top-level layout that places a badge relative to its content. The badge is positioned at the top-end corner of the anchor; its offset adapts depending on whether the badge has content.

kotlin
@Composable
fun BadgedBox(
    badge: @Composable BoxScope.() -> Unit,
    modifier: Modifier = Modifier,
    content: @Composable BoxScope.() -> Unit,
)
Parameter NameTypeDescriptionDefault ValueRequired
badge@Composable BoxScope.() -> UnitThe badge to display - typically a Badge-Yes
modifierModifierModifier applied to this BadgedBoxModifierNo
content@Composable BoxScope.() -> UnitThe anchor to which the badge will be positioned-Yes

BadgeDefaults

BadgeDefaults provides the default sizes and colors for a badge.

kotlin
object BadgeDefaults {
    val Size = 6.dp
    val LargeSize = 16.dp

    val containerColor: Color
        @Composable get() = MiuixTheme.colorScheme.error

    val contentColor: Color
        @Composable get() = MiuixTheme.colorScheme.onError
}
NameTypeDescriptionDefault Value
SizeDpSize of an icon-only badge (no content)6.dp
LargeSizeDpSize of a badge containing content16.dp
containerColorColorDefault background color of a badgeMiuixTheme.colorScheme.error
contentColorColorDefault content color of a badgeMiuixTheme.colorScheme.onError

Changelog

Released under the Apache-2.0 License