SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Lightbox

A full-screen photo viewer for a gallery, as a native <dialog> a trigger opens through Invoker Commands.

1 / 5Fern Cabin at dusk
2 / 5Living room
3 / 5Sleeping loft
4 / 5Private dock
5 / 5Trail to the falls
View code
tsx
<div>
	{photos.map((photo, index) => (
		<Lightbox.Trigger lightbox="fern-cabin" index={index} aria-label={`Open photo ${index + 1}`}>
			<img src={photo.thumb} alt="" />
		</Lightbox.Trigger>
	))}
	<Lightbox.Trigger lightbox="fern-cabin">Show all photos</Lightbox.Trigger>
</div>
<Lightbox
	id="fern-cabin"
	label="Photos of Fern Cabin"
	photos={photos.map((photo) => ({ src: photo.src, alt: photo.alt, caption: photo.caption }))}
/>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add lightbox

Usage

typescript
import { Lightbox } from "@sdxc/ui";

Renders the viewer: a full-screen dark <dialog> with a close button, one slide per photo (contained, with "n / N" and its caption) and step links between neighbours. Opened from a Lightbox.Trigger; Escape and the close button dismiss it.

Composition

The parts the component publishes, each a static property of the host.

  • Lightbox
  • Lightbox.TriggerRenders a button that opens the viewer named by lightbox as a modal, at photo index once the island has loaded.

Examples

tsx
<Lightbox id="cabin-photos" label="Photos" photos={photos} initial={Number(url.searchParams.get("photo")) - 1} />

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeRequiredDescription
idstringYesTargeted by each trigger's commandfor, and the prefix of every photo's own id.
labelstringYesThe gallery's name, such as "Photos of Fern Cabin", read when the viewer opens.
photosPhoto[]Yes
initialnumberNoRenders the viewer already open at this zero-based photo, for a page whose address names one (?photo=3). Without script it is a non-modal dialog covering the page; the island reopens it as a modal.
labelsPartial<Labels>No

Also accepts everything in Omit<TagProps<"dialog">, "children" | "open">.

Lightbox.Trigger

PropTypeRequiredDescription
lightboxstringYesid of the Lightbox this opens.
indexnumberNoZero-based photo the viewer opens at once the island has loaded.

Also accepts everything in Omit<TagProps<"button">, "commandfor" | "command">.

@sdxc/ui

Can’t find it? Contact us