Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Charts and metrics
KPI Card
A headline number with its label, change and sparkline.
import { KpiCard } from "@/registry/vcare/ui/kpi-card"
export default function KpiCardDemo() {
return (
// Two columns only when the box (not the window) has room for them.
<div className="@container w-full">
<div className="grid gap-4 @lg:grid-cols-2">
<KpiCard label="Revenue" value={482300} format="currency" currency="INR" delta={0.124} deltaLabel="vs last month" trend={[31, 35, 33, 40, 44, 41, 48]} />
<KpiCard label="Average wait" value="14 min" delta={-0.08} invertDelta deltaLabel="vs last week" trend={[22, 20, 19, 18, 16, 15, 14]} />
</div>
</div>
)
}Installation
npx shadcn@latest add @vcare/kpi-cardOr install directly from the URL: https://ui.vcarehms.com/r/kpi-card.json
- Add the registry items it uses: card, delta-badge, format, metric-value, sparkline, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/kpi-card.tsx
'use client';
import * as React from 'react';
import { cn } from '@/registry/vcare/lib/utils';
import { type NumberFormat } from '@/registry/vcare/lib/format';
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from '@/registry/vcare/ui/card';
import { DeltaBadge, getDeltaDirection } from '@/registry/vcare/ui/delta-badge';
import { Sparkline } from '@/registry/vcare/ui/sparkline';
import { MetricValue } from '@/registry/vcare/ui/metric-value';
export interface KpiCardProps extends Omit<React.ComponentProps<typeof Card>, 'children'> {
/** Metric name, e.g. "Revenue". */
label: string;
/** Current value. Numbers are formatted with `format`; strings render as-is. */
value: number | string;
/** Fractional change vs. the previous period, e.g. 0.124 for +12.4%. */
delta?: number;
/** Context for the delta, e.g. "vs. last 30 days". */
deltaLabel?: string;
/** Series for the sparkline. Rendered when it has two or more points. */
trend?: number[];
format?: NumberFormat;
/** ISO 4217 code, used when `format` is "currency". */
currency?: string;
/** Treat a decrease as good and an increase as bad (churn, latency, errors). */
invertDelta?: boolean;
/** Optional icon shown before the label. */
icon?: React.ReactNode;
children?: React.ReactNode;
}
function KpiCard({
label,
value,
delta,
deltaLabel,
trend,
format = 'number',
currency,
invertDelta = false,
icon,
className,
children,
...props
}: KpiCardProps) {
const direction = getDeltaDirection(delta);
const isPositive = direction === 'flat' ? null : (direction === 'up') !== invertDelta;
const trendColor = isPositive === true ? 'var(--color-emerald-500)' : isPositive === false ? 'var(--color-red-500)' : 'var(--primary)';
return (
<Card data-slot="kpi-card" data-direction={direction} className={cn('gap-3 py-4 sm:gap-4 sm:py-5', className)} {...props}>
<CardHeader className="px-4 sm:px-5">
<CardDescription className="flex min-w-0 items-center gap-2.5 flex-wrap font-medium [&>svg]:size-8 sm:[&>svg]:size-9 [&>svg]:shrink-0 [&>svg]:rounded-xl [&>svg]:bg-(--nav-active-bg) [&>svg]:p-2 [&>svg]:text-primary">
{icon}
{label}
</CardDescription>
<CardTitle className="text-2xl leading-9 font-extrabold whitespace-nowrap sm:text-[28px] tabular-nums tracking-tight">
<MetricValue value={value} format={format} currency={currency} />
</CardTitle>
{delta !== undefined ? (
<CardAction>
<DeltaBadge delta={delta} invert={invertDelta} />
</CardAction>
) : null}
</CardHeader>
{trend && trend.length > 1 ? (
<CardContent className="px-5">
<Sparkline data={trend} color={trendColor} />
</CardContent>
) : null}
{deltaLabel || children ? (
<CardContent className="text-muted-foreground flex items-center gap-2 px-5 text-xs">
{deltaLabel ? <span>{deltaLabel}</span> : null}
{children}
</CardContent>
) : null}
</Card>
);
}
export { KpiCard };Usage
import { KpiCard } from "@/components/ui/kpi-card"Exports
KpiCard
Dependencies
@vcare/card(registry)@vcare/delta-badge(registry)@vcare/format(registry)@vcare/metric-value(registry)@vcare/sparkline(registry)@vcare/utils(registry)
Raw item: /r/kpi-card.json