Ir al contenido
Español

Cómo funciona

One card: a header with the album name, the number of photos and a position counter, the pile, and dots. Every photo is rendered once and placed by a slot (front, right, left, waiting, just shown); each slot sets the same translate, rotate and scale variables, so a change of slot is one CSS transition that is retargeted from wherever the photo is when the index changes again. The set runs as a queue, left to right to front to out: Next slides the front photo out to the right and, halfway, drops it under the pile (a delayed z-index) while it fades; the right photo straightens and grows to the front, the left one moves right and the next in line fades in on the left. Previous plays the same shuffle backwards. Hover, keyboard focus or a touch drag fans the back photos about 1.5 times further with a light spring.

Úsalo para

  • A small set of photos in a feed, a trip summary or a profile, where the pile itself says there is more to see.
  • A compact preview of an album before opening the full gallery.

Busca otra opción cuando

  • Comparing many photos side by side or picking several: use a grid.
  • Throwing cards away by dragging: use the throw deck.

Uso

import { useState } from 'react'
import { PhotoFanStack } from './PhotoFanStack.jsx'

const photos = [
  { id: 'a', alt: 'Sunrise over green hills', background: 'linear-gradient(#f7b2a0, #fde7c2)' },
  { id: 'b', alt: 'Calm sea at noon', background: 'linear-gradient(#7cc4ec, #1f5d8a)' },
  { id: 'c', alt: 'Sand dunes at dusk', background: 'linear-gradient(#f28a5b, #e9a15a)' },
  { id: 'd', alt: 'A lake at night', background: 'linear-gradient(#141c3a, #2c3a6b)' },
]

export function TripAlbum() {
  const [index, setIndex] = useState(0)
  return <PhotoFanStack items={photos} index={index} onIndexChange={setIndex} title="Coast trip" />
}

Propiedades

PropiedadTipoPor defectoQué hace
items{ id, alt, background?, render?: () => ReactNode }[][]The photos, in order. alt names the photo for screen readers; background is any CSS background (a gradient or an image), render draws content inside the photo (a picture, a caption).
index / defaultIndex / onIndexChangenumber / number / (index) => void- / 0 / -The front photo, controlled or uncontrolled. The set wraps around: next after the last photo is the first.
title / subtitleReactNode / ReactNode'Album' / labels.count(n)The header of the card; the subtitle defaults to the number of photos.
fannumber8How far the back photos turn, in degrees. Hover and focus fan them about 1.5 times further.
announcebooleantrueAnnounce the new photo politely when it changes. Turn it off while your own code advances the photos on a timer.
labelsobject—Replaces built-in text: previous, next, stack, carousel, empty, count(n), counter(i, n), position(i, n, alt). Shallow-merged over the English defaults.
...restHTMLAttributes—Other attributes go to the root <section>.

Accesibilidad

  • The card is a section with aria-roledescription "photo album", named by its title.
  • The pile is a focusable group: Left and Right (and PageUp, PageDown) change the photo, Home and End go to the first and last; focus fans the pile so the focus is visible on the photos as well as the ring.
  • Only the front photo is exposed, as role="img" with its alt text; the photos behind are aria-hidden.
  • A polite live region announces the new position, for example “Photo 3 of 6: Sand dunes at dusk”; turn it off with announce={false} while photos advance on a timer.
  • Previous and next are real buttons, 36px (40px on touch screens), named through labels; with one photo they are disabled.
  • Reduced motion swaps the photos in place with a 160ms cross-fade: no sliding, no fanning, no following the finger.

Movimiento

Slot changes: transform 440ms cubic-bezier(0.32, 1.25, 0.5, 1) (a light overshoot), opacity and filter 260ms ease-out, z-index switches at 170ms. The photo leaving the front waits 170ms before fading, so it is seen sliding out before it disappears under the pile. Back photos sit at ±fan degrees, 26% of a photo to the side and 88% scale; hover or focus multiplies angle and offset by 1.55 and lifts the front photo 3px with the same spring. The counter rolls 8px in the direction of travel over 240ms. A swipe moves the front photo at 60% of the finger, up to 80px, tilting with it, and changes the photo past 40px. Fast presses retarget the running transitions, so the pile never jumps.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

PhotoFanStack.jsxphoto-fan-stack.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Listas
Carrusel en arco viene con Pro. La vista previa aparece al desbloquearlo.
Carrusel cilíndrico viene con Pro. La vista previa aparece al desbloquearlo.