PratikWebsite / components /Testimonials /TestimonialsSection.tsx
Keep-Triangle's picture
Upload 35 files
5d33320 verified
Raw History Blame Contribute Delete
9.87 kB
import React, { useState, useEffect } from 'react';
import { motion, AnimatePresence, useReducedMotion } from 'framer-motion';
import { Quote } from 'lucide-react';
import { TESTIMONIALS } from '../../data/mockData';
import { Testimonial } from '../../types';
// Configuration for easy background changes
const TESTIMONIAL_CONFIG = {
// Warm, organic paper/spice trade texture
backgroundUrl: 'https://messages-prod.27c852f3500f38c1e7786e2c9ff9e48f.r2.cloudflarestorage.com/127f0354-529e-41ed-a86e-e7c5b38fbada/1766075272000-019b3249-c833-740b-bff4-a0e2982db038.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=af634fe044bd071ab4c5d356fdace60f%2F20251218%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20251218T162752Z&X-Amz-Expires=3600&X-Amz-Signature=f98953947e1bb2f7bfacf717595c44c0038c0621612397413babb83817ca3edb&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject',
autoAdvanceInterval: 7000,
};
const TestimonialsSection: React.FC = () => {
const [activeIndex, setActiveIndex] = useState(0);
const [direction, setDirection] = useState<1 | -1>(1);
const prefersReducedMotion = useReducedMotion();
// Auto-advance
useEffect(() => {
const timer = setInterval(() => {
setDirection(1);
setActiveIndex((prev) => (prev + 1) % TESTIMONIALS.length);
}, TESTIMONIAL_CONFIG.autoAdvanceInterval);
return () => clearInterval(timer);
}, []);
const activeTestimonial = TESTIMONIALS[activeIndex];
// Helper to determine font family and size adjustment based on language
const getLanguageStyles = (lang: string) => {
switch(lang) {
case 'mr': // Marathi
case 'hi': // Hindi
return 'font-devanagari text-4xl md:text-5xl leading-snug';
case 'kn': // Kannada
return 'font-kannada text-3xl md:text-5xl leading-loose py-2';
case 'en': // English
default:
return 'font-serif text-3xl md:text-4xl leading-tight italic';
}
};
const slideVariants = {
enter: (dir: 1 | -1) => ({
opacity: 0,
y: prefersReducedMotion ? 0 : 24,
x: prefersReducedMotion ? 0 : dir * 18,
scale: prefersReducedMotion ? 1 : 0.985,
}),
center: {
opacity: 1,
y: 0,
x: 0,
scale: 1,
},
exit: (dir: 1 | -1) => ({
opacity: 0,
y: prefersReducedMotion ? 0 : -18,
x: prefersReducedMotion ? 0 : dir * -18,
scale: prefersReducedMotion ? 1 : 0.99,
}),
};
return (
<section className="relative py-32 bg-transparent overflow-hidden text-brand-dark">
<div className="absolute inset-0 bg-gradient-to-b from-black/20 via-black/10 to-black/30 pointer-events-none" />
{/* Textured Background - Changable via config */}
<div
className="absolute inset-0 opacity-0 pointer-events-none mix-blend-multiply transition-opacity duration-1000"
style={{
backgroundImage: `url("${TESTIMONIAL_CONFIG.backgroundUrl}")`,
backgroundSize: 'cover',
backgroundPosition: 'center',
}}
/>
{/* Gentle Vignette */}
<div className="absolute inset-0 bg-radial-gradient from-transparent to-black/40 pointer-events-none" />
<div className="relative z-10 max-w-5xl mx-auto px-6 md:px-12">
<motion.div
initial={{ opacity: 0, y: 18 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, amount: 0.35 }}
transition={{ duration: 0.9, ease: [0.16, 1, 0.3, 1] }}
className="rounded-[32px] border border-white/10 bg-[#F2EFE9] shadow-[0_35px_110px_-65px_rgba(0,0,0,0.85)] px-6 md:px-12 py-20"
>
{/* Header - Subtle & Grounded */}
<div className="text-center mb-16">
<motion.div
initial={{ opacity: 0, y: 8 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, amount: 0.6 }}
transition={{ duration: 0.8, ease: [0.16, 1, 0.3, 1] }}
className="flex items-center justify-center gap-4 mb-4"
>
<div className="h-[1px] w-12 bg-brand-maroon/20" />
<span className="text-brand-maroon/60 text-xs uppercase tracking-[0.2em] font-medium">Voices of the Trade</span>
<div className="h-[1px] w-12 bg-brand-maroon/20" />
</motion.div>
</div>
<div className="relative min-h-[450px] flex flex-col items-center justify-center">
<AnimatePresence mode="wait">
<motion.div
key={activeTestimonial.id}
custom={direction}
variants={slideVariants}
initial="enter"
animate="center"
exit="exit"
transition={{ duration: 0.75, ease: [0.16, 1, 0.3, 1] }}
className="text-center max-w-4xl"
>
{/* Quote Icon */}
<div className="flex justify-center mb-8">
<motion.div
key={`${activeTestimonial.id}-quote`}
initial={{ opacity: 0, y: 8, scale: 0.98 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
transition={{ duration: 0.7, ease: [0.16, 1, 0.3, 1] }}
className="p-4 rounded-full bg-brand-maroon/5 text-brand-maroon/40"
>
<Quote size={32} />
</motion.div>
</div>
{/* The Quote - Dynamic Font Family based on Language */}
<h3 className={`text-[#2a0a0a] mb-10 opacity-90 ${getLanguageStyles(activeTestimonial.language)}`}>
"{activeTestimonial.quote}"
</h3>
{/* Author Block */}
<motion.div
key={`${activeTestimonial.id}-author`}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.7, delay: 0.08, ease: [0.16, 1, 0.3, 1] }}
className="flex flex-col items-center"
>
{activeTestimonial.image && (
<div className="w-16 h-16 rounded-full overflow-hidden mb-4 border-2 border-brand-maroon/10 shadow-sm">
<img
src={activeTestimonial.image}
alt={activeTestimonial.name}
className="w-full h-full object-cover opacity-90"
/>
</div>
)}
<div className={`text-brand-maroon tracking-wide text-lg ${
activeTestimonial.language === 'en' ? 'font-sans font-semibold' : 'font-devanagari font-bold'
}`}>
{activeTestimonial.name}
</div>
<div className="text-sm text-gray-500 mt-1 font-sans">
{activeTestimonial.role} <span className="mx-1 opacity-30">•</span> {activeTestimonial.location}
</div>
</motion.div>
</motion.div>
</AnimatePresence>
</div>
{/* Navigation Dots */}
<div className="flex justify-center gap-3 mt-12">
{TESTIMONIALS.map((_, index) => (
<motion.button
key={index}
onClick={() => {
setDirection(index > activeIndex ? 1 : -1);
setActiveIndex(index);
}}
animate={
index === activeIndex
? { width: 32, height: 6, opacity: 1 }
: { width: 6, height: 6, opacity: 0.65 }
}
transition={{ duration: 0.45, ease: [0.16, 1, 0.3, 1] }}
className={`rounded-full transition-colors duration-300 ${
index === activeIndex
? 'bg-brand-maroon'
: 'bg-brand-maroon/20 hover:bg-brand-maroon/40'
}`}
aria-label={`Go to testimonial ${index + 1}`}
/>
))}
</div>
</motion.div>
</div>
</section>
);
};
export default TestimonialsSection;