Skip to content

Realtime Components

Overview

Katalyst provides components for displaying realtime data and connection status:

  • ConnectionStatus — Shows live/disconnected indicator
  • LiveCounter — Animated counter for realtime metrics
  • RealtimeDevSettings — Developer settings for mode switching

These components are designed to work with Katalyst's realtime primitives.


ConnectionStatus

Purpose

Displays the current realtime connection status with a pulsing indicator.

Basic usage

tsx
import { ConnectionStatus } from '@/shared/ui/components/realtime'
import { useRealtimeChannel } from '@/shared/infrastructure/realtime'

export function Header() {
  const { isConnected } = useRealtimeChannel({
    path: '/ws/app/realtime',
    channel: 'status',
  })

  return (
    <header>
      <ConnectionStatus
        isConnected={isConnected}
        mode="websocket"
        showLabel
      />
    </header>
  )
}

Props

PropTypeDefaultDescription
isConnectedbooleanRequiredConnection state
mode'websocket' | 'polling''websocket'Connection mode
showModebooleantrueShow WS/Poll indicator
showLabelbooleantrueShow text label
labels{ connected?, connecting?, disconnected? }Default labelsCustom labels
size'sm' | 'md' | 'lg''md'Size variant
classNamestring-Additional class

Visual states

  • Connected: Green pulsing dot with "Live" label
  • Connecting/Disconnected: Yellow static dot with status label

LiveCounter

Purpose

Displays an animated counter that smoothly transitions between values, ideal for realtime metrics.

Basic usage

tsx
import { LiveCounter } from '@/shared/ui/components/realtime'
import { useRealtimeCounter } from '@/shared/infrastructure/realtime'

export function ActiveUsersWidget() {
  const { count, previousCount, trend } = useRealtimeCounter({
    path: '/ws/metrics/realtime',
    channel: 'active-users',
  })

  return (
    <LiveCounter
      value={count}
      previousValue={previousCount}
      trend={trend}
      suffix=" users"
    />
  )
}

Props

PropTypeDefaultDescription
valuenumber | nullRequiredCurrent value
previousValuenumber | null-Start value for animation
trend'up' | 'down' | 'stable''stable'Trend direction
durationnumber1Animation duration (seconds)
decimalsnumber0Decimal places
prefixstring''Text before number
suffixstring''Text after number
separatorstring','Thousands separator
size'sm' | 'md' | 'lg' | 'xl''lg'Size variant
showTrendbooleantrueShow trend indicator
trendColors{ up?, down?, stable? }Default colorsCustom trend colors
classNamestring-Additional class

Example with formatting

tsx
<LiveCounter
  value={1234567}
  prefix="$"
  decimals={2}
  separator=","
  trend="up"
  size="xl"
/>
// Displays: $1,234,567.00 with up arrow

RealtimeDevSettings

Purpose

Developer settings dropdown for switching between polling and WebSocket modes. Useful during development or for users who need to force a specific mode.

Basic usage

tsx
import { RealtimeDevSettings } from '@/shared/ui/components/realtime'

export function DashboardHeader() {
  return (
    <header>
      <h1>Dashboard</h1>
      <RealtimeDevSettings />
    </header>
  )
}

Props

PropTypeDefaultDescription
classNamestring-Additional class

Usage with realtime data

These components are designed to work with Katalyst's realtime infrastructure:

tsx
import { useRealtimeChannel, useRealtimeMode } from '@/shared/infrastructure/realtime'
import { ConnectionStatus, LiveCounter } from '@/shared/ui/components/realtime'

export function RealtimeDashboard() {
  const { mode } = useRealtimeMode()
  const { isConnected, lastMessage } = useRealtimeChannel<{ count: number }>({
    path: '/ws/metrics/realtime',
    channel: 'active-users',
  })

  return (
    <div>
      <ConnectionStatus isConnected={isConnected} mode={mode} />
      <LiveCounter
        value={lastMessage?.data.count ?? null}
        trend="stable"
      />
    </div>
  )
}

Notes

  • LiveCounter uses react-countup for smooth animations
  • ConnectionStatus uses CSS animations for the pulsing effect
  • Both components support dark mode through Tailwind classes