Componentfeedback0.72 KB gzipZero dependencies

Connection Status

Connection badge with pinging dot and optional latency readout.

Preview

Live Preview
45ms

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add connection-status

Or install the full npm package:

npm install bigbullui
import { ConnectionStatus } from "@/components/ui/connection-status";

<ConnectionStatus />

Usage guidance

Use Connection Status when a ticket stub surface needs Connection badge with pinging dot and optional latency readout. Keep props minimal and prefer composition with sibling stubs.

Avoid Connection Status for long form flows or dense data grids where a dedicated layout block fits better.

Source code

connection-status.tsx

Zero dependencies (only React + utils). Copy and paste directly into your project:

"use client";

import * as React from "react";
import { cn } from "./lib/utils";

export interface ConnectionStatusProps extends React.HTMLAttributes<HTMLSpanElement> {
  latencyMs?: number;
  /** Connection state; simulated or detects navigator.onLine */
  online?: boolean;
}

/** Network status badge: live ping pulse indicator + latency. */
export function ConnectionStatus({ latencyMs, online = true, className, ...props }: ConnectionStatusProps) {
  const tone = !online ? "text-destructive" : latencyMs === undefined ? "text-success" : latencyMs < 100 ? "text-success" : latencyMs < 300 ? "text-warning" : "text-destructive";

  return (
    <span
      className={cn("inline-flex items-center gap-1.5 rounded-full border border-border bg-card px-2 py-0.5 font-mono text-[10px] uppercase tracking-wider", tone, className)}
      role="status"
      {...props}
    >
      <style>{`@keyframes csPing { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(2.2); opacity: 0; } }`}</style>
      <span className="relative flex size-1.5">
        {online && <span className="absolute inline-flex size-full rounded-full bg-current" style={{ animation: "csPing 1.6s ease-out infinite" }} aria-hidden="true" />}
        <span className={cn("relative inline-flex size-1.5 rounded-full", online ? "bg-current" : "bg-current")} aria-hidden="true" />
      </span>
      {!online ? "Offline" : latencyMs !== undefined ? `${latencyMs}ms` : "Online"}
    </span>
  );
}

Props

PropTypeDescription
latencyMsnumber
onlinebooleanConnection status; simulates navigator.onLine if omitted