Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Primitives

Badge

A small label or count that marks status, category or a number of new items.

Selector: mui-badge

Import
import { Badge } from '@mushilu-san/ui/primitives';
PreviewCode

Loading example…

Overview

Badge shows its content in a compact pill. Set variant to communicate the meaning, and size to fit the surrounding text.

With dot set, the badge is a small coloured marker with no text. It is hidden from assistive technology unless label is set, in which case the label is announced instead.

When to use

  • Showing a count of unread or new items next to a label.
  • Marking the state of an item, such as "Active" or "Draft".

When not to use

  • A call to action. Use a Button. Use Button instead.
  • A message that needs the user to act. Use an Alert.

Examples

Status dot

A dot needs a label when the colour is the only signal, so screen readers can announce it.

PreviewCode

Loading example…

Guidelines

Do

  • Pair the colour with text. "Active" in a success badge is clearer than green alone.
  • Use danger only for states that need attention, such as a failed sync.

Don't

  • Do not use a badge for a long sentence. Keep the text to a word or a short number.
  • Do not use a dot as the only indicator of an important state without a label.

Accessibility

Roles and attributes

ElementRoleNotes
host— (no role)Text badges are read as plain text.
dot badge—aria-hidden="true" when there is no label. With a label, the host carries aria-label.
  • Badges are not interactive. If a badge needs to be clicked, put it inside a button and describe the count in the button label.

API

Badge

Selector: mui-badge

NameTypeDefaultDescription
variant'primary' | 'info' | 'danger' | 'success' | 'warning' | 'default''default' Meaning of the badge: `default`, `primary`, `success`, `warning`, `danger` or `info`.
size'sm' | 'md' | 'lg''md' Badge size. Default `md`.
dotbooleanfalse Renders a small coloured dot without text. Pair with `label` so the status is announced. Accepts attribute presence, e.g. <… dot>.
labelstring | undefined— Accessible name for a dot badge. Ignored for text badges.

CSS parts

  • ::part(root)

Tokens

  • --mui-color-primary
  • --mui-color-danger
  • --mui-color-success
  • --mui-color-warning
  • --mui-color-info
  • --mui-radius-full