Components80 / 118
Journal Flip
A photo journal you flip through like a real one: the open page lies flat, read pages and pages to come stand in tight stacks of edges on each side. Drag or flick and the pages turn across, bending at the middle as they go and wobbling flat when they land; a flick riffles through a whole run.
GalleryGallery3D pages3D pagesDragDragPaper bendPaper bendSquash & stretchSquash & stretchGSAPGSAP
Journal
70 pages


first morning, still jet-lagged
02 Jun


first morning, still jet-lagged
02 Jun


first morning, still jet-lagged
02 Jun


got lost. best detour yet
03 Jun


got lost. best detour yet
03 Jun


got lost. best detour yet
03 Jun


the sea was louder than us
04 Jun


the sea was louder than us
04 Jun


the sea was louder than us
04 Jun

old streets, new shoes
05 Jun

old streets, new shoes
05 Jun

old streets, new shoes
05 Jun


found the tiny café
06 Jun


found the tiny café
06 Jun


found the tiny café
06 Jun


golden hour, every hour
07 Jun


golden hour, every hour
07 Jun


golden hour, every hour
07 Jun

climbed all of it
08 Jun

climbed all of it
08 Jun

climbed all of it
08 Jun


the city after dark
09 Jun


the city after dark
09 Jun


the city after dark
09 Jun


a long table, new friends
10 Jun


a long table, new friends
10 Jun


a long table, new friends
10 Jun

nothing planned today
11 Jun

nothing planned today
11 Jun

nothing planned today
11 Jun


back to the hill
12 Jun


back to the hill
12 Jun


back to the hill
12 Jun


last night here
13 Jun


last night here
13 Jun


