Skip to content
kerfjsGitHub

ConnBanner

A banner for offline, reconnecting, or a new version of the app.

SourcePackage @kerf-js/veneer

Preview

tsx
import { state } from '@kerf-js/core'import {  Button,  ConnBanner,  Stack} from '@kerf-js/veneer'export function Offline() {  const online = state(false)  const reconnect = async () => {    await wait(800)    online.value = true  }  return (    <Stack gap="related">      <ConnBanner        online={online.value}        retryIn={4}        changes={3}        onRetry={() => void reconnect()}      />      <Button        size="sm"        emphasis="outline"        tone="neutral"        onClick={() => (online.value = !online.value)}      >        {online.value ? 'Go offline' : 'Come back online'}      </Button>    </Stack>  )}const wait = (ms: number) =>  new Promise((done) => {    setTimeout(done, ms)  })

Installation

npm install @kerf-js/veneer

Usage

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

A new version

Set stale when a new build is out, and onReload and onLater handle the two choices.

tsx
import { state } from '@kerf-js/core'import { ConnBanner, Stack, Text } from '@kerf-js/veneer'export function NewVersion() {  const stale = state(true)  return (    <Stack gap="related">      <ConnBanner        stale={stale.value}        name="kerf"        onReload={() => (stale.value = false)}        onLater={() => (stale.value = false)}      />      <Text subtle>        {stale.value ? newBuildDescription : 'Dismissed.'}      </Text>    </Stack>  )}const newBuildDescription =  'A new build went out while this tab was open.'

Accessibility

  • This has no shortcuts of its own: controls inside it use Tab, Enter and Space as usual, and veneer's parts keep their roles and labels.

API Reference

PropTypeDefaultDescription
onlineLive<boolean>trueonline from @kerf-js/core/browser, its derived, or a boolean.
stateLive<string | undefined>—The .live state: live, connecting, reconnecting, offline.
staleLive<boolean | undefined>—Schema hash mismatch.
contractFailedbooleanfalseA mutation failed because the contract changed: the Banner turns caution.
retryInnumber—Seconds to the next try: Kerf's backoff.
changesnumber0Saved changes waiting to sync.
namestring'the app'"A new version of {name} is ready".
EventTypeDefaultDescription
onRetry(() => void)—Adds Retry now, to try before the backoff runs out.
onReload(() => void)—Save drafts, then reload.
onLater(() => void)—Later hides the stale banner for 30 minutes.

Parts

Every element carries a stable name, so you can style it from your own CSS: [data-scope="conn"] [data-part="msg"]

msg

RelatedSync indicatorRate limited