Context Indicator
A compact ring that shows how much of the conversation context is used.
Context Indicator
Basic Usage
Context Indicator
Loading demo...
Interaction Contract
- The ratio is
usedTokens / maxTokens, clamped to0–1, so an over-count never draws past a full ring. - A
maxTokensof0or less is treated as a ratio of0— 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%) anddanger(> 95%). Style overrides can key off that attribute. - The default label uses compact counts:
1.2Mat a million or more,12.3Kat a thousand or more, otherwise a rounded integer. Aformatterreplaces that text entirely. titleis always "text (percentage)", so the percentage stays visible on hover even with a customformatter.- The root is
role="meter"witharia-valuemin/aria-valuemax/aria-valuenowkept in sync. The SVG isaria-hidden, and the accessible name comes fromlabel.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
usedTokens | number | — | Tokens consumed so far. Required. |
maxTokens | number | — | Size of the context window. Required; a value of 0 or less is treated as a ratio of 0. |
label | string | 'Context usage' | Accessible name, written to aria-label. |
formatter | (used: number, max: number) => string | — | Replaces the text beside the ring. Falls back to the built-in compact count when unset. |
Events
TxContextIndicator emits no component events.
Slots
| Name | Scope | Description |
|---|---|---|
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
formatterfor localized number formatting instead of wrapping the component in your own text, or the percentage intitlewill disagree with what is displayed. - Only prompt the user near the limit — from
warningupward. 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.