AI
NUI logov3.1.0

Badge

A compact status or indicator component that can display numbers, icons, or small labels. Supports variants, sizes, pill shapes, dot mode, and interactive behavior (links or buttons).

tsx
import { Badge } from '@nofinite/nui';

Interactive Preview

New FeatureCompletedIn ProgressHigh Priorityv3.0.7

Usage

Basic Badge

tsx
import { Badge } from '@nofinite/nui';

<Badge>New</Badge>
<Badge variant="primary">Primary</Badge>
<Badge variant="success">Success</Badge>
<Badge variant="warning">Warning</Badge>
<Badge variant="danger">Danger</Badge>
<Badge variant="outline">Outline</Badge>

Badge with Count

tsx
<Badge count={5} />
<Badge count={120} max={99} />  {/* Displays 99+ */}

Dot Badge

tsx
<Badge dot variant="success" />

Pill Badge

tsx
<Badge pill variant="primary">
  Premium
</Badge>

Interactive Badge

tsx
<Badge onClick={() => alert('Clicked!')} variant="primary">
  Click Me
</Badge>

<Badge href="https://example.com" variant="primary">
  Go to Link
</Badge>

Badge with Icons

tsx
<Badge iconLeft={<Icon />} iconRight={<Icon />} variant="success">
  Messages
</Badge>

BadgeGroup

Groups multiple badges and optionally displays a +n overflow indicator.

Usage

tsx
import { Badge, BadgeGroup } from '@nofinite/nui';

<BadgeGroup max={3}>
  <Badge variant="success">Online</Badge>
  <Badge variant="warning">Away</Badge>
  <Badge variant="danger">Busy</Badge>
  <Badge variant="primary">Admin</Badge>
</BadgeGroup>;

Props

PropTypeDefaultDescription
childrenReact.ReactNode[]—Badge components to group
maxnumber3Maximum badges to show; excess displayed as +n
classNamestring""Additional CSS classes for the group container
...restReact.HTMLAttributes<HTMLDivElement>—Other native props

Variants

VariantDescription
defaultNeutral / gray
primaryBrand / accent color
successSuccess / green
warningWarning / amber
dangerError / red
outlineTransparent background with border

Sizes

SizeHeightFont SizeNotes
sm20px12pxCompact badges for tight spaces
md24px14pxDefault si

Shapes

  • Pill – Fully rounded with pill={true}
  • Dot – Small circular badge, hides content with dot={true}

Accessibility

  • Role and interactive elements

    • Non-interactive badges render as <span>.
    • href badges render as <a> (link role).
    • onClick badges render as <button> (button role).
  • Icons and counts are visible to screen readers.

  • Dot badges are visual-only; use aria-label via ...rest if necessary.


Best Practices

Do

  • Use badges to indicate status, counts, or labels.
  • Keep badge text short (1–2 words).
  • Use max in groups to prevent overflow.
  • Use dot for subtle notifications or status.

Don’t

  • Place essential information only inside dot badges.
  • Overload groups with too many badges; use max for overflow.
  • Use badges for primary navigation.

API Reference

PropTypeDefaultDescription
countnumber—Displays a numerical count inside the badge
maxnumber99The maximum number to display before showing a '+' (e.g., 99+)
variantenumdefault—
sizeenummd—
pillbooleanfalseRounds the edges to create a pill shape
dotbooleanfalseRenders a small, empty circular indicator instead of text
hrefstring—If provided, renders the badge as an <a> tag
onClickMouseEventHandler<HTMLElement>—If provided, renders the badge as a <button> tag
iconLeftReactNode——
iconRightReactNode——
asChildboolean—Renders the component using its child element