Skip to main content

Delta Number

Dashboard KPI counter wrapping spring-driven rolling digits with floating rise-and-fade delta chips colored by positive or negative change.

1,248

Customize

Rise (px)22
Chip duration (ms)1150

Installation

npx shadcn@latest add @kinetic/delta-number

Usage

Pass a numeric value and update it as live data arrives. DeltaNumber wraps RollingDigits to roll the main readout on a spring while spawning floating delta chips (+12, -3) that rise and fade above or beside the metric. Up to three concurrent chips can animate at once when updates arrive rapidly.

import { DeltaNumber } from "@/components/kinetic/ui/delta-number";

interface ActiveUsersKpiProps {
  readonly count: number;
}

export function ActiveUsersKpi({ count }: ActiveUsersKpiProps) {
  return (
    <DeltaNumber
      as="p"
      value={count}
      className="text-3xl font-semibold tracking-tight"
    />
  );
}

Sentiment colors, placement, and formatting

By default, positive deltas highlight in emerald and negative deltas highlight in destructive red, always paired with an explicit + or - sign (showSign defaults to true) so direction never depends on color alone. For metrics where lower values are better, such as latency or error rate, enable invertColors so decreases read as favorable and increases as unfavorable.

Position chips with placement ("top-right", "right", or "top"), tune travel and duration with risePx (default 22, clamped 6 to 48) and chipDurationMs (default 1150, clamped 400 to 3000), and customize formatting with format, formatDelta, locale, prefix, and suffix.

import { DeltaNumber } from "@/components/kinetic/ui/delta-number";

interface LatencyReadoutProps {
  readonly latencyMs: number;
}

export function LatencyReadout({ latencyMs }: LatencyReadoutProps) {
  return (
    <DeltaNumber
      value={latencyMs}
      suffix=" ms"
      invertColors
      placement="right"
      chipDurationMs={1200}
      risePx={18}
      format={{ maximumFractionDigits: 1 }}
      formatDelta={(delta) => `${delta > 0 ? "+" : ""}${delta.toFixed(1)} ms`}
      className="text-2xl font-semibold"
    />
  );
}

Imperative delta chips

Attach a DeltaNumberHandle ref and call flashDelta(delta) to emit a floating delta chip on demand without changing value.

import { useRef } from "react";
import {
  DeltaNumber,
  type DeltaNumberHandle,
} from "@/components/kinetic/ui/delta-number";

interface OrderFeedMetricProps {
  readonly revenue: number;
}

export function OrderFeedMetric({ revenue }: OrderFeedMetricProps) {
  const ref = useRef<DeltaNumberHandle>(null);

  return (
    <div className="space-y-3">
      <DeltaNumber
        ref={ref}
        value={revenue}
        format={{ style: "currency", currency: "USD" }}
        className="text-3xl font-semibold"
      />
      <button type="button" onClick={() => ref.current?.flashDelta(45)}>
        Preview +$45
      </button>
    </div>
  );
}

Motion preferences

chipDurationMs, blurPx (default 2.4, clamped at 8px max), and speed scale with the global Kinetic tempo. Under reduced motion, RollingDigits snaps immediately without blur, and floating chips use a short opacity-only fade (capped at 650ms) with no vertical rise or scale motion. Transient chips stay aria-hidden="true" so assistive technology is not flooded; the current formatted value remains accessible in .sr-only, with optional announceChanges enabling role="status".

API Reference

DeltaNumber

Dashboard counter built on RollingDigits that spawns rise-and-fade delta chips on value changes.

PropTypeDefaultDescription
valuenumber-Current numeric metric value.
formatIntl.NumberFormatOptions | ((value: number) => string)-Formatter for the main readout.
formatDelta(delta: number) => string-Custom formatter for floating delta chips.
placement"top-right" | "right" | "top""top-right"Anchor position where delta chips spawn.
chipDurationMsnumber1150Chip lifetime before fading out (400 to 3000ms).
risePxnumber22Upward travel distance in pixels (6 to 48).
invertColorsbooleanfalseSwaps positive and negative color semantics (useful for latency or error counts).
showSignbooleantruePrefixes positive values with + for non-color distinction.