import { useState } from 'react';
import { motion } from 'framer-motion';
interface FlipCardProps {
flipDirection?: 'horizontal' | 'vertical' | 'diagonal';
trigger?: 'hover' | 'click';
variant?: 'default' | 'lifted' | 'glow' | 'gradient-border';
export default function FlipCard({
flipDirection = 'horizontal',
const [isFlipped, setIsFlipped] = useState(false);
const getRotation = (flipped: boolean) => {
if (!flipped) return { rotateX: 0, rotateY: 0 };
return { rotateY: 180, rotateX: 0 };
return { rotateX: 180, rotateY: 0 };
return { rotateY: 180, rotateX: 15 };
return { rotateY: 180, rotateX: 0 };
lifted: 'hover:shadow-2xl',
glow: 'shadow-[0_0_30px_rgba(59,130,246,0.3)]',
const handleInteraction = () => {
if (trigger === 'click') {
setIsFlipped(!isFlipped);
const handleHoverStart = () => {
if (trigger === 'hover') {
const handleHoverEnd = () => {
if (trigger === 'hover') {
className={`relative w-full h-full ${className}`}
style={{ perspective: '1000px' }}
onClick={handleInteraction}
onMouseEnter={handleHoverStart}
onMouseLeave={handleHoverEnd}
{variant === 'gradient-border' && (
<div className="absolute -inset-[2px] rounded-2xl bg-gradient-to-r from-purple-500 via-pink-500 to-orange-500 opacity-75 blur-sm" />
className="relative w-full h-full"
style={{ transformStyle: 'preserve-3d' }}
animate={getRotation(isFlipped)}
absolute inset-0 w-full h-full rounded-2xl overflow-hidden
${variantStyles[variant]}
style={{ backfaceVisibility: 'hidden' }}
absolute inset-0 w-full h-full rounded-2xl overflow-hidden
${variantStyles[variant]}
backfaceVisibility: 'hidden',
flipDirection === 'vertical' ? 'rotateX(180deg)' : 'rotateY(180deg)',