Components

MetricCard

Dashboard tile that highlights a key metric value with freshness indicator and confidence score.

Category: DI Domain / Standalone

Import

import {
  MetricCard,
  type MetricCardProps,
  type MetricFreshness,
  type StalenessStatus,
} from "@hareru/ui"

Exports

NameTypeDescription
MetricCardComponentMetric display card (<article>)
MetricCardPropsTypeProps interface
MetricFreshnessTypeFreshness info: lastUpdatedAt, staleness, label
StalenessStatusType"fresh" | "stale" | "unknown"

Key Props

PropTypeDefaultDescription
metricNamestringInternal metric identifier (required)
displayNamestringDisplay label shown to the user (required)
valuenumber | nullMetric value (null = no data) (required)
unitstringUnit of measurement (e.g. "USD", "%")
descriptionstringMetric description
freshnessMetricFreshnessData freshness information
confidencenumber | nullConfidence score (0.0–1.0)
semanticModelNamestringSemantic model name (shown in footer)
loadingbooleanfalseLoading state (shows skeleton)
errorstringError message
onDefinitionClick() => void"View Definition" button handler
formatValue(value: number, unit?: string) => stringCustom value formatter. Default formats with toLocaleString('en-US') and appends unit if provided.

Types

interface MetricFreshness {
  lastUpdatedAt: Date
  staleness: "fresh" | "stale" | "unknown"
  label?: string  // e.g. "Updated 5 minutes ago"
}

States

StateTypeValuesDefaultCSS Reflection
loadingbooleanBEM modifier

Accessibility

  • ARIA attributes: aria-label
  • Semantic elements: article

Usage

import { MetricCard } from "@hareru/ui"

// Basic metric
<MetricCard
  metricName="total_amount"
  displayName="Total Sales"
  value={1234567}
  unit="USD"
  description="Sum of all order amounts"
/>

// With freshness and confidence
<MetricCard
  metricName="total_amount"
  displayName="Total Sales"
  value={1234567}
  unit="USD"
  freshness={{
    lastUpdatedAt: new Date(),
    staleness: "fresh",
    label: "Updated 5 minutes ago",
  }}
  confidence={0.98}
  semanticModelName="smb_sales"
  onDefinitionClick={() => console.log("open definition: total_amount")}
/>

// Loading state
<MetricCard
  metricName="total_amount"
  displayName="Total Sales"
  value={null}
  loading
/>

// Error state
<MetricCard
  metricName="total_amount"
  displayName="Total Sales"
  value={null}
  error="Failed to fetch metric data"
/>

Notes

  • Renders as an <article> element with <header> and <footer> semantic structure.
  • Confidence score is displayed as a percentage with color coding: high (≥95%), medium (≥80%), low (below 80%).
  • Freshness indicator shows staleness status with a tooltip showing the last update timestamp.
  • Designed for use with DI MCP get_metric_definition tool output.

On this page