--- title: 3d Carousel description: An immersive 3D carousel component with flippable cards arranged in a circular layout. Features drag navigation, keyboard controls, auto-rotation, and smooth animations with full theme support. --- ## Installation CLI Manual ```bash npx lightswind@latest add 3d-carousel ``` Copy and paste the following code into your project. ```tsx // components/ThreeDCarousel.tsx "use client"; import React, { useRef, useEffect, useState, TouchEvent, } from "react"; import { ChevronLeft, ChevronRight, ArrowRight } from "lucide-react"; import { Card, CardContent } from "./card"; import { useIsMobile } from "@/components/hooks/use-mobile"; export interface ThreeDCarouselItem { id: number; title: string; brand: string; description: string; tags: string[]; imageUrl: string; link: string; } interface ThreeDCarouselProps { items: ThreeDCarouselItem[]; autoRotate?: boolean; rotateInterval?: number; cardHeight?: number; title?: string; subtitle?: string; tagline?: string; isMobileSwipe?: boolean; } const ThreeDCarousel = ({ items = [ { id: 1, title: "Active Wear Innovation", brand: "Nike", description: "Integrating flexible sensors into performance gear to monitor muscle fatigue and heart rate in real-time.", tags: ["Sports", "Health", "IoT"], imageUrl: "https://images.unsplash.com/photo-1515243061678-14fc18b93935?q=80&w=2940&auto=format&fit=crop", link: "#", }, { id: 2, title: "Smart Ergonomics", brand: "Herman Miller", description: "Pressure-sensitive fabrics in office chairs that analyze posture and suggest adjustments for optimal health.", tags: ["Office", "Health", "Furniture"], imageUrl: "https://images.unsplash.com/photo-1505843490538-5133c6c7d0e1?q=80&w=2938&auto=format&fit=crop", link: "#", }, { id: 3, title: "Automotive Comfort", brand: "Tesla", description: "Intelligent car seats that adapt to passenger position and monitor vital signs for enhanced safety.", tags: ["Auto", "Safety", "Smart"], imageUrl: "https://images.unsplash.com/photo-1561580125-028ce3bfcb25?q=80&w=2940&auto=format&fit=crop", link: "#", }, ], autoRotate = true, rotateInterval = 4000, cardHeight = 500, title = "From Textile to Intelligence", subtitle = "Customer Cases", tagline = "Explore how our textile sensor technology is revolutionizing multiple industries with intelligent fabric solutions tailored to specific needs.", isMobileSwipe = true, }: ThreeDCarouselProps) => { const [active, setActive] = useState(0); const carouselRef = useRef(null); const [isInView, setIsInView] = useState(false); const [isHovering, setIsHovering] = useState(false); const [touchStart, setTouchStart] = useState(null); const [touchEnd, setTouchEnd] = useState(null); const isMobile = useIsMobile(); const minSwipeDistance = 50; useEffect(() => { if (autoRotate && isInView && !isHovering) { const interval = setInterval(() => { setActive((prev) => (prev + 1) % items.length); }, rotateInterval); return () => clearInterval(interval); } }, [isInView, isHovering, autoRotate, rotateInterval, items.length]); useEffect(() => { const observer = new IntersectionObserver( ([entry]) => setIsInView(entry.isIntersecting), { threshold: 0.2 } ); return () => observer.disconnect(); }, []); const onTouchStart = (e: TouchEvent) => { setTouchStart(e.targetTouches[0].clientX); setTouchEnd(null); }; const onTouchMove = (e: TouchEvent) => { setTouchEnd(e.targetTouches[0].clientX); }; const onTouchEnd = () => { if (!touchStart || !touchEnd) return; const distance = touchStart - touchEnd; if (distance > minSwipeDistance) { setActive((prev) => (prev + 1) % items.length); } else if (distance < -minSwipeDistance) { setActive((prev) => (prev - 1 + items.length) % items.length); } }; const getCardAnimationClass = (index: number) => { if (index === active) return "scale-100 opacity-100 z-20"; if (index === (active + 1) % items.length) return "translate-x-[40%] scale-95 opacity-60 z-10"; if (index === (active - 1 + items.length) % items.length) return "translate-x-[-40%] scale-95 opacity-60 z-10"; return "scale-90 opacity-0"; }; return (
setIsHovering(true)} onMouseLeave={() => setIsHovering(false)} onTouchStart={onTouchStart} onTouchMove={onTouchMove} onTouchEnd={onTouchEnd} ref={carouselRef} >
{items.map((item, index) => (

{item.brand.toUpperCase()}

{item.title}

{item.title}

{item.brand}

{item.description}

))}
{!isMobile && ( <> )}
{items.map((_, idx) => (
); }; export default ThreeDCarousel; ```
## Usage ```tsx import ThreeDCarousel, { ThreeDCarouselItem } from "@/components/ThreeDCarousel"; ``` ```tsx const items: ThreeDCarouselItem[] = [ { id: 1, title: "6th SENSE Safety System", brand: "FireCat Group", description: "AI-driven smart uniform tech for law enforcement, military & firefighters.", tags: ["Safety", "Military", "AI Sensors", "Monitoring"], imageUrl: "/img/firecat.jpg", link: "/projects/firecat" } ]; ```