Cómo funciona
The layout is one number: the row's position in cards, a registered CSS property on the stage. Each card works out its distance to it in CSS. Within one card of the centre it grows from the side size to full size, sharpens, gains a white rim and a deeper shadow, and its caption rises into view over a scrim; further out the side cards sit edge to edge, blur, sink into a veil of the background colour and fade after the visible range. A drag writes the position on every frame with a rubber band past the ends; a flick moves at least one card; otherwise a transition glides the row on the ease-out curve. Only the centre card's caption and button can be reached; the side cards are pointer shortcuts, with the dots and arrows doing the same job for the keyboard.
Úsalo para
- A featured row at the top of a magazine, portfolio or shop page, where one story at a time deserves the reader's full attention.
- Three to seven items with strong pictures. For a long list people scan, use a plain scrolling row or a grid.
Busca otra opción cuando
- Do not hide content people need to compare side by side; the blurred side cards cannot be read.
Uso
import { SpotlightCarousel } from './SpotlightCarousel.jsx'
const stories = [
{ id: 'concrete', eyebrow: 'Architecture', title: 'Quiet Concrete', text: 'Plain walls that let light do the talking.', action: 'Explore', image: '/covers/concrete.jpg' },
{ id: 'aurora', eyebrow: 'Editorial', title: 'Northern Light', text: 'A winter issue printed in four soft colours.', action: 'View story', image: '/covers/aurora.jpg' },
{ id: 'ceramics', eyebrow: 'Material Study', title: 'Warm Ceramics', text: 'Glazes tested on forty small vessels.', action: 'Inspect', image: '/covers/ceramics.jpg' },
]
export function Featured({ onOpen }) {
return (
<SpotlightCarousel
items={stories}
defaultIndex={1}
label="Featured stories"
renderMedia={(story) => <img src={story.image} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />}
onAction={(story) => onOpen(story.id)}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
items | T[] | [] | The cards, in order. By default each item's title, eyebrow, text and action fields are read; the getters below change that. |
renderMedia | (item, { index, active }) => ReactNode | — | The picture that fills each card, usually an image with object-fit: cover. Give it an empty alt: the card is named by its title. |
getTitle | (item, index) => string | — | Title shown on the centre card and used to name each slide. Defaults to item.title. |
getEyebrow | (item, index) => string | — | Small line above the title. Defaults to item.eyebrow. |
getText | (item, index) => string | — | One short sentence under the title. Defaults to item.text. |
getActionLabel | (item, index) => string | — | Label of the button on the centre card; no label, no button. Defaults to item.action. |
onAction | (item, index) => void | — | Called when the centre card's button is pressed. |
index | number | — | Controlled centre card. Omit to let the carousel keep its own. |
defaultIndex | number | 0 | First centre card for an uncontrolled carousel. |
onIndexChange | (index, item) => void | — | Called when a drag, a key, a dot, a side card or autoplay asks for another centre card. |
cardWidth | number | 220 | Width of the centre card in pixels; its height is cardWidth × cardRatio. |
cardRatio | number | 1.2 | Height over width of every card. |
sideScale | number | 0.66 | Size of the side cards relative to the centre one. |
blur | number | 3 | Blur of the side cards in pixels; 0 keeps them sharp. |
visible | number | 2 | How many cards show on each side before the rest fade out. |
dots | boolean | true | Show a dot per card under the row; otherwise a count such as 2 of 5. |
autoplay | number | 0 | Milliseconds between automatic moves; 0 turns it off. It waits while the carousel is pointed at or focused, adds a pause button, wraps at the end and never runs under reduced motion. |
paused | boolean | false | Holds autoplay from outside, for example while the carousel is off screen. |
label | string | 'Featured' | Accessible name of the carousel. |
labels | { previous?, next?, goTo?, slide?, hint?, pause?, play? } | — | Replaces the built-in English text; goTo and slide are functions of (n, total). |
Accesibilidad
- The section is a carousel (aria-roledescription) and each card a slide named by its title and position. The row is one focusable stop: Left and Right move one card, Home and End jump to the ends.
- Only the centre card is exposed; the side cards are aria-hidden and their buttons inert, so Tab goes from the row to the centre card's action, then to the previous, dots and next buttons.
- Each dot is a button named "Show 3 of 5" with aria-current on the centre one. A polite live region announces the new centre card.
- Autoplay stops while the carousel is pointed at or focused, has a visible pause button and never starts under reduced motion.
- A finger must move sideways before the row follows it, so vertical page scrolling that starts on the carousel still works.
Movimiento
The row glides for 560 ms on the ease-out curve; a throw takes 360 to 900 ms by distance. Under reduced motion the row jumps, the side cards are not blurred and autoplay is off; a drag still follows the finger.
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.
SpotlightCarousel.jsxspotlight-carousel.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.



