Count Badge

View as Markdown

How many are waiting, as a number or a dot, beside a nav item or on an icon.

When to use

How many are waiting, as a number or a dot, beside a nav item or on an icon. Use Status instead when the mark is a state, not a number.

Usage

import { CountBadge } from "./ui/uicontext/components/CountBadge.ts"
export const InboxLink = <M>(h: Html.H<M>, unread: number) =>	h.a.attrs({ href: "/inbox" }).children("Inbox ", CountBadge(h, { count: unread, noun: "unread message" }))

Examples

Over an icon

CountOverlay pins it to the corner. A button's aria-label hides what's inside it, so put countWords in the label too.

More than 99 unread notificationsAONew activity

Press the bell to read them.

API reference

CountBadgeView function

Options

CountBadge options
NameTypeDefaultDescription
countnumber—How many. Nothing is drawn at 0, unless showZero.
nounstring—What it counts, singular: "unread message". The plural adds an s; give nouns otherwise.
nounsstring—The plural when it isn't the noun and an s: "replies".
maxnumber99Above this it reads "99+". 99 by default.
dotboolean—A dot instead of a number.
labelstring—What the dot means, for a screen reader: "New activity".
tone"accent" | "danger" | "quiet"—accent (the default) for what needs you, danger for what's wrong, quiet for a plain tally.
showZeroboolean——
localestring——
styleStyle——

CountOverlayView function

Options

CountOverlay options
NameTypeDefaultDescription
countnumber—How many. Nothing is drawn at 0, unless showZero.
nounstring—What it counts, singular: "unread message". The plural adds an s; give nouns otherwise.
nounsstring—The plural when it isn't the noun and an s: "replies".
maxnumber99Above this it reads "99+". 99 by default.
dotboolean—A dot instead of a number.
labelstring—What the dot means, for a screen reader: "New activity".
tone"accent" | "danger" | "quiet"—accent (the default) for what needs you, danger for what's wrong, quiet for a plain tally.
showZeroboolean——
localestring——
styleStyle——

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/count-badge

Source