Skip to content

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

Simple Stats Hover Card for Ark UI

A Total Views tile showing 12,543 opens today, this week, and this month on a small breakdown card.

The tile shows an up-trend icon, 12,543, and Total Views. The card is titled View Statistics and lists Today 342, This Week 2,156, and This Month 8,932.

Reach for it when a total needs three periods and nothing more. On a touch screen, open the breakdown in a Popover. In React, Ark UI does not add up the views.

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 asChild>
    <button
      className="flex items-center gap-2 rounded-lg border bg-card p-4 text-start hover:bg-accent"
      type="button"
    >
      <TrendingUpIcon aria-hidden="true" className="size-5 text-success" />
      <div>
        <div className="font-bold text-2xl">12,543</div>
        <div className="text-muted-foreground text-sm">Total Views</div>
      </div>
    </button>
  </HoverCardTrigger>
  <HoverCardContent>
    <div className="flex flex-col gap-2">
      <h4 className="font-semibold text-sm">View Statistics</h4>
      <div className="flex flex-col gap-1 text-muted-foreground text-sm">
        <div className="flex justify-between">
          <span>Today:</span>
          <span className="font-medium text-foreground">342</span>
        </div>
        <div className="flex justify-between">
          <span>This Week:</span>
          <span className="font-medium text-foreground">2,156</span>
        </div>
        <div className="flex justify-between">
          <span>This Month:</span>
          <span className="font-medium text-foreground">8,932</span>
        </div>
      </div>
    </div>
{/* The rest of the file is under Installation. */}

FAQ

What is in the card?

View Statistics and three rows: Today 342, This Week 2,156 and This Month 8,932, with the numbers in the foreground color.

How is the stat tile made the trigger?

HoverCardTrigger takes asChild, and the demo passes the stat tile, a button.

How is the tile styled?

A bordered bg-card button with a trending-up icon in text-success, the number in large bold text and the label in muted text. text-start keeps the text aligned in both directions.

How wide is the card?

The default hover card width. Set a width class such as w-80 on the card to fit longer content.

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. Set openDelay and closeDelay on HoverCard; they default to 10 and 100. positioning picks another side than the bottom.

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

Sets asChild. The rest is on the Hover Card page.