moduix

Lightbox

An image-focused modal overlay for zoomed preview and dynamic gallery capture.

API Reference

Original primitive API

Behavior, accessibility details, and low-level props are documented by Base UI.

Base UI API

Basic

import { Lightbox, LightboxImage, LightboxContent } from "moduix";const thumbnail =  "https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&w=1200&q=80";const fullSize =  "https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&w=2200&q=90";export function LightboxDemo() {  return (    <Lightbox>      <LightboxImage src={thumbnail} alt="Mountain ridge at sunset" className={styles.previewImage} />      <LightboxContent>        <img src={fullSize} alt="Mountain ridge at sunset" className={styles.contentImage} />      </LightboxContent>    </Lightbox>  );}

Full list of component variables available for project-level overrides.

PropertyDefaultDescription
--lightbox-backdrop-bgvar(--backdrop-bg, var(--color-overlay))Controls backdrop fill.
--lightbox-backdrop-transitionvar(--transition-default)Controls backdrop transition.
--lightbox-close-bgvar(--color-background)Controls close button background.
--lightbox-close-bg-hovervar(--color-muted)Controls close button hover background.
--lightbox-close-colorvar(--color-foreground)Controls close icon color.
--lightbox-close-color-hovervar(--color-foreground)Controls close icon hover color.
--lightbox-close-icon-size0.875remControls close icon size.
--lightbox-close-offset-rightvar(--spacing-4)Controls close button right offset.
--lightbox-close-offset-topvar(--spacing-4)Controls close button top offset.
--lightbox-close-radiusvar(--radius-sm)Controls close button radius.
--lightbox-close-size2remControls close button size.
--lightbox-focus-ring-colorvar(--color-ring)Controls focus ring color.
--lightbox-height80dvhControls the popup height limit.
--lightbox-image-enter-duration240msControls image enter animation duration.
--lightbox-image-enter-scale0.9Controls image enter animation scale.
--lightbox-image-max-height80dvhControls max image height.
--lightbox-image-max-width80vwControls max image width.
--lightbox-image-radiusvar(--radius-md)Controls image corner radius in modal.
--lightbox-image-shadowvar(--shadow-lg)Controls image shadow in modal.
--lightbox-max-height80dvhControls max popup height.
--lightbox-max-width80vwControls max popup width.
--lightbox-scale0.82Controls popup initial scale.
--lightbox-transition220ms easeControls popup transition.
--lightbox-viewport-paddingvar(--spacing-4)Controls viewport padding.
--lightbox-width80vwControls the popup width limit.

Interactive variables scoped for docs preview without changing size scale tokens.

PropertyValueDefaultDescription
--lightbox-backdrop-bgvar(--backdrop-bg, var(--color-overlay))Controls backdrop fill.
--lightbox-close-bgvar(--color-background)Controls close button background.
--lightbox-height80dvhControls popup height.
--lightbox-image-radiusvar(--radius-md)Controls image corner radius.
--lightbox-width80vwControls popup width.

Anatomy

Lightbox is composed from dialog primitives and keeps image-specific structure in one content slot. LightboxContent renders internal service layers (portal, backdrop, viewport) and the visual image frame with an optional close button.

Lightbox
├─ LightboxTrigger (optional)
│  └─ LightboxImage (optional helper)
└─ LightboxContent
   ├─ portal (service slot)
   │  ├─ backdrop (service slot, optional)
   │  └─ viewport (service slot)
   │     └─ popup
   │        └─ frame
   │           ├─ LightboxClose (optional)
   │           └─ image content
<Lightbox>
  <LightboxImage src={thumbnail} alt="Preview image" />
  <LightboxContent>
    <img src={fullSize} alt="Preview image" />
  </LightboxContent>
</Lightbox>
PartRole
LightboxRoot state and behavior (open, defaultOpen, onOpenChange, modal, handle).
LightboxTriggerOpens the preview from any custom trigger composition.
LightboxImageHelper that wraps an image as a trigger and supports previewSrc mapping.
LightboxContentModal content slot that owns portal, backdrop, viewport, popup, and frame.
LightboxCloseOptional close control rendered in the frame area.
LightboxGalleryDynamic image capture mode for CMS-rendered or unknown image lists.

Use className for the popup surface and classNames for service slots like backdrop and viewport. Keep withBackdrop enabled in modal scenarios; disable it only for non-modal overlays.

Composition

Lightbox passes through dialog root behavior from Base UI. Use controlled state when external UI needs to open or close previews. LightboxContent supports container, slotProps, and classNames for service-slot customization, plus withBackdrop and withCloseButton for high-level behavior.

LightboxGallery adds delegation-based capture for dynamic content. It listens for image clicks inside rootRef or rootSelector and opens the preview with the clicked image source.

Examples

Use LightboxGallery when page content comes from CMS or admin HTML and individual images cannot be wrapped manually.

Mountain landscapeSea at sunsetForest and mountain road
import { LightboxGallery } from "moduix";import { Fragment, useRef } from "react";export function DynamicGalleryDemo() {  const rootRef = useRef<HTMLDivElement | null>(null);  return (    <Fragment>      <div ref={rootRef} className={styles.dynamicRoot}>        <img src={images.mountain} alt="Mountain landscape" className={styles.dynamicImage} />        <img src={images.sea} alt="Sea at sunset" className={styles.dynamicImage} />        <img src={images.forest} alt="Forest and mountain road" className={styles.dynamicImage} />      </div>      <LightboxGallery rootRef={rootRef} />    </Fragment>  );}

Customized Surface

Customize size limits, backdrop tone, and close button appearance with className, classNames, and CSS variables.

import { CloseButton, Lightbox, LightboxImage, LightboxContent } from "moduix";export function CustomizedLightboxDemo() {  return (    <Lightbox>      <LightboxImage src={thumbnail} alt="Road through forest" className={styles.previewImage} />      <LightboxContent        className={styles.customPopup}        classNames={{ backdrop: styles.customBackdrop }}        closeButton={<CloseButton aria-label="Close preview" className={styles.customClose} />}      >        <img src={fullSize} alt="Road through forest" className={styles.contentImage} />      </LightboxContent>    </Lightbox>  );}

On this page