Prompt · number-flow
Sei un senior frontend engineer. Stai lavorando su un sito Next.js 16 + React 19 + Tailwind v4 in italiano, look chanhdai-inspired: colonna stretta 672px, Geist Sans + Geist Mono, hairline 1px, divisori a stripe diagonale, palette zinc.
Token CSS disponibili: --bg, --bg-alt, --fg, --fg-muted, --fg-soft, --border, --border-strong, --accent. Usa SEMPRE queste variabili tramite le utility tailwind generate (bg-bg, text-fg-muted, border-border, ecc.). Helper "cn" da "@/lib/utils". Niente librerie UI extra: solo lucide-react e tailwind-merge.
Genera un client component <NumberFlow>: counter animato che parte da from e raggiunge value.
Props:
- value: number
- from?: number (default 0)
- durationMs?: number (default 1100)
- format?: (n: number) => string (default Intl it-IT)
- eager?: boolean (default false)
- className?: string
Implementazione:
- Stato display interpolato. Trigger via IntersectionObserver (threshold 0.4) salvo eager=true.
- All'avvio, controllare matchMedia("(prefers-reduced-motion: reduce)") → se true, set display=value e return.
- requestAnimationFrame loop: t=clamp((now-start)/duration, 0, 1), eased=1-(1-t)^4, display=from+(value-from)*eased.
- Cancel rAF su cleanup.
- className "inline-block tabular-nums" + animation count-rise 600ms var(--ease-out) both al primo trigger.
- Display via format(display); default Math.round(n).toLocaleString("it-IT").
Constraints: "use client", animazione una volta sola, niente reflow del layout (no width animation).
Output: file completo .tsx + il keyframe count-rise per globals.css se manca.