Count Badge

A count pinned to an icon or an avatar, which pops when it changes.

Dependenciesmotion
3 unread notifications128 unread messagesLLina is online

Installation#

pnpm dlx shadcn@latest add @balick/count-badge

Or pass the full URL: https://ui.balick.me/r/count-badge.json

Usage#

import { Bell } from "lucide-react"

import { CountBadge } from "@/components/ui/count-badge"

export function Notifications({ unread }: { unread: number }) {
  return (
    <CountBadge count={unread} label="unread notifications">
      <Bell className="size-5" />
    </CountBadge>
  )
}

Props#

PropTypeDefault
count

The number to show. Nothing shows at 0, unless showZero is set. Required.

number—
max

Past it, the badge reads "99+".

number99
dot

Show a plain dot instead of the number.

booleanfalse
showZero

Show the badge when the count is 0.

booleanfalse
tone

Red for alerts, green for presence, or the foreground color.

"danger" | "success" | "neutral""danger"
label

What is counted, read after the number by screen readers.

string—