Uptime bar
Daily status bars with uptime percentage and incident tooltips.
$
pnpm dlx shadcn@latest add https://lodeui.com/r/uptime-bar.jsonLive preview
API98.89% uptime
45 days agoToday
Webhooks96.67% uptime
45 days agoToday
components/examples/uptime-bar-demo.tsx
"use client";
import { UptimeBar, type UptimeDay } from "@/components/ui/uptime-bar";
const days = (bad: Record<number, ["degraded" | "down", string]>): UptimeDay[] =>
Array.from({ length: 45 }, (_, i) => ({ date: `Day ${i + 1}`, status: bad[i]?.[0] ?? "up", note: bad[i]?.[1] }));
export default function UptimeBarDemo() {
return (
<div className="w-full max-w-xl space-y-6">
<UptimeBar name="API" days={days({ 30: ["degraded", "Elevated latency for 18 min"] })} />
<UptimeBar name="Webhooks" days={days({ 40: ["down", "Deliveries delayed 42 min"], 41: ["degraded", "Backlog drained"] })} />
</div>
);
}When to use
- Status pages and service health over 30–90 days.
When not to use
- Live latency: use a line chart.
Installation
$
pnpm dlx shadcn@latest add https://lodeui.com/r/uptime-bar.json1Copy the source into your project
components/ui/uptime-bar.tsx"use client"; import * as React from "react"; import { cn } from "@/lib/utils"; export type DayStatus = "up" | "degraded" | "down" | "none"; export interface UptimeDay { date: string; status: DayStatus; /** e.g. "12 min partial outage" */ note?: string; } const color: Record<DayStatus, string> = { up: "bg-emerald-500", degraded: "bg-amber-500", down: "bg-destructive", none: "bg-muted", }; /** A row of daily bars with the uptime percentage, as on status pages. */ export function UptimeBar({ name, days, className }: { name: string; days: UptimeDay[]; className?: string }) { const [hover, setHover] = React.useState<number | null>(null); const tracked = days.filter((d) => d.status !== "none"); const pct = tracked.length ? (tracked.filter((d) => d.status === "up").length + tracked.filter((d) => d.status === "degraded").length * 0.5) / tracked.length : 1; const worst = days.some((d) => d.status === "down") ? "down" : days.some((d) => d.status === "degraded") ? "degraded" : "up"; const current = days[days.length - 1]?.status ?? "up"; return ( <div className={cn("space-y-2", className)}> <div className="flex items-center justify-between text-sm"> <span className="flex items-center gap-2 font-medium"> <span className={cn("size-2 rounded-full", color[current === "none" ? "up" : current])} /> {name} </span> <span className={cn("tabular-nums", worst === "up" ? "text-emerald-600 dark:text-emerald-400" : "text-muted-foreground")}>{(pct * 100).toFixed(2)}% uptime</span> </div> <div className="relative flex h-8 gap-[2px]" onPointerLeave={() => setHover(null)}> {days.map((d, i) => ( <span key={d.date} onPointerEnter={() => setHover(i)} aria-label={`${d.date}: ${d.status}${d.note ? `, ${d.note}` : ""}`} role="img" className={cn("flex-1 rounded-[2px] transition-opacity", color[d.status], hover !== null && hover !== i && "opacity-50")} /> ))} {hover !== null && ( <div className="pointer-events-none absolute bottom-full z-10 mb-2 -translate-x-1/2 whitespace-nowrap rounded-md border border-border bg-popover px-2.5 py-1.5 text-xs shadow-elev-2" style={{ left: `${((hover + 0.5) / days.length) * 100}%` }}> <p className="font-medium">{days[hover].date}</p> <p className="text-muted-foreground">{days[hover].note ?? (days[hover].status === "up" ? "No incidents" : days[hover].status === "none" ? "No data" : days[hover].status)}</p> </div> )} </div> <div className="flex justify-between text-[11px] text-muted-foreground"> <span>{days.length} days ago</span> <span>Today</span> </div> </div> ); }
Usage
Import it from @/components/ui/uptime-bar after installing.
example.tsx
import { UptimeBar } from "@/components/ui/uptime-bar";
export function Api({ days }: { days: { date: string; status: "up" | "degraded" | "down" | "none" }[] }) {
return <UptimeBar name="API" days={days} />;
}API reference
UptimeBar
One bar per day with an uptime percentage.
name
string
Service name.
days
{ date; status; note? }[]
status: up, degraded, down or none.
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | – | Service name. |
| days | { date; status; note? }[] | – | status: up, degraded, down or none. |
Accessibility
- role="img" with a summary; each bar has a label with date, status and note.
Motion
- Hovering a bar dims the others.
Responsive behavior
- Bars shrink to fit; show fewer days on phones.
Performance
- One element per day.
Notes for AI
- Use none for days before monitoring started.
This page as Markdown, for assistants and coding agents:
/components/uptime-bar/markdownThe full library index for assistants is at /llms.txt.
Related
Lode·229 doc pages·llms.txt