Skip to main content

CamoBadge

Concept​

1. Why​

A badge marks something with a count ("3") or a dot (something new), usually on an icon (notifications, a cart) or on a navigation item. It's tiny, but every design system has it, and navigation bars and rails use it.

2. Shape​

Material mapping preview: M3 badges. A small badge is a 6 dp dot. A large badge is 16 tall, labelSmall, error fill and onError text.

3. API​

Contract​

fun CamoBadge(
count: Int? = null, // null → dot
max: Int = 99, // above → "99+"
tone: Tone? = null, // null → BadgeTheme.defaultTone (skin default: Error, the attention family)
appearance: Appearance? = null, // null → BadgeTheme.defaultAppearance (skin default: Solid); Solid | Soft | Outline
contentDescription: String? = null, // e.g. "3 unread messages"; defaults to "{count} new" / "New"
)
fun CamoBadgedBox(badge: Widget, content: Slot) // anchors a badge on an icon or avatar

State → renderer: BadgeState(text?, isDot, tone, appearance). Slots: none.

Tokens used​

  • the tone family (default error / onError)
  • typography.labelSmall, shapes.full

Component theme​

theme.components.badge: BadgeTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.

FieldTypeMaterial defaultWhat it's for
defaultAppearanceAppearanceSolidthe appearance used when a call passes none (ADR-28: a brand's default variant)
dotSizeDp6dot badge
height / minWidthDp16 / 16count badge
textStyleCamoTextStylelabelSmallcount text
offsetOffset(−4, 4) from the top-endposition on the anchor
defaultToneToneErrorthe tone when a call passes none (ADR-28: a brand whose badges are, say, Info sets it once)

Accessibility​

  • The badge merges into its anchor's description: "Notifications, 3 unread", using contentDescription.
  • It's never focusable on its own.
  • Count changes are not announced automatically (that would be noisy). Apps announce important changes themselves.

4. Build steps​

  1. CamoBadge, CamoBadgedBox (top-end positioning, mirrored in RTL), and BadgeRenderer.
  2. Tests: dot vs count; "99+"; the merged description on a CamoIconButton; the position mirrors in RTL.

Done when

  • A notification icon button with a count badge, and a navigation item with a dot, render and announce correctly.

5. Edge cases​

CaseDecided behavior
count = 0The badge isn't shown. Apps normally hide it; core also renders nothing for 0.
Negative countsTreated as 0.
Font scale 200%The count text grows, and the pill widens. The dot doesn't scale.
Changed in the M7 build (2026-10-28)
  • BadgeTheme gains padding (around the count), borderWidth (the Outline appearance) and strings (the default descriptions, "3 new" / "New").
  • offset is where the badge's center sits from the anchor's top-end corner (x toward the end, y down); both skins use (−4, 4).
  • BadgeState(text, tone, appearance); isDot is derived from a missing text. Tone.Default is the primary family.
  • Fluent's badge is its small CounterBadge: a 6 dot, a 16 pill, danger by default.

Implementation​

1. Why​

A badge is a small dot or count anchored to an icon or avatar. Kotlin needs a custom Layout for CamoBadgedBox (place the badge at the anchor's top-end corner with the theme offset, mirrored in RTL) and a way to add the badge's text to the anchor's announcement.

2. Shape​

3. API​

@Composable
public fun CamoBadge(
modifier: Modifier = Modifier,
count: Int? = null,
max: Int = 99,
tone: Tone? = null, // null → BadgeTheme.defaultTone
appearance: Appearance? = null,
contentDescription: String? = null,
)

@Composable
public fun CamoBadgedBox(badge: @Composable () -> Unit, modifier: Modifier = Modifier, content: @Composable () -> Unit)
  • Text: count > max → "$max+"; count == 0 renders nothing (a zero count isn't a badge).
  • Layout: Layout(content = { content(); badge() }) measures the anchor, then places the badge so its center sits at the anchor's top-end corner plus style.offset; placeRelative mirrors it in RTL. The badge doesn't change the anchor's size.
  • Semantics: CamoBadge itself is clearAndSetSemantics {}; it publishes its description (contentDescription ?: "$count new" / "New") to CamoBadgedBox, which adds it to the anchor with semantics { stateDescription = … }. On a nav item the result reads "Inbox, tab, 3 unread".

4. Build steps​

  1. BadgeTheme / Style (with defaultTone), CamoBadge, CamoBadgedBox, the DebugSkin renderer.
  2. commonTest: dot vs count vs 99+; zero hides; the position in LTR and RTL; the anchor's announcement includes the badge.

Done when

  • Badges on an icon button, an avatar and a navigation item announce correctly and sit at the right corner in both directions.

5. Edge cases​

CaseDecided behavior
Badge larger than the anchorAllowed; it overflows (not clipped). Parents that clip need padding.
Count changesAnimated with AnimatedContent (reduced motion: instant).
Changed in the M7 build (2026-10-28)
  • The description travels through the box: an anchor that is its own merged node claims it with Modifier.badgeAnchor() or rememberBadgeText() (CamoIconButton and CamoAvatar do); plain content (an icon) merges into the box, which adds it as stateDescription.
  • CamoBadgedBox(badge, modifier, content); count changes animate with AnimatedContent (fade and scale, durationShort, so reduced motion is instant).