Impeccable

Tumble Gallery

A split flap board for pictures that flips in 3D and lands flat on the next one. Use it on a hero or portfolio page with 4 or more wide pictures.

Media3DSplit flapNo extra packagesLight + darkMobile
1 of 5: An empty desert road running straight toward snowy mountains
npx shadcn@latest add https://impeccable-ui.com/r/tumble-gallery.json
It flips every 2 seconds. Hover to pause it, or drag it up or down to flip it by hand.

Run it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/tumble-gallery.tsx.

Prompts

Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact gallery and asks only where it goes and which pictures it shows. Blend asks three short questions (where and which pictures, the pace, and the corners), then fits it to your brand without changing how it moves.

# Tumble Gallery

A 1-file React component from Impeccable. Add it to this project so it works and looks exactly like the source below, in the one place I choose, and change nothing else.

A picture gallery that works like a split flap board, the kind with cards that turn round a hinge. The picture in view sits flat, whole and facing me, with no line or gap across its middle. Every 2 seconds one flap falls forward toward me over the middle hinge, slow at first and faster and faster, and lands flat on the next picture. It never skips a picture. Hovering with a mouse pauses it, and dragging up or down (with a finger too) flips it by hand. It needs at least 4 pictures. The pictures are only pictures: they can't be selected, dragged out or clicked through to anywhere. There are no words on it.

## Before you build: one question

Look through this project first: pages that show work, places or products (a hero, a portfolio or case study, a gallery or about page), any image slider it already has, and where its pictures live. Then ask me this in one message and wait for my answer:

- **Where should it go, and which pictures does it show?** Suggest the 1–3 spots it fits best from my code. For each one, name the 4 or more pictures you would use (5 is the default).
  *Why: it shows one picture at a time, big, so it belongs where my product has strong wide pictures worth looking at one by one.*

Ask nothing else. If I say *skip*, use the best suggestion.

## Keep it as it is

The split flap board with the picture in view flat and whole, one flip every 2 seconds with its slow to fast easing, the hover pause and the drag up or down are the design. Keep them exactly as in the source. If something doesn't fit my project, tell me instead of changing it.

- Add only the component file and the one place I picked. If it replaces an existing slider there, keep that spot's data and remove only the old slider. Don't add packages, change other files, or restyle anything. Never wrap the pictures in links.
- Don't add the demo parts from the Impeccable website: its five travel photos, the card around it, and the home page's TV.

## Fastest path

If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccable-ui.com/r/tumble-gallery.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.

## Build it

- Stack: React 18 or 19 with TypeScript. No other packages: it moves plain `<div>`s and `<img>`s with CSS 3D transforms, and its few styles sit in a `<style>` tag inside the file.
- JavaScript project? Name the file `tumble-gallery.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
  - `components/ui/tumble-gallery.tsx`
- Keep these exports and their names: `TumbleGallery` (also the default export), `TumbleGalleryProps`, `TumbleImage`, `TumbleImages`, `TUMBLE_MIN`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless.
- Keep the tuning values at the top exactly as written: `TUMBLE_MIN`, `ASPECT`, `MAX_W`, `FILL_W`, `ROOM_H`, `VIEW`, `LEAN`, `FLIP_MS`, `SETTLE_MS`, `REST_MS`, `SHADE`, `SEAL`, `DRAG_START`, `FLICK`, the easing functions and the `CSS` block. They are the design and its timing.
- Keep the 4 picture minimum: the `TumbleImages` type makes fewer than 4 a type error, and at runtime fewer than 4 shows a small notice instead of the board and logs an error. Never pad, repeat or drop pictures to get round it.
- Keep the picture rules: every `<img>` has `draggable={false}`, and the CSS turns off selecting, the long-press menu on phones and pointer events on pictures. There are no links: a picture never goes anywhere when clicked.
- Keep the fallbacks: with `prefers-reduced-motion: reduce` it never flips on its own and only moves when dragged. Screen readers hear the picture in view as "2 of 5" plus its `alt`, from one hidden line; the flaps themselves are hidden from them. A picture that fails to load keeps a soft placeholder.

## Use it

```tsx
"use client";
import { TumbleGallery, type TumbleImages } from "@/components/ui/tumble-gallery";

