Luca Perullo
Components

Component

LiveNew

Typing Animation

useEffect + setInterval. Tag personalizzabile (h1/h2/h3/p/span). Caret 1px su animation steps(2).

TextTypewriterClient
Open in ClaudeSorgente

Esempio01

typing-animation.tsx
001Default · phrase

002Hero · large headline
Now writing

003Code · mono command
$

Note Cleanup completo su unmount (clearTimeout + clearInterval). Il blinking si ferma quando shown.length === text.length.

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 · typing-animation
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 componente <TypingAnimation> typewriter.
Props:
- text: string.
- duration?: number (ms per char, default 50).
- delay?: number (ms prima di iniziare, default 0).
- as?: "h1"|"h2"|"h3"|"p"|"span" (default "p").
- className?: string.

Implementazione:
- "use client". useState shown + done. useEffect: setTimeout(delay) → setInterval(duration) che incrementa l'indice e fa setShown(text.slice(0, i)).
- Caret span animato con keyframe typing-caret-blink (50% opacity 0). Disabilita animation quando done.
- Cleanup: clearTimeout + clearInterval.

Output: file completo src/components/typing-animation.tsx.

Uso tipico03

tsx
<TypingAnimation text="Hello, world." duration={50} />

Dipendenze04

npm
  • tailwind-merge
  • clsx
Interno
  • @/lib/utils#cn

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