Skip to content
kerfjsGitHub

ConnectionBanner

A full-width notice for when the connection drops, with Retry.

SourcePackage @kerf-js/veneer

Preview

tsx
import { state } from '@kerf-js/core'import {  Button,  ConnectionBanner,  ConnectionPill,  Row,  Stack} from '@kerf-js/veneer'export function Offline() {  const status = state<    'live' | 'reconnecting' | 'offline'  >('live')  const retry = async () => {    status.value = 'reconnecting'    await pause(1500)    status.value = 'live'  }  return (    <Stack gap="related">      <ConnectionBanner        state={status}        onRetry={() => void retry()}      />      <Row        gap="related"        justify="between"      >        <ConnectionPill state={status} />        <Button          emphasis="outline"          tone="neutral"          size="sm"          onClick={() =>            (status.value =              status.value === 'offline'                ? 'live'                : 'offline')          }        >          {status.value === 'offline'            ? 'Reconnect'            : 'Lose the connection'}        </Button>      </Row>    </Stack>  )}const pause = (ms: number) =>  new Promise((done) => {    setTimeout(done, ms)  })

Installation

npm install @kerf-js/veneer

Usage

tsx
import { ConnectionBanner } from '@kerf-js/veneer'

Accessibility

  • It stays quiet for assistive technology: the pill does the announcing.

API Reference

PropTypeDefaultDescription
stateStatus—The status: a string, a state or a getter.
delaynumber3000How long to wait while reconnecting, in ms.
offlineunknown"You're offline. Showing what was saved; new notifications will arrive when you reconnect."The offline text.
reconnectingunknown'Reconnecting… changes you make are queued.'The reconnecting text.
EventTypeDefaultDescription
onRetry(() => void)—Adds Retry now.

RelatedConnection pillAlert