CwOfflineOverlay
Full-screen offline state with reconnect toast. For demo mode, toggle simulation to force the overlay.
let simulateOffline = $state(false);
<CwSwitch
label="Simulate offline"
bind:checked={simulateOffline}
/>
<CwOfflineOverlay
forceOffline={simulateOffline}
onRetry={() => (simulateOffline = false)}
/>
Documentation Upgrade
Start here
CwOfflineOverlay can either follow the browser network state automatically or be forced into offline mode for testing. It also shows a short reconnected toast when the connection comes back.
How to think about it
- Use real browser state in production Leave `forceOffline` undefined when you want the component to respond to actual `online` and `offline` browser events.
- Force the state in demos or tests Pass `true` or `false` to `forceOffline` when you need deterministic UI state.
- Decide what Retry should do If you do not pass `onRetry`, the component falls back to reloading the page.
Props and callbacks
| API | Type | Details |
|---|
forceOffline | boolean | undefined | Forces the offline state for demos or tests. Leave undefined to use real browser state. |
reconnectedDurationMs Default: 3000 | number | How long the "back online" toast stays visible. |
onRetry | () => void | Retry handler. Falls back to `window.location.reload()` when omitted. |
showRetryButton Default: true | boolean | Shows or hides the retry button. |
retryLabel Default: Try Again | string | Text displayed inside the retry button. |
Copy-paste examples
These snippets intentionally show the full public API surface the live demo relies on.
Test the overlay with a local toggle
This is the safest way to develop the offline UI.
<script lang="ts">
let simulateOffline = $state(false);
</script>
<CwSwitch label="Simulate offline" bind:checked={simulateOffline} />
<CwOfflineOverlay
forceOffline={simulateOffline}
onRetry={() => (simulateOffline = false)}
/>
Production usage with custom retry behavior
Leave `forceOffline` unset when the browser should drive the state.
<CwOfflineOverlay
reconnectedDurationMs={5000}
retryLabel="Reconnect now"
onRetry={() => refreshDashboardData()}
/>