shadcn.io is not affiliated with official shadcn/ui
Connectivity Live Banner Block for React
A connection top bar for a collaborative editor, wired to the browser's online and offline events: Connected, then "You're offline" with a Retry now button and a tinted strip, then "Back online" for a few seconds.
Installation
Overview
A connection top bar for React with Base UI, for an app that keeps working when the network doesn't. One centred line under the page's top rule starts on "Connected to realtime sync" with a green dot. When the browser fires its offline event the line becomes "You're offline, changes are saved on this device", the dot turns to the warning colour, a faint tint fills the strip, and a Retry now button appears inline; when online fires it says "Back online, your changes are synced" for four seconds and settles on Connected again. All four lines share one grid cell, so the bar never changes height, and a polite status line that is in the page from the start announces each change. It's built from Guides and Status, with CSS transitions and your theme's tokens for every colour. For editors, dashboards and any surface with realtime sync.
FAQ
How do I see the offline state?
The preview shows the connected line, because the browser is online. Open your browser's developer tools, go to the Network panel and switch throttling to Offline (or use the device toolbar's offline option): the bar changes at once. Switch it back and the bar says "Back online" for four seconds. The same works in an automated test by setting the browser context offline.
What does it actually listen to?
The offline and online events on window, plus navigator.onLine once after the first render, so a page opened while offline starts on the offline line. The listeners are removed when the block unmounts. The server always renders the connected line, and the browser corrects it after the first render, so the two never disagree.
What does Retry now do?
It shows "Checking your connection…" for about a second, then reads navigator.onLine once and settles on Back online or back on offline. That flag only says whether the device has a network, not whether your server answers. For a real check, replace the timer in the checking effect with a request to a small health endpoint and set the result from its answer.
What do screen readers hear?
A status line that is in the page from the start, visually hidden, gets its text when the state changes: "You're offline. Changes are saved on this device." and "Back online. Your changes are synced." Nothing is announced at load, and the Connected line is silent when it returns after Back online. The visible lines that aren't current are hidden from assistive technology and can't take focus.
Related
- Pro
Live Indicator Banner
Live statusA heartbeat callout for a monitoring tool: a framed status dot that sends out one ring on each poll, an all-systems-operational heading, a line with how long ago it checked and the p95 latency, and a status-page link.
- 1,248Pro
Data Sync Live Banner
Live statusA sync callout for a data warehouse: one run plays on load, a counter rolling up to 1,248 records over a thin progress bar, then "Warehouse synced" with a countdown to the next run.
- Pro
Saved Draft Top Bar Banner
Utility barsA top bar for a writing tool that reports its autosave with a green dot and a ticking time, and a Restore previous button that swaps in place to Restored with an Undo.
- Pro
Error Alert Banner
AlertsA failed-deploy callout for a deploy platform: a band with a failure icon, a heading naming the commit, a Shine Button to retry, and a framed excerpt that quotes the failing lines with the bad one marked.
- Pro
Top Bar Banner
Top barsA slim announcement strip for a writing app's release: one centred line with the version, the news and an underlined link, and a ghost button that folds the strip away.
- Pro
API Health Live Banner
Live statusA live-health callout for an API gateway: a green status dot, an all-operational heading, a sentence with the median response time and the one slow minute, a status-page link, and a framed figure of the last 30 minutes as slim latency bars.