KPI & Timeframe Telemetry Strip
One framed four-up metric bar (2x2 on tablet, stacked on mobile) with a UI SDK SegmentedControl timeframe switch that updates every number, icon + sign delta pills, tabular numbers, and inline sparklines.
Install UI SDK & packages
npm install @ui-sdk/react @ui-sdk/core lucide-react
Give your agent the UI SDK skill
npx skills add vercel-labs/ui --skill ui-sdk
"use client"; import * as React from "react"; import { RefreshCw, TrendingDown, TrendingUp } from "lucide-react"; import { Button } from "@ui-sdk/react/button"; import { Field, FieldLabel } from "@ui-sdk/react/field"; import { SegmentedControl, SegmentedControlItem } from "@ui-sdk/react/segmented-control"; const card = "rounded-2xl border border-[#d8e0ea] bg-white shadow-[0_18px_44px_rgba(15,23,42,0.12)] dark:border-slate-400/20 dark:bg-[#111827] dark:shadow-[0_24px_60px_rgba(0,0,0,0.5)]"; const btnBase = "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-[10px] font-bold transition hover:-translate-y-px active:translate-y-px disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500"; const btnSm = "h-9 px-3 text-[13px]"; const btnGhost = `${btnBase} border border-slate-300 bg-linear-to-b from-white to-slate-100 text-slate-900 shadow-[inset_0_1px_0_rgba(255,255,255,0.95),inset_0_-1.5px_0_rgba(15,23,42,0.08),0_1px_2px_rgba(15,23,42,0.06)] hover:border-slate-400 dark:border-slate-400/35 dark:from-[#243047] dark:to-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.09),inset_0_-1.5px_0_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55`; export interface KpiMetric { label: string; /** Already formatted, like "$12,460" or "138 ms". */ value: string; /** Already formatted change, like "+14.2%" or "-12 ms". */ delta: string; direction: "up" | "down"; /** Whether the change is good news. Down can be good (faster responses). */ tone: "good" | "bad" | "neutral"; /** Oldest to newest. Two or more points draw the sparkline. */ series: number[]; } export interface KpiRange { key: string; label: string; comparedTo: string; metrics: KpiMetric[]; } const DEFAULT_RANGES: KpiRange[] = [ { key: "24h", label: "24h", comparedTo: "the previous 24 hours", metrics: [ { label: "Revenue", value: "$1,840", delta: "+6.2%", direction: "up", tone: "good", series: [52, 48, 61, 58, 66, 63, 71, 69, 74, 72, 80, 84] }, { label: "New signups", value: "38", delta: "+11.8%", direction: "up", tone: "good", series: [2, 3, 2, 4, 3, 5, 3, 4, 2, 3, 4, 3] }, { label: "MCP calls", value: "4,206", delta: "-3.1%", direction: "down", tone: "bad", series: [380, 402, 371, 390, 365, 352, 360, 341, 338, 330, 322, 315] }, { label: "Median response", value: "142 ms", delta: "-9 ms", direction: "down", tone: "good", series: [158, 155, 151, 153, 149, 150, 147, 146, 145, 144, 143, 142] }, ], }, { key: "7d", label: "7d", comparedTo: "the previous 7 days", metrics: [ { label: "Revenue", value: "$12,460", delta: "+14.2%", direction: "up", tone: "good", series: [1480, 1520, 1610, 1575, 1690, 1740, 1705, 1790, 1820, 1880, 1905, 1960] }, { label: "New signups", value: "264", delta: "+9.1%", direction: "up", tone: "good", series: [31, 34, 30, 36, 38, 35, 39, 41, 37, 40, 42, 44] }, { label: "MCP calls", value: "31,880", delta: "+18.4%", direction: "up", tone: "good", series: [3600, 3820, 3910, 4050, 4180, 4120, 4300, 4460, 4520, 4610, 4780, 4890] }, { label: "Median response", value: "138 ms", delta: "-12 ms", direction: "down", tone: "good", series: [152, 150, 149, 147, 146, 144, 145, 142, 141, 140, 139, 138] }, ], }, { key: "30d", label: "30d", comparedTo: "the previous 30 days", metrics: [ { label: "Revenue", value: "$54,410", delta: "+21.6%", direction: "up", tone: "good", series: [1310, 1380, 1420, 1395, 1510, 1580, 1640, 1700, 1760, 1810, 1870, 1960] }, { label: "New signups", value: "1,119", delta: "+15.4%", direction: "up", tone: "good", series: [28, 30, 33, 31, 35, 34, 38, 37, 40, 39, 42, 44] }, { label: "MCP calls", value: "128,400", delta: "+24.9%", direction: "up", tone: "good", series: [3100, 3240, 3420, 3610, 3700, 3880, 4010, 4190, 4330, 4520, 4700, 4890] }, { label: "Median response", value: "151 ms", delta: "+6 ms", direction: "up", tone: "bad", series: [141, 142, 144, 143, 146, 147, 149, 148, 150, 152, 151, 151] }, ], }, ]; const TONE_CLS: Record<KpiMetric["tone"], string> = { good: "border-emerald-600/30 bg-emerald-50 text-emerald-800 dark:border-emerald-400/40 dark:bg-emerald-400/15 dark:text-emerald-300", bad: "border-red-600/30 bg-red-50 text-red-800 dark:border-red-400/45 dark:bg-red-400/15 dark:text-red-300", neutral: "border-slate-300 bg-slate-50 text-slate-700 dark:border-slate-400/35 dark:bg-[#162033] dark:text-slate-200", }; function Sparkline({ series }: { series: number[] }) { if (series.length < 2) return null; const min = Math.min(...series); const span = Math.max(...series) - min || 1; const points = series .map((value, index) => `${((index / (series.length - 1)) * 100).toFixed(1)},${(29 - ((value - min) / span) * 26).toFixed(1)}`) .join(" "); return ( <svg viewBox="0 0 100 32" preserveAspectRatio="none" aria-hidden="true" className="mt-1 block h-9 w-full text-sky-600 max-sm:mt-0 dark:text-sky-400" > <polygon points={`0,32 ${points} 100,32`} fill="currentColor" opacity={0.12} /> <polyline points={points} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" vectorEffect="non-scaling-stroke" /> </svg> ); } export function KpiTelemetryStrip({ title = "Workspace telemetry", ranges = DEFAULT_RANGES, defaultRange = "7d", onRangeChange, onRefresh, }: { title?: string; ranges?: KpiRange[]; defaultRange?: string; onRangeChange?: (rangeKey: string) => void; /** Return a Promise to show the button as busy until your data lands. */ onRefresh?: (rangeKey: string) => Promise<void> | void; }) { const [rangeKey, setRangeKey] = React.useState(defaultRange); const active = ranges.find((range) => range.key === rangeKey) ?? ranges[0]; if (!active) return null; return ( <section aria-label={title} className={`${card} overflow-hidden`}> <div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-3 border-b border-[#d8e0ea] px-4 py-4 sm:px-5 dark:border-slate-400/20"> <div className="min-w-0"> <h2 className="text-[17px] font-bold tracking-tight text-slate-900 dark:text-slate-50">{title}</h2> <p className="mt-0.5 text-[12.5px] text-slate-600 dark:text-slate-400">Compared with {active.comparedTo}</p> </div> <div className="flex flex-wrap items-center gap-2.5"> <Field className="flex items-center"> <FieldLabel className="sr-only">Timeframe</FieldLabel> <SegmentedControl value={active.key} onValueChange={(next) => { if (!next) return; setRangeKey(next); onRangeChange?.(next); }} className="inline-flex gap-0.5 rounded-[11px] border border-[#d8e0ea] bg-slate-50 p-[3px] dark:border-slate-400/20 dark:bg-[#162033]" > {ranges.map((range) => ( <SegmentedControlItem key={range.key} value={range.key} className="h-8 cursor-pointer rounded-lg px-3 text-[13px] font-semibold text-slate-600 transition-colors data-checked:bg-sky-700 data-checked:font-bold data-checked:text-white data-unchecked:hover:text-slate-900 dark:text-slate-400 dark:data-checked:bg-sky-400 dark:data-checked:text-[#031521] dark:data-unchecked:hover:text-slate-50" > {range.label} </SegmentedControlItem> ))} </SegmentedControl> </Field> <Button onClick={() => onRefresh?.(active.key)} className={`${btnGhost} ${btnSm} group`}> <RefreshCw className="size-3.5 group-data-pending:animate-spin" aria-hidden="true" /> <span>Refresh metrics</span> </Button> </div> </div> <div className="grid grid-cols-1 gap-px bg-[#d8e0ea] sm:grid-cols-2 lg:grid-cols-4 dark:bg-slate-400/20"> {active.metrics.map((metric) => { const DeltaIcon = metric.direction === "up" ? TrendingUp : TrendingDown; return ( <div key={metric.label} role="group" aria-label={metric.label} className="grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-2.5 gap-y-1.5 bg-white px-4 pt-4 pb-3.5 sm:px-5 dark:bg-[#111827]" > <span className="text-[12.5px] font-semibold text-slate-600 dark:text-slate-400">{metric.label}</span> <span className={`inline-flex h-[22px] items-center gap-1 whitespace-nowrap rounded-full border px-2 text-[11.5px] font-bold tabular-nums ${TONE_CLS[metric.tone]}`} > <DeltaIcon className="size-3" aria-hidden="true" /> <span className="sr-only">{metric.direction === "up" ? "Up" : "Down"}</span> {metric.delta} </span> <span className="text-[30px] leading-tight font-bold tracking-tight text-slate-900 tabular-nums max-sm:text-[26px] sm:col-span-2 dark:text-slate-50"> {metric.value} </span> <div className="min-w-0 max-sm:w-24 sm:col-span-2"> <Sparkline series={metric.series} /> </div> </div> ); })} </div> </section> ); } export default KpiTelemetryStrip;
More in Dashboard & Data
Agent Approval Inbox & Slide-Over Reading Pane
MSAI one-line scannable agent inbox paired with a slide-over reading pane. Quick Approve/Skip actions live on hover in the list and stay pinned in a fixed decision footer inside the reading pane with Undo and arrow-key navigation.
Key-Value Detail Inspector Drawer
Slide-over UI SDK Drawer inspector: semantic <dl> metadata grid, editable status Select and notes Textarea, and a sticky footer with a tactile Copy ID button and a high-contrast Archive record button that confirms in an AlertDialog, then shows the archived state with Restore.
Live Worker & Job Queue Panel
Background job monitor modeled on Template Factory's build workers: live UI SDK Progress bars, Running / Queued / Paused / Done / Failed badges with icons, per-job pause, resume, retry and a Cancel run that confirms in an AlertDialog, a Collapsible log per job, and a queue-wide pause.