"use client"; import { useState, useRef, useCallback } from "react"; interface MagicRevealProps { avantLabel: string; apresLabel: string; avantImage: string; apresImage: string; height?: string; } export default function MagicReveal({ avantLabel, apresLabel, avantImage, apresImage, height = "h-64", }: MagicRevealProps) { const [position, setPosition] = useState(50); const containerRef = useRef(null); const dragging = useRef(false); const updatePosition = useCallback((clientX: number) => { if (!containerRef.current) return; const rect = containerRef.current.getBoundingClientRect(); const x = clientX - rect.left; const percent = Math.max(0, Math.min(100, (x / rect.width) * 100)); setPosition(percent); }, []); const handlePointerDown = useCallback((e: React.PointerEvent) => { dragging.current = true; (e.target as HTMLElement).setPointerCapture(e.pointerId); updatePosition(e.clientX); }, [updatePosition]); const handlePointerMove = useCallback((e: React.PointerEvent) => { if (!dragging.current) return; updatePosition(e.clientX); }, [updatePosition]); const handlePointerUp = useCallback(() => { dragging.current = false; }, []); return (
{/* Après (fond complet) */} {apresLabel} {/* Avant (clipé à gauche) */}
{avantLabel}
{/* Barre de séparation */}
{/* Labels gauche/droite */}
AVANT
APRÈS
{/* Légendes sous l'image */}
{avantLabel} {apresLabel}
); }