Ir al contenido

Lightbox

Imágenes al tamaño de la ventana, una a la vez: las capturas de un reporte, las imágenes de un bucket. Las flechas pasan de una a otra; Escape cierra.

import { Lightbox } from '@sypnia/ui/react'

En esta página
  1. Capturas de un reporte
  2. Cuándo usarlo
  3. Para todos
  4. Props

Capturas de un reporte

Pulsa una miniatura y usa las flechas.

Código
import { useState } from 'react';
import { Lightbox } from '@sypnia/ui/react';

// Press a thumbnail. Arrow keys move; Escape closes and the focus goes back to the thumbnail.
const shot = (title: string, hue: number) => 'data:image/svg+xml;utf8,' + encodeURIComponent(
  `<svg xmlns="http://www.w3.org/2000/svg" width="1280" height="800" viewBox="0 0 1280 800"><rect width="1280" height="800" fill="hsl(${hue} 30% 92%)"/><rect x="40" y="40" width="1200" height="64" rx="12" fill="hsl(${hue} 30% 82%)"/><rect x="40" y="140" width="380" height="620" rx="12" fill="hsl(${hue} 30% 86%)"/><rect x="460" y="140" width="780" height="300" rx="12" fill="hsl(${hue} 30% 86%)"/><text x="80" y="82" font-family="sans-serif" font-size="28" fill="hsl(${hue} 30% 25%)">${title}</text></svg>`);
const images = [
  { src: shot('Sign-in error', 10), alt: 'The sign-in page with the error «Wrong code»', caption: 'The error appears after the second try.' },
  { src: shot('Console log', 200), alt: 'The browser console with two red lines', caption: 'Two requests answer 401.' },
  { src: shot('Network tab', 140), alt: 'The network tab with the failing request selected' },
];
export default function Screenshots() {
  const [open, setOpen] = useState(false);
  const [index, setIndex] = useState(0);
  return (
    <>
      <div className="sy-row">
        {images.map((img, i) => (
          <button key={i} type="button" className="sy-card" onClick={() => { setIndex(i); setOpen(true); }} aria-label={`Open: ${img.alt}`}>
            <img src={img.src} alt="" width={160} height={100} />
          </button>
        ))}
      </div>
      <Lightbox label="Screenshots of the report" images={images} index={index} onIndex={setIndex} open={open} onClose={() => setOpen(false)} />
    </>
  );
}

Cuándo usarlo

Úsalo cuando

  • Miniaturas que la gente abre para leer los detalles.
  • Dale a cada imagen un alt que diga qué muestra, y un pie cuando ayude.

No lo uses cuando

  • Una sola imagen pequeña que se lee bien como está.
  • Documentos: abre los PDF en su propio visor.

Para todos

  • Es un diálogo nombrado por label; el contador se lee cuando cambia la imagen.
  • Las flechas y los botones se mueven; Escape, la cruz o un toque en el espacio alrededor de la imagen la cierran, y el foco vuelve a la miniatura.
  • En celulares los botones van debajo de la imagen, de a dos.

Props

LightboxTipoPor defecto
imagesobligatorio LightboxImage[]
indexobligatorio number
labelobligatorio

What the images are: «Screenshots of the report».

string
onCloseobligatorio () => void
onIndexobligatorio (index: number) => void
openobligatorio boolean
  1. Capturas de un reporte
  2. Cuándo usarlo
  3. Para todos
  4. Props

    Busca páginas, secciones y términos