Skip to main content

Context

A token window usage gauge with a spring-animated trigger ring, RollingDigits readouts, portaled floating breakdown card, segmented bar, and cost estimation.

Customize

Open delay (ms)180
Close delay (ms)160
Speed0.45
Blur reveal (px)8

Installation

npx shadcn@latest add @kinetic/context

Usage

Compose Context, ContextTrigger, ContextContent, ContextContentHeader, ContextContentBody, and ContextContentFooter.

import {
  Context,
  ContextContent,
  ContextContentBody,
  ContextContentFooter,
  ContextContentHeader,
  ContextTrigger,
} from "@/components/kinetic/ui/context";

export function TokenWindowMeter() {
  return (
    <Context
      usedTokens={48200}
      maxTokens={400000}
      modelId="gpt-6.2-astra"
      usage={{
        inputTokens: 32000,
        outputTokens: 6400,
        reasoningTokens: 4200,
        cachedInputTokens: 5600,
      }}
    >
      <ContextTrigger />
      <ContextContent>
        <ContextContentHeader />
        <ContextContentBody />
        <ContextContentFooter />
      </ContextContent>
    </Context>
  );
}

Token breakdown and cost estimation

ContextContentHeader renders a spring-morphing segmented progress bar across inputTokens, outputTokens, reasoningTokens, and cachedInputTokens. ContextContentBody automatically mounts ContextInputUsage, ContextOutputUsage, ContextReasoningUsage, and ContextCacheUsage, while ContextContentFooter estimates USD cost when modelId matches a built-in rate entry or receives an explicit cost.

import {
  Context,
  ContextCacheUsage,
  ContextContent,
  ContextContentBody,
  ContextContentFooter,
  ContextContentHeader,
  ContextInputUsage,
  ContextOutputUsage,
  ContextTrigger,
  type ContextUsageData,
} from "@/components/kinetic/ui/context";

interface CustomContextMeterProps {
  readonly usedTokens: number;
  readonly maxTokens: number;
  readonly usage: ContextUsageData;
  readonly compact?: boolean;
}

export function CustomContextMeter({
  usedTokens,
  maxTokens,
  usage,
  compact = true,
}: CustomContextMeterProps) {
  return (
    <Context usedTokens={usedTokens} maxTokens={maxTokens} usage={usage} compact={compact}>
      <ContextTrigger />
      <ContextContent side="top" align="end">
        <ContextContentHeader />
        <ContextContentBody>
          <ContextInputUsage label="Prompt" />
          <ContextOutputUsage label="Completion" />
          <ContextCacheUsage label="Cached" />
        </ContextContentBody>
        <ContextContentFooter cost={0.042} />
      </ContextContent>
    </Context>
  );
}

Motion preferences

Context coordinates speed={0.45}, blurPx={8}, openDelay={180}, and closeDelay={160} across the circular gauge spring, segmented bar transitions, RollingDigits wheels, and spatial popover entrance. Reduced motion updates arcs, bars, and readouts immediately.

API Reference

Context

Zero-dependency context meter controller coordinating hover-intent delays, spring gauge state, and shared motion preferences.

PropTypeDefaultDescription
usedTokens / maxTokens / usage / modelId / compactnumber / number / ContextUsageData / string / boolean- / - / undefined / undefined / falseToken usage inputs, model rate key for USD estimation, and compact number notation.
open / defaultOpen / onOpenChangeboolean / boolean / (open: boolean) => voidfalseControlled or initial popover state.
openDelay / closeDelaynumber / number180 / 160Pointer hover open and close intent delays in milliseconds.
animated / speed / blurPxboolean / number / numbertrue / 0.45 / 8Toggles motion, scales spring/digit timing, and sets spatial reveal blur radius (px).

ContextTrigger / ContextContent

Spring-arc circular gauge trigger (with optional asChild) and portaled viewport-aware spatial popover.

PropTypeDefaultDescription
asChild (ContextTrigger)booleanfalseMerges hover/focus/click trigger props onto a custom child element via Slot.
side / align / sideOffset (ContextContent)"top" | "bottom" | "left" | "right" / "start" | "center" | "end" / number"bottom" / "center" / 8Preferred popover placement, alignment, and pixel gap from ContextTrigger.
speed / blurPx (ContextContent)number / numberinheritedOptional overrides for spatial popover entrance speed and blur.

ContextContentHeader / ContextContentBody / ContextContentFooter / ContextInputUsage / ContextOutputUsage / ContextReasoningUsage / ContextCacheUsage

Morphing multi-segment progress bar, RollingDigits readouts, and per-category token/cost breakdown rows.

PropTypeDefaultDescription
showBar (ContextContentHeader)booleantrueShows or hides the spring-morphing segmented usage bar.
cost (ContextContentFooter)number-Explicit USD total overriding computed model rates.
tokens / cost / label (Usage rows)number / number / React.ReactNode-Row-level overrides for token counts, cost, and label.