• CMSnpm version

    • ContentBuilder
    • InviteUserForm
    • LoginForm
    • RenewPasswordForm
  • UInpm version

    • Get started
    • Accordion
    • AlertBubble
    • AnnouncementBar
    • Avatar
    • AvatarFileInput
    • Badge
    • Button
    • ButtonGroup
    • ButtonList
    • Calendar
    • Checkbox
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • Chip
    • ColorRadio
    • ColorRadioGroup
    • Combobox
    • DatePicker
    • DatePickerInput
    • DateRangePicker
    • DateRangePickerInput
    • DatetimePicker
    • DatetimePickerInput
    • Dialog
    • Dropdown
    • Dropzone
    • ErrorMessage
    • FileInput
    • FlashMessages
    • FormComponent
    • Icon
    • IconButton
    • ImageGallery
    • InfoBox
    • Input
    • Label
    • Layout
    • Lightbox
    • ListItem
    • Loader
    • Lozenge
    • Message
    • Modal
    • ✅ ModalDialog
    • ✅ ModalHeader
    • MultiCombobox
    • MultiSelect
    • Pagination
    • Paper
    • Radio
    • RadioGroup
    • RasterImage
    • Select
    • ✅ Tabs
    • TextInput
    • TextLink
    • Textarea
    • TimePicker
    • TimePickerInput
    • Toggle
    • Tooltip
    • Typography
  • Formnpm version

    • AvatarFileInput
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • ColorRadioGroup
    • Combobox
    • DatePickerInput
    • DateRangePickerInput
    • DatetimePickerInput
    • Dropzone
    • FileInput
    • Form
    • FormRenderer
    • GpsInput
    • MoneyInput
    • MultiCombobox
    • MultiSelect
    • NumberInput
    • PasswordInput
    • RadioGroup
    • Select
    • TextInput
    • Textarea
    • TimePickerInput
    • Toggle
  • DataGridnpm version

    • Getting started
    • DataGrid
    • DataGridCustomExample
    • DataGridV2
    • ExportButton
    • FilterList
    • Filters
    • FiltersButton
    • FulltextInput
    • HiddenColumns
    • HiddenColumnsButton
    • Pagination
    • RowCounts
    • RowsPerPageSelect
    • SelectedRowsToolbar
    • Table
    • TableV2
    • ToolbarControl
    • ToolbarCustoms
    • ToolbarTabs
  • Wysiwygnpm version

    • Getting started
  • Resizernpm version

    • Readme
  • Routernpm version

    • Readme
  • Corenpm version

    • Readme
    • Utils
  • Core-Reactnpm version

    • Readme
  • Stylesnpm version

    • Readme
  • Localizenpm version

    • Readme
  • Analyticsnpm version

    • Readme
  • Datepickernpm version

    • Readme
  • Icons-generatornpm version

    • Readme
  • Smart-addressnpm version

    • Readme
  • E2Enpm version

    • Readme

Lightbox

Lightbox is a component that displays images in a modal dialog with navigation controls. It allows users to view images in a larger size and navigate through a collection of images.

CSS dependencies

@import url("@uxf/ui/css/icon.css");
@import url("@uxf/ui/css/lightbox.css");

Basic Usage

import { Lightbox, useLightboxImage } from "@uxf/ui/lightbox";

function ImageGallery() {
  const images = [
    { src: "image1.jpg", title: "Image 1" },
    { src: "image2.jpg", title: "Image 2" },
    { src: "image3.jpg", title: "Image 3" },
  ];

  return (
    <Lightbox>
      <div className="flex gap-2">
        {images.map((image) => (
          <GalleryImage 
            key={image.src} 
            src={image.src} 
            title={image.title} 
          />
        ))}
      </div>
    </Lightbox>
  );
}

function GalleryImage(props: { src: string; title: string }) {
  // useLightboxImage hook registers the image with the Lightbox context
  const openLightbox = useLightboxImage({
    src: props.src,
    title: props.title,
    // Optional custom content to display with the image
    customContent: <div>Custom description for {props.title}</div>,
  });

  return (
    <img
      src={props.src}
      alt={props.title}
      className="cursor-pointer"
      onClick={openLightbox}
    />
  );
}

Custom Buttons

You can customize the navigation buttons by providing your own components:

import { Lightbox, type LightboxButtonProps } from "@uxf/ui/lightbox";

function CustomCloseButton(props: LightboxButtonProps) {
  return (
    <button 
      className="my-custom-close-button" 
      onClick={props.onClick}
    >
      Close
    </button>
  );
}

function CustomNextButton(props: LightboxButtonProps) {
  return (
    <button 
      className="my-custom-next-button" 
      onClick={props.onClick}
    >
      Next →
    </button>
  );
}

function CustomPrevButton(props: LightboxButtonProps) {
  return (
    <button 
      className="my-custom-prev-button" 
      onClick={props.onClick}
    >
      ← Prev
    </button>
  );
}

function CustomLightbox() {
  return (
    <Lightbox
      CloseButtonElement={CustomCloseButton}
      NextButtonElement={CustomNextButton}
      PrevButtonElement={CustomPrevButton}
    >
      {/* Your gallery content */}
    </Lightbox>
  );
}

Custom Dialog

For complete customization, you can provide your own dialog component:

import {Lightbox, type LightboxCustomDialogProps} from "@uxf/ui/lightbox";
import {useLightboxDialog} from "@uxf/ui/lightbox/components/use-lightbox-dialog";

function CustomLightboxDialog(props: LightboxCustomDialogProps) {
    const { imageSrc, imageCustomContent, swipableHandlers } = useLightboxDialog({
        imageIndex: props.imageIndex,
        images: props.images,
        onClose: props.onClose,
        onNext: props.onNext,
        onPrev: props.onPrev,
    });

    return (
        <div className="my-custom-lightbox-dialog">
            <button onClick={props.onClose}>Close</button>

            <div className="image-container">
                <img src={currentImage.src} alt={currentImage.title}/>
                {currentImage.customContent && (
                    <div className="custom-content">
                        {currentImage.customContent}
                    </div>
                )}
            </div>

            <div className="navigation">
                <button onClick={props.onPrev}>Previous</button>
                <button onClick={props.onNext}>Next</button>
            </div>
        </div>
    );
}

function CustomDialogLightbox() {
    return (
        <Lightbox DialogElement={CustomLightboxDialog}>
            {/* Your gallery content */}
        </Lightbox>
    );
}

Props

Lightbox Props

| Prop | Type | Description | |------|------|-------------| | children | ReactNode | Content to be rendered inside the Lightbox | | CloseButtonElement | FC<LightboxButtonProps> | Custom close button component | | NextButtonElement | FC<LightboxButtonProps> | Custom next button component | | PrevButtonElement | FC<LightboxButtonProps> | Custom previous button component | | DialogElement | FC<LightboxCustomDialogProps> | Custom dialog component | | isBackdropCloseDisabled | boolean | Disables closing the lightbox when clicking on the backdrop |

Default
Open in new tab