Components/Context Indicator

Context Indicator

A compact ring that shows how much of the conversation context is used.

VerifiedSince 0.3.9

Context Indicator

Basic Usage

Context Indicator

Loading demo...

Interaction Contract

  • The ratio is usedTokens / maxTokens, clamped to 01, so an over-count never draws past a full ring.
  • A maxTokens of 0 or less is treated as a ratio of 0 — no divide-by-zero and no thrown error.
  • Three colour levels are derived from the ratio and exposed on data-level: ok (≤ 80%), warning (> 80%) and danger (> 95%). Style overrides can key off that attribute.
  • The default label uses compact counts: 1.2M at a million or more, 12.3K at a thousand or more, otherwise a rounded integer. A formatter replaces that text entirely.
  • title is always "text (percentage)", so the percentage stays visible on hover even with a custom formatter.
  • The root is role="meter" with aria-valuemin / aria-valuemax / aria-valuenow kept in sync. The SVG is aria-hidden, and the accessible name comes from label.

API

Props

NameTypeDefaultDescription
usedTokensnumberTokens consumed so far. Required.
maxTokensnumberSize of the context window. Required; a value of 0 or less is treated as a ratio of 0.
labelstring'Context usage'Accessible name, written to aria-label.
formatter(used: number, max: number) => stringReplaces the text beside the ring. Falls back to the built-in compact count when unset.

Events

TxContextIndicator emits no component events.

Slots

NameScopeDescription
detail{ ratio: number, used: number, max: number }Appended after the text — a place for a percentage, a remaining count, or a "clear context" affordance.

Best Practices

  • Pass the model's real window size rather than a hardcoded constant, so the indicator does not lie after a model switch.
  • Use formatter for localized number formatting instead of wrapping the component in your own text, or the percentage in title will disagree with what is displayed.
  • Only prompt the user near the limit — from warning upward. Below that this is background information and should not compete for attention.
  • If you place it inside a clickable region, give that region its own accessible name: role="meter" conveys nothing about being actionable.