Componentes · Interacción
Carrusel <Carousel>
Una fila de tarjetas que se desliza con el dedo, la rueda o los botones.
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'Ejemplos
Galería de fotos
El carrusel por defecto: cada hijo es una diapositiva, centrada, con las vecinas asomando; flechas finas de 72 px debajo (controls="line"). Nunca avanza solo ni da la vuelta. Con el carrusel enfocado, ← → mueven una foto e Inicio / Fin van a los extremos. Dentro de un contenedor, bleed={false}.
---
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
const photos = [1, 2, 3, 4, 5].map((n) => `/assets/about/collage-${n}-640.webp`)
---
<Carousel id="ejemplo-carrusel-galeria" label="Fotos de la casa" bleed={false}>
{photos.map((src, i) => <Media src={src} alt={`Foto ${i + 1} de la casa`} aspect="3/2" />)}
</Carousel> Fila de tarjetas (landings)
align="start" alinea cada tarjeta al margen izquierdo, progress añade una línea de 2 px que dice dónde estás y controls="disc" cambia las flechas por discos rellenos de 56 px. En los extremos el disco se apaga al 40 %. slideWidth fija el ancho de cada tarjeta en % del carrusel.
---
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
import Text from '@vivla-cms/ds/primitives/Text.astro'
const places = [
{ name: 'Ibiza', src: '/assets/home/dest-ibiza-b-640.webp' },
{ name: 'Menorca', src: '/assets/home/dest-menorca-640.webp' },
{ name: 'Costa Brava', src: '/assets/about/collage-1-640.webp' },
{ name: 'Baqueira', src: '/assets/about/collage-2-640.webp' },
{ name: 'Sotogrande', src: '/assets/about/collage-3-640.webp' },
{ name: 'Mallorca', src: '/assets/about/collage-4-640.webp' },
]
---
<Carousel
id="ejemplo-carrusel-tarjetas"
label="Destinos"
bleed={false}
align="start"
progress
controls="disc"
slideWidth={{ mobile: 68, desktop: 33 }}
>
{
places.map((place) => (
<article class="flex flex-col gap-3">
<Media src={place.src} alt="" aspect="4/5" />
<Text size="lead" weight="medium">{place.name}</Text>
</article>
))
}
</Carousel> Tarjeta anterior recortada (peek)
Con align="start", peek deja asomar por la izquierda un trozo de la tarjeta anterior (en % del ancho, desde 48rem). Al empezar, la recortada es la primera: invita a deslizar hacia los dos lados (Landings Performance 83:625).
---
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
const photos = [1, 2, 3, 4, 5].map((n) => `/assets/about/collage-${n}-640.webp`)
---
<Carousel
id="ejemplo-carrusel-peek"
label="Casas en la nieve"
bleed={false}
align="start"
peek={7.8}
progress
controls="disc"
slideWidth={{ mobile: 75, desktop: 38 }}
>
{photos.map((src, i) => <Media src={src} alt={`Casa ${i + 1}`} aspect="4/3" />)}
</Carousel> Solo deslizar
controls="none" quita flechas y línea de progreso: una fila que se recorre con el dedo, la rueda o el teclado. start elige la diapositiva inicial (empieza en 0).
---
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
const photos = [1, 2, 3, 4, 5].map((n) => `/assets/about/collage-${n}-640.webp`)
---
<Carousel
id="ejemplo-carrusel-sin-controles"
label="Haz de Baqueira tu segundo hogar"
bleed={false}
controls="none"
start={2}
slideWidth={{ mobile: 70, desktop: 30 }}
>
{photos.map((src, i) => <Media src={src} alt={`Foto ${i + 1}`} aspect="1/1" />)}
</Carousel> A sangre, de borde a borde
Con bleed (por defecto) el carrusel ocupa todo el ancho de la pantalla y las flechas se quedan dentro del margen de la página. Es el de la galería de la ficha.
---
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
const photos = [1, 2, 3, 4, 5].map((n) => `/assets/about/collage-${n}-640.webp`)
---
<div class="py-10">
<Carousel id="ejemplo-carrusel-sangre" label="Galería de la casa" start={1}>
{photos.map((src, i) => <Media src={src} alt={`Foto ${i + 1} de la casa`} aspect="3/2" />)}
</Carousel>
</div> Alineado con el título en pantallas grandes
Con align="start", la primera tarjeta empieza en el margen de página (inset="gutter", por defecto). inset="wide" la hace empezar donde empieza un Container width="wide", así la fila queda alineada con el título de la sección también en pantallas más anchas que 1512 (en un Mac de 1728 el título iba a 148 px y las tarjetas a 40). Prueba Escritorio y compara la tarjeta con el título.
---
import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'
import Container from '@vivla-cms/ds/primitives/Container.astro'
import Heading from '@vivla-cms/ds/primitives/Heading.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
import Text from '@vivla-cms/ds/primitives/Text.astro'
const homes = [
{ name: 'Ibiza', place: 'Desde 1/8', src: '/assets/home/dest-ibiza-b-640.webp' },
{ name: 'Menorca', place: 'Desde 1/8', src: '/assets/home/dest-menorca-640.webp' },
{ name: 'Costa Brava', place: 'Desde 1/8', src: '/assets/about/collage-1-640.webp' },
{ name: 'Baqueira', place: 'Desde 1/8', src: '/assets/about/collage-2-640.webp' },
]
---
<Container width="wide">
<Heading level={3} size="h2" class="mb-8">Destinos</Heading>
</Container>
<Carousel id="ejemplo-carrusel-inset" label="Destinos" align="start" inset="wide" controls="disc" slideWidth={{ mobile: 72, desktop: 28 }}>
{
homes.map((home) => (
<article class="flex flex-col gap-2">
<Media src={home.src} alt="" aspect="4/5" />
<Text size="lead" weight="medium">{home.name}</Text>
<Text size="small" tone="muted">{home.place}</Text>
</article>
))
}
</Carousel> Props
| Prop | Valores | Por defecto | Para qué |
|---|---|---|---|
| id * | string | — | Element id; the track is ${id}-track (the buttons' aria-controls). |
| label * | string | — | Accessible name of the region, e.g. «Fotos de Casa Taula». |
| start | number | 0 | Slide centred on load, 0-based (default 0). |
| slideWidth | SlideWidth | — | Slide width in percent of the carousel width: { mobile: 80, desktop: 69 }. |
| bleed | boolean | true | Full-bleed rail: controls inset by the page gutter (default true). |
| track | string | — | dataLayer event pushed when a prev / next click moves the rail, e.g. carousel_nav. |
| trackLabel | string | — | track_label param of that event, e.g. listing_gallery. |
| progress | boolean | false | A 2 px progress line above the buttons that fills from the left as the
rail scrolls (Landings Performance 158:5830; grows instead of sliding since
the 05/11 web review). Below md the line stands alone and
the buttons hide (Components_Web ficha gallery 401:2150, mobile). Track line-subtle (Foundations
border/subtle, #CCC on light grounds), thumb on-surface — Jaime 16/10.
Hidden, like the buttons, when everything fits. |
| controls | linediscnone | 'disc' | disc = the 56 px Icon button (default, Components_Web 154:94) · line = the older thin arrows (56 px, 72 from 48rem; Web 2026 ficha 234:1860 — no caller left, kept for one release) · none = no buttons and no progress line (swipe / keyboard only). |
| inset | gutterwide | — | align="start" only, from 48rem: percent of the carousel width of the
previous card left cut at the left edge at rest (the first card at the
start). Default 0 = slides snap to the page gutter.
Where the first slide starts (align="start"): the page gutter, which is
where every Container starts. Since 05/11 the page has no cap, so
wide (the left edge of a capped Container width="wide", added on
15/10 when a 1728 px Mac showed the title at 148 and the cards at 40) IS
the gutter: it is kept as an alias so callers and the ds.vivla.dev
example keep working. Prefer the default. |
| peek | number | 0 | — |
| align | centerstart | 'center' | center (default) snaps the slide to the middle · start snaps it to the left edge of the rail, inset by the page gutter, so a row of cards reads from the left (Landings Performance carousels). |
| gap | gridm | 'grid' | align="start" only: the space between slides. grid (default) = the
Foundations medianil, 20 at every width (Layout 768:47) · m = space/m,
32 (Conoce VIVLA team rail, phone 1590:2492). |
Slots: contenido
Notas del código
El comentario de cabecera de Carousel.astro, tal cual (en inglés, como el código): si cambia el código, cambia esto.
horizontal scroll-snap rail with peeking neighbours and prev / next buttons under the slides, at the edges. The buttons are the Components_Web «Icon button» (74zqbI8QliQL1oyXyFbsBT 154:94, the ficha gallery «PDP/house photo» 401:2132): a 56 px disc at every width, icon 20, action/primary fill → action/primary/bg-hover, disabled #ccc / #867c79, focus ring 2 px separated 2 px.
<Carousel id="listing-gallery" label={`Fotos de ${home.name}`} start={1}>
{photos.map((photo) => (
<figure><Media {...photo} aspect="3/2" radius="none" /></figure>
))}
</Carousel> Every direct child of the slot is one slide: the rail sizes and snaps it (centre snap, one slide per swipe). Slide width is a share of the carousel's own width: 80 % on phones and 69 % from 48rem by default (slideWidth), and the track is padded so the first and last slides can centre too.
Card rows (Landings Performance 158:5830, 14/10): align="start" snaps each slide to the page gutter instead of the centre (the row reads from the left), progress adds a 2 px line that fills from the left as the rail scrolls: the visible share at the start, the whole line at the end (it grows, it never slides — web review 05/11). At either end of the rail the disc there is aria-disabled and takes the disabled roles (Foundations «Slider arrow» 1202:1661: grey disc, grey arrow, the same in light and dark), keeping its full-strength focus ring. controls="none" drops the buttons and the progress line: a swipe-only row (the photo row «Haz de Baqueira tu segundo hogar» 88:1117). Keyboard (← / → on the focused track) and the slide semantics stay.
peek (from 48rem, align="start" only): every resting position leaves that share of the carousel width of the previous card cut at the left edge — at the start, the FIRST card is the one cut (Landings Performance 83:625: first card at x −118 of 1512 → peek={7.8}). The track drops its left gutter and each slide snaps with a negative scroll-margin-left, so swipe, buttons and keys all land on the same peeked positions.
<Carousel id="destinos" label="Destinos" align="start" progress controls="disc"
peek={7.8} slideWidth={{ mobile: 68, desktop: 33, desktopMax: 31.3125 }}>…</Carousel> Behaviour:
- Never autoplays and never loops: it moves only on swipe, scroll, the
buttons or the keyboard, and stops at both ends (the button there is
`aria-disabled`, so focus is never dropped). - Keyboard: the track is focusable; ← / → move one slide, Home / End jump
to the ends, only while the track itself has focus (a control inside a
slide keeps its keys, so it is never scrolled away while focused). The
buttons work with Enter / Space. The focus ring follows the nearest theme
(`outline-focus`), so it stays visible on the accent band. - Motion: programmatic moves use
scroll-behavior: smooth, which the
reduced-motion rule in base.css turns into an instant jump. A width change
(rotation, resize) re-centres the current slide without animation. - Hidden: a carousel bound while hidden (closed Dialog, collapsed
Accordion, inactive Tabs panel) keeps its `start` slide and centres it the
first time it gets a width. - No JS: a plain scrollable rail with a visible scrollbar; the buttons stay
`hidden`. The script hides the scrollbar once it has bound the controls,
and hides the controls whenever everything fits. Moving from code (e.g. a lightbox opening at the photo that was clicked): set data-start before the carousel binds, or dispatch on the root, before or after showing it:
root.dispatchEvent(new CustomEvent('ds-carousel:go', { detail: { index: 4, instant: true } })) index is 0-based and clamped; instant skips the smooth scroll; announce (default false) reads the new position in the live status.
Analytics: with track, a click on prev / next that actually moves pushes { event: track, track_direction: 'prev' | 'next', track_label } to the GTM dataLayer (track_label only with trackLabel). Clicks on a disabled end button, keys and swipes push nothing.
Accessibility (APG carousel): the root is a labelled region with aria-roledescription «carrusel» / «carousel»; the script gives each non-interactive slide role="group", aria-roledescription «diapositiva» / «slide» and a «3 de 7» name (an existing role or aria-label is kept), and a polite live status reads the position after a button or key move. Every string comes from uiLabel (carousel, carouselSlide, carouselSlideOf, carouselPrev, carouselNext). Slides get data-current="true" on the centred one for styling (e.g. dimming neighbours). Colours are roles only: put it in a themed <Section>.
bleed (default true) is for a rail that runs edge to edge of the page: the controls row then sits inside the page gutter. Inside a Container pass bleed={false}.
Dónde se usa
8 veces en 5 archivos de la web y los bloques del CMS.