Skip to content

shadcn.io is an independent project built on shadcn/ui

User Stats Hover Card for React

An Active Users tile showing 8,432 opens active and new counts, plus 1,234 online and a peak of 3,421.

The tile shows a people icon, 8,432, and Active Users. The card is titled User Activity, with 8,432 active, 2,156 new today, 1,234 online now, and a peak of 3,421.

Use it on an admin dashboard when the headline needs a breakdown. A tap should open a Popover. In React, Base UI does not track live users. The counts are sample text.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Hover Card anatomy: trigger, positioner, arrow, content

Usage

<HoverCard>
  <HoverCardTrigger
    closeDelay={100}
    delay={10}
    render={
      <button
        className="flex items-center gap-2 rounded-lg border bg-card p-4 text-start hover:bg-accent"
        type="button"
      />
    }
  >
    <UsersIcon aria-hidden="true" className="size-5 text-info" />
    <div>
      <div className="font-bold text-2xl">8,432</div>
      <div className="text-muted-foreground text-sm">Active Users</div>
    </div>
  </HoverCardTrigger>
  <HoverCardContent className="w-72 max-w-full">
    <div className="flex flex-col gap-3">
      <h4 className="font-semibold text-sm">User Activity</h4>
      <div className="grid grid-cols-2 gap-4">
        <div>
          <div className="font-bold text-xl">8,432</div>
          <div className="text-muted-foreground text-xs">Active</div>
        </div>
        <div>
          <div className="font-bold text-xl">2,156</div>
          <div className="text-muted-foreground text-xs">New Today</div>
        </div>
      </div>
      <Separator />
{/* The rest of the file is under Installation. */}

FAQ

What is in the card?

8,432 Active and 2,156 New Today in a two-column grid, a separator, then Online Now 1,234 and Peak Today 3,421.

How is the stat tile made the trigger?

HoverCardTrigger takes the stat tile through render, a button with its classes.

Why is the users icon blue?

It uses text-info, the informational token, since the number is neither good nor bad. It follows the theme in light and dark mode.

How wide is the card?

w-72 on the card, for the extra content. The class is on HoverCardContent. max-w-full keeps it inside narrow screens.

How do I change how fast the card opens and closes?

The card opens a moment after the pointer rests on the trigger and stays up long enough for the pointer to move into it. Both delays are in milliseconds. The demo sets delay 10 and closeDelay 100 on HoverCardTrigger. side and align on HoverCardContent place it.

Does the card open from the keyboard and on touch screens?

Focusing the tile opens the card, moving focus away or pressing Escape closes it. Touch screens have no hover, so keep what matters reachable elsewhere, or use a Popover when the card has to open on a tap.

API Reference

Hover Card

No extra props in this demo. The rest is on the Hover Card page.

Separator

No extra props in this demo. The rest is on the Separator page.