last night here
13 Jun
6 / 70
Drag or flick the pagesClick a page in a stack
Tweak
LIVELIVEText
Usage
Follows your tweaks.
usage.tsx
import { JournalFlip } from "@/components/inreact/journal-flip";
const pages = [
{ photo: "/trip/01.jpg", inset: "/trip/01-b.jpg", caption: "first morning, still jet-lagged", date: "02 Jun" },
{ photo: "/trip/02.jpg", caption: "got lost. best detour yet", date: "03 Jun" },
// ...
];
export function Trip() {
return (
<div className="h-[620px]">
<JournalFlip pages={pages} />
</div>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/journal-flip.jsonOr copy the source
Install the dependencies, then save this as components/inreact/journal-flip.tsx.
terminal
npm install gsapcomponents/inreact/journal-flip.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef, useState } from "react";
/**
* Journal Flip: a photo journal you flip through like a real one.
*
* The open page lies flat in front of you; the pages you've read and the ones
* still to come stand on either side as tight stacks of page edges. Drag,
* flick, swipe, use the arrows (or click a page in a stack) and the pages
* turn across. The paper bends as it turns: each page folds a little at its
* middle, more the faster it moves, and when it lands it wobbles flat again.
* A flick can riffle through a whole run of pages at once.
*
* <JournalFlip pages={[{ photo: "/trip/1.jpg", caption: "first light", date: "12 Jun" }]} />
*/
export interface JournalPage {
photo: string;
focus?: string;
/** A small taped photo on the page. */
inset?: string;
caption?: string;
date?: string;
}
export interface JournalFlipProps {
pages: JournalPage[];
title?: string;
/** Page count to show (defaults to the number of pages). */
total?: number;
/** Background of the area (CSS). */
background?: string;
/** The page it opens on. */
startIndex?: number;
onChange?: (index: number) => void;
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));
const smooth = (t: number) => t * t * (3 - 2 * t);
// laid out once at this size and scaled to fit
const DW = 1000, DH = 620, PW = 450, PH = 350;
const SIDE = 10; // pages visible in each stack
const SCRIPT = `"Segoe Print", "Bradley Hand", "Comic Sans MS", cursive`;
// the page's drop shadow sits on one layer behind both halves, and each half outlines only its outer sides,
// so nothing is drawn down the middle where the halves meet
const SHADOW = "0 10px 26px rgba(5,6,20,.32)";
const SEAM = 1; // the right half tucks 1px under the left, so a sub-pixel gap can never open while pages turn
function PageFace({ p, half }: { p: JournalPage; half: 0 | 1 }) {
// each page is drawn as two halves (so it can bend at the middle); both
// halves render the full page and show their side of it
return (
<div className="absolute top-0 h-full overflow-hidden" style={{ width: PW, left: half ? -PW / 2 + SEAM : 0 }}>
<img src={p.photo} alt="" draggable={false} className="pointer-events-none absolute inset-0 h-full w-full object-cover" style={{ objectPosition: p.focus ?? "50% 45%" }} />
<div className="absolute inset-0" style={{ background: "linear-gradient(180deg, rgba(0,0,0,.18) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,.22) 100%)" }} />
{p.inset && (
<div className="absolute top-[22px] right-[26px] w-[118px] rotate-[6deg] bg-white p-[6px] pb-[20px] shadow-[0_4px_12px_rgba(0,0,0,.28)]">
<img src={p.inset} alt="" draggable={false} className="pointer-events-none h-[104px] w-full object-cover" />
<span className="absolute -top-[9px] left-1/2 h-[16px] w-[52px] -translate-x-1/2 -rotate-[4deg] bg-[#f6e7b0]/80" />
</div>
)}
{p.caption && (
<div className="absolute bottom-[22px] left-[24px] max-w-[230px] -rotate-[3deg] rounded-[4px] bg-[#fffaf0]/92 px-3 py-1.5 text-[19px] leading-tight text-[#2b2620] shadow-[0_2px_8px_rgba(0,0,0,.2)]" style={{ fontFamily: SCRIPT }}>
{p.caption}
</div>
)}
{p.date && (
<div className="absolute top-[20px] left-[22px] rounded-full bg-black/35 px-2.5 py-1 font-mono text-[10px] tracking-[0.14em] text-white uppercase backdrop-blur-[2px]">{p.date}</div>
)}
</div>
);
}
export function JournalFlip({ pages, title = "Journal", total, background = "#2c3150", startIndex = 0, onChange, className }: JournalFlipProps) {
const wrapRef = useRef<HTMLDivElement>(null);
const stageRef = useRef<HTMLDivElement>(null);
const pageEls = useRef<(HTMLDivElement | null)[]>([]);
const folds = useRef<(HTMLDivElement | null)[]>([]);
const [scale, setScale] = useState(1);
const [at, setAt] = useState(() => clamp(0, Math.max(0, pages.length - 1), startIndex));
const go = useRef<(k: number) => void>(() => {});
const n = pages.length;
const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
useEffect(() => {
const el = wrapRef.current;
if (!el) return;
const ro = new ResizeObserver(([e]) => setScale(Math.min(e.contentRect.width / DW, (e.contentRect.height || DH) / DH)));
ro.observe(el);
return () => ro.disconnect();
}, []);
useEffect(() => {
const stage = stageRef.current;
if (!stage || !n) return;
const still = reduced();
const s0 = clamp(0, n - 1, startIndex);
const st = { p: s0, v: 0, target: s0, drag: false, wob: 0, vwob: 0, wasMoving: false };
let current = s0;
const last = pages.map(() => "");
go.current = (k: number) => {
st.target = clamp(0, n - 1, k);
const i = Math.round(st.target);
if (i !== current) {
current = i;
setAt(i);
onChangeRef.current?.(i);
}
};
// where a page sits for an offset d from the open page
const slot = (d: number) => {
const a = Math.abs(d), sg = Math.sign(d) || 1;
if (a < 1) {
const e = smooth(a);
return { x: sg * e * (PW / 2 + 34), ry: -sg * e * 74, z: -e * 46, sh: e };
}
const k = Math.min(a, SIDE + 1) - 1;
return { x: sg * (PW / 2 + 34 + k * 15), ry: -sg * (74 + Math.min(k, 6) * 1.2), z: -46 - k * 9, sh: 1 };
};
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
const h = dt / 2;
for (let s = 0; s < 2; s++) {
if (!st.drag) {
if (still) {
st.p = st.target;
st.v = 0;
} else {
const k = 60, c = 2 * 0.86 * Math.sqrt(k);
st.v += (k * (st.target - st.p) - c * st.v) * h;
st.p += st.v * h;
}
}
// the paper's follow-through when it lands
const kw = 210, cw = 2 * 0.2 * Math.sqrt(kw);
st.vwob += (-kw * st.wob - cw * st.vwob) * h;
st.wob += st.vwob * h;
}
const moving = Math.abs(st.v) > 0.25 || st.drag;
if (!moving && st.wasMoving && !still) st.vwob += clamp(-90, 90, st.v * 40 - 30);
st.wasMoving = moving;
// bend: the paper lags behind its own turn
const bendAll = still ? 0 : clamp(-26, 26, st.v * 9);
for (let k = 0; k < n; k++) {
const d = k - st.p, a = Math.abs(d);
const el = pageEls.current[k];
if (!el) continue;
if (a > SIDE + 1.5) {
if (last[k] !== "hidden") {
el.style.visibility = "hidden";
last[k] = "hidden";
}
continue;
}
const sl = slot(d);
// pages bend most while they're crossing over; the open page carries the wobble
const crossing = a < 1.2 ? 1 - Math.min(1, a) * 0.4 : 0.25;
const bend = bendAll * crossing + (a < 0.5 ? st.wob * (1 - a * 2) : 0);
const tr = `translate3d(${sl.x.toFixed(2)}px,0,${sl.z.toFixed(2)}px) rotateY(${sl.ry.toFixed(2)}deg)`;
const key = `${tr}|${bend.toFixed(2)}|${sl.sh.toFixed(2)}`;
if (key !== last[k]) {
el.style.visibility = "visible";
el.style.transform = tr;
el.style.zIndex = String(1000 - Math.round(a * 10));
const f = folds.current[k];
if (f) f.style.transform = `rotateY(${bend.toFixed(2)}deg)`;
// side pages fall into shade; the fold darkens with the bend
el.style.setProperty("--shade", (sl.sh * 0.55).toFixed(3));
el.style.setProperty("--fold", (Math.abs(bend) / 110).toFixed(3));
last[k] = key;
}
}
};
gsap.ticker.add(tick);
// drag / flick
const PX = 150;
let sx = 0, sp = 0, lx = 0, lt = 0, moved = 0, id = -1;
const lx_ = (e: { clientX: number }) => {
const r = stage.getBoundingClientRect();
return (e.clientX - r.left) / (r.width / DW);
};
const onDown = (e: PointerEvent) => {
if (e.button !== 0) return;
id = e.pointerId;
st.drag = true;
sx = lx = lx_(e);
sp = st.p;
lt = performance.now();
moved = 0;
};
const onMove = (e: PointerEvent) => {
if (e.pointerId !== id || !st.drag) return;
const x = lx_(e);
const dx = x - sx;
moved = Math.max(moved, Math.abs(dx));
if (moved > 4 && !stage.hasPointerCapture(e.pointerId)) {
try {
stage.setPointerCapture(e.pointerId);
} catch {
/* capture is a nicety */
}
}
const now = performance.now(), ddt = Math.max(1, now - lt) / 1000;
st.v = st.v * 0.6 + (-(x - lx) / PX / ddt) * 0.4;
lx = x;
lt = now;
let p = sp - dx / PX;
if (p < 0) p = -Math.pow(-p, 0.7) * 0.4;
if (p > n - 1) p = n - 1 + Math.pow(p - (n - 1), 0.7) * 0.4;
st.p = p;
};
const onUp = (e: PointerEvent) => {
if (e.pointerId !== id) return;
id = -1;
if (!st.drag) return;
st.drag = false;
if (moved < 5) {
const page = (e.target as HTMLElement).closest<HTMLElement>("[data-page]");
if (page) go.current(Number(page.dataset.page));
else go.current(Math.round(st.p));
return;
}
go.current(Math.round(st.p + clamp(-8, 8, st.v * 0.42)));
};
let wacc = 0, wlock = 0;
const onWheel = (e: WheelEvent) => {
const dx = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.shiftKey ? e.deltaY : 0;
if (!dx) return;
e.preventDefault();
const now = performance.now();
if (now < wlock) return;
wacc += dx;
if (Math.abs(wacc) > 40) {
go.current(Math.round(st.target) + Math.sign(wacc));
wacc = 0;
wlock = now + 260;
}
};
const onKey = (e: KeyboardEvent) => {
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
e.preventDefault();
go.current(Math.round(st.target) + (e.key === "ArrowRight" ? 1 : -1));
};
stage.addEventListener("pointerdown", onDown);
stage.addEventListener("pointermove", onMove);
stage.addEventListener("pointerup", onUp);
stage.addEventListener("pointercancel", onUp);
stage.addEventListener("wheel", onWheel, { passive: false });
stage.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
stage.removeEventListener("pointerdown", onDown);
stage.removeEventListener("pointermove", onMove);
stage.removeEventListener("pointerup", onUp);
stage.removeEventListener("pointercancel", onUp);
stage.removeEventListener("wheel", onWheel);
stage.removeEventListener("keydown", onKey);
};
}, [n, pages]);
const btn = "grid size-11 place-items-center rounded-full bg-white text-[#1d2036] shadow-[0_2px_8px_rgba(0,0,0,.25)] transition-transform duration-200 hover:scale-105 active:scale-95 disabled:opacity-40";
return (
<div ref={wrapRef} className={["relative h-full w-full overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
<div
ref={stageRef}
tabIndex={0}
role="region"
aria-roledescription="carousel"
aria-label={title}
className="absolute top-1/2 left-1/2 cursor-grab touch-pan-y outline-none select-none active:cursor-grabbing"
style={{ width: DW, height: DH, marginLeft: -DW / 2, marginTop: -DH / 2, transform: `scale(${scale})` }}
>
<div className="absolute inset-x-0 text-center text-white" style={{ top: 34 }}>
<div className="text-[30px] font-semibold tracking-[-0.02em]">{title}</div>
<div className="mt-1.5 flex items-center justify-center gap-1.5 text-[13px] text-white/75">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M4 5.5A2.5 2.5 0 0 1 6.5 3H20v15H6.5A2.5 2.5 0 0 0 4 20.5v-15Z" />
<path d="M4 20.5A2.5 2.5 0 0 1 6.5 18H20" />
</svg>
{total ?? n} pages
</div>
</div>
{/* the book */}
<div className="absolute inset-x-0 [perspective:1300px]" style={{ top: 112, height: PH + 40 }}>
{/* its shadow on the table */}
<div className="absolute left-1/2 -translate-x-1/2 rounded-[50%]" style={{ top: PH - 20, height: 90, width: 900, background: "radial-gradient(closest-side, rgba(8,10,25,.55), rgba(8,10,25,0))" }} />
<div className="absolute inset-0 [transform-style:preserve-3d]">
{pages.map((p, k) => (
<div
key={k}
ref={(el) => void (pageEls.current[k] = el)}
data-page={k}
role="group"
aria-roledescription="slide"
aria-label={`Page ${k + 1}${p.caption ? `: ${p.caption}` : ""}`}
className="absolute left-1/2 [transform-style:preserve-3d] will-change-transform"
style={{ top: 14, width: PW, height: PH, marginLeft: -PW / 2 }}
>
{/* the page's shadow on the table, behind both halves (shadow only: an opaque layer here would hide the half as it folds back) */}
<div className="pointer-events-none absolute inset-0 rounded-[16px]" style={{ boxShadow: SHADOW }} />
{/* a narrow strip of the same page behind the hinge: any edge pixel of the halves blends into identical picture, never a line */}
<div className="pointer-events-none absolute top-0 h-full overflow-hidden" style={{ left: PW / 2 - 2, width: 4, transform: "translateZ(-0.5px)" }}>
<div className="absolute top-0 h-full" style={{ left: -(PW / 2 - 2), width: PW }}>
<PageFace p={p} half={0} />
</div>
<div className="absolute inset-0 bg-[#0b0d1d]" style={{ opacity: "var(--shade, 0)" }} />
</div>
{/* left half */}
<div className="absolute top-0 left-0 h-full overflow-hidden rounded-l-[16px]" style={{ width: PW / 2 }}>
<PageFace p={p} half={0} />
<div className="pointer-events-none absolute inset-0 bg-[#0b0d1d]" style={{ opacity: "var(--shade, 0)" }} />
<div className="pointer-events-none absolute inset-0 rounded-l-[16px] border border-r-0 border-white/20" />
</div>
{/* right half: folds at the middle as the paper bends */}
<div
ref={(el) => void (folds.current[k] = el)}
className="absolute top-0 h-full overflow-hidden rounded-r-[16px] [transform-origin:0_50%]"
style={{ width: PW / 2 + SEAM, left: PW / 2 - SEAM }}
>
<PageFace p={p} half={1} />
{/* the fold catches a little more shade */}
<div className="pointer-events-none absolute inset-0 bg-[#0b0d1d]" style={{ opacity: "calc(var(--shade, 0) + var(--fold, 0))" }} />
<div className="pointer-events-none absolute inset-0 rounded-r-[16px] border border-l-0 border-white/20" />
</div>
</div>
))}
</div>
</div>
<div className="absolute inset-x-0 flex items-center justify-center gap-3" style={{ top: 540 }}>
<button type="button" aria-label="Previous page" className={btn} disabled={at === 0} onClick={() => go.current(at - 1)}>
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="m14.5 6-6 6 6 6" />
</svg>
</button>
<div className="min-w-[88px] rounded-full bg-white/12 px-4 py-2.5 text-center text-[13px] font-medium text-white tabular-nums">
{at + 1} / {total ?? n}
</div>
<button type="button" aria-label="Next page" className={btn} disabled={at === n - 1} onClick={() => go.current(at + 1)}>
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="m9.5 6 6 6-6 6" />
</svg>
</button>
</div>
</div>
</div>
);
}
export default JournalFlip;
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
7 propspages{ photo; focus?; inset?; caption?; date? }[]The pages.titlestringTitle above the book.default "Journal"default "Journal"totalnumberPage count to show (defaults to the number of pages).backgroundstringBackground (CSS).default "#2c3150"default "#2c3150"startIndexnumberThe page it opens on.default 0default 0onChange(index: number) => voidCalled when the open page changes.classNamestringExtra classes (give the container a height).