Hero Autograd
A small DAG of inputs, ops, and a loss node that fades in, glows in the accent color from left to right (the forward pass), then reverses with a cooler dashed wave that surfaces the per-node gradient labels (the backward pass). Decorative by default.
Customize
Hero
320px
default
Installation
npx shadcn@latest add https://craftbits.dev/r/hero-autograd.jsonUsage
import { HeroAutograd } from "@craft-bits/core";
<HeroAutograd size={320} />Understanding the component
- Single inline SVG, single loop. The whole illustration is one
<svg viewBox="0 0 400 280">. A singlesetTimeout-drivenrunCycleschedules every wave (entrance, forward, backward, reset) and re-arms itself every 8 seconds. - Spring-smoothed motion values. Every node and edge owns its own
useSpring(useMotionValue(0))for visibility, warm glow, cool glow, gradient-label opacity, forward edge activation, and backward edge activation. The cycle only writes target values — the springs handle the easing. - Reduced-motion fallback.
usePrefersReducedMotion()short-circuits the loop and renders the resting (revealed) state directly — no waves, no gradient labels mid-pulse. - Themeable via two props.
accentColorpaints the forward wave andgradientColorpaints the backward wave. Both default to CSS variables, so the component picks up your theme without explicit props.
Variants / Examples
// Larger hero for a landing-page section.
<HeroAutograd size={480} />
// Custom palette — paint the forward wave teal, the backward wave magenta.
<HeroAutograd
size={360}
accentColor="#14b8a6"
gradientColor="#ec4899"
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | 280 | Pixel width of the rendered SVG. Height tracks the 400:280 viewBox. |
accentColor | string | 'var(--cb-accent, #f59e0b)' | Forward-pass glow color. Accepts any CSS color. |
gradientColor | string | 'var(--cb-accent-cool, var(--cb-accent, #8b5cf6))' | Backward-pass glow color (also used for the gradient-label text). |
className | string | — | Extra classes merged onto the root <svg>. |
aria-label | string | — | If set, the SVG is treated as a labeled image; otherwise it renders as decorative (aria-hidden). |
Accessibility
- Decorative by default (
aria-hidden="true"when noaria-labelis provided). Screen readers skip it. - Pass
aria-label="…"to promote the SVG torole="img"with a name. - Respects
prefers-reduced-motion— the animation loop is skipped and the graph renders in its resting state.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/chrome/icons/heroes/HeroAutograd.tsx).