parsaaghayi-front/src/app/_components/testimonials/page.tsx
2024-09-29 17:28:30 +03:30

152 lines
6.5 KiB
TypeScript

"use client";
import React, { useEffect, useRef, useState } from "react";
interface Testimonial {
name: string;
position: string;
image: string;
quote: string;
}
export default function Testimonials() {
const [currentIndex, setCurrentIndex] = useState<number>(0); // شروع با آیتم وسطی
const sliderRef = useRef<HTMLDivElement | null>(null);
const [isHovered, setIsHovered] = useState<boolean>(false);
const [bulletClicked, setBulletClicked] = useState<boolean>(false);
// const [maxHeight, setMaxHeight] = useState<number>(0);
const testimonials: Testimonial[] = [
{
name: "Sarah Johnson",
position: "Founder & CEO of Innovate Solutions",
image: "/images/user-1.svg",
quote:
'The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.',
},
{
name: "Michael Lee",
position: "Chief Executive Officer at Tech Innovators",
image: "/images/user-1.svg",
quote:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
},
{
name: "Emma Davis",
position: "CEO & Lead Strategist at Visionary Ventures",
image: "/images/user-1.svg",
quote:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
},
{
name: "John Doe",
position: "COO at Startup Labs",
image: "/images/user-1.svg",
quote:
"All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet.",
},
{
name: "Jane Smith",
position: "Founder at Health Innovations",
image: "/images/user-1.svg",
quote:
"It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.",
},
];
// Auto-scroll every 5 seconds
useEffect(() => {
if (sliderRef.current) {
let maxHeight = 0;
// Iterate through each child of the slider
Array.from(sliderRef.current.children).forEach((child) => {
const childHeight = child.clientHeight; // Get the height of the child
if (childHeight > maxHeight) {
maxHeight = childHeight; // Update maxHeight if current child is taller
}
});
// setMaxHeight(maxHeight + 20); // Set the maximum height
}
if (!isHovered && !bulletClicked) {
const interval = setInterval(() => {
setCurrentIndex((prevIndex) =>
prevIndex === testimonials.length - 1 ? 0 : prevIndex + 1,
);
}, 2000);
return () => clearInterval(interval);
}
}, [isHovered, bulletClicked]);
return (
<div
className="flex w-full max-w-[90%] flex-wrap justify-center pt-[100px]"
id="testimonials"
>
<h2 className="text-[55px] font-[800] text-black">Testimonials</h2>
<p className="my-10 text-justify text-[21px] font-[400] text-black">
Lorem ipsum dolor sit amet consectetur. Mollis erat duis aliquam mauris
est risus lectus. Phasellus consequat urna tellus
</p>
<div
className="no-scrollbar relative flex min-h-[780px] w-full select-none flex-nowrap items-start gap-8 overflow-x-scroll py-4 sm:min-h-[560px] lg:min-h-[450px] xl:min-h-[370px] 2xl:min-h-[370px]" // Hide scrollbar using CSS
ref={sliderRef}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => {
setIsHovered(false);
setBulletClicked(false);
}}
>
{testimonials.map((testimonial, index) => (
<div
className={`testimonial absolute flex w-[80%] flex-wrap items-center justify-around gap-3 rounded-lg bg-[#F8F8F8] p-5 hover:cursor-grab md:w-[70%] ${currentIndex === index ? "start-[15%] z-20 scale-105 drop-shadow-lg sm:start-[15%] md:start-[25%]" : "start-0 z-10 scale-90 grayscale"} ${
currentIndex === index ? "" : "blur-[2px]"
}`}
key={index}
>
<div className="flex justify-center lg:w-[30%]">
<img
src={testimonial.image}
className="pointer-events-none w-[50px] min-w-[100px] sm:w-[150px]"
alt="user profile picture"
/>
</div>
<div className="flex flex-wrap items-center lg:w-[60%]">
<p className="mb-3 w-full text-justify text-[15px] font-[400] text-black">
<span className="me-2 text-[12px] font-[700] text-[#FD6F00] sm:text-[21px]">
</span>
{testimonial.quote}
<span className="ms-2 text-[21px] font-[700] text-[#FD6F00]">
</span>
</p>
<h5 className="w-full text-[20px] font-[700] text-[#000]">
{testimonial.name}
</h5>
<p className="w-full text-[15px] font-[400] text-[#000]">
{testimonial.position}
</p>
</div>
</div>
))}
</div>
<ul className="mt-10 flex w-full items-center justify-center gap-5">
{testimonials.map((_, index) => (
<li
key={index}
className={`${
currentIndex === index ? "bg-[#FD6F00]" : "bg-[#D9D9D9]"
} h-[16px] w-[40px] rounded-lg hover:cursor-pointer`}
onClick={() => {
setCurrentIndex(index);
setBulletClicked(true);
}}
></li>
))}
</ul>
</div>
);
}