Components
This code implements a visually appealing and functional testimonial slider component. It addresses the need to showcase multiple testimonials in a dynamic and engaging way, improving user experience and content presentation. The component fetches an array of testimonials, each containing an image, quote, name, and role. It uses a state variable (active) to track the currently displayed testimonial. The slider cycles through testimonials automatically at a set interval (configurable via autorotateTiming). Users can manually switch between testimonials by clicking the buttons displayed below. The smooth transitions are handled by the Transition component from the @headlessui/react library. The useEffect hook manages the autorotation and ensures the parent container dynamically adjusts height to accommodate the content. The component utilizes the Image component from Next.js for efficient image loading and rendering. The styling leverages a CSS-in-JS approach, although it could be swapped for a CSS framework. It uses a ref to access the DOM element and adjust the height dynamically. This component is ideal for websites and applications needing to showcase client testimonials, reviews, or similar content. For instance, it could be used on a landing page to build trust, on a product page to highlight user feedback, or within a case study section to present client success stories. The component features smooth animations using custom easing functions. The design is clean and modern, with a focus on accessibility and user experience. Users can choose to disable the automatic rotation for a more controlled experience.
Loading preview...
import { FancyTestimonialsSlider } from "@/components/ui/rotating-testimonial-slider";
export default function DemoOne() {
const testimonials = [
{
img: "https://randomuser.me/api/portraits/men/91.jpg",
quote: "21st.dev's components make building UIs effortless great work!",
name: "Jessie J",
role: "Acme LTD",
},
{
img: "https://randomuser.me/api/portraits/women/12.jpg",
quote:
"21st.dev simplifies complex designs with ready-to-use components.",
name: "Nick V",
role: "Malika Inc.",
},
{
img: "https://randomuser.me/api/portraits/men/45.jpg",
quote: "With 21st.dev, creating responsive UIs is a breeze.",
name: "Amelia W",
role: "Panda AI",
},
];
return (
<div className="relative h-[500px] w-full overflow-hidden rounded-lg bg-background">
<div className="mt-[64px] flex justify-center px-12">
<FancyTestimonialsSlider testimonials={testimonials} />
</div>
</div>
);
}