Calm motion: animations on this site only fade, with no movement
ConnectionStatus
Online, offline, or reconnecting
A small line that tells people when the app lost its connection and when it came back. Use it in a live app, for example one on a Phoenix socket, where work stops without a connection. For a message that people must act on, use an alert or a banner instead.
Basic
Online
- The component listens to the browser's
onlineandofflineevents by itself.stateadds your socket's state:online,connecting, oroffline. When the browser is offline, that wins overstate. - While the connection is good, the line is empty. After a problem, "Back online" shows for four seconds, and then the line is empty again. Set
alwaysto show the online state too, for example in a status bar. - The line is a status, so a screen reader speaks each change once, without moving focus. The status stays in the page while it is empty, so the first problem is spoken too.
- The dot is green, amber, or red. The words carry the same meaning, so color is never the only signal. The amber dot pulses while the app reconnects, and it stops under reduced motion.
- The first render assumes online, because the server cannot know. The browser's real state is read after mount.
- Change the words with
labelsor a label pack:online,back,connecting, andoffline.
Usage
ts
import { BlessConnectionStatus } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
state | "online" | "connecting" | "offline" | — | your socket's state; the browser's own offline state wins over it |
always | boolean | — | show the online state too, not only a problem and the recovery |
labels | Partial<{ online: string; back: string; connecting: string; offline: string; }> | — |