Skip to content
Data Display

Stat Card

KPI card with an icon chip, animated count-up value, and a trend badge. StatGrid staggers a row.

MotionfadeUp via StatGrid stagger + AnimatedNumber count-up

Install

Install Kineto and follow the theme setup once in your app.

bash
npm install kineto
tsx
import { StatCard, StatGrid } from "kineto/stat-card";

Preview

Balance
$0
27.4%

vs last month

Spending
$0
10%

vs last month

Investing
$0
4.2%

vs last month

tsx
"use client";

import * as React from "react";
import { motion, type HTMLMotionProps } from "motion/react";
import { ArrowDownRight, ArrowUpRight, type LucideIcon } from "lucide-react";

import { cn } from "@/lib/cn";
import { fadeUp, staggerContainer, viewportOnce } from "@/lib/motion-presets";
import { AnimatedNumber } from "@/components/ui/animated-number";

function TrendBadge({ value }: { value: number }) {
  const up = value >= 0;
  return (
    <span
      className={cn(
        "inline-flex items-center gap-0.5 rounded-full px-1.5 py-0.5 text-xs font-medium",
        up ? "bg-success/12 text-success" : "bg-destructive/10 text-destructive"
      )}
    >
      {up ? (
        <ArrowUpRight className="size-3" />
      ) : (
        <ArrowDownRight className="size-3" />
      )}
      {Math.abs(value)}%
    </span>
  );
}

export interface StatCardProps extends Omit<HTMLMotionProps<"div">, "title"> {
  label: string;
  value: number;
  prefix?: string;
  suffix?: string;
  format?: (value: number) => string;
  icon?: LucideIcon;
  /** Override the icon chip tint, e.g. "bg-chart-2/12 text-chart-2". */
  iconClassName?: string;
  /** Signed percentage; positive renders an up/green badge, negative down/red. */
  trend?: number;
  trendLabel?: string;
  /** Optional trailing slot in the header (e.g. a period select or menu). */
  children?: React.ReactNode;
}

const StatCard = React.forwardRef<HTMLDivElement, StatCardProps>(
  (
    {
      className,
      label,
      value,
      prefix,
      suffix,
      format,
      icon: Icon,
      iconClassName,
      trend,
      trendLabel,
      children,
      ...props
    },
    ref
  ) => (
    <motion.div
      ref={ref}
      variants={fadeUp}
      className={cn(
        "rounded-xl border border-border bg-card p-5 shadow-soft",
        className
      )}
      {...props}
    >
      <div className="flex items-center justify-between gap-3">
        <div className="flex items-center gap-2.5">
          {Icon ? (
            <span
              className={cn(
                "flex size-9 items-center justify-center rounded-lg bg-primary/10 text-primary [&_svg]:size-4",
                iconClassName
              )}
            >
              <Icon />
            </span>
          ) : null}
          <span className="text-sm font-medium text-muted-foreground">{label}</span>
        </div>
        {children}
      </div>

      <div className="mt-4 flex items-end justify-between gap-3">
        <div className="font-display text-3xl font-semibold tracking-tight text-foreground">
          {prefix}
          <AnimatedNumber value={value} format={format} />
          {suffix}
        </div>
        {typeof trend === "number" ? <TrendBadge value={trend} /> : null}
      </div>

      {trendLabel ? (
        <p className="mt-1.5 text-xs text-muted-foreground">{trendLabel}</p>
      ) : null}
    </motion.div>
  )
);
StatCard.displayName = "StatCard";

const columnClasses: Record<2 | 3 | 4, string> = {
  2: "sm:grid-cols-2",
  3: "sm:grid-cols-3",
  4: "sm:grid-cols-2 lg:grid-cols-4",
};

export interface StatGridProps extends HTMLMotionProps<"div"> {
  columns?: 2 | 3 | 4;
}

const StatGrid = React.forwardRef<HTMLDivElement, StatGridProps>(
  ({ className, columns = 4, children, ...props }, ref) => (
    <motion.div
      ref={ref}
      variants={staggerContainer(0.08)}
      initial="hidden"
      whileInView="visible"
      viewport={viewportOnce}
      className={cn("grid grid-cols-1 gap-4", columnClasses[columns], className)}
      {...props}
    >
      {children}
    </motion.div>
  )
);
StatGrid.displayName = "StatGrid";

export { StatCard, StatGrid };

src/components/application/stat-card.tsx

Props

PropTypeDefaultDescription
label / valuestring / number—Metric name and value.
iconLucideIcon—Icon shown in the tinted chip.
trendnumber—Signed % — positive is up/green, negative down/red.
prefix / suffixstring—Wrap the value (e.g. "$", "%").