返回组件列表
数据展示

指标卡片

适用于仪表盘和概览面板的紧凑 KPI 卡片。

页面预览
源码
这里展示 registry 中会被 shadcn 安装到目标项目的组件源码。
registry/default/metric-card/metric-card.tsx
import { TrendingUpIcon } from "lucide-react"

import { Badge } from "@/components/ui/badge"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"

type MetricCardProps = {
  label?: string
  value?: string
  change?: string
  description?: string
}

export function MetricCard({
  label = "Active users",
  value = "24,892",
  change = "+12.4%",
  description = "Compared with the previous period",
}: MetricCardProps) {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <div className="flex items-start justify-between gap-3">
          <div className="flex flex-col gap-1">
            <CardDescription>{label}</CardDescription>
            <CardTitle className="text-3xl">{value}</CardTitle>
          </div>
          <Badge variant="secondary">
            <TrendingUpIcon data-icon="inline-start" />
            {change}
          </Badge>
        </div>
      </CardHeader>
      <CardContent>
        <p className="text-sm text-muted-foreground">{description}</p>
      </CardContent>
    </Card>
  )
}