Components / Patterns

Stat card

A metric on a card — label, value, an action such as a status badge, and a footer.

Conversations
1,284
+12%
Last 30 days
Credits used
8,420
82%
Of 10,000 this month
Spend
$46.10
Within limit
Resets on the 1st
pnpm exec shadcn add @intelligo/stat-card

Inside an app made by intelligo create, or any shadcn project that names the registry.

built on

Nothing else from the registry.

used by these pages

Usage, Billing Settings

Source

What shadcn add writes to components/ui/stat-card.tsx. It is yours from then on.

import * as React from "react";

import {
  Card,
  CardAction,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@showcase/components/ui/card";
import { cn } from "@showcase/lib/utils";

/**
 * A metric on a card: a label, the value, an optional
 * action such as a status badge, and a footer for context. Composed from
 * Card so it follows whatever the consumer's card looks like.
 */
function StatCard({ className, ...props }: React.ComponentProps<typeof Card>) {
  return (
    <Card
      data-slot="stat-card"
      className={cn("@container/stat-card", className)}
      {...props}
    />
  );
}

function StatCardHeader(props: React.ComponentProps<typeof CardHeader>) {
  return <CardHeader data-slot="stat-card-header" {...props} />;
}

function StatCardLabel(props: React.ComponentProps<typeof CardDescription>) {
  return <CardDescription data-slot="stat-card-label" {...props} />;
}

function StatCardValue({
  className,
  ...props
}: React.ComponentProps<typeof CardTitle>) {
  return (
    <CardTitle
      data-slot="stat-card-value"
      className={cn(
        "text-2xl font-semibold tracking-tight tabular-nums @[16rem]/stat-card:text-3xl",
        className
      )}
      {...props}
    />
  );
}

function StatCardAction(props: React.ComponentProps<typeof CardAction>) {
  return <CardAction data-slot="stat-card-action" {...props} />;
}

function StatCardFooter({
  className,
  ...props
}: React.ComponentProps<typeof CardFooter>) {
  return (
    <CardFooter
      data-slot="stat-card-footer"
      className={cn(
        "flex-col items-start gap-1 text-sm text-muted-foreground",
        className
      )}
      {...props}
    />
  );
}

export {
  StatCard,
  StatCardHeader,
  StatCardLabel,
  StatCardValue,
  StatCardAction,
  StatCardFooter,
};

Ready to try it? Three commands and the app runs against a stub model.