No.244 · AI & Chat
Context Meter
How full the model's context window is, and with what: one bar split by instructions, files, conversation and tools, warning near the limit and squeezing on compact.
The prompt
Written for the variant you picked above: Paper
Build a context-window meter for an AI chat. One 14px pill track shows the window (200k tokens) with segments for what's using it — Instructions, Files, Conversation, Tool results — each in a fixed series colour from a colour-blind-checked palette, separated by 2px gaps, widths animating (650ms, ease-out) whenever they change. A thin tick marks 90%. Above it: the used total as a large tabular number over the limit, and a percentage that turns amber past 75% and red past 90%, where the track also gets a slow pulsing red ring. Hovering a segment (or its legend row) dims the others and the hint line explains it ("Files: 38.4k tokens (34% of what's used)"); otherwise the hint describes the state ("Plenty of room", "Getting full…", "Almost full — compact to keep going"). Buttons add a file or a long reply; Compact squeezes the bar (a quick vertical squash with desaturation) and replaces the conversation with a summary about 8% of its size and trims tool results. The track is a role="meter" with a full text value. Selected variant — Paper (paper): Apply the paper theme. Where the brief above gives no colour values for it, choose a restrained paper palette with text at 4.5:1 contrast or better. Keep the geometry, states and motion described above unchanged. This selection takes precedence over references to other themes or options in the general brief. Implement this selected appearance; do not add a variant picker or alternative appearances unless requested. Implementation requirements: Use React and TypeScript. Keep the component self-contained, with uniquely scoped CSS and no animation libraries. Include required imports, styles and font setup in the result. Interaction: Hover segments or legend rows to see what's using the context; add a file or a long reply, then Compact to summarise. Motion: Segment widths 650ms; compact squash 650ms; warning ring pulses every 1.6s past 90%. Accessibility: The bar is role="meter" with aria-valuenow/max and a valuetext listing every segment; the hint is a polite live region; the legend repeats every colour with its label. Reduced motion removes the transitions and pulse. Responsive behavior: A card up to about 40rem wide that fills narrower screens; dense rows and side columns stack on phones. Touch: Everything is tap-driven; hover hints have tap or focus equivalents. Preserve keyboard access, visible focus and reduced-motion behavior. Keep fictional demo data and simulated service calls in a separate usage example; expose callbacks for real actions and recover from rejected requests. Keep usage-example links inside the demo: use local buttons or prevent navigation. Demonstration links must not navigate to Vitrine routes or open other pages; preserve real URL support in the reusable component itself. Verify the result at narrow and wide viewport sizes, with keyboard input and reduced motion enabled.
Notes
- Interaction
- Hover segments or legend rows to see what's using the context; add a file or a long reply, then Compact to summarise.
- Motion
- Segment widths 650ms; compact squash 650ms; warning ring pulses every 1.6s past 90%.
- Accessibility
- The bar is role="meter" with aria-valuenow/max and a valuetext listing every segment; the hint is a polite live region; the legend repeats every colour with its label. Reduced motion removes the transitions and pulse.
- Responsive
- A card up to about 40rem wide that fills narrower screens; dense rows and side columns stack on phones.
- On touch
- Everything is tap-driven; hover hints have tap or focus equivalents.