Data display
Image & Lightbox
Images that reserve their space, load lazily, show a placeholder and a fallback; and a full-screen viewer with keyboard and swipe navigation.
import { Image, Lightbox } from '@reactloom/ui';Examples
Image
aspectRatio reserves the space before loading; a failed image shows a fallback named by alt.
import { HStack, Image } from '@reactloom/ui';
const photo = (hue: number) =>
'data:image/svg+xml;utf8,' +
encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 9"><defs><linearGradient id="g"><stop offset="0" stop-color="hsl(${hue} 60% 55%)"/><stop offset="1" stop-color="hsl(${hue + 40} 60% 35%)"/></linearGradient></defs><rect width="16" height="9" fill="url(#g)"/></svg>`);
export default function Example() {
return (
<HStack wrap>
<Image src={photo(200)} alt="Gradient from blue to teal" aspectRatio={16 / 9} width={220} radius="md" />
<Image src="data:image/png;base64," alt="Product photo (missing)" aspectRatio={16 / 9} width={220} radius="md" />
</HStack>
);
}Lightbox
Open from thumbnails; ← and → move, the position is announced, Escape closes.
import { HStack, Image, Lightbox } from '@reactloom/ui';
import { useState } from 'react';
const photo = (hue: number) =>
'data:image/svg+xml;utf8,' +
encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 9"><rect width="16" height="9" fill="hsl(${hue} 55% 50%)"/></svg>`);
const images = [
{ src: photo(10), alt: 'Red swatch', caption: 'Warm palette' },
{ src: photo(140), alt: 'Green swatch', caption: 'Fresh palette' },
{ src: photo(220), alt: 'Blue swatch', caption: 'Cool palette' },
];
export default function Example() {
const [index, setIndex] = useState<number | null>(null);
return (
<>
<HStack>
{images.map((img, i) => (
<button key={img.src} type="button" onClick={() => setIndex(i)} aria-label={`Open ${img.alt}`} style={{ padding: 0, border: 0, background: 'none', cursor: 'zoom-in' }}>
<Image src={img.src} alt="" aspectRatio={4 / 3} width={120} radius="sm" />
</button>
))}
</HStack>
<Lightbox images={images} open={index !== null} onOpenChange={(open) => !open && setIndex(null)} index={index ?? 0} onIndexChange={setIndex} />
</>
);
}API reference
| Prop | Type | Default |
|---|---|---|
altrequiredRequired; "" for decorative images. | string | — |
src | string | — |
aspectRatioWidth / height of the frame, e.g. 16 / 9. | number | — |
fit | 'cover' | 'contain' | 'cover' |
blurDataURL · placeholderShown until the image loads. | string · ReactNode | — |
fallbackShown if the image fails. | ReactNode | an icon |
radius | Radius | — |
loading | 'lazy' | 'eager' | 'lazy' |
classNames · stylesroot, image, placeholder, fallback. | Partial<Record<ImageSlot, …>> | — |
| Prop | Type | Default |
|---|---|---|
imagesrequired | { src, alt, caption? }[] | — |
open / defaultOpen / onOpenChange | boolean | — |
index / defaultIndex / onIndexChange | number | — |
loopWrap from last to first. | boolean | true |
messagesButton names and the position text. | Partial<LightboxMessages> | — |
classNames · stylesdialog, stage, image, caption, counter, previous, next, zoom. | Partial<Record<LightboxSlot, …>> | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Image
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): root, image, placeholder, fallback.
CSS variables
| Variable | Default |
|---|---|
--pl-image-bg | var(--pl-color-bg-subtle) |
--pl-image-radius | 0 |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-fit] | cover · contain |
[data-radius] | none · sm · md · lg · full |
[data-state] | present when on |
Theme tokens it reads
--pl-color-bg-subtle --pl-color-fg-subtle --pl-radius-full --pl-radius-lg --pl-radius-md --pl-radius-sm
Lightbox
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): dialog, stage, image, caption, counter, previous, next, zoom.
CSS variables
| Variable | Default |
|---|---|
--pl-lightbox-bg | rgb(10 12 16 / 0.96) |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-zoomed] | present when on |
Accessibility
- The Lightbox is a modal dialog named by the current image’s alt text; focus returns to the thumbnail.
- Swiping is a touch convenience; the buttons and arrow keys do the same.
| Key | Action |
|---|---|
| ← / → | Previous or next image |
| Home / End | First or last image |
| Escape | Close |
Usage guidelines
Do
- Always write alt text that says what the image shows.
- Set aspectRatio so the page does not jump while images load.
Don’t
- Don’t put essential text only inside images.