Skip to main content
Clever Ops

Latency Heartbeat

A tiny inline streaming-health signal, an SVG heartbeat trace pulsing beside a mono millisecond readout, with an honest destructive shift past a threshold; parks flat when idle.

Preview & code

Loading Latency Heartbeat preview

Installation

pnpm dlx shadcn@latest add @cleverui/latency-heartbeat

Requires the @cleverui registry in your components.json, a one-off, two-line setup.

Usage

tsx
import { LatencyHeartbeat } from '@/components/ui/latency-heartbeat'
Exampletsx
'use client'

import { useEffect, useState } from 'react'
import { useReducedMotion } from 'motion/react'
import { LatencyHeartbeat } from '@/components/ui/latency-heartbeat'

/** Deterministic Meridian streaming run, settle, degrade past warnAt, recover. */
type Sample = { ms: number; streaming: boolean; holdMs: number }

const SEQUENCE: Sample[] = [
  { ms: 48, streaming: true, holdMs: 900 },
  { ms: 62, streaming: true, holdMs: 800 },
  { ms: 91, streaming: true, holdMs: 800 },
  { ms: 118, streaming: true, holdMs: 900 },
  { ms: 340, streaming: true, holdMs: 1000 },
  { ms: 720, streaming: true, holdMs: 900 },
  { ms: 1240, streaming: true, holdMs: 1200 },
  { ms: 1840, streaming: true, holdMs: 1400 },
  { ms: 980, streaming: true, holdMs: 1000 },
  { ms: 410, streaming: true, holdMs: 900 },
  { ms: 156, streaming: true, holdMs: 1000 },
  { ms: 88, streaming: true, holdMs: 1200 },
  { ms: 72, streaming: false, holdMs: 2000 },
]

export default function LatencyHeartbeatDemo() {
  const reduced = useReducedMotion()
  const [index, setIndex] = useState(0)
  const sample = SEQUENCE[index] ?? SEQUENCE[0]!

  useEffect(() => {
    if (reduced) {
      // composed mid-stream frame under reduced motion
      setIndex(3)
      return
    }
    const id = window.setTimeout(() => {
      setIndex((i) => (i + 1) % SEQUENCE.length)
    }, sample.holdMs)
    return () => window.clearTimeout(id)
  }, [index, sample.holdMs, reduced])

  const frame = reduced
    ? { ms: 118, streaming: true }
    : { ms: sample.ms, streaming: sample.streaming }

  return (
    <div className="mx-auto flex min-h-[280px] w-full max-w-md flex-col justify-center px-4 py-16 sm:px-6">
      <div className="overflow-hidden rounded-2xl border border-border/60 bg-card">
        <div className="border-b border-border/60 px-4 py-3 sm:px-5">
          <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground sm:text-xs">
            meridian-ops · stream footer
          </p>
        </div>
        <div className="space-y-4 px-4 py-6 sm:px-5">
          <p className="text-sm leading-relaxed text-foreground">
            {frame.streaming
              ? 'Reconciling Acme Logistics charge against Xero invoice inv_2026_03_8841…'
              : 'Stream settled, refund proposal ready for review.'}
          </p>
          <div className="flex items-center justify-between gap-3 border-t border-border/60 pt-3">
            <LatencyHeartbeat
              ms={frame.ms}
              streaming={frame.streaming}
              warnAt={1000}
              label="latency"
            />
            <span className="shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground">
              gpt-4.1-mini
            </span>
          </div>
        </div>
      </div>
    </div>
  )
}

API reference

LatencyHeartbeat accepts the following props.

PropTypeDefaultDescription
ms*numberlatest latency sample, fully prop-driven, the component measures nothing
streamingbooleanfalsetrue while tokens flow; drives the pulse travel, false parks the trace flat
warnAtnumber1000ms at which the trace and readout shift to destructive with a mono 'slow' word
labelstring'latency'mono micro-label before the trace

…plus everything from Omit< React.HTMLAttributes<HTMLDivElement>, 'onDrag' | 'onDragStart' | 'onDragEnd' | 'onAnimationStart' >: className, event handlers, aria attributes and the rest pass straight through.

Frequently asked questions

How do I install the Latency Heartbeat component?

Register the @cleverui registry in your components.json ("@cleverui": "https://cleverops.com.au/r/{name}.json"), then run `npx shadcn@latest add @cleverui/latency-heartbeat`. The shadcn CLI copies the source into your project, you own the code from that point. You can also copy the source directly from this page.

What dependencies does Latency Heartbeat require?

Latency Heartbeat uses motion on top of React and Tailwind CSS. You don't need to install it manually, the shadcn CLI resolves and installs npm dependencies automatically when you add the component.

Can I theme Latency Heartbeat to match my brand?

Yes. The component is styled entirely with Tailwind utilities over standard design tokens (primary, background, muted, border), so it inherits your existing shadcn/ui theme automatically. Change your CSS variables and the component follows, no source edits needed for palette, radius, or fonts.

Want this built for you?

CleverUI is built by the Clever Ops web team. If you'd rather ship a hand-coded, fast, custom website than assemble one, we build them for Australian businesses every week.

Explore web development services