Data display
Stat
A key number with its change and an optional chart. The arrow is neutral; use tone="danger" only when the change is bad. The tile is a container: the value size and the padding follow the width of the tile, not the screen. From 15rem the value is text-3xl with p-5; from 12rem text-2xl; from 10rem text-xl; below that text-lg, with p-4 under 15rem. So four money tiles in a row, or two on a phone (about 158 px each), hold an amount with decimals. The label, change and hint keep their sizes. The tile takes its width from its parent (a grid cell, flex-1 or a width); in a parent that sizes to its content it is 9rem wide.
import { Stat } from "@percentsa/ui";Examples
Revenue
184,250
Increase +12.4%
vs last month
Active users
12,480
No change 0%
Churn
2.4%
Increase +0.6%
Higher is worse
Code
export function StatExample() {
const t = useT();
return (
<div className="grid w-full grid-cols-[repeat(auto-fit,minmax(min(12rem,100%),1fr))] gap-3">
<Stat label={t("Revenue", "الإيرادات")} value={<Money amount={184250} />} change={{ value: "+12.4%", direction: "up" }} hint={t("vs last month", "مقارنة بالشهر الماضي")} />
<Stat label={t("Active users", "المستخدمون النشطون")} value={<FormattedNumber value={12480} />} change={{ value: "0%", direction: "flat" }} />
<Stat label={t("Churn", "معدل الإلغاء")} value="2.4%" change={{ value: "+0.6%", direction: "up", tone: "danger" }} hint={t("Higher is worse", "الارتفاع سيئ")} />
</div>
);
}
/** Four money tiles in a row: the value size follows the tile width (a container query on the tile), so an amount with decimals fits at 158 px. */Collected
123,456.78
Increase 12.5%
Yesterday: 98,000.00
Sales
248,910.50
Decrease 3.0%
Refunds
4,120.00
Increase 0.4%
Orders
1,284
Decrease 3.0%
Yesterday: 1,324
Code
export function StatMoneyRowExample() {
const t = useT();
return (
<div className="grid w-full grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4">
<Stat label={t("Collected", "المبالغ المحصلة")} value={<Money amount={123456.78} decimals={2} />} change={{ value: "12.5%", direction: "up" }} hint={t("Yesterday: 98,000.00", "أمس: 98,000.00")} />
<Stat label={t("Sales", "المبيعات")} value={<Money amount={248910.5} decimals={2} />} change={{ value: "3.0%", direction: "down" }} />
<Stat label={t("Refunds", "المرتجعات")} value={<Money amount={4120} decimals={2} />} change={{ value: "0.4%", direction: "up", tone: "danger" }} />
<Stat label={t("Orders", "الطلبات")} value="1,284" change={{ value: "3.0%", direction: "down" }} hint={t("Yesterday: 1,324", "أمس: 1,324")} />
</div>
);
}