Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Visitor Counter

ProNew

Who is on the site now, today, this week and all time, on digits that roll like an odometer, with a sparkline and five layouts. The numbers come from your props.

Installation

pnpm dlx shadcn@latest add @viewport/visitor-counter

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
stats*VisitorStat[]

The counters, most important first. The first one is featured and gets the sparkline.

—
livenumber

How many people are on the site right now. Shown with a pulsing dot.

—
liveLabelstring

Text after the live number.

"online now"
trendnumber[]

Recent values for the sparkline next to the first counter, oldest first.

—
layout"row" | "mini" | "card" | "list" | "compact"

`row` is a line of counters, `mini` a small two-column box, `card` the full panel, `list` a centred column and `compact` the short version of the card.

"card"
titlestring

Heading of the `card`, `list` and `compact` layouts.

"Stats"
iconReact.ReactNode

Replaces the chart icon next to the title.

—
tone"surface" | "inverse"

`inverse` paints it in the foreground color, for use over photos and dark sections.

"surface"
colorstring

Color of the sparkline and the live dot.

"var(--primary)"
loadingboolean

Shows placeholders while the first numbers are on their way.

false
errorstring | boolean

Replaces the numbers with this message. Pass `true` for the default one.

false
onRetry() => void

Adds a "Try again" button to the error.

—
localestring

Locale for digit grouping.

"en-US"
classNamestring—

Accessibility

  • Counters are a description list, so each number is read with its label.
  • The live number is announced politely once it has settled, not on every tick.
  • Loading marks the region busy; an error is an alert with a “Try again” button.
  • Under reduced motion digits swap in place, the sparkline is drawn at once and the live dot stops pinging.