# Stat Card — Implementation Guide ## What is a stat card A stat card displays a single KPI metric with an optional trend indicator. Used on dashboards to show at-a-glance numbers like "Total Properties: 42 (+10%)". --- ## Component interface ```ts interface StatCardProps { title: string; value: number | string; trend?: { value: number; isPositive: boolean; }; subtitle?: string; onClick?: () => void; } ``` --- ## StatCard component Create at `components/StatCard.tsx`: ```tsx import React from "react"; import { Card } from "@/components/ui/card"; import { TrendingUp, TrendingDown } from "lucide-react"; interface StatCardProps { title: string; value: number | string; trend?: { value: number; isPositive: boolean; }; subtitle?: string; onClick?: () => void; } export const StatCard: React.FC = ({ title, value, trend, subtitle, onClick }) => { return (

{title}

{value}

{trend && ( {trend.isPositive ? ( ) : ( )} {Math.abs(trend.value)}% )}
{subtitle &&

{subtitle}

}
); }; ``` This version uses Lucide icons (`TrendingUp`/`TrendingDown`) instead of custom SVGs for portability across projects. --- ## Layout: stat card grid Display stat cards in a responsive grid: ```tsx
``` --- ## Computing trend values Calculate trends from current vs previous period: ```ts const trends = useMemo(() => { const previousTotal = metrics.totalProperties - Math.round(metrics.totalProperties * 0.1); const trendPercent = previousTotal > 0 ? Math.round(((metrics.totalProperties - previousTotal) / previousTotal) * 100) : 0; return { value: Math.abs(trendPercent), isPositive: trendPercent >= 0, }; }, [metrics]); ``` --- ## Trend badge color conventions | Trend | Background | Text | Meaning | |-------|------------|------|---------| | Positive (up) | `bg-emerald-100` | `text-emerald-800` | Growth, improvement | | Negative (down) | `bg-pink-100` | `text-pink-800` | Decline, concern | | Neutral | `bg-gray-100` | `text-gray-600` | No change | --- ## Accessibility - Card uses `cursor-pointer` and `hover:shadow-lg` only when `onClick` is provided. - Trend icons have implicit meaning from color + direction icon. - Stat values use large, bold text for visibility. - Title uses `uppercase tracking-wide` for visual hierarchy without heading tags (appropriate in a card grid).