Skip to main content

Overview

import MetricSection from "@components/MetricCard";

Description

The MetricCard component is a reusable card component designed to display individual metrics with optional trend indicators. It supports three display modes: simple mode (title and value only), detailed mode with trend, and detailed mode with trend and trend label.

Display Modes

The MetricCard supports three display modes:

  1. Simple Mode: When only title and value are provided

    • Shows only the title and value
    • Clean and minimal display
  2. Detailed Mode with Trend: When trend is provided without trendLabel

    • Shows the value and trend on the same line
    • Trend is displayed in green (positive) or red (negative)
  3. Detailed Mode with Trend and Label: When both trend and trendLabel are provided

    • Shows the value on one line
    • Shows the trend and trend label on a second line
    • Trend is displayed in green (positive) or red (negative)

Example Usage

// Simple Mode
const simpleMetric = {
title: "Revenue",
value: "$50,000"
};

// Detailed Mode with Trend
const trendMetric = {
title: "Active Users",
value: "1,234",
trend: "-5%",
isPositive: false
};

// Detailed Mode with Trend and Label
const detailedMetric = {
title: "Conversion Rate",
value: "2.5%",
trend: "15%",
trendLabel: "vs last month",
isPositive: true
};

// Usage

<div style={{ width: "200px" }}>
<MetricCard metric={simpleMetric} />
</div>
<div style={{ width: "200px" }}>
<MetricCard metric={trendMetric} />
</div>
<div style={{ width: "200px" }}>
<MetricCard metric={detailedMetric} />
</div>

Results

Simple Mode

Detailed Mode with Trend

Detailed Mode with Trend and Label

Props

Prop NameTypeDefault ValueDescription
metricobject-The metric object containing all the data to be displayed in the card.

Metric Object Structure

The metric prop should be an object with the following properties:

PropertyTypeRequiredDescription
titlestringYesThe title of the metric card.
valuestringYesThe main value to be displayed.
trendstringNoThe trend value (e.g., "+15%", "-5%").
trendLabelstringNoAdditional label for the trend (e.g., "vs last month").
isPositivebooleanNoIndicates if the trend is positive. Defaults to true if not specified.