Retour au catalogue

Services Card Stack 3D

Services sous forme de pile 3D de cartes. Hover pour eventailler et parcourir les services.

servicescomplex Both Responsive a11y
boldelegantagencysaasuniversalcentered
Theme
"use client";

import React from "react";
import { motion } from "framer-motion";
import * as LucideIcons from "lucide-react";

interface ServiceItem {
  id: string;
  title: string;
  description: string;
  icon?: string;
}

interface ServicesCardStack3dProps {
  badge?: string;
  title?: string;
  subtitle?: string;
  services: ServiceItem[];
}

function getIcon(name?: string) {
  if (!name) return null;
  return (LucideIcons as unknown as Record<string, React.ElementType>)[name] || null;
}

export default function ServicesCardStack3d({ badge, title, subtitle, services }: ServicesCardStack3dProps) {
  const [fanned, setFanned] = React.useState(false);
  const [activeIdx, setActiveIdx] = React.useState(0);
  const total = services.length;

  return (
    <section className="py-[var(--section-padding-y,6rem)]" style={{ backgroundColor: "var(--color-background)" }}>
      <div className="mx-auto max-w-6xl px-[var(--container-padding-x,1.5rem)]">
        <motion.div
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.5 }}
          className="text-center max-w-2xl mx-auto mb-16"
        >
          {badge && (
            <span className="inline-block text-xs font-medium tracking-wider uppercase px-3 py-1 rounded-full border mb-4" style={{ color: "var(--color-accent)", borderColor: "var(--color-border)" }}>
              {badge}
            </span>
          )}
          {title && <h2 className="text-3xl font-bold tracking-tight md:text-4xl lg:text-5xl" style={{ color: "var(--color-foreground)" }}>{title}</h2>}
          {subtitle && <p className="mt-4 text-base" style={{ color: "var(--color-foreground-muted)" }}>{subtitle}</p>}
        </motion.div>

        <div
          className="relative mx-auto flex items-center justify-center"
          style={{ height: 380, perspective: "1200px" }}
          onMouseEnter={() => setFanned(true)}
          onMouseLeave={() => { setFanned(false); setActiveIdx(0); }}
        >
          {services.map((service, i) => {
            const Icon = getIcon(service.icon);
            const offset = i - Math.floor(total / 2);
            const isActive = fanned && activeIdx === i;

            return (
              <motion.div
                key={service.id}
                onMouseEnter={() => setActiveIdx(i)}
                className="absolute w-72 rounded-2xl border p-6 cursor-pointer"
                style={{
                  borderColor: isActive ? "var(--color-accent)" : "var(--color-border)",
                  backgroundColor: "var(--color-background-card)",
                  zIndex: isActive ? 50 : total - i,
                }}
                animate={{
                  rotateZ: fanned ? offset * 8 : offset * 1,
                  x: fanned ? offset * 80 : offset * 4,
                  y: fanned ? Math.abs(offset) * 15 : i * 4,
                  scale: isActive ? 1.08 : fanned ? 0.95 : 1 - i * 0.03,
                }}
                transition={{ type: "spring", stiffness: 200, damping: 20 }}
              >
                {Icon && (
                  <div className="mb-4 inline-flex items-center justify-center rounded-xl p-3" style={{ backgroundColor: "var(--color-accent-subtle, var(--color-background-alt))" }}>
                    <Icon className="h-6 w-6" style={{ color: "var(--color-accent)" }} />
                  </div>
                )}
                <h3 className="text-lg font-semibold" style={{ color: "var(--color-foreground)" }}>{service.title}</h3>
                <p className="mt-2 text-sm leading-relaxed" style={{ color: "var(--color-foreground-muted)" }}>{service.description}</p>
              </motion.div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

Avis

Services Card Stack 3D — React Services Section — Incubator