Skip to main content
Glama
ImageLightbox.jsx1.79 kB
import React, { useState, useEffect } from 'react'; import Lightbox from 'yet-another-react-lightbox'; import Captions from 'yet-another-react-lightbox/plugins/captions'; import 'yet-another-react-lightbox/styles.css'; import 'yet-another-react-lightbox/plugins/captions.css'; function ImageLightbox({ isOpen, onClose, images, currentIndex = 0 }) { const [index, setIndex] = useState(currentIndex); useEffect(() => { setIndex(currentIndex); }, [currentIndex]); // Format images for lightbox const slides = images.map((img) => ({ src: typeof img === 'string' ? img : img.src, title: typeof img === 'string' ? '' : img.title || '', description: typeof img === 'string' ? '' : img.description || '' })); return ( <Lightbox open={isOpen} close={onClose} index={index} slides={slides} plugins={[Captions]} on={{ view: ({ index }) => setIndex(index) }} captions={{ descriptionTextAlign: 'center', descriptionMaxLines: 3 }} styles={{ container: { backgroundColor: 'rgba(0, 0, 0, 0.95)' }, captionsDescriptionContainer: { background: 'rgba(0, 0, 0, 0.8)', color: '#ffffff' } }} /> ); } // Hook to manage lightbox state export function useLightbox() { const [isOpen, setIsOpen] = useState(false); const [currentIndex, setCurrentIndex] = useState(0); const [images, setImages] = useState([]); const openLightbox = (imageList, index = 0) => { setImages(imageList); setCurrentIndex(index); setIsOpen(true); }; const closeLightbox = () => { setIsOpen(false); }; return { isOpen, currentIndex, images, openLightbox, closeLightbox }; } export default ImageLightbox;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cjo4m06/mcp-shrimp-task-manager'

If you have feedback or need assistance with the MCP directory API, please join our Discord server