Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Core

CountBadge

Number or dot on the corner of another element (MUI's Badge).

import { CountBadge } from "@stylhero/ui";

Example

Code
import { Avatar, CountBadge, IconButton, Stack, InfoIcon, MailIcon } from "@stylhero/ui";

function CountBadgeExample() {
  return (
    <Stack direction="row" gap={6} align="center">
      <CountBadge count={3} label="3 unread messages">
        <IconButton label="Messages" variant="secondary"><MailIcon /></IconButton>
      </CountBadge>
      <CountBadge count={120} max={99} label="120 notifications">
        <IconButton label="Notifications" variant="secondary"><InfoIcon /></IconButton>
      </CountBadge>
      <CountBadge dot tone="success" label="Online">
        <Avatar name="Ana López" />
      </CountBadge>
    </Stack>
  );
}

Props

PropTypeDefaultDescription
children required ReactNode - The thing the count sits on, e.g. an IconButton or Avatar.
count number 0 0 hides the badge unless showZero.
dot boolean - A plain dot instead of a number (e.g. "online", "unread").
label string - Screen-reader text, e.g. "3 unread messages". Defaults to the number.
max number 99 Shows "99+" above this.
showZero boolean -
tone "danger" | "primary" | "accent" | "success" "danger"

Also takes every <span> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.

Accessibility

  • The count is announced through label (e.g. "3 unread messages"), not as a bare number.

Generated from src/components/Badge.tsx. Something wrong or missing? Open an issue.