testimonials updated

This commit is contained in:
parsa aghaei 2024-09-29 15:53:50 +03:30
parent 89a2a23fc1
commit 7b752c015a
2 changed files with 86 additions and 34 deletions

View File

@ -1,84 +1,122 @@
"use client";
import React, { useEffect, useRef, useState, MouseEvent } from "react";
import React, { useEffect, useState } from "react";
interface Testimonial {
name: string;
position: string;
image: string;
quote: string;
}
export default function Testimonials() {
const [currentIndex, setCurrentIndex] = useState(0);
// const [autoSlideInterval, setAutoSlideInterval] = useState<any>(null);
const nextSlide = () => {
setCurrentIndex((prevIndex) =>
prevIndex === testimonials.length - 1 ? 0 : prevIndex + 1,
);
};
// const prevSlide = () => {
// setCurrentIndex((prevIndex) =>
// prevIndex === 0 ? testimonials.length - 1 : prevIndex - 1,
// );
// };
useEffect(() => {
const interval = setInterval(nextSlide, 5000); // Slide every 5 seconds
// setAutoSlideInterval(interval);
return () => clearInterval(interval); // Clean up interval on component unmount
}, []);
const 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:
"Lorem ipsum dolor sit amet consectetur. In enim cursus odio accumsan. Id leo urna velit neque mattis id tellus arcu ondimentum. Augue dictum dolor elementum convallis dignissim malesuada commodo ultrices.",
'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 dolor sit amet consectetur. In enim cursus odio accumsan. Id leo urna velit neque mattis id tellus arcu ondimentum. Augue dictum dolor elementum convallis dignissim malesuada commodo ultrices.",
"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:
"Lorem ipsum dolor sit amet consectetur. In enim cursus odio accumsan. Id leo urna velit neque mattis id tellus arcu ondimentum. Augue dictum dolor elementum convallis dignissim malesuada commodo ultrices.",
"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"
id="testimonials"
>
<h2 className="text-[55px] font-[800] text-black">Testominials</h2>
<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="flex select-none flex-wrap items-center justify-center gap-8 overflow-hidden hover:cursor-grab">
<div
className="relative flex w-full select-none no-scrollbar flex-nowrap items-start py-4 gap-8 overflow-x-scroll min-h-[780px] 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={`flex w-full max-w-[600px] flex-wrap items-center justify-around gap-3 rounded-lg bg-[#F8F8F8] p-5 ${
className={`testimonial absolute flex flex-wrap w-[80%] md:w-[70%] items-center justify-around gap-3 rounded-lg bg-[#F8F8F8] p-5 hover:cursor-grab ${currentIndex === index ? "left-[15%] sm:left-[15%] md:left-[25%] z-20 scale-105 drop-shadow-lg" : "left-0 z-10 scale-90 grayscale"} ${
currentIndex === index ? "" : "blur-[2px]"
}`}
key={index}
>
<div className="flex w-full justify-center sm:w-[30%]">
<div className="flex justify-center lg:w-[30%]">
<img
src={testimonial.image}
className="w-[100px] sm:w-[150px]"
className="pointer-events-none w-[50px] min-w-[100px] sm:w-[150px]"
alt="user profile picture"
/>
</div>
<div className="flex w-full flex-wrap items-center sm:w-[60%]">
<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-[21px] font-[700] text-[#FD6F00]">
<span className="me-2 text-[12px] sm:text-[21px] font-[700] text-[#FD6F00]">
</span>
{testimonial.quote}
<span className="ms-2 text-[21px] font-[700] text-[#FD6F00]">
</span>
@ -93,6 +131,7 @@ export default function Testimonials() {
</div>
))}
</div>
<ul className="mt-10 flex w-full items-center justify-center gap-5">
{testimonials.map((_, index) => (
<li
@ -100,7 +139,10 @@ export default function Testimonials() {
className={`${
currentIndex === index ? "bg-[#FD6F00]" : "bg-[#D9D9D9]"
} h-[16px] w-[40px] rounded-lg hover:cursor-pointer`}
onClick={() => setCurrentIndex(index)}
onClick={() => {
setCurrentIndex(index);
setBulletClicked(true);
}}
></li>
))}
</ul>

View File

@ -272,3 +272,13 @@ html {
opacity: 0.95;
transition: all ease-in-out 0.5s;
}
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.testimonial{
transition: all ease-in-out 0.5s;
}