Connection banner
FreeSays when the app lost its connection and what that means, counts down to the next try, and confirms when it is back.
pnpm dlx shadcn@latest add https://caliperui.site/r/connection-banner.jsonWhen to use #
Use it for
- Apps that keep working offline or queue changes.
- Realtime tools where a dropped connection loses updates.
Skip it when
- Static sites; the browser already says so.
Installation #
pnpm dlx shadcn@latest add https://caliperui.site/r/connection-banner.json
Adds its 3 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage #
This is the code behind the preview above.
import { useRef, useState } from "react" import { Button } from "@/components/ui/button" import { ConnectionBanner } from "@/components/ui/connection-banner" const wait = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)); export function ConnectionBannerDemo() { const [online, setOnline] = useState(true); const tries = useRef(0); return ( <div className="grid w-full max-w-md gap-3"> <ConnectionBanner online={online} onRetry={async () => { await wait(700); tries.current += 1; // The second try succeeds, as a real reconnect would. if (tries.current >= 2) { tries.current = 0; setOnline(true); return true; } return false; }} /> <Button size="sm" variant="secondary" className="w-fit" onClick={() => setOnline((value) => !value)}>{online ? "Go offline" : "Come back online"}</Button> </div> ); }
API reference #
ConnectionBanner
component
Accessibility #
It exposes status semantics, with aria-hidden kept in step with state. Changes that matter are announced through a live region.
No custom key handling; Tab and the native activation keys do the work.
Motion #
Transitions use the shared duration and easing tokens. Under prefers-reduced-motion those tokens collapse to instant and travel distances go to zero, so state changes still happen without movement.