Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 20x 277x 20x 20x 42x 277x | import { Skeleton } from "@/components/detail";
import React from "react";
/**
* A page's headline figures, as a row of stat tiles: each a label (sentence
* case), its value (proportional figures, auto-compact), and a line under
* it — a comparison, or what the figure counts.
*/
export interface StatTileProps {
label: string;
value: React.ReactNode;
/** A comparison or a qualifier: "+12 on the 30 days before". */
hint?: React.ReactNode;
loading?: boolean;
}
export const StatTile: React.FC<StatTileProps> = ({ label, value, hint, loading }) => (
<div className="min-w-0 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-4 py-3">
<div className="text-xs text-gray-500 dark:text-gray-400 truncate">{label}</div>
{loading ? (
<Skeleton className="mt-1.5 h-6 w-16" />
) : (
<div className="mt-0.5 text-xl font-semibold text-gray-900 dark:text-gray-100 truncate">
{value}
</div>
)}
{hint && !loading && (
<div className="mt-0.5 text-[11px] text-gray-400 dark:text-gray-500 truncate">{hint}</div>
)}
</div>
);
/** Grid classes by tile count, whole strings so Tailwind keeps them. */
const COLUMNS: Record<number, string> = {
2: "grid-cols-2",
3: "grid-cols-2 sm:grid-cols-3",
4: "grid-cols-2 sm:grid-cols-4",
5: "grid-cols-2 sm:grid-cols-3 lg:grid-cols-5",
6: "grid-cols-2 sm:grid-cols-3 lg:grid-cols-6",
7: "grid-cols-2 sm:grid-cols-4 lg:grid-cols-7",
};
export const KpiStrip: React.FC<{ tiles: StatTileProps[]; className?: string }> = ({
tiles,
className = "",
}) => (
<div className={`grid gap-3 ${COLUMNS[tiles.length] ?? COLUMNS[4]} ${className}`}>
{tiles.map((tile) => (
<StatTile key={tile.label} {...tile} />
))}
</div>
);
export default KpiStrip;
|