StatCard

Metric tile. New values count into place and briefly flash; pass live values from your data source. Cards.

Open playground
Demo counter
0 updates
Sample trend12.4%
0

About

StatCard is a React component in the Cards category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { StatCard } from "@ashutoshswamy/smoui" and set label, value, prefix among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { useEffect, useState } from "react";
import { StatCard } from "@ashutoshswamy/smoui";

function LiveStat() {
  const [value, setValue] = useState(24);
  useEffect(() => {
    const timer = setInterval(() => setValue(n => n + 1), 2500);
    return () => clearInterval(timer);
  }, []);
  return <StatCard label="Demo counter" value={value} />;
}

Props 5

label

Metric name.

string
value

Counts and flashes whenever the value changes.

number
prefix / suffix / decimals

Number formatting.

string / string / number
delta

Percent change. Sign sets arrow and color.

number
data

Trend line points.

number[]