0

NumberBadge

A self-anchoring count badge for avatars and icons with animated counts and 99+ overflow.

CN58
import { IconBell } from "@tabler/icons-react"

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

Installation

bunx --bun shadcn@latest add @ondo-ui/number-badge

This installs NumberBadge along with badge, number-count, and the @number-flow/react dependency.

Usage

import { NumberBadge } from "@/components/compositions/number-badge"
<NumberBadge value={5}>
  <Avatar>{/* … */}</Avatar>
</NumberBadge>

NumberBadge wraps its children (the anchor) and overlays the count in a corner. Pass a value above max to get 99+; a value of 0 hides the badge unless showZero is set.

Examples

Overflow and hide-on-zero

value above max (default 99) renders as 99+; a value of 0 hides the badge. Step past both thresholds to see it.

CN33
"use client"

import * as React from "react"

Variants and placement

NumberBadge supports every Badge variant and all four placement corners.

CN8default
CN8secondary
CN8destructive
CN8outline
CN8ghost
CN8top-right
CN8top-left
CN8bottom-right
CN8bottom-left
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { NumberBadge } from "@/components/compositions/number-badge"

API reference

NumberBadge accepts every Badge prop (except children, repurposed as the anchor), plus:

PropTypeDefaultDescription
valuenumberRequired count. > max shows {max}+.
maxnumber99Overflow cap.
showZerobooleanfalseRender the badge when value is 0.
placement"top-right" | "top-left" | "bottom-right" | "bottom-left""top-right"Corner over children.
variantBadge variants"default"Passed to Badge.
childrenReact.ReactNodeAnchor element the badge floats over.
classNamestringMerged onto the overlaid Badge.

Built on

NumberBadge composes:

  • Badge — the badge shell and its variants.
  • NumberCount — the animated count inside.

Need an inline (non-anchored) numeric badge? Compose Badge and NumberCount directly.