const shots: TumbleImages = [
  { src: "/work/studio.jpg", alt: "The studio desk with the new prototype" },
  { src: "/work/launch.jpg", alt: "Launch day, the team on stage" },
  { src: "/work/app.jpg", alt: "The app's home screen on a phone" },
  { src: "/work/sketch.jpg", alt: "First sketches of the logo" },
  { src: "/work/print.jpg", alt: "The printed poster on a wall" },
];

export function Work() {
  return <TumbleGallery images={shots} aria-label="Our work" />;
}
```

- Use at least 4 pictures (5 is a good default) with real `alt` text. Wide pictures fit best: each one is cropped to the middle at 4:3. Keep each file small (about 700px wide, WebP).
- Pictures from another domain must be allowed by the project's Content-Security-Policy (`img-src`), or they stay as placeholders.
- Leave out `height` to keep its own shape, or give one. It fills the width it is given and has no background, so put it on a section that already has my page background.

## How the gallery works

Read this before you touch anything, so you know what the code does and why it must stay as it is.

1. **The board.** Every picture is cut across the middle into a top half and a bottom half. Each flap is half a picture tall and hangs on one hinge across the middle: its front shows the top half of one picture and its back shows the bottom half of the next. So when a flap falls over the hinge, it uncovers the next top half behind it and lands showing the matching bottom half, and the picture in view is always whole, flat and facing me. The two halves in view overlap by 2px at the hinge (showing the same pixels), so no line or gap shows across it; only those two flat halves overlap, never a leaning flap.
2. **The wheel.** The flaps go round the hinge like the cards of a card file. Flaps waiting on top stand behind the one in view, each leaning 7 degrees further back; fallen flaps hang below, each leaning 7 degrees further back; one at a time swings round the back from the bottom stack to the top one, out of sight. That flap is why it needs at least 4 pictures. A deep perspective (2.2 picture heights) makes a flap swinging at me look big, like the reference.
3. **The flip.** Every 2 seconds (`interval`) exactly one flap falls, so it moves to the next picture and never skips one. The flip takes 0.8 seconds with a cubic ease in: slow at the start and faster and faster until it lands.
4. **Light.** A flap's front darkens as it tips toward me and its back lightens as it lands (up to 42%), so each flap reads as a turning card.
5. **The pause.** A mouse over it pauses it after the flip in progress lands, and a fresh 2 second rest starts when the mouse leaves. It also rests while it is off screen or the tab is hidden.
6. **The hand.** A press becomes a drag after 4px. Dragging down pulls the top flaps toward me over the hinge, half a picture's height for each flap; dragging up turns them back. Letting go lands on the nearest picture, and a flick moves one more, but one drag never goes more than one picture away. This works with a finger too, so on a phone a swipe that starts on the gallery flips it instead of scrolling the page.
7. **Size.** It fills its width. Without `height` it keeps a 3:2 shape (at most 560px tall), and each picture is at most 580px wide and 72% of the width, so a flap swinging toward me never gets cut off. Only transforms and opacity change while it moves.

## Check

- It type-checks and the page renders with no console errors.
- The picture in view is flat and whole, with no line across its middle. Every 2 seconds one flap falls toward me, slow at first and faster at the end, and lands on the next picture in under a second, never skipping one. Hovering pauses it, dragging up or down flips it, and clicking a picture does nothing. Passing 3 pictures shows the notice instead of the board.
- It looks right in light and dark mode (check both): the pictures, the darkening flaps and the placeholders read well on each background.
- It works with a finger on a phone: a swipe up or down on it flips it, a long press shows no picture menu, and nothing scrolls sideways.
- With `prefers-reduced-motion: reduce`, it never flips on its own and only moves when dragged.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, where it's placed, and every place where you had to do something differently from the source, and why.

## Source

The reference implementation. Copy it as-is, then apply only the changes listed above.

### `components/ui/tumble-gallery.tsx`

```tsx
"use client";

