About
Image viewer that morphs from the thumbnail, with swipe, zoom, and pull to close. From chanhdai.com (ncdai), MIT.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Lightbox to your project and fits it to your theme.
Code
How Lightbox is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import { Lightbox, LightboxCaption, LightboxClose, LightboxContent, LightboxFooter, LightboxHeader, LightboxItem, LightboxMedia, LightboxSlide, LightboxSlides, LightboxTrigger, LightboxZoom, LightboxZoomIn, LightboxZoomOut } from "@/components/ui/chanhdai-lightbox"
export default function LightboxSingleDemo() {
return (
<Lightbox>
<figure className="w-full max-w-xs">
<LightboxTrigger
index={0}
className="w-full overflow-hidden rounded-xl"
>
{({ imageRef }) => (
<img
ref={imageRef}
className="block h-auto w-full rounded-[inherit] outline -outline-offset-1 outline-foreground/10"
src={IMAGE.src}
alt={IMAGE.alt}
width={IMAGE.width}
height={IMAGE.height}
/>
)}
</LightboxTrigger>
<figcaption className="mt-2 text-center text-sm text-muted-foreground">
{IMAGE.caption}
</figcaption>
</figure>
<LightboxContent aria-label={IMAGE.caption}>
<LightboxSlides>
<LightboxSlide>
<LightboxItem index={0} caption={IMAGE.caption}>
<LightboxZoom maxZoom={4} scrollToZoom>
<LightboxMedia width={IMAGE.width} height={IMAGE.height}>
<img
src={IMAGE.src}
alt={IMAGE.alt}
width={IMAGE.width}
height={IMAGE.height}
draggable={false}
/>
</LightboxMedia>
</LightboxZoom>
</LightboxItem>
</LightboxSlide>
</LightboxSlides>
<LightboxHeader>
<LightboxZoomOut />
<LightboxZoomIn />
<LightboxClose />
</LightboxHeader>
<LightboxFooter>
<LightboxCaption />
</LightboxFooter>
</LightboxContent>
</Lightbox>
)
}
const IMAGE = {
src: "https://cdn.21st.dev/assets/mirror/4f/4f55c5c761cbed10abdf223bf3de4eda4ce73a699a2ac83ba4ccbbefe7f0c112.webp",
alt: "The whole cabinet from the front: iPhones and their boxes on two shelves, and an iPad with its box on the bottom shelf.",
caption: "Apple Museum cabinet",
width: 1000,
height: 1488,
}







