import React, { useMemo } from "react";
/**
* PhotoGrid — Instagram-style masonry grid for Docusaurus.
*
* Usage in any .mdx page:
*
* import PhotoGrid from "@site/src/components/PhotoGrid";
*
*
*
* Props:
* photos — string[] — paths relative to /static (required)
* columns — number — desktop columns, default 3
* gap — string — grid gap, default "12px"
* shuffle — boolean — randomize order on each page load, default false
*/
export default function PhotoGrid({ photos = [], columns = 3, gap = "12px", shuffle = false }) {
const displayPhotos = useMemo(() => {
if (!shuffle) return photos;
const arr = [...photos];
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}, [photos, shuffle]);
if (!displayPhotos.length) return null;
return (
<>
{displayPhotos.map((src, i) => (
))}
>
);
}