import { useEffect, useRef, type CSSProperties } from "react";

/**
 * Tumble Gallery
 * A split flap board for pictures. The picture you see sits flat, facing you, cut
 * across the middle by an invisible hinge. Every few seconds one flap falls forward
 * over the hinge, slow at first and faster and faster, like a card falling under
 * gravity, and lands on the next picture. Hover pauses it,
 * dragging up or down flips it by hand. It needs at least 4 pictures: the flaps go
 * round a wheel, and with fewer the one travelling round the back would show.
 * One file, React only, CSS 3D, no packages.
 */

export type TumbleImage = {
  /** Picture address. Same site, or a site your Content-Security-Policy allows. */
  src: string;
  /** Says what the picture shows. Read by screen readers. */
  alt: string;
};

/** At least 4 pictures. Fewer is a type error, and at runtime it shows a notice instead. */
export type TumbleImages = [TumbleImage, TumbleImage, TumbleImage, TumbleImage, ...TumbleImage[]];

export type TumbleGalleryProps = {
  images: TumbleImages;
  /** Flip on its own. Off: it only moves when dragged. */
  autoPlay?: boolean;
  /** How long each picture rests before the next flip, in ms. */
  interval?: number;
  /** Corner radius of each picture, in px. */
  radius?: number;
  /** Height of the gallery, any CSS height. Left out, it keeps a shape that fits its width. */
  height?: number | string;
  className?: string;
  style?: CSSProperties;
  "aria-label"?: string;
};

/* ---------- Tuning (the design and its timing) ---------- */
export const TUMBLE_MIN = 4; // the wheel needs one flap free to travel round the back
const ASPECT = 4 / 3; // picture width / height
const MAX_W = 580; // px, the widest a picture gets
const FILL_W = 0.72; // a picture takes at most this much of the width (a flap swinging at you looks wider)
const ROOM_H = 1.16; // the gallery is this many pictures tall
const VIEW = 2.2; // perspective distance, x picture height (smaller = deeper 3D)
const LEAN = 7; // deg each flap waiting in a stack leans back behind the one in front
const FLIP_MS = 800; // one flip to the next picture
const SETTLE_MS = 320; // a short drag lands in this long at least
const REST_MS = 2000; // the rest between flips
const SHADE = 0.42; // a flap turned edge-on darkens this much
const SEAL = 2; // px: the two halves of the picture in view overlap this much at the hinge (same pixels), so no line shows
const DRAG_START = 4; // px before a press becomes a drag
const FLICK = 0.2; // s of a flick's speed carried into where it lands
const EASE_IN = (x: number) => x * x * x; // slow at first, faster and faster
const EASE_OUT = (x: number) => 1 - Math.pow(1 - x, 3);

const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));
const f2 = (v: number) => Math.round(v * 100) / 100;

