Lightbox

Lightbox displays images and videos in a full-screen viewer with zoom, navigation, and optional metadata.

Basics

Basic lightbox with navigation and metadata.

Loading demo…

import { useState } from 'react'; import { TouchableOpacity } from 'react-native'; import { Block, Lightbox, Image, Row } from '@plocks/ui'; import { SAMPLE_IMAGES } from './data'; export function Demo() { // `null` closes the lightbox; any index opens it on that image. const [openIndex, setOpenIndex] = useState<number | null>(null); return ( <Block> <Row gap="sm" wrap="wrap"> {SAMPLE_IMAGES.map((image, index) => ( <TouchableOpacity key={image.id} onPress={() => setOpenIndex(index)}> <Image src={image.uri} w={120} h={90} rounded resizeMode="cover" /> </TouchableOpacity> ))} </Row> <Lightbox opened={openIndex !== null} images={SAMPLE_IMAGES} initialIndex={openIndex ?? 0} onClose={() => setOpenIndex(null)} showMetadata /> </Block> ); }

Advanced

Advanced lightbox configurations with custom handlers.

Loading demo…

import { useState } from 'react'; import { Block, Button, Lightbox, Row, Text } from '@plocks/ui'; import type { LightboxItem } from '@plocks/ui'; import { SAMPLE_IMAGES } from './data'; export function Demo() { const [active, setActive] = useState<'minimal' | 'custom' | null>(null); const [downloaded, setDownloaded] = useState<string | null>(null); return ( <Block> <Row gap="sm" wrap="wrap"> <Button variant="outline" onPress={() => setActive('minimal')}> Minimal </Button> <Button variant="outline" onPress={() => setActive('custom')}> Custom download </Button> </Row> {/* Chrome stripped back to the image itself — swipe and arrow keys still navigate. */} <Lightbox opened={active === 'minimal'} images={SAMPLE_IMAGES} onClose={() => setActive(null)} showThumbnails={false} showDownloadButton={false} /> {/* `onDownload` replaces the built-in behaviour, so the host app decides what saving means. */} <Lightbox opened={active === 'custom'} images={SAMPLE_IMAGES} onClose={() => setActive(null)} onDownload={(image: LightboxItem) => setDownloaded(image.title ?? image.id)} showMetadata /> {downloaded ? ( <Text size="sm" c="secondary"> Downloaded {downloaded} </Text> ) : null} </Block> ); }

Zoom

Double-tap or pinch an image to zoom, drag to pan, and use maxZoom to cap the scale. On web, ctrl/⌘ + wheel and the + - 0 Z keys zoom too.

Loading demo…

import { useState } from 'react'; import { Button, Lightbox } from '@plocks/ui'; import type { LightboxItem } from '@plocks/ui'; const IMAGES: LightboxItem[] = [ { id: 'mountains', uri: require('../../../../assets/images/scene-mountains.png'), title: 'Mountain Landscape' }, { id: 'forest', uri: require('../../../../assets/images/scene-forest.png'), title: 'Forest Path' }, { id: 'lake', uri: require('../../../../assets/images/scene-lake.png'), title: 'Alpine Lake' }, ]; export function Demo() { const [opened, setOpened] = useState(false); return ( <> <Button onPress={() => setOpened(true)}>Open lightbox</Button> <Lightbox opened={opened} images={IMAGES} maxZoom={4} onClose={() => setOpened(false)} /> </> ); }

Video slides

Mix type: 'video' slides in with images. Web plays them in the browser's player; native uses expo-video when it is installed and otherwise shows the poster.

Loading demo…

import { useState } from 'react'; import { Button, Lightbox } from '@plocks/ui'; import type { LightboxItem } from '@plocks/ui'; const SLIDES: LightboxItem[] = [ { id: 'ocean', uri: require('../../../../assets/images/scene-ocean.png'), title: 'Coastal Sunrise' }, { id: 'flower', type: 'video', src: 'https://developer.mozilla.org/shared-assets/videos/flower.mp4', poster: 'https://developer.mozilla.org/shared-assets/images/examples/flowers.jpg', title: 'Flower', muted: true, loop: true, }, { id: 'city', uri: require('../../../../assets/images/scene-city.png'), title: 'City at Dusk' }, ]; export function Demo() { const [opened, setOpened] = useState(false); return ( <> <Button onPress={() => setOpened(true)}>Open lightbox</Button> <Lightbox opened={opened} images={SLIDES} onClose={() => setOpened(false)} /> </> ); }
Scan to open this page on your phoneplocks.dev/ui/Lightbox