opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Users
  4. Testimonial
Back to Users

Components / Users

Testimonial

Free Users React component — TestimonialCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Auto-advancing testimonial carousel with stars, quote, avatar, and dot navigation. Social proof that moves on its own.

Preview

The way each component feels cohesive without being overly uniform is genuinely impressive. Spacing, type, and interaction details across 33 categories usually fall apart at scale, but this holds together with real care.

Reviewer

Niyazi Gözkenç

Product Hunt

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/users/testimonial-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { TestimonialCard } from "@/components/users/testimonial-card";

    <TestimonialCard />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/users/testimonial-card.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
"use client";
 
import {
forwardRef,
useEffect,
useState,
type ComponentPropsWithoutRef,
} from "react";
import Image from "next/image";
 
import { cn } from "@/lib/cn";
import { Star, Quote, ChevronLeft, ChevronRight } from "lucide-react";
 
export type TestimonialItem = {
quote: string;
name: string;
role: string;
rating?: number;
avatar?: string;
};
 
export type TestimonialCardProps = Readonly<
{
testimonials?: TestimonialItem[];
quote?: string;
name?: string;
role?: string;
rating?: number;
avatar?: string;
avatarAlt?: string;
quoteIcon?: React.ReactNode;
autoPlayMs?: number;
onChange?: (index: number) => void;
} & ComponentPropsWithoutRef<"div">
>;
 
import { PRODUCT_HUNT_TESTIMONIALS } from "@/lib/home/testimonials";
 
const RATING_STARS = [
"star-1",
"star-2",
"star-3",
"star-4",
"star-5",
] as const;
 
const defaultTestimonials: TestimonialItem[] = PRODUCT_HUNT_TESTIMONIALS;
 
// Production-ready Testimonial component — styled with Tailwind CSS.
export const TestimonialCard = forwardRef<HTMLDivElement, TestimonialCardProps>(
(
{
className,
testimonials,
quote = defaultTestimonials[0].quote,
name = defaultTestimonials[0].name,
role = defaultTestimonials[0].role,
rating = 5,
avatar = "/profile-picture.png",
avatarAlt = "Reviewer",
quoteIcon,
autoPlayMs = 6000,
onChange,
...props
},
ref,
) => {
const items =
testimonials ??
defaultTestimonials.map((item, index) =>
index === 0 ? { ...item, quote, name, role, rating, avatar } : item,
);
 
const [index, setIndex] = useState(0);
const [animating, setAnimating] = useState(false);
const current = items[index];
 
const goTo = (next: number) => {
if (animating || next === index) return;
setAnimating(true);
setIndex(next);
onChange?.(next);
globalThis.setTimeout(() => setAnimating(false), 320);
};
 
const prev = () => goTo((index - 1 + items.length) % items.length);
const next = () => goTo((index + 1) % items.length);
 
useEffect(() => {
if (autoPlayMs <= 0) return;
const timer = globalThis.setInterval(() => {
setIndex((current) => {
const next = (current + 1) % items.length;
onChange?.(next);
return next;
});
}, autoPlayMs);
return () => globalThis.clearInterval(timer);
}, [autoPlayMs, items.length, onChange]);
 
return (
<div
ref={ref}
data-slot="testimonial-card"
className={cn(
"relative w-72 rounded-2xl border border-neutral-100 bg-white p-6 font-sans shadow-lg",
className,
)}
{...props}
>
<style>{`
@keyframes testimonial-fade {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
`}</style>
 
<div
data-slot="testimonial-card-quote-icon"
className="pointer-events-none absolute top-5 right-5 text-neutral-100 select-none"
>
{quoteIcon ?? <Quote size={24} />}
</div>
 
<div
key={current.name}
style={{ animation: "testimonial-fade 0.32s ease-out" }}
>
<div
data-slot="testimonial-card-rating"
className="mb-4 flex gap-0.5"
>
{RATING_STARS.slice(0, current.rating ?? 5).map((starId) => (
<Star
key={starId}
size={12}
className="text-yellow-400"
fill="#FFD700"
/>
))}
</div>
 
<p
data-slot="testimonial-card-quote"
className="relative z-10 mb-6 text-sm leading-relaxed text-neutral-700"
>
{current.quote}
</p>
 
<div
data-slot="testimonial-card-author"
className="flex items-center gap-3 border-t border-neutral-100 pt-4"
>
<div
data-slot="testimonial-card-avatar"
className="h-10 w-10 overflow-hidden rounded-full border-2 border-neutral-100"
>
<Image
src={current.avatar ?? avatar}
alt={avatarAlt}
width={40}
height={40}
className="h-full w-full object-cover"
/>
</div>
 
<div data-slot="testimonial-card-author-info">
<p className="text-sm font-semibold text-neutral-900">
{current.name}
</p>
<p className="text-[11px] text-neutral-400">{current.role}</p>
</div>
</div>
</div>
 
<div className="mt-4 flex items-center justify-between">
<div className="flex gap-1">
{items.map((item) => (
<button
key={item.name}
type="button"
aria-label={`Go to testimonial ${items.indexOf(item) + 1}`}
onClick={() => goTo(items.indexOf(item))}
className={cn(
"h-1.5 cursor-pointer rounded-full transition-all duration-300",
items.indexOf(item) === index
? "w-5 bg-neutral-900"
: "w-1.5 bg-neutral-200 hover:bg-neutral-300",
)}
/>
))}
</div>
 
<div className="flex gap-1">
<button
type="button"
aria-label="Previous testimonial"
onClick={prev}
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border border-neutral-200 text-neutral-500 transition-colors hover:bg-neutral-50"
>
<ChevronLeft size={14} />
</button>
<button
type="button"
aria-label="Next testimonial"
onClick={next}
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border border-neutral-200 text-neutral-500 transition-colors hover:bg-neutral-50"
>
<ChevronRight size={14} />
</button>
</div>
</div>
</div>
);
},
);
 
TestimonialCard.displayName = "TestimonialCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/users/testimonial-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.