image-gallery-1

PreviousNext

Masonry-style responsive gallery using random images with dynamic aspect ratios.

Docs
efferdblock

Preview

Loading preview…
registry/image-gallery/1/image-gallery.tsx
import { LazyImage } from "@/components/lazy-image";

export function ImageGallery() {
	return (
		<div className="relative flex min-h-screen w-full flex-col items-center justify-center px-4 py-10">
			<div className="mx-auto grid w-full max-w-5xl grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-4 md:gap-6">
				{Array.from({ length: 4 }).map((_, col) => (
					<div className="grid gap-4" key={col}>
						{/* biome-ignore lint/nursery/noShadow: false positive */}
						{Array.from({ length: 8 }).map((_, index) => {
							const isPortrait = Math.random() > 0.5;
							const width = isPortrait ? 1080 : 1920;
							const height = isPortrait ? 1920 : 1080;
							const ratio = isPortrait ? 9 / 16 : 16 / 9;

							return (
								<LazyImage
									alt={`Image ${col}-${index}`}
									fallback={`https://placehold.co/${width}x${height}/`}
									inView={true}
									key={`${col}-${index}`}
									ratio={ratio}
									src={`https://picsum.photos/seed/${col}-${index}/${width}/${height}`}
								/>
							);
						})}
					</div>
				))}
			</div>
		</div>
	);
}

Installation

npx shadcn@latest add @efferd/image-gallery-1

Usage

import { ImageGallery1 } from "@/components/image-gallery-1"
<ImageGallery1 />