Examples

Image

aspectRatio reserves the space before loading; a failed image shows a fallback named by alt.

Preview
Gradient from blue to tealProduct photo (missing)
Example.tsx
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.

Preview
Example.tsx
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

Image props
PropTypeDefault
altrequired
Required; "" for decorative images.
string—
src
string—
aspectRatio
Width / height of the frame, e.g. 16 / 9.
number—
fit
'cover' | 'contain''cover'
blurDataURL · placeholder
Shown until the image loads.
string · ReactNode—
fallback
Shown if the image fails.
ReactNodean icon
radius
Radius—
loading
'lazy' | 'eager''lazy'
classNames · styles
root, image, placeholder, fallback.
Partial<Record<ImageSlot, …>>—
Lightbox props
PropTypeDefault
imagesrequired
{ src, alt, caption? }[]—
open / defaultOpen / onOpenChange
boolean—
index / defaultIndex / onIndexChange
number—
loop
Wrap from last to first.
booleantrue
messages
Button names and the position text.
Partial<LightboxMessages>—
classNames · styles
dialog, 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

VariableDefault
--pl-image-bgvar(--pl-color-bg-subtle)
--pl-image-radius0

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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

VariableDefault
--pl-lightbox-bgrgb(10 12 16 / 0.96)

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.
Keyboard interactions
KeyAction
← / →Previous or next image
Home / EndFirst or last image
EscapeClose

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.