Components85 / 118
Trip Card
An activity card whose photos fan out when you reach for it, like a hand of cards, each on its own spring and leaning toward your cursor. The title takes on a colour picked from the photos, the arrow slides out and back in, and clicking a photo brings it to the front.
CardCardPhoto stackPhoto stackHoverHoverSpringsSpringsSquash & stretchSquash & stretchGSAPGSAP
City Walk



~4 Hours6 kmEasy
A slow loop through colourful streets, quiet corners and the best coffee in town.
Hover the cardClick a photo to bring it forward
Tweak
LIVELIVEContent
Card
Look
320px
Usage
Follows your tweaks.
usage.tsx
import { TripCard } from "@/components/inreact/trip-card";
export function Activity() {
return (
<TripCard
title="City Walk"
photos={["/trips/1.jpg", "/trips/2.jpg", "/trips/3.jpg"]}
stats={["~4 Hours","6 km","Easy"]}
description="A slow loop through colourful streets, quiet corners and the best coffee in town."
href="/trips/city-walk"
/>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/trip-card.jsonOr copy the source
Install the dependencies, then save this as components/inreact/trip-card.tsx.
terminal
npm install gsapcomponents/inreact/trip-card.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef, useState } from "react";
/**
* Trip Card: an activity card whose photos fan out when you reach for it.
*
* A clean card: a big title with an arrow, a tight stack of photos, a row of
* stats and a line of description. Hover it and the photos fan out like a
* hand of cards, each on its own spring (they stretch as they travel, squash
* as they land and settle at different moments), leaning toward your cursor
* at different depths. The title takes on a colour picked from the photos
* themselves, and the arrow slides out and back in. Click a photo to bring it
* to the front. GSAP.
*
* <TripCard title="Mountain Hike" photos={["/a.jpg", "/b.jpg", "/c.jpg"]} stats={["~8 Hours", "8 km", "Medium"]} />
*/
export interface TripCardProps {
title: string;
/** Up to three photos (back to front). */
photos: string[];
/** Short facts under the photos (time, distance, level…). */
stats?: string[];
description?: string;
href?: string;
/** The title's hover colour (picked from the photos if not given). */
accent?: string;
/** Card width, px. */
width?: number;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
// where each photo sits, stacked and fanned (card-relative, px at 320 wide)
const STACK = [
{ x: 0, y: 0, r: -2, s: 1 },
{ x: 12, y: -2, r: 1, s: 1 },
{ x: 24, y: -4, r: 3, s: 1 },
];
const FAN = [
{ x: -4, y: 8, r: -7, s: 1 },
{ x: 78, y: 0, r: -11, s: 1.02 },
{ x: 156, y: -30, r: -27, s: 1.06 },
];
/** a legible, slightly deepened version of a photo's average colour */
function pickAccent(src: string): Promise<string> {
return new Promise((resolve) => {
const im = new Image();
im.crossOrigin = "anonymous";
im.onload = () => {
try {
const c = document.createElement("canvas");
c.width = c.height = 16;
const x = c.getContext("2d")!;
x.drawImage(im, 0, 0, 16, 16);
const d = x.getImageData(0, 0, 16, 16).data;
let r = 0, g = 0, b = 0, n = 0;
for (let i = 0; i < d.length; i += 4) {
// favour saturated pixels, so skies and greys don't wash it out
const mx = Math.max(d[i], d[i + 1], d[i + 2]), mn = Math.min(d[i], d[i + 1], d[i + 2]);
const w = 0.2 + (mx - mn) / 255;
r += d[i] * w;
g += d[i + 1] * w;
b += d[i + 2] * w;
n += w;
}
r /= n;
g /= n;
b /= n;
// deepen to about 30% lightness, keep the hue
const l = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
const k = clamp(0.25, 1, 0.32 / Math.max(0.05, l));
resolve(`rgb(${Math.round(r * k)}, ${Math.round(g * k)}, ${Math.round(b * k)})`);
} catch {
resolve("#3f4a22");
}
};
im.onerror = () => resolve("#3f4a22");
im.src = src;
});
}
export function TripCard({ title, photos, stats = [], description, href, accent, width = 320, className }: TripCardProps) {
const rootRef = useRef<HTMLDivElement>(null);
const titleRef = useRef<HTMLDivElement>(null);
const arrowA = useRef<HTMLSpanElement>(null);
const arrowB = useRef<HTMLSpanElement>(null);
const imgs = useRef<(HTMLDivElement | null)[]>([]);
const [tint, setTint] = useState(accent ?? "#3f4a22");
const [order, setOrder] = useState(() => photos.slice(0, 3).map((_, i) => i));
const orderRef = useRef(order);
orderRef.current = order;
const K = width / 320;
const P = Math.round(96 * K); // photo size
useEffect(() => {
if (accent) return setTint(accent);
let live = true;
pickAccent(photos[photos.length - 1] ?? photos[0]).then((c) => live && setTint(c));
return () => void (live = false);
}, [accent, photos]);
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const still = reduced();
const N = Math.min(3, photos.length);
// a spring body per photo, each a touch different (they settle at different moments)
const B = Array.from({ length: N }, (_, i) => ({ x: STACK[i].x, y: STACK[i].y, r: STACK[i].r, s: 1, vx: 0, vy: 0, vr: 0, vs: 0, k: 170 - i * 22, z: 0.5 - i * 0.04, lx: 0, ly: 0, pop: 0, vpop: 0 }));
let fan = 0;
const aim = { x: 0, y: 0, tx: 0, ty: 0 };
const last = B.map(() => "");
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
const h = dt / 2;
aim.x += (aim.tx - aim.x) * Math.min(1, dt * 7);
aim.y += (aim.ty - aim.y) * Math.min(1, dt * 7);
const ord = orderRef.current;
// each photo owns its spring; its slot (target) comes from the current order
B.forEach((b, photo) => {
const slot = Math.max(0, ord.indexOf(photo));
const tgt = fan ? FAN[slot] : STACK[slot];
// each photo leans toward the cursor by its depth
const depth = (slot + 1) / N;
const tx = tgt.x * K + aim.x * 10 * depth * fan, ty = tgt.y * K + aim.y * 8 * depth * fan, tr = tgt.r + aim.x * 4 * depth * fan, ts = tgt.s;
for (let i = 0; i < 2; i++) {
if (still) {
b.x = tx;
b.y = ty;
b.r = tr;
b.s = ts;
break;
}
const c = 2 * b.z * Math.sqrt(b.k);
b.vx += (b.k * (tx - b.x) - c * b.vx) * h;
b.x += b.vx * h;
b.vy += (b.k * (ty - b.y) - c * b.vy) * h;
b.y += b.vy * h;
b.vr += (b.k * (tr - b.r) - c * b.vr) * h;
b.r += b.vr * h;
b.vs += (b.k * (ts - b.s) - c * b.vs) * h;
b.s += b.vs * h;
const kp = 300, cp = 2 * 0.22 * Math.sqrt(kp);
b.vpop += (-kp * b.pop - cp * b.vpop) * h;
b.pop += b.vpop * h;
}
// stretch along the travel, squash as it lands
const sp = Math.hypot(b.vx, b.vy);
const st = still ? 0 : clamp(0, 0.12, sp * 0.0006);
const ang = (Math.atan2(b.vy, b.vx) * 180) / Math.PI;
const pop = clamp(-0.15, 0.2, b.pop);
const tr2 = `translate3d(${b.x.toFixed(2)}px,${b.y.toFixed(2)}px,0) rotate(${b.r.toFixed(2)}deg) rotate(${(ang - b.r).toFixed(1)}deg) scale(${((1 + st) * (b.s + pop)).toFixed(4)},${((b.s - pop * 0.6) / (1 + st)).toFixed(4)}) rotate(${(-(ang - b.r)).toFixed(1)}deg)`;
if (tr2 !== last[photo]) {
const el = imgs.current[photo];
if (el) {
el.style.transform = tr2;
el.style.zIndex = String(10 + slot);
}
last[photo] = tr2;
}
});
};
gsap.ticker.add(tick);
const onEnter = () => {
fan = 1;
if (still) return;
B.forEach((b, i) => (b.vy -= 160 + i * 60)); // a little hop as they spread
gsap.to(titleRef.current, { color: "var(--tint)", duration: 0.45, ease: "power2.out" });
// the arrow slides out, and back in from the left
gsap.timeline()
.to(arrowA.current, { x: "110%", opacity: 0, duration: 0.22, ease: "power2.in" })
.fromTo(arrowB.current, { x: "-110%", opacity: 0 }, { x: "0%", opacity: 1, duration: 0.45, ease: "back.out(2.2)" }, 0.12);
};
const onLeave = () => {
fan = 0;
aim.tx = aim.ty = 0;
if (still) return;
gsap.to(titleRef.current, { color: "#111114", duration: 0.45, ease: "power2.out" });
gsap.to(arrowB.current, { x: "110%", opacity: 0, duration: 0.2, ease: "power2.in" });
gsap.fromTo(arrowA.current, { x: "-110%", opacity: 0 }, { x: "0%", opacity: 1, duration: 0.45, ease: "back.out(2.2)", delay: 0.1 });
};
const onMove = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
aim.tx = clamp(-1, 1, ((e.clientX - r.left) / r.width - 0.5) * 2);
aim.ty = clamp(-1, 1, ((e.clientY - r.top) / r.height - 0.5) * 2);
};
// click a photo: it comes to the front with a jelly pop
const onClick = (e: MouseEvent) => {
const el = (e.target as HTMLElement).closest<HTMLElement>("[data-photo]");
if (!el) return;
e.preventDefault();
e.stopPropagation();
const idx = Number(el.dataset.photo);
const ord = orderRef.current.filter((x) => x !== idx).concat(idx);
setOrder(ord);
const b = B[idx];
if (b && !still) b.vpop += 2.6;
};
root.addEventListener("pointerenter", onEnter);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointermove", onMove);
root.addEventListener("click", onClick, true);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointerenter", onEnter);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("click", onClick, true);
};
}, [photos, K]);
const Wrap = href ? "a" : "div";
return (
<div ref={rootRef} className={["relative inline-block select-none", className].filter(Boolean).join(" ")} style={{ width, ["--tint" as string]: tint }}>
<Wrap
{...(href ? { href } : {})}
className="block rounded-[22px] bg-white text-[#111114] no-underline outline-none focus-visible:ring-2 focus-visible:ring-black/30"
style={{ padding: Math.round(22 * K), boxShadow: "0 1px 2px rgba(10,40,50,.08), 0 14px 34px rgba(10,40,50,.16), 0 30px 60px rgba(10,40,50,.1)" }}
>
<div ref={titleRef} className="font-semibold tracking-[-0.03em]" style={{ fontSize: Math.round(52 * K), lineHeight: 1.02, color: "#111114" }}>
{title}{" "}
<span className="relative inline-block overflow-hidden align-[-0.08em]" style={{ width: "0.85em", height: "0.9em" }}>
{[arrowA, arrowB].map((ref, i) => (
<span key={i} ref={ref} className="absolute inset-0 grid place-items-center" style={{ opacity: i ? 0 : 1 }}>
<svg viewBox="0 0 24 24" width="0.8em" height="0.8em" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M4 12h15M13 5.5 19.5 12 13 18.5" />
</svg>
</span>
))}
</span>
</div>
{/* the photos */}
<div className="relative" style={{ height: Math.round(P * 1.18), marginTop: Math.round(18 * K) }}>
{photos.slice(0, 3).map((src, i) => (
<div
key={i}
ref={(el) => void (imgs.current[i] = el)}
data-photo={i}
className="absolute bottom-0 left-0 cursor-pointer will-change-transform"
style={{ width: P, height: P * 1.04, transformOrigin: "50% 80%" }}
>
<div className="h-full w-full overflow-hidden rounded-[16px] bg-[#ddd]" style={{ border: `${Math.max(2, Math.round(3 * K))}px solid #fff`, boxShadow: "0 2px 4px rgba(0,0,0,.12), 0 10px 22px rgba(0,0,0,.18)" }}>
<img src={src} alt="" draggable={false} className="pointer-events-none h-full w-full object-cover" />
</div>
</div>
))}
</div>
{stats.length > 0 && (
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-[#111114]/80" style={{ marginTop: Math.round(16 * K), fontSize: Math.max(10, Math.round(11.5 * K)) }}>
{stats.map((s, i) => (
<span key={i} className="inline-flex items-center gap-1.5">
<span className="size-[0.55em] rounded-full bg-current opacity-50" />
{s}
</span>
))}
</div>
)}
{description && (
<p className="leading-[1.4] text-[#111114]/70" style={{ marginTop: Math.round(10 * K), fontSize: Math.max(11, Math.round(14 * K)) }}>
{description}
</p>
)}
</Wrap>
</div>
);
}
export default TripCard;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
8 propstitlestringThe card title.photosstring[]Up to three photos (back to front).statsstring[]Short facts (time, distance, level…).descriptionstringA line of description.hrefstringMake the card a link.accentstringTitle hover colour (picked from the photos if not given).widthnumberCard width, px.default 320default 320classNamestringExtra classes.