Context
A token window usage gauge with a spring-animated trigger ring, RollingDigits readouts, portaled floating breakdown card, segmented bar, and cost estimation.
Customize
Installation
npx shadcn@latest add @kinetic/contextUsage
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.
| Prop | Type | Default | Description |
|---|---|---|---|
usedTokens / maxTokens / usage / modelId / compact | number / number / ContextUsageData / string / boolean | - / - / undefined / undefined / false | Token usage inputs, model rate key for USD estimation, and compact number notation. |
open / defaultOpen / onOpenChange | boolean / boolean / (open: boolean) => void | false | Controlled or initial popover state. |
openDelay / closeDelay | number / number | 180 / 160 | Pointer hover open and close intent delays in milliseconds. |
animated / speed / blurPx | boolean / number / number | true / 0.45 / 8 | Toggles 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.
| Prop | Type | Default | Description |
|---|---|---|---|
asChild (ContextTrigger) | boolean | false | Merges 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" / 8 | Preferred popover placement, alignment, and pixel gap from ContextTrigger. |
speed / blurPx (ContextContent) | number / number | inherited | Optional 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.
| Prop | Type | Default | Description |
|---|---|---|---|
showBar (ContextContentHeader) | boolean | true | Shows 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. |