const CSS = `
.tg-root{position:relative;width:100%;aspect-ratio:1.5;max-height:560px;overflow:hidden;color:var(--foreground,var(--fg,currentColor));user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;touch-action:pinch-zoom;cursor:grab;-webkit-tap-highlight-color:transparent}
.tg-root[data-drag]{cursor:grabbing}
.tg-stage{position:absolute;left:50%;top:50%;width:0;height:0;transform-style:preserve-3d;pointer-events:none}
.tg-flap{position:absolute;left:calc(var(--tg-w) / -2);top:calc(var(--tg-h) / -2);width:var(--tg-w);height:calc(var(--tg-h) / 2);transform-origin:50% 100%;transform-style:preserve-3d;will-change:transform}
.tg-root:not([data-ready]) .tg-flap{visibility:hidden}
.tg-face{position:absolute;left:0;right:0;top:0;bottom:0;overflow:hidden;-webkit-backface-visibility:hidden;backface-visibility:hidden;background:color-mix(in srgb,currentColor 9%,transparent)}
.tg-front{border-radius:var(--tg-r) var(--tg-r) 0 0}
.tg-back{border-radius:0 0 var(--tg-r) var(--tg-r);transform:rotateX(180deg)}
.tg-face img{position:absolute;left:0;width:100%;height:var(--tg-h);max-width:none;max-height:none;object-fit:cover;pointer-events:none;user-select:none;-webkit-user-select:none;-webkit-user-drag:none;-webkit-touch-callout:none}
.tg-front img{top:0}
.tg-back img{top:calc(var(--tg-h) / -2)}
.tg-flap[data-seal] .tg-face{bottom:-${SEAL}px}
.tg-flap[data-seal] .tg-back img{top:calc(var(--tg-h) / -2 + ${SEAL}px)}
.tg-shade{position:absolute;inset:0;background:#000;opacity:0;pointer-events:none}
.tg-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.tg-note{display:flex;align-items:center;justify-content:center;padding:24px;border:1px dashed color-mix(in srgb,currentColor 30%,transparent);border-radius:12px;font:14px/1.5 system-ui,sans-serif;text-align:center;color:var(--foreground,var(--fg,currentColor))}
`;

