Ir al contenido

Image

Una imagen en una caja de forma conocida, para que nada se mueva cuando llega: el skeleton guarda su lugar hasta que carga, y si no puede cargar, la caja lo dice.

import { Image, ImageSkeleton } from '@sypnia/ui/react'

En esta página
  1. Formas, un fallo y un skeleton
  2. Skeleton
  3. Cuándo usarlo
  4. Para todos
  5. Props

Formas, un fallo y un skeleton

Drawing of hills under a sunDrawing of hills, squareDrawing of hills, shown wholeThe storefront
Código
import { Image, ImageSkeleton } from '@sypnia/ui/react';

// A box of known shape: nothing moves when the picture arrives. The last one cannot load and says so.
const art = (hue: number) => 'data:image/svg+xml;utf8,' + encodeURIComponent(
  `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800" viewBox="0 0 1200 800"><rect width="1200" height="800" fill="hsl(${hue} 35% 88%)"/><circle cx="880" cy="250" r="130" fill="hsl(${hue} 45% 70%)"/><path d="M0 620 L320 380 L560 560 L780 420 L1200 700 L1200 800 L0 800Z" fill="hsl(${hue} 30% 62%)"/></svg>`);
export default function Shapes() {
  return (
    <div className="sy-grid">
      <Image src={art(30)} alt="Drawing of hills under a sun" />
      <Image src={art(200)} alt="Drawing of hills, square" ratio="1" />
      <Image src={art(140)} alt="Drawing of hills, shown whole" ratio="4 / 3" fit="contain" />
      <Image src="data:image/png;base64,AAAA" alt="The storefront" ratio="4 / 3" />
      <ImageSkeleton ratio="4 / 3" />
    </div>
  );
}

Skeleton

A plain warm colour
Código
import { Image, ImageSkeleton } from '@sypnia/ui/react';

// A picture and its skeleton: the same box, so nothing moves when it arrives.
export default function Skeleton() {
  return (
    <div className="sy-cols sy-cols--stack">
      <Image ratio="4 / 3" alt="A plain warm colour" src={'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300"><rect width="400" height="300" fill="hsl(30 40% 80%)"/></svg>')} />
      <ImageSkeleton ratio="4 / 3" />
    </div>
  );
}

Cuándo usarlo

Úsalo cuando

  • Capturas, fotos de productos, portadas.
  • fit="contain" cuando debe verse la imagen completa.

No lo uses cuando

  • Iconos: usa Icon. Avatares: usa Avatar.

Para todos

  • alt dice qué muestra la imagen; vacío solo si es decoración.
  • Una imagen que falla conserva su nombre para los lectores de pantalla.

Props

ImageTipoPor defecto
altobligatorio string
srcobligatorio string
fit

cover fills the box and crops; contain shows the whole picture.

"cover" | "contain" cover
lazy

Loads it only when it comes near the screen.

boolean true
ratio

Width / height: «16 / 9», «1», «4 / 3».

string 16 / 9
rounded boolean true
ImageSkeletonTipoPor defecto
ratio string 16 / 9
rounded boolean true
  1. Formas, un fallo y un skeleton
  2. Skeleton
  3. Cuándo usarlo
  4. Para todos
  5. Props

    Busca páginas, secciones y términos