What it does
NetworkStatus renders a colored status dot with an optional pulsing ring and text label that reflect the browser's live connectivity. It subscribes to the window online and offline events via the shared useNetworkStatus hook and reads connection-quality metrics (effectiveType, downlink, rtt) from the Network Information API, bucketing them into fast, moderate, slow, or unknown. The dot and ring color derive from the live status by default, shifting automatically between online (green), slow (amber), and offline (red). Every value is also available through the onStatusChange callback and the render prop for fully custom UI.
Composition and API
The Network Status component subscribes to the window online and offline events and to the Network Information API change event, re-rendering whenever connectivity changes. It exposes an onStatusChange callback with a full snapshot (online, status, quality, effectiveType, downlink, rtt, saveData), a render prop for fully custom output, and a controlled online prop for SSR, demos, and tests. Color is derived from the live status by default but can be overridden with any appearance token.
Common use cases
Show a persistent online/offline badge in an app header or status bar so users always know their connectivity at a glance. Warn users on a slow connection (3G or below) before they start a large upload or download. Disable or queue network-dependent actions while the user is offline and resume them automatically when connectivity is restored. Surface effective connection type and downlink speed in diagnostics dashboards or developer tooling to help debug performance issues in low-bandwidth environments.
Accessibility
The root carries data-status and data-quality attributes for styling and assistive context, and a text label communicates the state to screen readers. The pulsing ring is purely decorative (aria-hidden) and respects prefers-reduced-motion. Avoid relying on color alone — keep the label visible so the state is conveyed without depending on the dot color.
Next.js integration notes
navigator.onLine and the Network Information API are browser-only. The component is SSR-safe: it renders optimistically as online on the server and during the first client render, then syncs to the real connection inside an effect to avoid hydration mismatches. The Network Information API (effectiveType, downlink) is Chromium-only, so connection-quality detail degrades gracefully where it is unavailable.
FAQ
Which browsers support connection-quality detection?
Online/offline detection via navigator.onLine works everywhere. The richer connection quality (effectiveType, downlink, rtt) comes from the Network Information API, which is currently Chromium-only. When it is unavailable the component still reports online/offline and simply omits the quality detail.
How do I render a fixed state for SSR or testing?
Pass the controlled online prop (online or online={false}). When set, live detection is disabled and the component renders that state deterministically, which is ideal for server rendering, Storybook, and unit tests.
Can I customize the colors and labels?
Yes. Override the label copy with the labels prop ({ online, offline, slow }), force any palette with the appearance prop, and theme the dot via the --zui-network-status-* CSS variables. By default the appearance is derived from the live status.