export function TumbleGallery({
  images,
  autoPlay = true,
  interval = REST_MS,
  radius = 20,
  height,
  className,
  style,
  "aria-label": ariaLabel = "Gallery",
}: TumbleGalleryProps) {
  const rootRef = useRef<HTMLDivElement>(null);
  const stageRef = useRef<HTMLDivElement>(null);
  const srRef = useRef<HTMLDivElement>(null);
  const list: TumbleImage[] = Array.isArray(images) ? images : [];
  const n = list.length;
  const tooFew = n < TUMBLE_MIN;

  // The newest props, read by the running loop without restarting it.
  const live = useRef({ autoPlay, rest: REST_MS, radius: 20 });
  live.current = {
    autoPlay,
    rest: Number.isFinite(interval) ? clamp(interval, 300, 60000) : REST_MS,
    radius: Number.isFinite(radius) ? Math.max(0, radius) : 20,
  };

  const srcKey = list.map((i) => i.src).join("\n");
  const altKey = list.map((i) => i.alt).join("\n");
  const relayout = useRef<(() => void) | null>(null);

  useEffect(() => {
    if (tooFew) console.error(`TumbleGallery needs at least ${TUMBLE_MIN} images, it got ${n}. It shows a notice until it has ${TUMBLE_MIN}.`);
  }, [tooFew, n]);

  useEffect(() => {
    const root = rootRef.current;
    const stage = stageRef.current;
    if (!root || !stage || tooFew) return;
    const flaps = Array.from(stage.children) as HTMLElement[];
    const count = flaps.length;
    const shades = flaps.map((f) => Array.from(f.querySelectorAll<HTMLElement>(".tg-shade")));
    const alts = altKey.split("\n");
    const reduce = window.matchMedia("(prefers-reduced-motion: reduce)");

    /* ---------- Pictures: keep a soft placeholder, never the broken icon ---------- */
    const cleanups: (() => void)[] = [];
    stage.querySelectorAll("img").forEach((img) => {
      const hide = () => (img.style.visibility = "hidden");
      if (img.complete && img.getAttribute("src") && !img.naturalWidth) hide();
      img.addEventListener("error", hide);
      cleanups.push(() => img.removeEventListener("error", hide));
    });

    /* ---------- Layout ---------- */
    let H = 200, stepPx = 100;
    const layout = () => {
      const r = root.getBoundingClientRect();
      const w = Math.max(1, r.width);
      const h = Math.max(1, r.height);
      H = Math.max(24, Math.min(h / ROOM_H, (w * FILL_W) / ASPECT, MAX_W / ASPECT));
      const W = H * ASPECT;
      stepPx = H * 0.5; // dragging half a picture flips one flap
      root.style.perspective = `${Math.round(Math.max(420, H * VIEW))}px`;
      root.style.setProperty("--tg-w", `${Math.round(W)}px`);
      root.style.setProperty("--tg-h", `${Math.round(H / 2) * 2}px`);
      root.style.setProperty("--tg-r", `${Math.min(live.current.radius, H / 2)}px`);
      draw();
    };

    /* ---------- The wheel ---------- */
    // Flap i shows the top half of picture i on its front and the bottom half of picture i+1 on its back.
    // t (0..count) is how far flap i has gone round since it was the top of the picture in view:
    // 0..1 it falls over the hinge, then it waits in the bottom stack, swings round the back,
    // and waits in the top stack, each waiting flap leaning a little further back.
    const low = 1 + Math.floor((count - 1) / 2); // last place in the bottom stack
    const angleOf = (t: number) => {
      if (t <= 1) return 180 * t;
      if (t <= low) return 180 + LEAN * (t - 1);
      const backFrom = 180 + LEAN * (low - 1);
      const backTo = 360 - LEAN * (count - low - 1);
      if (t <= low + 1) return backFrom + (backTo - backFrom) * (t - low);
      return backTo + (360 - backTo) * (t - low - 1) / Math.max(1e-6, count - low - 1);
    };

    /* ---------- State ---------- */
    let pos = 0; // flaps fallen; the picture in view is pos (mod count)
    let from = 0, to = 0, animStart = 0, animMs = 0;
    let animating = false, easeIn = true;
    let restUntil = 0;
    let hovering = false;
    let inView = true;
    let raf = 0;
    let shown = -1;
    let pointer = -1, startY = 0, startPos = 0, dragging = false;
    let lastY = 0, lastT = 0, vel = 0; // flaps a second

    const draw = () => {
      for (let i = 0; i < count; i++) {
        const t = (((pos - i) % count) + count) % count;
        const a = angleOf(t);
        flaps[i].style.transform = `rotateX(${f2(-a)}deg)`;
        // Only the two flat halves in view overlap; a leaning flap's overlap would poke out in front.
        const seal = a < 0.5 || a > 359.5 || Math.abs(a - 180) < 0.5;
        if (seal !== flaps[i].hasAttribute("data-seal")) flaps[i].toggleAttribute("data-seal", seal);
        const c = Math.cos((a * Math.PI) / 180);
        const [front, back] = shades[i];
        // The front darkens as it tips toward you, the back lightens as it lands.
        if (front) front.style.opacity = String(f2(SHADE * clamp(1 - c, 0, 1)));
        if (back) back.style.opacity = String(f2(SHADE * clamp(1 + c, 0, 1)));
      }
      const mid = ((Math.round(pos) % count) + count) % count;
      if (mid !== shown) {
        shown = mid;
        if (srRef.current) srRef.current.textContent = `${mid + 1} of ${count}: ${alts[mid] ?? ""}`;
      }
    };

    const flipTo = (target: number, ms: number, now: number, inOut: boolean) => {
      from = pos;
      to = target;
      animStart = now;
      animMs = Math.max(1, ms);
      easeIn = inOut;
      animating = true;
      kick();
    };

    const canAuto = () => live.current.autoPlay && !reduce.matches && !hovering && inView && !document.hidden && pointer < 0;

    const tick = (now: number) => {
      raf = 0;
      if (animating) {
        const p = clamp((now - animStart) / animMs, 0, 1);
        pos = from + (to - from) * (easeIn ? EASE_IN : EASE_OUT)(p);
        if (p >= 1) {
          animating = false;
          pos = ((to % count) + count) % count; // keep the numbers small
          restUntil = now + live.current.rest;
        }
        draw();
      } else if (canAuto() && !dragging) {
        if (!restUntil) restUntil = now + live.current.rest;
        if (now >= restUntil) {
          flipTo(Math.round(pos) + 1, FLIP_MS, now, true);
        }
      }
      if (animating || canAuto()) raf = requestAnimationFrame(tick);
    };
    const kick = () => {
      if (!raf) raf = requestAnimationFrame(tick);
    };

    /* ---------- Drag up or down ---------- */
    const onDown = (e: PointerEvent) => {
      if (pointer >= 0 || (e.pointerType === "mouse" && e.button !== 0)) return;
      pointer = e.pointerId;
      startY = lastY = e.clientY;
      lastT = performance.now();
      startPos = pos;
      vel = 0;
      dragging = false;
    };
    const onMove = (e: PointerEvent) => {
      if (e.pointerId !== pointer) return;
      if (!dragging) {
        if (Math.abs(e.clientY - startY) < DRAG_START) return;
        dragging = true;
        animating = false;
        startPos = pos;
        startY = e.clientY;
        root.setAttribute("data-drag", "");
        try {
          root.setPointerCapture(e.pointerId);
        } catch {}
      }
      const now = performance.now();
      const dt = Math.max(1, now - lastT) / 1000;
      // Dragging down pulls the top flaps over the hinge toward you.
      const v = (e.clientY - lastY) / stepPx / dt;
      vel = vel * 0.6 + v * 0.4;
      lastY = e.clientY;
      lastT = now;
      pos = startPos + (e.clientY - startY) / stepPx;
      draw();
      e.preventDefault();
    };
    const onUp = (e: PointerEvent) => {
      if (e.pointerId !== pointer) return;
      pointer = -1;
      root.removeAttribute("data-drag");
      if (!dragging) return;
      dragging = false;
      if (performance.now() - lastT > 90) vel = 0; // held still before letting go
      // Never more than one picture away from where the drag started: no skipping.
      const base = Math.round(startPos);
      const target = clamp(Math.round(pos + clamp(vel * FLICK, -1, 1)), base - 1, base + 1);
      const dist = Math.abs(target - pos);
      flipTo(target, Math.max(SETTLE_MS, FLIP_MS * 0.6 * dist), performance.now(), false);
    };
    const onEnter = (e: PointerEvent) => {
      if (e.pointerType === "mouse") hovering = true;
    };
    const onLeave = (e: PointerEvent) => {
      if (e.pointerType !== "mouse") return;
      hovering = false;
      restUntil = 0; // a fresh rest before the next flip
      kick();
    };
    const resume = () => {
      restUntil = 0;
      kick();
    };

    /* ---------- Wiring ---------- */
    relayout.current = layout;
    layout();
    root.setAttribute("data-ready", "");
    kick();

    const ro = new ResizeObserver(layout);
    ro.observe(root);
    const io = new IntersectionObserver(([entry]) => {
      inView = entry.isIntersecting;
      if (inView) resume();
    });
    io.observe(root);
    const onVis = () => !document.hidden && resume();
    document.addEventListener("visibilitychange", onVis);
    reduce.addEventListener?.("change", resume);
    root.addEventListener("pointerdown", onDown);
    root.addEventListener("pointermove", onMove);
    root.addEventListener("pointerup", onUp);
    root.addEventListener("pointercancel", onUp);
    root.addEventListener("pointerenter", onEnter);
    root.addEventListener("pointerleave", onLeave);
    const noDrag = (e: Event) => e.preventDefault();
    root.addEventListener("dragstart", noDrag);

    return () => {
      cancelAnimationFrame(raf);
      ro.disconnect();
      io.disconnect();
      document.removeEventListener("visibilitychange", onVis);
      reduce.removeEventListener?.("change", resume);
      root.removeEventListener("pointerdown", onDown);
      root.removeEventListener("pointermove", onMove);
      root.removeEventListener("pointerup", onUp);
      root.removeEventListener("pointercancel", onUp);
      root.removeEventListener("pointerenter", onEnter);
      root.removeEventListener("pointerleave", onLeave);
      root.removeEventListener("dragstart", noDrag);
      cleanups.forEach((f) => f());
      root.removeAttribute("data-ready");
      relayout.current = null;
    };
  }, [srcKey, altKey, tooFew]);

  // Radius can change without a restart.
  useEffect(() => {
    relayout.current?.();
  }, [radius]);

  if (tooFew) {
    return (
      <div className={className} style={style} role="alert">
        <style>{CSS}</style>
        <div className="tg-note">
          Tumble Gallery needs at least {TUMBLE_MIN} images. It has {n}.
        </div>
      </div>
    );
  }

  const boxStyle: CSSProperties = { ...style };
  if (height !== undefined) {
    boxStyle.height = typeof height === "number" ? `${height}px` : height;
    boxStyle.aspectRatio = "auto";
    boxStyle.maxHeight = "none";
  }

  return (
    <div
      ref={rootRef}
      className={className ? `tg-root ${className}` : "tg-root"}
      style={boxStyle}
      role="region"
      aria-roledescription="carousel"
      aria-label={ariaLabel}
    >
      <style>{CSS}</style>
      <div ref={srRef} className="tg-sr" aria-live="off">
        {`1 of ${n}: ${list[0]?.alt ?? ""}`}
      </div>
      <div ref={stageRef} className="tg-stage" aria-hidden="true">
        {list.map((img, i) => {
          const next = list[(i + 1) % n];
          return (
            <div key={`${i}-${img.src}`} className="tg-flap">
              <div className="tg-face tg-front">
                <img src={img.src} alt="" draggable={false} decoding="async" />
                <div className="tg-shade" />
              </div>
              <div className="tg-face tg-back">
                <img src={next.src} alt="" draggable={false} decoding="async" />
                <div className="tg-shade" />
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
}

export default TumbleGallery;
```

Usage

Give it at least 4 pictures, each with an alt.

"use client";
import { TumbleGallery, type TumbleImages } from "@/components/ui/tumble-gallery";

// At least 4 pictures. Fewer is a type error.
const shots: TumbleImages = [
  { src: "/work/studio.jpg", alt: "The studio desk with the new prototype" },
  { src: "/work/launch.jpg", alt: "Launch day, the team on stage" },
  { src: "/work/app.jpg", alt: "The app's home screen on a phone" },
  { src: "/work/sketch.jpg", alt: "First sketches of the logo" },
  { src: "/work/print.jpg", alt: "The printed poster on a wall" },
];

export function Work() {
  return <TumbleGallery images={shots} aria-label="Our work" />;
}

Keep each picture small (about 700px wide, WebP). Pictures from another site must be allowed by your Content-Security-Policy (img-src), or they stay as soft placeholders.

How it moves

A split flap board for pictures, flipping like a card file.

Each picture is cut across the middle onto two flaps that hang on one hinge. The picture in view always sits flat and whole, facing you. Every 2 seconds one flap falls toward you over the middle hinge, slow at first and faster and faster, and lands on the next picture in 0.8 seconds. It never skips a picture, and no line shows across the middle. The flaps darken as they tip and lighten as they land.

A mouse over it pauses it. Drag down to pull flaps toward you, drag up to turn them back; a flick moves one more, never further. It needs at least 4 pictures, because one flap always swings round the back, out of sight. Pictures are never links and can't be selected or dragged out. With reduced motion it never flips on its own and only moves when you drag it.

Props

PropDefaultWhat it does
images—The pictures, in order. Each is { src, alt }. At least 4 (5 is a good default): fewer is a type error, and at runtime shows a small notice instead. Wide pictures fit best, cropped to 4:3. They are never links.
autoPlaytrueFlip on its own. Off, it only moves when dragged.
interval2000How long each picture rests before the next flip, in ms.
radius20Corner radius of each picture, in px.
heightautoHeight of the gallery, any CSS height. Left out, it keeps a 3:2 shape, at most 560px tall.
aria-label"Gallery"Name of the gallery for screen readers.
className / style—On the outer box. It has no background and no words; the placeholders take its text color.