"use client" import { useOutsideClick } from "@/hooks/out-side-click" import { AnimatePresence, motion } from "framer-motion" import { ArrowLeft, ArrowRight, ExternalLink, X } from "lucide-react" import Image from "next/image" import type React from "react" import { createContext, useContext, useEffect, useRef, useState } from "react" interface CaseStudy { id: string title: string description: string image: string category: string fullDescription?: string link?: string technologies?: string[] company?: string content?: React.ReactNode } interface CaseStudiesCarouselProps { title: string description: string caseStudies: CaseStudy[] } const CarouselContext = createContext<{ onCardClose: (index: number) => void currentIndex: number }>({ onCardClose: () => {}, currentIndex: 0, }) export default function CaseStudiesCarousel({ title = "Case Studies", description = "Discover how leading companies and developers are leveraging modern web technologies to build exceptional digital experiences. These case studies showcase real-world applications and success stories.", caseStudies = [ { id: "shadcn", title: "shadcn/ui: Building a Modern Component Library", description: "Explore how shadcn/ui revolutionized React component development", category: "Component Library", fullDescription: "shadcn/ui has transformed how developers build React applications by providing a collection of reusable components that are both beautiful and accessible. Unlike traditional component libraries, shadcn/ui offers a unique approach where you copy and own the code, allowing for maximum customization while maintaining a consistent design language. This case study explores how this innovative approach has changed the component library landscape.", technologies: ["React", "Radix UI", "Tailwind CSS", "TypeScript"], company: "shadcn", link: "https://ui.shadcn.com", image: "/blocks/case-studies-1/image-1.jpg", }, { id: "tailwind", title: "Tailwind CSS: The Utility-First Revolution", description: "Discover how Tailwind CSS transformed the way developers style applications", category: "CSS Framework", fullDescription: "Tailwind CSS introduced a utility-first approach to styling that has dramatically changed how developers build interfaces. By providing low-level utility classes, Tailwind enables rapid UI development without leaving your HTML, resulting in more consistent designs and faster development cycles. This case study examines how Tailwind CSS has grown from a controversial idea to one of the most popular styling solutions in modern web development.", technologies: ["CSS", "PostCSS", "JavaScript", "HTML"], company: "Tailwind Labs", link: "https://tailwindcss.com", image: "/blocks/case-studies-1/image-2.jpg", }, { id: "astro", title: "Astro: The All-in-One Web Framework", description: "Learn how Astro's innovative 'Islands Architecture' and zero-JS approach", category: "Web Framework", fullDescription: "Astro has pioneered the 'Islands Architecture' approach, allowing developers to build faster websites by shipping less JavaScript to the client. By default, Astro renders your entire site to static HTML, then selectively hydrates only the interactive components when needed. This case study explores how Astro's innovative approach has enabled developers to build high-performance websites without sacrificing developer experience.", technologies: ["JavaScript", "TypeScript", "HTML", "CSS"], company: "Astro", link: "https://astro.build", image: "/blocks/case-studies-1/image-3.jpg", }, { id: "react", title: "React: Pioneering Component-Based UI", description: "See how React continues to shape modern web development with its component model", category: "JavaScript Library", fullDescription: "React introduced a component-based architecture that has fundamentally changed how developers build user interfaces. By breaking UIs into reusable, composable components and introducing a virtual DOM for efficient updates, React established patterns that have influenced virtually every modern frontend framework. This case study examines React's journey from a controversial library to the foundation of modern web development.", technologies: ["JavaScript", "JSX", "Virtual DOM", "Hooks"], company: "Meta (formerly Facebook)", link: "https://react.dev", image: "/blocks/case-studies-1/image-4.jpg", }, { id: "nextjs", title: "Next.js: The React Framework", description: "Explore how Next.js has become the go-to framework for React applications", category: "React Framework", fullDescription: "Next.js has established itself as the leading React framework by providing an elegant solution to common challenges in web development. With features like server-side rendering, static site generation, and automatic code splitting, Next.js enables developers to build high-performance React applications with minimal configuration. This case study explores how Next.js has evolved to address the needs of modern web applications.", technologies: ["React", "JavaScript", "TypeScript", "Server Components"], company: "Vercel", link: "https://nextjs.org", image: "/blocks/case-studies-1/image-5.jpg", }, ], }: CaseStudiesCarouselProps) { const carouselRef = useRef(null) const [activeIndex, setActiveIndex] = useState(0) const [canScrollLeft, setCanScrollLeft] = useState(false) const [canScrollRight, setCanScrollRight] = useState(true) const checkScrollAbility = () => { if (carouselRef.current) { const { scrollLeft, scrollWidth, clientWidth } = carouselRef.current setCanScrollLeft(scrollLeft > 0) setCanScrollRight(scrollLeft < scrollWidth - clientWidth - 10) } } useEffect(() => { checkScrollAbility() window.addEventListener("resize", checkScrollAbility) return () => window.removeEventListener("resize", checkScrollAbility) }, []) const scroll = (direction: "left" | "right") => { if (carouselRef.current) { const scrollAmount = direction === "left" ? -300 : 300 carouselRef.current.scrollBy({ left: scrollAmount, behavior: "smooth", }) } } const handleCardClose = (index: number) => { if (carouselRef.current) { const cardWidth = window.innerWidth < 768 ? 224 : 320 const gap = window.innerWidth < 768 ? 16 : 24 const scrollPosition = index * (cardWidth + gap) carouselRef.current.scrollTo({ left: scrollPosition, behavior: "smooth", }) setActiveIndex(index) } } return (

{title}

{description}

{caseStudies.map((study, index) => ( ))}
) } function CaseStudyCard({ card, index, layout = false, }: { card: CaseStudy index: number layout?: boolean }) { const [open, setOpen] = useState(false) const containerRef = useRef(null) const { onCardClose } = useContext(CarouselContext) useEffect(() => { function onKeyDown(event: KeyboardEvent) { if (event.key === "Escape") { handleClose() } } if (open) { document.body.style.overflow = "hidden" } else { document.body.style.overflow = "auto" } window.addEventListener("keydown", onKeyDown) return () => window.removeEventListener("keydown", onKeyDown) }, [open]) useOutsideClick(containerRef, () => handleClose()) const handleOpen = () => { setOpen(true) } const handleClose = () => { setOpen(false) onCardClose(index) } const cardContent = card.content || (

{card.fullDescription || card.description}

{card.technologies && card.technologies.length > 0 && (

Technologies

{card.technologies.map((tech) => ( {tech} ))}
)} {card.image && (
{card.title}
)} {card.company && (

Company

{card.company}

)} {card.link && (
Visit Website
)}
) return ( <> {open && (
{card.category} {card.title}
{cardContent}
)}
{card.category} {card.title}
{card.title} ) }