import React, { useState, useRef } from 'react'; interface DepthSliderProps { image: string; depth: string; } export default function DepthSlider({ image, depth }: DepthSliderProps) { const [sliderPosition, setSliderPosition] = useState(50); // percentage (0 - 100) const containerRef = useRef(null); const isDragging = useRef(false); const handleMove = (clientX: number) => { if (!containerRef.current) return; const rect = containerRef.current.getBoundingClientRect(); const x = clientX - rect.left; const percentage = Math.max(0, Math.min(100, (x / rect.width) * 100)); setSliderPosition(percentage); }; const handleMouseMove = (e: React.MouseEvent) => { // We update on hover or active dragging if (e.buttons === 1 || isDragging.current) { handleMove(e.clientX); } }; const handleMouseDown = (e: React.MouseEvent) => { isDragging.current = true; handleMove(e.clientX); }; const handleMouseUp = () => { isDragging.current = false; }; const handleTouchMove = (e: React.TouchEvent) => { if (e.touches[0]) { handleMove(e.touches[0].clientX); } }; return (
{ isDragging.current = true; }} onTouchEnd={() => { isDragging.current = false; }} className="relative w-full aspect-square rounded-2xl overflow-hidden border border-white/10 select-none cursor-ew-resize bg-gray-950 shadow-inner group animate-in fade-in zoom-in-95 duration-500" > {/* Base Image (Underneath) */} Base visual {/* Depth Map (On Top, clipped to reveal right side) */}
Depth map visual
{/* Divider Line */}
{/* Slider Handle Knob */}
{/* Floating Labels */}
Original Image
Depth Geometry
); }