Saltar al contenido
DS

Componentes · Contenido

Imagen <Media>

Fotos con proporción fija, punto focal y carga diferida; nunca una URL de Cloudinary a mano.

import Media from '@vivla-cms/ds/primitives/Media.astro'

Ejemplos

Proporciones

aspect fija la caja y recorta la foto (fit="cover"). De panorámica a retrato: 21/9 (sobre nosotros), 16/9, 3/2, 4/3, 5/4, 1/1, 4/5, 3/4 (equipo), 2/3 (Casa Ribes). auto respeta la proporción del archivo.

21/9
16/9
3/2
4/3
5/4
1/1
4/5
3/4
2/3
auto

Punto focal

position mueve el recorte dentro de una proporción fija: una palabra (top, bottom, left, right, center), un punto en porcentaje ({ x: 50, y: 30 }) o el texto que guardan los campos de foco del CMS ('center 30%'). Con aspect="auto" no hace nada: no hay recorte.

top
center
bottom
{ x: 80, y: 50 }
'center 30%'

Encaje y radio

fit="contain" mete la imagen entera en la caja (planos, gráficos) sobre el marcador surface-alt; cover (por defecto) la recorta. radius acepta none, media y card: los tres son 0 en Foundations, pero la prop queda por si diseño lo cambia.

Plano de una casa
fit="cover"
Plano de una casa
fit="contain"
radius="media"

Imágenes adaptables: srcset y dirección de arte

srcset + sizes dejan que el navegador elija el ancho. sources crea un <picture>: aquí el móvil recibe otro recorte. Media nunca construye URLs de Cloudinary: el que la llama transforma primero (cloudinarySrcset en los bloques, deliverUrl en la web). La primera imagen de una página va con loading="eager" y fetchpriority="high".

Una casa VIVLA frente al mar

Capa a sangre (fill)

aspect="fill" estira la imagen al padre (que necesita alto) y la fija en absoluto: es la foto fija bajo un vídeo de hero o el fondo de una banda con texto encima.

Tu casa, seis semanas al año

Props

Props de Media
Prop Valores Por defecto Para qué
src * string — —
alt * string — —
srcset string — —
sizes string — —
sources { media: string; srcset: string; sizes?: string; type?: string }[] [] Art-direction <source>s (e.g. a portrait crop under 48rem); non-empty renders a <picture>.
width number — —
height number — —
aspect | '16/9' | '4/3' | '3/2' | '5/4' | '1/1' | '4/5' | '3/4' | '2/3' | '21/9' | 'auto' | 'fill' 'auto' —
fit covercontain 'cover' —
position PositionKeyword | FocalPoint | string | null — Crop anchor (object-position): keyword, focal point in percent, or a CSS object-position string such as 'center 30%'. Default: centre.
radius nonemediacard 'media' —
loading lazyeager 'lazy' —
fetchpriority highlowauto — —
poster string — Video src only: the poster image URL (already transformed), shown before the first frame.
decoding asyncsyncauto 'async' —
imgClass string '' —

Notas del código

El comentario de cabecera de Media.astro, tal cual (en inglés, como el código): si cambia el código, cambia esto.

thin <img> wrapper with aspect ratio, radius and a surface-alt placeholder while the image loads.

It REQUIRES an already-transformed src (and srcset) — this primitive never builds Cloudinary URLs itself (house rule: no raw Cloudinary URLs in markup). Callers transform first:

import { cloudinaryTransform, cloudinarySrcset, CARD_WIDTHS }
  from '@vivla-cms/cms-blocks/image'          // packages / blocks
import { deliverUrl, resolveImageUrl } from '@/lib/cms-image' // apps/web

<Media src={cloudinaryTransform(url, 1280)} srcset={cloudinarySrcset(url, CARD_WIDTHS)}
       sizes="(min-width: 62rem) 50vw, 100vw" alt={alt} aspect="4/3" />

Art direction: sources renders a <picture> whose <source>s win over the <img> (which stays the fallback with its own src / srcset / sizes). Order them most specific first, exactly like hand-written <picture> markup:

<Media src={cloudinaryTransform(wide, 1600)} srcset={cloudinarySrcset(wide, HERO_WIDTHS)}
       sizes="100vw" alt={alt} aspect="fill" loading="eager" fetchpriority="high"
       sources={[{ media: '(max-width: 47.9375rem)',
                   srcset: cloudinarySrcset(tall, MOBILE_WIDTHS), sizes: '100vw' }]} />

aspect="fill" stretches the wrapper to its parent (h-full w-full, no ratio) and pins the image absolutely: use it for full-bleed layers such as the still under a hero <Video>. The parent must have a height.

Portrait and panoramic crops (Figma evidence): 2/3 Casa Ribes 383:1904, 272:2666 (647×965); 3/4 about-us team 456:2131 (464×607), 332:4547; 21/9 about-us 452:2109 / 456:2133 (1512×718, plan D30 snap).

position moves the crop inside a fixed aspect (it has no effect with auto, where nothing is cropped): a keyword, a focal point in percent (0 = left / top; numeric strings accepted), or a CSS object-position string as CMS focal-point fields store it (stepPanel.imageFocal). Keywords render a utility class; anything else an inline object-position. A string that cannot be read in percent (lengths, calc()) renders the default centre and logs a dev warning.

<Media {...img} aspect="3/4" position="top" />
<Media {...img} aspect="21/9" position={{ x: 50, y: 30 }} />
<Media {...img} aspect="16/9" position={block.imageFocal} />  // 'center 30%'

A video file as src (.mp4/.webm/.mov, or a Cloudinary /video/upload/ URL) renders a muted loop video in the same frame instead of the <img> (10/11/2026: any CMS photo field without its own «Vídeo» also takes a video). poster (an already-transformed image URL: cms-blocks mediaPoster()) shows at once and the file waits until the frame is near the viewport; without one the video's first frame is the poster. It plays only while in view and never for reduced-motion or Save-Data visitors (DS Video, firstFrame). alt names it; srcset / sources are ignored.

<Media src={mediaUrl(field)} poster={mediaPoster(field)} alt={alt} aspect="4/5" />

In dev a raw Cloudinary URL logs a warning so it is caught before review.

Dónde se usa

82 veces en 47 archivos de la web y los bloques del CMS.

Ver los archivos
esc