Luca Perullo
Components

Component

LiveNew

Animated Theme Toggler

document.startViewTransition + animate clipPath sul ::view-transition-new(root). Fallback a class swap diretto se l'API non c'è.

ThemeTransitionClient
Open in ClaudeSorgente

Esempio01

animated-theme-toggler.tsx
001Default · click to wipe
Cliccami per cambiare tema
002In navbar · with brand mark
LP / 2025
003Side rail · with hint
Theme
View Transition API · circular wipe

Note L'API View Transitions è supportata su Chrome 111+ e Safari 18+. Sul resto fa toggle senza wipe (zero glitch visivi).

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 · animated-theme-toggler
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 <AnimatedThemeToggler> con wipe circolare via View Transitions API.
Props:
- className?: string + ...rest button props.

Implementazione:
- "use client". useState<boolean> isDark, useEffect mount: leggi html.dark.
- onClick: calcola click coords + radius max distanza dai 4 angoli viewport. apply = toggle + setIsDark.
- Se document.startViewTransition mancante → apply, return.
- Altrimenti: tx = startViewTransition(apply); await tx.ready; root.animate({ clipPath: [circle(0px), circle(radius)] }, { duration: 600, easing: cubic-bezier(0.23,1,0.32,1), pseudoElement: "::view-transition-new(root)" }).
- Render <button class="press"> con Lucide Sun/Moon, h-11 w-11.

Output: file completo src/components/animated-theme-toggler.tsx.

Uso tipico03

tsx
<AnimatedThemeToggler />

Dipendenze04

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

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