Luca Perullo
Components

Component

LiveNew

Number Flow

Counter animato: rAF interpola dal valore di partenza al target con ease-out forte, mentre l'intero blocco fa un blur-rise di 600ms. Si attiva al primo intersect. Locale-aware via formatter.

MotionStatClient
Open in ClaudeSorgente

Esempio01

number-flow.tsx
Visite
0
Stelle
0
Repo
0

Note Combina due meccanismi: (1) rAF interpola il numero con ease-out custom, (2) il container ha animation count-rise (translateY + blur) di 600ms. prefers-reduced-motion: il global CSS collassa entrambi e il valore appare istantaneo.

Prompt LLM02

Incolla in Claude o ChatGPT per generare la tua variante. Include il contesto del brand, i token e i vincoli del progetto.

Prompt · number-flow
Open in Claude
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.

Uso tipico03

tsx
<NumberFlow value={12480} />

Dipendenze04

npm
  • tailwind-merge
  • clsx
Interno
  • @/lib/utils#cn
  • globals.css#@keyframes count-rise
  • globals.css#--ease-out

Ti è servito? Dimmelo, oppure proponi il prossimo componente.