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

ConnectionStatus

Purpose

Displays the current realtime connection status with a pulsing indicator.

Basic usage

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

export function Header() {
  const { isConnected, mode } = useRealtimeConnection()

  return (
    <header>
      <ConnectionStatus
        isConnected={isConnected}
        mode={mode}
        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'

export function ActiveUsersWidget() {
  const { current, previous, trend } = useActiveUsers()

  return (
    <LiveCounter
      value={current}
      previousValue={previous}
      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

Usage with realtime data

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

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

export function RealtimeDashboard() {
  const { value, previousValue, trend, isConnected, mode } = useRealtimeMetric('activeUsers')

  return (
    <div>
      <ConnectionStatus isConnected={isConnected} mode={mode} />
      <LiveCounter
        value={value}
        previousValue={previousValue}
        trend={trend}
      />
    </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