Hero Attention
A looping illustrative SVG that visualises attention as a soft lookup by similarity: five token nodes take turns as the query and beam weighted arcs to the rest, with a softmax-style bar chart below reading out the live weight distribution.
Customize
Hero
accent
false
Installation
npx shadcn@latest add https://craftbits.dev/r/hero-attention.jsonUsage
import { HeroAttention } from "@craft-bits/core";
<HeroAttention />Tint the accent by setting text colour on a parent, or pass an explicit colour:
<div className="text-cb-accent">
<HeroAttention />
</div>
<HeroAttention accentColor="#4A7BF7" />Understanding the component
- Single inline SVG. One
<svg viewBox="0 0 400 280">paints every frame. Passsizefor a fixed pixel width or let it fill its parent. - Three-phase loop. Tokens at index 0, 2, and 4 each become the query for ~2.2 seconds, emitting variable-width beams to the others. After a brief hold the cycle restarts. Phase plans, beam widths, and target weights are precomputed module constants.
- Springs from
@craft-bits/core/motion. Glow opacity usesSPRINGS.bouncy, scale usesSPRINGS.snap, beam stroke and bar height useSPRINGS.dampedso widths track without overshoot. - Reduced motion respected.
usePrefersReducedMotionshort-circuits the cycle; the hero paints a single static phase instead. Thepausedprop forces the same behaviour explicitly. - Tokens, not hex. The surface uses
var(--cb-bg), labels usevar(--cb-fg-muted), and the accent defaults tocurrentColorso anytext-cb-*utility on a parent tints the active query, beams, and bar fill.
Variants / Examples
// Paused — useful for thumbnails / OG images.
<HeroAttention paused />
// Fixed pixel width.
<HeroAttention size={480} />
// Explicit accent override.
<HeroAttention accentColor="var(--cb-info, #3b82f6)" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
accentColor | string | 'currentColor' | Colour for the active query, beams, and bar fill. |
size | number | — | Optional fixed pixel width. Omit to fill the parent. |
paused | boolean | false | When true, render a single static phase instead of looping. |
className | string | — | Extra classes merged onto the root <svg>. |
Accessibility
- The hero is decorative (
aria-hidden="true"); pair it with adjacent text that conveys the meaning. Override witharia-labelandrole="img"on the consuming wrapper if it needs to be announced. - The looping animation pauses automatically when
prefers-reduced-motion: reduceis set. Thepausedprop offers a manual escape hatch (e.g. for thumbnails, print, or OG screenshots). - Colour contrast tracks the parent text colour through
currentColor, so the hero inherits anyprefers-contrastoverrides applied site-wide.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/chrome/icons/heroes/HeroAttention.tsx).