← All components Next componentAcoustic Ripple Wall→
Sections · Deck
Monolith Stack Deck
Polished obsidian monoliths on titanium plinths, standing in a slanted row over a dark mirror floor. The front one carries the quote and a glowing inlay; click, swipe or use the arrows and it glides away while the next moves forward.
<MonolithStackDeck />Live
Click, swipe or use the arrows
Customize
Stone
Accent#c4b5fd
Stone#0d0c12
Text#ffffff
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add monolith-stack-deck
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/drei framer-motion && npm install -D @types/three
02
Add the component
One self-contained file: create components/MonolithStackDeck.tsx and paste it in.
components/MonolithStackDeck.tsx
1"use client";23import {4 useCallback,5 useEffect,6 useMemo,7 useRef,8 useState,9 type KeyboardEvent,10 type ReactNode,11 type RefObject,12} from "react";13import * as THREE from "three";14import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";15import { Canvas, useFrame, useThree, type CanvasProps } from "@react-three/fiber";16import { Environment, Lightformer, MeshReflectorMaterial } from "@react-three/drei";17import { motion } from "framer-motion";1819/**20 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep21 * their own tailored scenes).22 *23 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its24 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):25 *26 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }27 *28 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,29 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are30 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.31 */3233/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */34export type TiltAxis = "both" | "x-only" | "y-only" | "none";3536/** 1. Cursor: how the pointer pulls, pushes and drags the object. */37interface CursorProps {38 /** Reach of the pointer's influence, in the component's own space: CSS pixels for pixel-laid-out widgets, world units for 3D scenes (each component says which). Default 220 (px). */39 cursorRadius?: number;40 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */41 cursorForce?: number;42 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */43 magneticStrength?: number;44 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */45 cursorDamping?: number;46}4748/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */49interface TiltProps {50 /** Largest lean towards the pointer, in degrees. Default 15. */51 maxTiltAngle?: number;52 /** Axes that follow the pointer. Default "both". */53 tiltAxis?: TiltAxis;54 /** Lean away from the pointer instead of towards it. Default false. */55 invertTilt?: boolean;56 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */57 parallaxOffset?: number;58}5960/** 3. Text and 3D typography, for components that draw a label. */61interface Text3DProps {62 /** The label drawn by the component. */63 text?: string;64 /** Scale of the lettering. Default 1. */65 fontSize?: number;66 /** Extrusion depth of 3D letters. Default 0.2. */67 textDepth?: number;68 /** Bevelled, light-catching edges on 3D letters. Default true. */69 bevelEnabled?: boolean;70 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */71 fontUrl?: string;72}7374/** 4. Rendering, materials and glow. */75interface MaterialProps {76 /** Main color of the object. Default "#6366f1". */77 primaryColor?: string;78 /** Color of the glow. Default "#00f0ff". */79 emissiveColor?: string;80 /** Strength of the glow, 0 (none) to 3. Default 1. */81 emissiveIntensity?: number;82 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */83 roughness?: number;84 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */85 metalness?: number;86 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */87 transmission?: number;88 /** Technical wireframe rendering. Default false. */89 wireframe?: boolean;90}9192/** 5. Particles, idle motion and shader animation. */93interface MotionProps {94 /** Number of instanced elements. Default depends on the component. */95 particleCount?: number;96 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */97 autoRotateSpeed?: number;98 /** Pulses or ripples per second. Default 1. */99 pulseRate?: number;100 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */101 displacementScale?: number;102}103104/** 6. Environment and camera. */105interface EnvironmentProps {106 /** Camera field of view, in degrees. Default depends on the component. */107 cameraFov?: number;108 /** Color of the depth fog. Default "#0a0a0a". */109 fogColor?: string;110 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */111 fogDensity?: number;112}113114/** 7. Performance and accessibility. */115interface PerformanceProps {116 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */117 lowPowerMode?: boolean;118 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */119 respectReducedMotion?: boolean;120 /** Stop the render loop while the component is scrolled out of view. Default true. */121 pauseWhenOffscreen?: boolean;122}123124/** Every group at once. Components extend only the groups they apply (see the top of this file). */125interface Base3DComponentProps126 extends CursorProps,127 TiltProps,128 Text3DProps,129 MaterialProps,130 MotionProps,131 EnvironmentProps,132 PerformanceProps {}133134type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;135136/** The values a prop takes when it is left out. A component may override one, and then documents it. */137const DEFAULT_3D_PROPS: Defaults = {138 cursorRadius: 220,139 cursorForce: 1,140 magneticStrength: 0,141 cursorDamping: 0.1,142 maxTiltAngle: 15,143 tiltAxis: "both",144 invertTilt: false,145 parallaxOffset: 1,146 fontSize: 1,147 textDepth: 0.2,148 bevelEnabled: true,149 primaryColor: "#6366f1",150 emissiveColor: "#00f0ff",151 emissiveIntensity: 1,152 roughness: 0.3,153 metalness: 0.5,154 transmission: 0,155 wireframe: false,156 autoRotateSpeed: 0,157 pulseRate: 1,158 displacementScale: 1,159 fogColor: "#0a0a0a",160 fogDensity: 0,161 lowPowerMode: false,162 respectReducedMotion: true,163 pauseWhenOffscreen: true,164};165166/** True under 768px: scenes recompose (camera farther, layouts in columns). */167function useIsMobile() {168 const [mobile, setMobile] = useState(false);169 useEffect(() => {170 const query = window.matchMedia("(max-width: 767px)");171 const sync = () => setMobile(query.matches);172 sync();173 query.addEventListener("change", sync);174 return () => query.removeEventListener("change", sync);175 }, []);176 return mobile;177}178179function usePrefersReducedMotion() {180 const [reduced, setReduced] = useState(false);181 useEffect(() => {182 const query = window.matchMedia("(prefers-reduced-motion: reduce)");183 const sync = () => setReduced(query.matches);184 sync();185 query.addEventListener("change", sync);186 return () => query.removeEventListener("change", sync);187 }, []);188 return reduced;189}190191/** Pointer over an element, in -1..1 (y up), through window listeners (no re-render). */192function usePointer(target: RefObject<HTMLElement | null>) {193 const pointer = useRef({ x: 0, y: 0, inside: false });194 useEffect(() => {195 const move = (event: PointerEvent) => {196 const el = target.current;197 if (!el) return;198 const r = el.getBoundingClientRect();199 const p = pointer.current;200 p.x = ((event.clientX - r.left) / r.width) * 2 - 1;201 p.y = -(((event.clientY - r.top) / r.height) * 2 - 1);202 p.inside = Math.abs(p.x) <= 1 && Math.abs(p.y) <= 1;203 };204 window.addEventListener("pointermove", move, { passive: true });205 return () => window.removeEventListener("pointermove", move);206 }, [target]);207 return pointer;208}209210/**211 * Keeps the camera's view wide enough for content `width` world units across (portrait screens get a212 * farther camera instead of cropped sides). Call inside the Canvas.213 */214function FitWidth({ width, distance, target = [0, 0, 0] }: { width: number; distance: number; target?: [number, number, number] }) {215 const camera = useThree((s) => s.camera) as THREE.PerspectiveCamera;216 const size = useThree((s) => s.size);217 useEffect(() => {218 const aspect = size.width / Math.max(size.height, 1);219 const halfFov = THREE.MathUtils.degToRad(camera.fov / 2);220 // Distance at which `width` fits horizontally, never closer than the requested distance221 const needed = width / 2 / (Math.tan(halfFov) * aspect);222 const dir = camera.position.clone().sub(new THREE.Vector3(...target)).normalize();223 camera.position.copy(new THREE.Vector3(...target).addScaledVector(dir, Math.max(distance, needed)));224 camera.lookAt(...target);225 camera.updateProjectionMatrix();226 }, [camera, size, width, distance, target]);227 return null;228}229230// Shared by the testimonial sections: the testimonial shape, the common props and sample content.231232interface TestimonialItem {233 id: string;234 author: string;235 role: string;236 company: string;237 quote: string;238 /** 0 to 5 stars. */239 rating?: number;240 /** A result worth highlighting, e.g. "+140% conversion". */241 highlightMetric?: string;242}243244interface DeepTestimonialProps {245 /** The testimonials, in order. */246 items: TestimonialItem[];247 /** Pointer, drag, swipe and tilt. Default true. */248 interactive?: boolean;249 /**250 * Each section has its own material (holographic foil, porcelain, acoustic felt, obsidian): "glass" is its251 * translucent version, "solid" its opaque one. The default depends on the section.252 */253 variant?: "glass" | "solid";254 /** Speed of the motion (rotation, scrolling, idle float). Default 1. */255 speed?: number;256 /** Color of the highlights, of the active card's border and of the card details. Default "#a78bfa". */257 accentColor?: string;258 /** Base color of the cards' material (foil, porcelain, felt, stone). The default depends on the section. */259 surfaceColor?: string;260 /** Color of the quotes and names. The default depends on the section (dark ink on porcelain, light elsewhere). */261 textColor?: string;262 /** Extra classes for the section. */263 className?: string;264}265266const TESTIMONIAL_DEFAULTS = {267 interactive: true,268 variant: "glass",269 speed: 1,270 accentColor: "#a78bfa",271} as const;272273// Small pieces of the testimonial cards, shared by every section (no 3D dependency).274275/** Five stars, `rating` of them filled. */276function Stars({ rating, color, size = 13, empty = "rgba(255,255,255,0.18)" }: { rating: number; color: string; size?: number; empty?: string }) {277 const full = Math.max(0, Math.min(5, Math.round(rating)));278 return (279 <span className="flex gap-0.5" role="img" aria-label={`${full} out of 5 stars`}>280 {Array.from({ length: 5 }, (_, i) => (281 <svg key={i} viewBox="0 0 20 20" width={size} height={size} aria-hidden="true" style={{ fill: i < full ? color : empty }}>282 <path d="M10 1.5l2.6 5.4 5.9.8-4.3 4.1 1 5.8L10 14.8l-5.2 2.8 1-5.8L1.5 7.7l5.9-.8z" />283 </svg>284 ))}285 </span>286 );287}288289/** "AB" from "Ada Byron". */290function initials(name: string) {291 return name292 .split(/\s+/)293 .filter(Boolean)294 .slice(0, 2)295 .map((part) => part[0]?.toUpperCase() ?? "")296 .join("");297}298299/** `color` at `percent`% opacity, for any CSS color. */300function fade(color: string, percent: number) {301 return `color-mix(in srgb, ${color} ${percent}%, transparent)`;302}303304/**305 * The <Canvas> frameloop for `pauseWhenOffscreen`: "never" while the element is out of view. Put the ref306 * on the element that wraps the canvas (outside it: this hook runs in the component, not in the scene).307 */308function useOffscreenFrameloop(ref: RefObject<HTMLElement | null>, pauseWhenOffscreen: boolean = DEFAULT_3D_PROPS.pauseWhenOffscreen): "always" | "never" {309 // In view at first: some WebGL backends show an opaque canvas if it is paused before its first frame310 const [inView, setInView] = useState(true);311 useEffect(() => {312 const el = ref.current;313 if (!el || !pauseWhenOffscreen) return undefined;314 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));315 observer.observe(el);316 return () => observer.disconnect();317 }, [ref, pauseWhenOffscreen]);318 return !pauseWhenOffscreen || inView ? "always" : "never";319}320321// Building blocks of the testimonial sections. The quotes are real HTML of the section, laid in 3D over322// the canvas (see the card layer below): crisp on any screen, selectable, read by screen readers and323// indexed, and present even before WebGL has started.324325/** CSS size of a card's HTML. Its 3D slab has the same proportions. */326const CARD_PX = { width: 360, height: 236 };327328type Variant = NonNullable<DeepTestimonialProps["variant"]>;329330function isTouchDevice() {331 return typeof window !== "undefined" && window.matchMedia("(pointer: coarse)").matches;332}333334interface TestimonialCanvasProps extends Omit<CanvasProps, "children" | "style" | "gl" | "frameloop" | "dpr"> {335 children: ReactNode;336}337338/**339 * Canvas filling its positioned parent: pixel ratio capped (1.5 on touch screens), render loop paused340 * off-screen. The canvas itself ignores the pointer; the cards (HTML) and the section handle it.341 */342function TestimonialCanvas({ children, ...canvasProps }: TestimonialCanvasProps) {343 const ref = useRef<HTMLDivElement>(null);344 const frameloop = useOffscreenFrameloop(ref, true);345 const [touch] = useState(isTouchDevice);346 return (347 <div ref={ref} className="absolute inset-0">348 <Canvas349 dpr={[1, touch ? 1.5 : 2]}350 frameloop={frameloop}351 gl={{ antialias: !touch, alpha: true, powerPreference: "high-performance" }}352 style={{ pointerEvents: "none" }}353 {...canvasProps}354 >355 {children}356 </Canvas>357 </div>358 );359}360361/** The card layouts, one per material family. */362type CardTheme = "porcelain" | "felt";363364/** Default text color of each layout. */365const CARD_TEXT: Record<CardTheme, string> = { porcelain: "#17151d", felt: "#efeaf6" };366367interface TestimonialCardProps {368 item: TestimonialItem;369 accent: string;370 theme: CardTheme;371 /** Text color. Default: CARD_TEXT[theme]. */372 text?: string;373}374375const figureStyle = { width: CARD_PX.width, height: CARD_PX.height, backfaceVisibility: "hidden", WebkitBackfaceVisibility: "hidden" } as const;376377/** The quote as semantic HTML: a figure with a blockquote and its attribution. */378function TestimonialCard({ item, accent, theme, text = CARD_TEXT[theme] }: TestimonialCardProps) {379 if (theme === "porcelain") {380 // Editorial: dark ink on white, a large accent quote mark, an initials badge381 return (382 <figure className="relative m-0 flex flex-col overflow-hidden text-left" style={{ ...figureStyle, color: text, padding: "18px 24px 20px" }}>383 <div className="flex items-start justify-between">384 <span aria-hidden="true" className="font-serif text-[52px] leading-[0.8]" style={{ color: accent }}>385 “386 </span>387 {item.highlightMetric ? (388 <span className="mt-1 rounded-md px-2 py-1 font-mono text-[10px] font-semibold uppercase tracking-[0.1em]" style={{ background: fade(text, 6), color: fade(text, 70) }}>389 {item.highlightMetric}390 </span>391 ) : null}392 </div>393 <blockquote className="m-0 mt-1 line-clamp-4 font-serif text-[16px] leading-[1.42]" style={{ color: fade(text, 90) }}>394 {item.quote}395 </blockquote>396 <figcaption className="mt-auto flex items-center gap-3">397 <span aria-hidden="true" className="grid size-8 shrink-0 place-items-center rounded-full text-[11px] font-semibold text-white" style={{ background: `linear-gradient(135deg, ${accent}, ${text})` }}>398 {initials(item.author)}399 </span>400 <span className="flex min-w-0 flex-col">401 <span className="text-[13px] font-semibold">{item.author}</span>402 <span className="truncate text-[11px]" style={{ color: fade(text, 55) }}>403 {item.role} · {item.company}404 </span>405 </span>406 {item.rating !== undefined ? (407 <span className="ml-auto">408 <Stars rating={item.rating} color={text} size={11} empty={fade(text, 15)} />409 </span>410 ) : null}411 </figcaption>412 </figure>413 );414 }415416 // Felt: quiet and centered, the metric as an eyebrow, the quote, the name417 return (418 <figure className="m-0 flex flex-col items-center justify-center overflow-hidden text-center" style={{ ...figureStyle, color: text, padding: "20px 26px" }}>419 {item.highlightMetric ? (420 <span className="font-mono text-[10px] uppercase tracking-[0.28em]" style={{ color: accent }}>421 {item.highlightMetric}422 </span>423 ) : null}424 <blockquote className="m-0 mt-3 line-clamp-4 text-[15px] font-light leading-[1.5]" style={{ color: fade(text, 90) }}>425 “{item.quote}”426 </blockquote>427 <figcaption className="mt-4 flex flex-col items-center gap-1">428 <span className="text-[12px] font-medium tracking-[0.04em]">429 {item.author} <span style={{ color: fade(text, 45) }}>— {item.company}</span>430 </span>431 {item.rating !== undefined ? <Stars rating={item.rating} color={accent} size={10} empty={fade(text, 18)} /> : null}432 </figcaption>433 </figure>434 );435}436437// The cards are ordinary DOM elements of the section (same React tree, server-friendly, no portal), laid438// in 3D with CSS: a "camera" element reproduces the WebGL camera (perspective + inverse view matrix)439// and each card takes the world matrix of an anchor object in the scene, like three's CSS3DRenderer.440// The anchors are scaled so a card spans its slab.441442interface CardLayer {443 view: RefObject<HTMLDivElement | null>;444 camera: RefObject<HTMLDivElement | null>;445 anchors: RefObject<(THREE.Object3D | null)[]>;446 elements: RefObject<(HTMLDivElement | null)[]>;447}448449function useCardLayer(): CardLayer {450 const view = useRef<HTMLDivElement>(null);451 const camera = useRef<HTMLDivElement>(null);452 const anchors = useRef<(THREE.Object3D | null)[]>([]);453 const elements = useRef<(HTMLDivElement | null)[]>([]);454 return useMemo(() => ({ view, camera, anchors, elements }), []);455}456457/** Where card `index` lies in the scene: put it inside the card's group, just in front of its slab. */458function CardAnchor({ layer, index, width, z, px = CARD_PX.width }: { layer: CardLayer; index: number; width: number; z: number; px?: number }) {459 return (460 <group461 ref={(object) => {462 layer.anchors.current[index] = object;463 }}464 position={[0, 0, z]}465 scale={width / px}466 />467 );468}469470const cssNumber = (v: number) => (Math.abs(v) < 1e-10 ? 0 : v);471472// The layer measures the world in CSS pixels (WORLD_PX per world unit) so the cards keep a transform scale473// close to 1: at a tiny scale (1 px per unit), Chromium rasterizes the text far from its layout box.474// Scaling the whole view space does not change the perspective projection.475const WORLD_PX = 150;476477function cameraCss(m: THREE.Matrix4) {478 const e = m.elements;479 const k = WORLD_PX;480 const f = [e[0], -e[1], e[2], e[3], e[4], -e[5], e[6], e[7], e[8], -e[9], e[10], e[11], e[12] * k, -e[13] * k, e[14] * k, e[15]];481 return `matrix3d(${f.map(cssNumber).join(",")})`;482}483484function objectCss(m: THREE.Matrix4) {485 const e = m.elements;486 const k = WORLD_PX;487 const f = [e[0] * k, e[1] * k, e[2] * k, e[3], -e[4] * k, -e[5] * k, -e[6] * k, -e[7], e[8] * k, e[9] * k, e[10] * k, e[11], e[12] * k, e[13] * k, e[14] * k, e[15]];488 return `translate(-50%,-50%)matrix3d(${f.map(cssNumber).join(",")})`;489}490491/** Inside the Canvas, after the scene: copies the camera and the anchors onto the card layer every frame. */492function CardLayerSync({ layer }: { layer: CardLayer }) {493 const last = useRef({ perspective: -1, width: -1, height: -1 });494 useFrame(({ camera, size }) => {495 const view = layer.view.current;496 const cam = layer.camera.current;497 if (!view || !cam) return;498 const perspective = (camera as THREE.PerspectiveCamera).projectionMatrix.elements[5] * 0.5 * size.height;499 const l = last.current;500 if (l.perspective !== perspective) {501 view.style.perspective = `${perspective}px`;502 view.style.visibility = "visible";503 l.perspective = perspective;504 }505 if (l.width !== size.width || l.height !== size.height) {506 cam.style.width = `${size.width}px`;507 cam.style.height = `${size.height}px`;508 l.width = size.width;509 l.height = size.height;510 }511 camera.updateMatrixWorld();512 cam.style.transform = `translateZ(${perspective}px)${cameraCss(camera.matrixWorldInverse)}translate(${size.width / 2}px,${size.height / 2}px)`;513 layer.anchors.current.forEach((anchor, i) => {514 const el = layer.elements.current[i];515 if (!anchor || !el) return;516 anchor.updateWorldMatrix(true, false);517 el.style.transform = objectCss(anchor.matrixWorld);518 });519 });520 return null;521}522523/** The DOM side of the layer, over the canvas. Its cards are LayerCards. */524function CardLayerView({ layer, children }: { layer: CardLayer; children: ReactNode }) {525 return (526 // Hidden until the first frame has placed the cards (before that they would pile up in a corner)527 <div ref={layer.view} className="pointer-events-none absolute inset-0 overflow-hidden" style={{ visibility: "hidden" }}>528 <div ref={layer.camera} className="absolute left-0 top-0" style={{ transformStyle: "preserve-3d" }}>529 {children}530 </div>531 </div>532 );533}534535interface LayerCardProps extends Partial<TestimonialCardProps> {536 layer: CardLayer;537 index: number;538 /** A repeated copy (rings, ribbons): hidden from screen readers so each quote is read once. */539 duplicate?: boolean;540 onSelect?: () => void;541 onHover?: (hovered: boolean) => void;542 /** A card of your own instead of TestimonialCard (the anchor's `px` must match its width). */543 children?: ReactNode;544}545546/** One card of the layer, placed every frame on its anchor. */547function LayerCard({ layer, index, duplicate = false, onSelect, onHover, children, ...card }: LayerCardProps) {548 return (549 <div550 ref={(el) => {551 layer.elements.current[index] = el;552 }}553 aria-hidden={duplicate ? true : undefined}554 className="absolute left-0 top-0 rounded-2xl outline-none focus-visible:ring-2 focus-visible:ring-white/70"555 style={{ pointerEvents: onSelect || onHover ? "auto" : "none", cursor: onSelect ? "pointer" : undefined, transformStyle: "preserve-3d", willChange: "transform" }}556 role={onSelect ? "button" : undefined}557 tabIndex={onSelect && !duplicate ? 0 : undefined}558 onClick={onSelect}559 onKeyDown={560 onSelect561 ? (event) => {562 if (event.key === "Enter" || event.key === " ") {563 event.preventDefault();564 onSelect();565 }566 }567 : undefined568 }569 onPointerEnter={onHover ? () => onHover(true) : undefined}570 onPointerLeave={onHover ? () => onHover(false) : undefined}571 >572 {children ?? (card.item && card.accent && card.theme ? <TestimonialCard item={card.item} accent={card.accent} theme={card.theme} text={card.text} /> : null)}573 </div>574 );575}576577interface DragHandlers {578 onStart?: () => void;579 /** Movement since the last event, CSS px. */580 onMove: (dx: number, dy: number) => void;581 /** Release velocity, CSS px per second, and the total horizontal travel. */582 onEnd?: (vx: number, vy: number, travelX: number) => void;583}584585/** Mouse, pen or touch drag on an element, with release velocity. Vertical page scroll stays native on touch. */586function useDrag(target: RefObject<HTMLElement | null>, enabled: boolean, handlers: DragHandlers) {587 const ref = useRef(handlers);588 useEffect(() => {589 ref.current = handlers;590 });591 useEffect(() => {592 const el = target.current;593 if (!el || !enabled) return undefined;594 let id: number | null = null;595 let lastX = 0;596 let lastY = 0;597 let startX = 0;598 let lastT = 0;599 let vx = 0;600 let vy = 0;601 const down = (e: PointerEvent) => {602 if (e.button !== 0 || id !== null) return;603 id = e.pointerId;604 lastX = startX = e.clientX;605 lastY = e.clientY;606 lastT = performance.now();607 vx = vy = 0;608 ref.current.onStart?.();609 };610 const move = (e: PointerEvent) => {611 if (e.pointerId !== id) return;612 const now = performance.now();613 const dt = Math.max(1, now - lastT) / 1000;614 const dx = e.clientX - lastX;615 const dy = e.clientY - lastY;616 vx = vx * 0.6 + (dx / dt) * 0.4;617 vy = vy * 0.6 + (dy / dt) * 0.4;618 lastX = e.clientX;619 lastY = e.clientY;620 lastT = now;621 ref.current.onMove(dx, dy);622 };623 const up = (e: PointerEvent) => {624 if (e.pointerId !== id) return;625 id = null;626 const idle = performance.now() - lastT > 90;627 ref.current.onEnd?.(idle ? 0 : vx, idle ? 0 : vy, e.clientX - startX);628 };629 el.addEventListener("pointerdown", down);630 window.addEventListener("pointermove", move, { passive: true });631 window.addEventListener("pointerup", up);632 window.addEventListener("pointercancel", up);633 return () => {634 el.removeEventListener("pointerdown", down);635 window.removeEventListener("pointermove", move);636 window.removeEventListener("pointerup", up);637 window.removeEventListener("pointercancel", up);638 };639 }, [target, enabled]);640}641642export interface MonolithStackDeckProps extends DeepTestimonialProps {643 /** "solid" (default): polished obsidian. "glass": smoked glass tinted by surfaceColor. */644 variant?: DeepTestimonialProps["variant"];645 /** Color of the stone or of the smoked glass. Default "#0d0c12". */646 surfaceColor?: string;647 /** Color of the quote and the name. Default "#ffffff". */648 textColor?: string;649}650651/** CSS size of a monolith's card: portrait, like the stone. */652const MONO_PX = { width: 300, height: 404 };653const W = 2.3;654const H = W * (MONO_PX.height / MONO_PX.width);655const D = 0.36;656const PLINTH_H = 0.16;657const FLOOR_Y = -H / 2 - PLINTH_H;658const VISIBLE = 4; // monoliths shown behind the front one659const LEAVE_TIME = 0.75; // s, at speed 1660const SWIPE_PX = 60;661const ORIGIN: [number, number, number] = [0.9, -0.3, -1.4];662663interface Pose {664 x: number;665 y: number;666 z: number;667 ry: number;668}669670/** Below the floor: monoliths beyond the visible row wait there, and rise when their turn comes. */671const SUNK = FLOOR_Y - H / 2 - 0.3;672673/** The front monolith faces you; the others recede in a slanted row, turning towards the light. */674function slotPose(slot: number): Pose {675 const s = Math.min(slot, VISIBLE);676 return { x: s * 0.66, y: slot <= VISIBLE ? 0 : SUNK, z: -s * 1.1, ry: -s * 0.17 };677}678679/** Where a monolith goes when it leaves: gliding out of frame to the left, turning away. */680const EXIT: Pose = { x: -8.5, y: 0, z: 0.6, ry: 0.9 };681682interface Plate extends Pose {683 slot: number;684 /** Seconds left in its exit; 0 when it is in the row. */685 leaving: number;686}687688/* -------------------------------------------------------------------------- */689/* One monolith */690/* -------------------------------------------------------------------------- */691692interface MonolithHandle {693 group: THREE.Group | null;694 /** 0 to 1: the inlaid accent line lights up on the front monolith. */695 setGlow: (amount: number) => void;696}697698interface MonolithProps {699 index: number;700 variant: Variant;701 surface: string;702 accent: string;703 layer: CardLayer;704 handle: (api: MonolithHandle) => void;705}706707function inlayShape(width: number, height: number, radius: number, line: number) {708 const outer = new THREE.Shape();709 const hole = new THREE.Path();710 const trace = (path: THREE.Shape | THREE.Path, w: number, h: number, r: number) => {711 path.moveTo(-w + r, -h);712 path.lineTo(w - r, -h);713 path.quadraticCurveTo(w, -h, w, -h + r);714 path.lineTo(w, h - r);715 path.quadraticCurveTo(w, h, w - r, h);716 path.lineTo(-w + r, h);717 path.quadraticCurveTo(-w, h, -w, h - r);718 path.lineTo(-w, -h + r);719 path.quadraticCurveTo(-w, -h, -w + r, -h);720 };721 trace(outer, width / 2, height / 2, radius);722 trace(hole, width / 2 - line, height / 2 - line, Math.max(radius - line, 0.001));723 outer.holes.push(hole);724 return outer;725}726727function Monolith({ index, variant, surface, accent, layer, handle }: MonolithProps) {728 const geometries = useMemo(() => {729 const body = new RoundedBoxGeometry(W, H, D, 6, 0.05);730 const inlay = new THREE.ShapeGeometry(inlayShape(W - 0.2, H - 0.2, 0.08, 0.012), 8);731 inlay.translate(0, 0, D / 2 + 0.002);732 const plinth = new RoundedBoxGeometry(W * 1.08, PLINTH_H, D * 1.9, 3, 0.02);733 plinth.translate(0, -H / 2 - PLINTH_H / 2, 0);734 return { body, inlay, plinth };735 }, []);736737 const materials = useMemo(() => {738 const tint = new THREE.Color(surface);739 const body =740 variant === "glass"741 ? new THREE.MeshPhysicalMaterial({ color: "#ffffff", transmission: 1, thickness: 2.4, roughness: 0.1, ior: 1.52, clearcoat: 1, clearcoatRoughness: 0.04, attenuationColor: tint, attenuationDistance: 0.55 })742 : new THREE.MeshPhysicalMaterial({ color: tint, roughness: 0.16, metalness: 0.15, clearcoat: 1, clearcoatRoughness: 0.05, reflectivity: 0.7, envMapIntensity: 1.6 });743 const inlay = new THREE.MeshStandardMaterial({ color: accent, metalness: 1, roughness: 0.28, emissive: new THREE.Color(accent), emissiveIntensity: 0.1 });744 // Brushed titanium pedestal745 const plinth = new THREE.MeshPhysicalMaterial({ color: "#3a3842", metalness: 1, roughness: 0.32, clearcoat: 0.3 });746 return { body, inlay, plinth };747 }, [variant, surface, accent]);748749 useEffect(() => () => Object.values(geometries).forEach((g) => g.dispose()), [geometries]);750 useEffect(() => () => Object.values(materials).forEach((m) => m.dispose()), [materials]);751752 const group = useRef<THREE.Group>(null);753 useEffect(() => {754 handle({755 get group() {756 return group.current;757 },758 setGlow(value) {759 materials.inlay.emissiveIntensity = 0.1 + value * 1.6;760 },761 });762 }, [handle, materials]);763764 return (765 <group ref={group}>766 <mesh geometry={geometries.body} material={materials.body} />767 <mesh geometry={geometries.inlay} material={materials.inlay} />768 <mesh geometry={geometries.plinth} material={materials.plinth} />769 <CardAnchor layer={layer} index={index} width={W} z={D / 2 + 0.01} px={MONO_PX.width} />770 </group>771 );772}773774/* -------------------------------------------------------------------------- */775/* Gallery */776/* -------------------------------------------------------------------------- */777778/** Fine dust drifting through the light, for depth. */779function Dust({ accent, still }: { accent: string; still: boolean }) {780 const points = useRef<THREE.Points>(null);781 const { geometry, material } = useMemo(() => {782 const count = 260;783 const positions = new Float32Array(count * 3);784 for (let i = 0; i < count; i++) {785 positions[i * 3] = -4 + Math.random() * 10;786 positions[i * 3 + 1] = FLOOR_Y + Math.random() * 5;787 positions[i * 3 + 2] = -7 + Math.random() * 9;788 }789 const g = new THREE.BufferGeometry();790 g.setAttribute("position", new THREE.BufferAttribute(positions, 3));791 const m = new THREE.PointsMaterial({ color: new THREE.Color(accent).lerp(new THREE.Color("#ffffff"), 0.6), size: 0.022, transparent: true, opacity: 0.55, depthWrite: false, blending: THREE.AdditiveBlending, sizeAttenuation: true });792 return { geometry: g, material: m };793 }, [accent]);794 useEffect(795 () => () => {796 geometry.dispose();797 material.dispose();798 },799 [geometry, material]800 );801 useFrame((state) => {802 if (still || !points.current) return;803 const t = state.clock.elapsedTime;804 points.current.position.set(Math.sin(t * 0.05) * 0.4, Math.sin(t * 0.07) * 0.25, 0);805 points.current.rotation.y = Math.sin(t * 0.03) * 0.05;806 });807 return <points ref={points} geometry={geometry} material={material} />;808}809810interface GalleryProps {811 count: number;812 variant: Variant;813 surface: string;814 accent: string;815 plates: RefObject<Plate[]>;816 layer: CardLayer;817 speed: number;818 still: boolean;819 interactive: boolean;820 pointer: RefObject<{ x: number; y: number; inside: boolean }>;821 mobile: boolean;822}823824function Gallery({ count, variant, surface, accent, plates, layer, speed, still, interactive, pointer, mobile }: GalleryProps) {825 const monoliths = useRef<(MonolithHandle | null)[]>([]);826 const tilt = useRef({ x: 0, y: 0 });827 const bindings = useMemo(828 () =>829 Array.from({ length: count }, (_, i) => (api: MonolithHandle) => {830 monoliths.current[i] = api;831 }),832 [count]833 );834835 useFrame((_, delta) => {836 const dt = Math.min(delta, 1 / 30);837 // Unhurried, critically damped motion: no bounce, a weighty glide838 const lambda = still ? 60 : 5.5 * Math.max(speed, 0.2);839 const ptr = pointer.current;840 const t = tilt.current;841 t.x = THREE.MathUtils.damp(t.x, interactive && ptr.inside ? -ptr.y * 0.09 : 0, 3, dt);842 t.y = THREE.MathUtils.damp(t.y, interactive && ptr.inside ? ptr.x * 0.14 : 0, 3, dt);843844 plates.current.forEach((p, i) => {845 if (p.leaving > 0) {846 p.leaving = Math.max(0, p.leaving - dt * Math.max(speed, 0.2));847 if (p.leaving === 0) {848 // Out of frame: it rises out of the floor at the back of the row849 const back = slotPose(p.slot);850 Object.assign(p, { x: back.x, y: SUNK, z: back.z, ry: back.ry });851 }852 }853 const target = p.leaving > 0 ? EXIT : slotPose(p.slot);854 p.x = THREE.MathUtils.damp(p.x, target.x, lambda, dt);855 p.y = THREE.MathUtils.damp(p.y, target.y, lambda, dt);856 p.z = THREE.MathUtils.damp(p.z, target.z, lambda, dt);857 p.ry = THREE.MathUtils.damp(p.ry, target.ry, lambda, dt);858859 // How close it is to the front position860 const front = 1 - THREE.MathUtils.smoothstep(Math.abs(p.x) + Math.abs(p.z) + Math.abs(p.ry), 0.04, 0.7);861 const api = monoliths.current[i];862 const g = api?.group;863 if (g) {864 g.position.set(p.x, p.y, p.z);865 g.rotation.set(t.x * front, p.ry + t.y * front, 0);866 }867 if (g) g.visible = p.y > SUNK + 0.05 && p.x > EXIT.x + 0.5;868 api?.setGlow(p.leaving > 0 ? 0 : front);869 // Only the front monolith shows its quote870 const el = layer.elements.current[i];871 if (el) el.style.opacity = String(p.leaving > 0 ? 0 : front * front);872 });873 });874875 return (876 <>877 <fog attach="fog" args={["#060509", 9, 19]} />878 <ambientLight intensity={0.15} />879 <spotLight position={[-3, 7, 6]} angle={0.42} penumbra={1} intensity={120} decay={1.6} distance={24} color="#ffffff" />880 {/* Strip lights in front: a soft sheen across the faces and one crisp vertical streak */}881 <Environment resolution={256} frames={1}>882 {/* The camera looks down on the faces, so they mirror what lies low in front of them */}883 <Lightformer form="rect" intensity={0.55} position={[0, -2.4, 9]} scale={[14, 5, 1]} />884 <Lightformer form="rect" intensity={0.8} position={[0, 3.5, 9]} scale={[7, 2.2, 1]} />885 <Lightformer form="rect" intensity={3} position={[-2.2, -1.5, 9]} scale={[0.3, 14, 1]} />886 <Lightformer form="rect" intensity={2} position={[4.5, 1, 6]} rotation-y={-0.6} scale={[0.3, 9, 1]} />887 <Lightformer form="rect" intensity={2.6} color={accent} position={[0, 1, -7]} scale={[9, 0.6, 1]} />888 <Lightformer form="rect" intensity={0.8} position={[0, 8, 0]} rotation-x={Math.PI / 2} scale={[10, 10, 1]} />889 </Environment>890 <Dust accent={accent} still={still} />891892 {Array.from({ length: count }, (_, i) => (893 <Monolith key={i} index={i} variant={variant} surface={surface} accent={accent} layer={layer} handle={bindings[i]} />894 ))}895896 {/* Dark polished floor reflecting the row */}897 <mesh rotation-x={-Math.PI / 2} position={[1, FLOOR_Y, -3]}>898 <planeGeometry args={[40, 30]} />899 <MeshReflectorMaterial900 resolution={mobile ? 256 : 512}901 blur={[320, 90]}902 mixBlur={1}903 mixStrength={5}904 mixContrast={1}905 mirror={0.85}906 depthScale={1.1}907 minDepthThreshold={0.35}908 maxDepthThreshold={1.3}909 color="#09080c"910 roughness={0.7}911 metalness={0.6}912 />913 </mesh>914 </>915 );916}917918/* -------------------------------------------------------------------------- */919/* Card */920/* -------------------------------------------------------------------------- */921922/** "+140% conversion" → ["+140%", "conversion"]. */923function splitMetric(metric: string): [string, string] {924 const space = metric.indexOf(" ");925 return space < 0 ? [metric, ""] : [metric.slice(0, space), metric.slice(space + 1)];926}927928function MonolithCard({ item, accent, text, active, still }: { item: TestimonialItem; accent: string; text: string; active: boolean; still: boolean }) {929 const metric = item.highlightMetric ? splitMetric(item.highlightMetric) : null;930 return (931 <figure932 className="relative m-0 flex flex-col overflow-hidden text-left"933 style={{ color: text, width: MONO_PX.width, height: MONO_PX.height, padding: "30px 28px 26px", backfaceVisibility: "hidden", WebkitBackfaceVisibility: "hidden" }}934 >935 <div className="flex items-center justify-between">936 <span className="font-mono text-[10px] uppercase tracking-[0.32em]" style={{ color: fade(text, 50) }}>{item.company}</span>937 {item.rating !== undefined ? <Stars rating={item.rating} color={accent} size={10} empty={fade(text, 18)} /> : null}938 </div>939 <span aria-hidden="true" className="mt-4 h-px w-10" style={{ background: accent }} />940 <blockquote className="m-0 mt-5 line-clamp-6 font-serif text-[20px] italic leading-[1.38]" style={{ color: fade(text, 92) }}>“{item.quote}”</blockquote>941 {metric ? (942 <p className="m-0 mt-auto flex items-baseline gap-2">943 <span className="bg-clip-text text-[34px] font-semibold leading-none tracking-tight text-transparent" style={{ backgroundImage: `linear-gradient(120deg, ${text} 30%, ${accent})` }}>944 {metric[0]}945 </span>946 <span className="font-mono text-[10px] uppercase tracking-[0.2em]" style={{ color: fade(text, 45) }}>{metric[1]}</span>947 </p>948 ) : null}949 <figcaption className={`${metric ? "mt-5" : "mt-auto"} flex items-center gap-3 border-t pt-4`} style={{ borderColor: fade(text, 10) }}>950 <span aria-hidden="true" className="grid size-9 shrink-0 place-items-center rounded-full text-[11px] font-semibold" style={{ boxShadow: `inset 0 0 0 1px ${accent}88`, background: "rgba(255,255,255,0.04)", color: accent }}>951 {initials(item.author)}952 </span>953 <span className="flex min-w-0 flex-col">954 <span className="text-[13px] font-semibold">{item.author}</span>955 <span className="truncate text-[11px]" style={{ color: fade(text, 50) }}>{item.role}</span>956 </span>957 </figcaption>958 {/* A light sweep across the stone when it arrives in front */}959 {active && !still ? (960 <motion.span961 aria-hidden="true"962 className="pointer-events-none absolute inset-y-0 w-1/2"963 style={{ background: "linear-gradient(100deg, transparent, rgba(255,255,255,0.13), transparent)" }}964 initial={{ left: "-60%" }}965 animate={{ left: "130%" }}966 transition={{ duration: 1.3, delay: 0.35, ease: [0.4, 0, 0.2, 1] }}967 />968 ) : null}969 </figure>970 );971}972973/* -------------------------------------------------------------------------- */974/* Section */975/* -------------------------------------------------------------------------- */976977const ArrowIcon = ({ flip }: { flip?: boolean }) => (978 <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={flip ? { transform: "scaleX(-1)" } : undefined}>979 <path d="M5 12h14M13 6l6 6-6 6" />980 </svg>981);982983/**984 * A gallery of polished obsidian monoliths (or smoked glass) on titanium plinths, standing in a slanted985 * row over a dark mirror floor, in the dark. The front monolith carries the quote, with an inlaid accent line that986 * lights up; it follows the pointer slightly. Click it, swipe, use the arrows or the progress bar: it987 * glides away to the left and the next one moves forward, while it rejoins the back of the row.988 */989export default function MonolithStackDeck({990 items,991 interactive = TESTIMONIAL_DEFAULTS.interactive,992 variant = "solid",993 speed = TESTIMONIAL_DEFAULTS.speed,994 accentColor = "#c4b5fd",995 surfaceColor = "#0d0c12",996 textColor = "#ffffff",997 className = "",998}: MonolithStackDeckProps) {999 const section = useRef<HTMLElement>(null);1000 const reduced = usePrefersReducedMotion();1001 const mobile = useIsMobile();1002 const pointer = usePointer(section);1003 const layer = useCardLayer();1004 const count = items.length;1005 const [front, setFront] = useState(0);10061007 const order = useRef<number[]>([]);1008 const plates = useRef<Plate[]>([]);1009 // A new list resets the row1010 useEffect(() => {1011 order.current = items.map((_, i) => i);1012 plates.current = items.map((_, i) => ({ ...slotPose(i), slot: i, leaving: 0 }));1013 setFront(0);1014 }, [items]);10151016 const settle = useCallback(() => {1017 order.current.forEach((card, slot) => {1018 const p = plates.current[card];1019 if (p) p.slot = slot;1020 });1021 setFront(order.current[0] ?? 0);1022 }, []);10231024 /** The front monolith leaves to the left and rejoins the back of the row. */1025 const next = useCallback(() => {1026 if (order.current.length < 2) return;1027 const card = order.current.shift() as number;1028 order.current.push(card);1029 const p = plates.current[card];1030 if (p) p.leaving = LEAVE_TIME;1031 settle();1032 }, [settle]);10331034 /** The last monolith comes back to the front, from the left. */1035 const previous = useCallback(() => {1036 if (order.current.length < 2) return;1037 const card = order.current.pop() as number;1038 order.current.unshift(card);1039 const p = plates.current[card];1040 if (p) Object.assign(p, { ...EXIT, leaving: 0 });1041 // It glides back in from the left; the one that left the row sinks into the floor1042 settle();1043 }, [settle]);10441045 const goTo = useCallback(1046 (index: number) => {1047 const steps = order.current.indexOf(index);1048 if (steps <= 0) return;1049 if (steps > order.current.length / 2) {1050 for (let k = order.current.length - steps; k > 0; k--) previous();1051 } else {1052 for (let k = 0; k < steps; k++) next();1053 }1054 },1055 [next, previous]1056 );10571058 useDrag(section, interactive, {1059 onMove: () => undefined,1060 onEnd: (_vx, _vy, travel) => {1061 if (travel < -SWIPE_PX) next();1062 else if (travel > SWIPE_PX) previous();1063 },1064 });10651066 const onKeyDown = (event: KeyboardEvent) => {1067 if (!interactive) return;1068 if (event.key === "ArrowRight") {1069 event.preventDefault();1070 next();1071 } else if (event.key === "ArrowLeft") {1072 event.preventDefault();1073 previous();1074 }1075 };10761077 const frontItem: TestimonialItem | undefined = items[front];1078 const button = "grid size-11 place-items-center rounded-full border border-white/15 bg-white/[0.03] text-white/80 backdrop-blur transition-colors hover:border-white/40 hover:text-white";10791080 return (1081 <section1082 ref={section}1083 aria-label="Customer testimonials"1084 aria-roledescription="carousel"1085 tabIndex={interactive ? 0 : undefined}1086 onKeyDown={onKeyDown}1087 className={`relative h-[min(92svh,820px)] min-h-[600px] w-full select-none overflow-hidden outline-none focus-visible:ring-2 focus-visible:ring-white/40 ${className}`}1088 style={{ touchAction: "pan-y", background: "#060509" }}1089 >1090 <TestimonialCanvas camera={{ fov: 30, near: 0.1, far: 60, position: [0, 1.5, 11] }}>1091 <FitWidth width={mobile ? 4.2 : 7.6} distance={10} target={ORIGIN} />1092 <Gallery count={count} variant={variant} surface={surfaceColor} accent={accentColor} plates={plates} layer={layer} speed={speed} still={reduced} interactive={interactive} pointer={pointer} mobile={mobile} />1093 <CardLayerSync layer={layer} />1094 </TestimonialCanvas>1095 <CardLayerView layer={layer}>1096 {items.map((item, i) => (1097 <LayerCard key={item.id} layer={layer} index={i} item={item} accent={accentColor} onSelect={interactive && i === front ? next : undefined}>1098 <MonolithCard item={item} accent={accentColor} text={textColor} active={i === front} still={reduced} />1099 </LayerCard>1100 ))}1101 </CardLayerView>11021103 {interactive && count > 1 ? (1104 <div className="absolute inset-x-0 bottom-7 flex flex-col items-center gap-4 text-white">1105 <div className="flex items-center gap-5">1106 <button type="button" onClick={previous} aria-label="Previous testimonial" className={button}>1107 <ArrowIcon flip />1108 </button>1109 <span className="min-w-20 text-center font-mono text-xs tracking-[0.25em] text-white/45">1110 <span className="text-white">{String(front + 1).padStart(2, "0")}</span> — {String(count).padStart(2, "0")}1111 </span>1112 <button type="button" onClick={next} aria-label="Next testimonial" className={button}>1113 <ArrowIcon />1114 </button>1115 </div>1116 <div className="flex gap-1.5">1117 {items.map((item, i) => (1118 <button key={item.id} type="button" onClick={() => goTo(i)} aria-label={`Show testimonial ${i + 1}`} aria-current={i === front ? "true" : undefined} className="group h-4 w-7 py-[7px]">1119 <span className="block h-[2px] w-full rounded-full transition-colors duration-500" style={{ background: i === front ? accentColor : "rgba(255,255,255,0.16)" }} />1120 </button>1121 ))}1122 </div>1123 </div>1124 ) : null}1125 <p className="sr-only" aria-live="polite">1126 {frontItem ? `${frontItem.author}, ${frontItem.role} at ${frontItem.company}: ${frontItem.quote}` : ""}1127 </p>1128 </section>1129 );1130}
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import MonolithStackDeck from "@/components/MonolithStackDeck";23export default function Section() {4 return (5 // The component fills this box: give it a position and a height6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>7 <MonolithStackDeck8 variant="solid"9 speed={1}10 accentColor="#c4b5fd"11 surfaceColor="#0d0c12"12 textColor="#ffffff"13 interactive14 items={testimonials}15 />16 </div>17 );18}