Testimonial Stack
A social post card with a highlighted line stacks in with other testimonials.
Source
components/kuchi/testimonial-stack.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/InstrumentSans";4import { loadFont as loadSerif } from "@remotion/google-fonts/InstrumentSerif";5import type React from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 interpolateColors,11 spring,12 useCurrentFrame,13 useVideoConfig,14} from "remotion";15import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";16import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";17import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1819const { fontFamily: instrumentSans } = loadFont("normal", {20 weights: ["400"],21 subsets: ["latin"],22});23const { fontFamily: serif } = loadSerif("normal", {24 weights: ["400"],25 subsets: ["latin"],26});2728export interface TestimonialQuote {29 text: string;30 highlight?: string;31 name: string;32 role: string;33 handle?: string;34 avatarColor?: string;35 stars?: number;36 date?: string;37 source?: "x" | "none";38}3940export interface TestimonialStackProps {41 quotes?: TestimonialQuote[];42 ending?: "pile" | "fan";43 theme?: "light" | "dark";44 accent?: string;45 speed?: number;46 title?: string;47 framesPerQuote?: number;48 /** Text color of the cards and title; overrides the theme ink. */49 ink?: string;50 /** Solid fill in place of the gradient ground; "transparent" drops it. */51 background?: string;52 /** Typeface for the cards and title. Load it yourself; Instrument Sans by default. */53 fontFamily?: string;54 /** Corner radius of the cards, in px. */55 radius?: number;56 /** Rotation of the piled cards; 0 lays them straight. */57 tilt?: number;58 /** Size of the stack, around the frame's center. */59 scale?: number;60 /** Frames to hold the first frame before anything moves. */61 delay?: number;62 ground?: GshPresetId;63 groundParams?: Partial<GradientParams>;64}6566const DEFAULT_QUOTES: TestimonialQuote[] = [67 {68 text: "We shipped our launch video in a single afternoon. The motion looks like a design team spent weeks on it.",69 highlight: "looks like a design team spent weeks on it",70 name: "Maya Chen",71 role: "Founder, Kitebase",72 handle: "@mayachen",73 date: "Oct 14",74 source: "x",75 },76 {77 text: "Dropped three components into our Remotion project and the demo basically built itself. Owning the code is the right call.",78 highlight: "the demo basically built itself",79 name: "Leo Park",80 role: "Staff Engineer, Lumen",81 handle: "@leopark",82 date: "Oct 15",83 source: "x",84 },85 {86 text: "Our launch clip got 3.4× the replies of anything we posted this year. The best tool we added this quarter.",87 highlight: "3.4× the replies",88 name: "Priya Raman",89 role: "Head of Growth, Fernway",90 stars: 5,91 date: "Oct 16",92 source: "none",93 },94 {95 text: "I’m not a motion designer and it doesn’t matter anymore. Every scene is production-ready out of the box.",96 highlight: "production-ready out of the box",97 name: "Daniel Okafor",98 role: "Indie hacker",99 handle: "@danokafor",100 date: "Oct 18",101 source: "x",102 },103];104105function hash(n: number) {106 const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;107 return x - Math.floor(x);108}109110function initials(name: string) {111 return name112 .split(/\s+/)113 .map((p) => p[0] ?? "")114 .slice(0, 2)115 .join("")116 .toUpperCase();117}118119const ENTER = Easing.bezier(0.22, 1, 0.36, 1);120const MOVE = Easing.bezier(0.65, 0, 0.35, 1);121const CARD = { mass: 0.8, damping: 18, stiffness: 160 };122const MORPH = { damping: 200 };123const ramp = (f: number, a: number, b: number, ease = ENTER) =>124 interpolate(f, [a, b], [0, 1], {125 extrapolateLeft: "clamp",126 extrapolateRight: "clamp",127 easing: ease,128 });129130const CARD_W = 560;131const CARD_H = 252;132const RADIUS = 20;133const PAD = 30;134135const THEMES = {136 light: {137 ground: "paper-crease" as GshPresetId,138 base: "#EEECE8",139 card: "#FFFFFF",140 ink: "#141416",141 body: "rgba(20,20,22,0.5)",142 muted: "rgba(20,20,22,0.55)",143 hairline: "rgba(20,20,22,0.08)",144 avatar: "#EDEBE6",145 avatarInk: "rgba(20,20,22,0.7)",146 star: "#141416",147 starOff: "rgba(20,20,22,0.12)",148 title: "#141416",149 shadow: (air: number) =>150 `0 0 0 1px rgba(20,20,30,0.06), 0 1px 2px rgba(20,20,30,0.05), 0 ${10 + air * 24}px ${28 + air * 32}px -8px rgba(30,30,60,${0.14 + air * 0.05})`,151 },152 dark: {153 ground: "charcoal-satin" as GshPresetId,154 base: "#050506",155 card: "#141416",156 ink: "#EDEDEF",157 body: "rgba(237,237,239,0.48)",158 muted: "rgba(237,237,239,0.52)",159 hairline: "rgba(255,255,255,0.07)",160 avatar: "#232327",161 avatarInk: "rgba(237,237,239,0.75)",162 star: "#EDEDEF",163 starOff: "rgba(255,255,255,0.14)",164 title: "#F4F4F5",165 shadow: (air: number) =>166 `inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 1px rgba(255,255,255,0.08), 0 ${12 + air * 24}px ${36 + air * 32}px -8px rgba(0,0,0,0.7)`,167 },168} as const;169170type Palette = (typeof THEMES)[keyof typeof THEMES];171172function Star({ size, color }: { size: number; color: string }) {173 return (174 <svg width={size} height={size} viewBox="0 0 24 24" aria-hidden>175 <path176 d="M12 2.6l2.85 5.95 6.55.8-4.83 4.5 1.24 6.48L12 17.2l-5.81 3.13 1.24-6.48-4.83-4.5 6.55-.8z"177 fill={color}178 />179 </svg>180 );181}182183function QuoteCard({184 quote,185 lit,186 c,187 dim,188 fontFamily,189 fg,190}: {191 quote: TestimonialQuote;192 lit: number;193 c: Palette;194 dim: number;195 fontFamily: string;196 fg: string;197}) {198 const idx = quote.highlight ? quote.text.indexOf(quote.highlight) : -1;199 const before = idx >= 0 ? quote.text.slice(0, idx) : quote.text;200 const marked = idx >= 0 ? (quote.highlight as string) : "";201 const after = idx >= 0 ? quote.text.slice(idx + marked.length) : "";202 const markColor = interpolateColors(lit, [0, 1], [c.body, fg]);203 const sub = quote.handle ? `${quote.handle} · ${quote.role}` : quote.role;204205 return (206 <div207 style={{208 width: CARD_W,209 minHeight: CARD_H,210 boxSizing: "border-box",211 padding: `${PAD}px ${PAD}px ${PAD - 6}px`,212 display: "flex",213 flexDirection: "column",214 fontFamily,215 fontWeight: 400,216 color: fg,217 WebkitFontSmoothing: "antialiased",218 opacity: 1 - dim * 0.9,219 }}220 >221 {quote.stars ? (222 <div style={{ display: "flex", gap: 3, marginBottom: 14 }}>223 {[0, 1, 2, 3, 4].map((s) => (224 <Star225 key={s}226 size={17}227 color={s < (quote.stars ?? 0) ? c.star : c.starOff}228 />229 ))}230 </div>231 ) : null}232 <div233 style={{234 position: "relative",235 fontSize: 25,236 lineHeight: 1.36,237 letterSpacing: "-0.018em",238 color: c.body,239 textWrap: "pretty",240 }}241 >242 <span243 style={{244 position: "absolute",245 left: -16,246 top: -3,247 fontFamily: serif,248 fontSize: 40,249 lineHeight: 1,250 color: c.muted,251 }}252 >253 “254 </span>255 {before}256 {marked ? <span style={{ color: markColor }}>{marked}</span> : null}257 {after}”258 </div>259260 <div261 style={{262 marginTop: "auto",263 paddingTop: 16,264 borderTop: `1px solid ${c.hairline}`,265 display: "flex",266 alignItems: "center",267 gap: 12,268 }}269 >270 <div271 style={{272 width: 38,273 height: 38,274 borderRadius: 999,275 flexShrink: 0,276 background: c.avatar,277 display: "flex",278 alignItems: "center",279 justifyContent: "center",280 color: c.avatarInk,281 fontSize: 15,282 letterSpacing: "0.02em",283 }}284 >285 {initials(quote.name)}286 </div>287 <div style={{ flex: 1, minWidth: 0 }}>288 <div style={{ fontSize: 19, lineHeight: 1.25 }}>{quote.name}</div>289 <div290 style={{291 fontSize: 18,292 lineHeight: 1.3,293 color: c.muted,294 whiteSpace: "nowrap",295 overflow: "hidden",296 textOverflow: "ellipsis",297 }}298 >299 {sub}300 </div>301 </div>302 {quote.date ? (303 <div304 style={{305 alignSelf: "flex-start",306 fontSize: 18,307 lineHeight: 1.25,308 color: c.muted,309 fontVariantNumeric: "tabular-nums",310 whiteSpace: "nowrap",311 }}312 >313 {quote.date}314 </div>315 ) : null}316 </div>317 </div>318 );319}320321/** The foreground at `scale`, around the frame's center; nothing extra at 1. */322function ScaleLayer({323 scale,324 children,325}: {326 scale: number;327 children: React.ReactNode;328}) {329 if (scale === 1) return children;330 return (331 <AbsoluteFill style={{ transform: `scale(${scale})` }}>332 {children}333 </AbsoluteFill>334 );335}336337export function TestimonialStack({338 quotes = DEFAULT_QUOTES,339 ending = "pile",340 title = "What builders said after launch week",341 theme = "light",342 speed = 1,343 framesPerQuote = 50,344 ink,345 background,346 fontFamily = instrumentSans,347 radius = RADIUS,348 tilt = 1,349 scale: sceneScale = 1,350 delay = 0,351 ground,352 groundParams,353}: TestimonialStackProps) {354 const rawFrame = Math.max(0, useCurrentFrame() - delay);355 const { fps, width, height } = useVideoConfig();356 const frame = rawFrame * speed;357 const tall = height > width;358 const SW = tall ? 700 : 1280;359 const k = width / SW;360 const stageH = height / k;361 const c = THEMES[theme];362363 const n = quotes.length;364 const per = framesPerQuote;365 const startOf = (i: number) => (i === 0 ? -6 : 4 + i * per);366367 const lands = quotes.map((_, i) =>368 spring({ frame: frame - startOf(i), fps, config: CARD }),369 );370 const covers = quotes.map((_, i) =>371 ramp(frame, startOf(i) + 4, startOf(i) + 16),372 );373374 const fanStart = startOf(n - 1) + per - 6;375 const cols = tall ? 1 : n <= 3 ? n : Math.ceil(n / 2);376 const rows = Math.ceil(n / cols);377 const gap = tall ? 20 : 22;378 const titleBlock = title ? (tall ? 120 : 64) : 0;379 const fanScale = Math.min(380 tall ? 1 : 0.88,381 (SW - (tall ? 60 : 220) - gap * (cols - 1)) / (cols * CARD_W),382 (stageH - (tall ? 200 : 70) - titleBlock - gap * (rows - 1)) /383 (rows * CARD_H),384 );385 const cellW = CARD_W * fanScale + gap;386 const cellH = CARD_H * fanScale + gap;387 const wallH = titleBlock + rows * cellH - gap;388 const wallTop = -wallH / 2;389 const fanOf = (i: number) =>390 ending === "fan"391 ? spring({392 frame: frame - fanStart - (n - 1 - i) * 3,393 fps,394 config: MORPH,395 durationInFrames: 22,396 })397 : 0;398 const fanAll =399 ending === "fan"400 ? spring({401 frame: frame - fanStart,402 fps,403 config: MORPH,404 durationInFrames: 22 + (n - 1) * 3,405 })406 : 0;407 const titleIn = ramp(frame, fanStart + 10, fanStart + 24);408409 const camScale = interpolate(frame, [0, fanStart + 60], [1.02, 1.06], {410 extrapolateRight: "clamp",411 });412 const cam = interpolate(fanAll, [0, 1], [camScale, 1]);413 const pileScale = 1;414415 return (416 <AbsoluteFill417 style={{418 backgroundColor: background === undefined ? c.base : undefined,419 overflow: "hidden",420 }}421 >422 {background === undefined ? (423 <GshGround424 preset={groundParams ? undefined : (ground ?? c.ground)}425 params={groundParams}426 timeOffset={theme === "dark" ? 6 : 4}427 timeScale={0.35}428 />429 ) : (430 <AbsoluteFill431 style={{432 background: background === "transparent" ? undefined : background,433 }}434 />435 )}436 <ScaleLayer scale={sceneScale}>437 <div438 style={{439 position: "absolute",440 left: 0,441 top: 0,442 width: SW,443 height: stageH,444 transform: `scale(${k})`,445 transformOrigin: "0 0",446 }}447 >448 <div449 style={{450 position: "absolute",451 inset: 0,452 transform: `scale(${cam})`,453 transformOrigin: "50% 50%",454 }}455 >456 {ending === "fan" && title ? (457 <div458 style={{459 position: "absolute",460 left: tall ? 30 : 0,461 right: tall ? 30 : 0,462 top: stageH / 2 + wallTop,463 textAlign: "center",464 fontFamily,465 fontSize: tall ? 44 : 38,466 lineHeight: 1.1,467 fontWeight: 400,468 letterSpacing: "-0.03em",469 textWrap: "balance",470 WebkitFontSmoothing: "antialiased",471 color: ink ?? c.title,472 opacity: titleIn,473 transform: `translateY(${(1 - titleIn) * 10}px)`,474 filter:475 titleIn < 1 ? `blur(${(1 - titleIn) * 4}px)` : undefined,476 }}477 >478 {title}479 </div>480 ) : null}481 {quotes.map((quote, i) => {482 if (frame < startOf(i)) return null;483 const p = lands[i];484 const dx = i % 2 === 0 ? -1 : 1;485 const finalRot = dx * (1 + hash(i + 1) * 1.8) * tilt;486 const jitterX = (hash(i + 7) - 0.5) * (tall ? 20 : 36);487 const jitterY = (hash(i + 13) - 0.5) * 10;488489 let depth = 0;490 for (let j = i + 1; j < n; j++) depth += covers[j];491 const visibleDepth = Math.min(depth, 3);492493 let x = interpolate(p, [0, 1], [dx * SW * 0.78, jitterX]);494 let y =495 interpolate(496 p,497 [0, 1],498 [stageH * 0.58 + hash(i + 3) * 120, jitterY],499 ) -500 visibleDepth * 12;501 let rot = interpolate(502 p,503 [0, 1],504 [finalRot + dx * 12 * tilt, finalRot],505 );506 let scale =507 interpolate(p, [0, 1], [1.06, 1]) *508 (1 - visibleDepth * 0.045) *509 pileScale;510 let dim = Math.min(1, depth);511 let opacity = depth > 3 ? Math.max(0, 4 - depth) : 1;512513 if (ending === "fan") {514 const f = fanOf(i);515 const col = i % cols;516 const r = Math.floor(i / cols);517 const tx = (col - (cols - 1) / 2) * cellW;518 const ty =519 wallTop + titleBlock + r * cellH + (CARD_H * fanScale) / 2;520 x = interpolate(f, [0, 1], [x, tx]);521 y = interpolate(f, [0, 1], [y, ty]);522 rot = interpolate(f, [0, 1], [rot, 0]);523 scale = interpolate(f, [0, 1], [scale, fanScale]);524 dim = interpolate(f, [0, 1], [dim, 0]);525 opacity = interpolate(f, [0, 1], [opacity, 1]);526 }527528 const air = 1 - Math.min(1, p);529 const lit = ramp(frame - startOf(i), 14, 30, MOVE);530531 return (532 <div533 key={`${quote.name}-${i}`}534 style={{535 position: "absolute",536 left: SW / 2,537 top: stageH / 2,538 transform: `translate(-50%, -50%) translate(${x}px, ${y}px) rotate(${rot}deg) scale(${scale})`,539 opacity,540 zIndex: i,541 borderRadius: radius,542 background: c.card,543 boxShadow: c.shadow(air),544 }}545 >546 <QuoteCard547 quote={quote}548 lit={lit}549 c={c}550 dim={dim}551 fontFamily={fontFamily}552 fg={ink ?? c.ink}553 />554 </div>555 );556 })}557 </div>558 </div>559 </ScaleLayer>560 </AbsoluteFill>561 );562}









