# Add the "Image Gallery" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/image-gallery) to this Pantheon Content Publisher (P1) Next.js project. A captioned photo grid where each photo opens a full-screen view with next, previous and close links, no JavaScript.

## Steps

1. Create `components/puck/image-gallery-block.tsx` with the exact file contents below. If `components/puck/` doesn't exist, find the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`) and put it there.
2. In `puck.config.tsx`, import it: `import { imageGalleryBlock } from "./components/puck/image-gallery-block";`
3. Register it under `components` as `ImageGalleryBlock: imageGalleryBlock`.
4. Add `"ImageGalleryBlock"` to the best-fitting entry in `categories` (this block's library category is "Content"). Create a category only if none fits.
5. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
6. If `package.json` has a `sync:registry` script, tell the user it must run (or that CI will run it) before the new component appears in the P1 editor.

## Rules

- Do not add dependencies. The block is self-contained by design: one type-only import from `@puckeditor/core`, Tailwind v4 classes, no client JavaScript.
- Keep the files as-is unless the user asks for changes. The accent color is `indigo-*`; if the project has brand colors, offer to swap them with a find-and-replace on `indigo-`.
- Images are plain `imageUrl` + `imageAlt` text fields. If this project defines a P1 media-library field (search for `"p1-media"`), offer to switch to it.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/image-gallery-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";

/**
 * Image Gallery — a captioned photo grid where each photo opens a full-screen view with
 * previous/next and close links. Built on URL fragments and CSS :target, so it needs no JavaScript
 * and every control is a real, keyboard-reachable link. Register: `ImageGalleryBlock: imageGalleryBlock`.
 */

type Heading = "h1" | "h2" | "h3" | "h4";

export type ImageGalleryProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  columns: "2" | "3" | "4";
  shape: "landscape" | "square" | "portrait";
  images: { imageUrl: string; imageAlt: string; caption: string; credit: string }[];
};

const gridCols: Record<ImageGalleryProps["columns"], string> = {
  "2": "sm:grid-cols-2",
  "3": "sm:grid-cols-2 lg:grid-cols-3",
  "4": "sm:grid-cols-3 lg:grid-cols-4",
};

const shapeClass: Record<ImageGalleryProps["shape"], string> = {
  landscape: "aspect-4/3",
  square: "aspect-square",
  portrait: "aspect-4/5",
};

const linkRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white";

export const imageGalleryBlock: ComponentConfig<ImageGalleryProps> = {
  label: "Image Gallery",
  fields: {
    heading: { type: "text", label: "Heading" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change." },
    },
    intro: { type: "textarea", label: "Intro" },
    columns: {
      type: "select",
      label: "Columns",
      options: [
        { label: "2 columns", value: "2" },
        { label: "3 columns", value: "3" },
        { label: "4 columns", value: "4" },
      ],
      metadata: { help: "Columns on wide screens. Phones always show one column." },
    },
    shape: {
      type: "select",
      label: "Thumbnail shape",
      options: [
        { label: "Landscape 4:3", value: "landscape" },
        { label: "Square", value: "square" },
        { label: "Portrait 4:5", value: "portrait" },
      ],
      metadata: { help: "Thumbnails are cropped to this shape. The full-size view always shows the whole photo." },
    },
    images: {
      type: "array",
      label: "Photos",
      min: 1,
      max: 24,
      getItemSummary: (item) => item?.caption?.slice(0, 40) || item?.imageAlt?.slice(0, 40) || "Photo",
      defaultItemProps: { imageUrl: "https://picsum.photos/seed/meadow/1600/1200", imageAlt: "", caption: "", credit: "" },
      arrayFields: {
        imageUrl: { type: "text", label: "Image URL", metadata: { help: "Use a large image; it's shown full-screen when opened." } },
        imageAlt: { type: "text", label: "Alt text", metadata: { help: "Describe the photo for screen reader users. Required here, since the photo is also a link." } },
        caption: { type: "text", label: "Caption", metadata: { help: "Shown under the thumbnail and in the full-size view. Leave blank to hide it." } },
        credit: { type: "text", label: "Credit", metadata: { help: "Photographer or source, shown in the full-size view. Leave blank to hide it." } },
      },
    },
  },
  defaultProps: {
    heading: "Summer at the parks",
    headingLevel: "h2",
    intro: "A few favorite moments from this year's camps, concerts and community workdays. Select any photo to see it full size.",
    columns: "3",
    shape: "landscape",
    images: [
      { imageUrl: "https://picsum.photos/seed/splashpad/1600/1200", imageAlt: "Children running through fountains at a splash pad on a sunny afternoon", caption: "Opening day at the Westside splash pad", credit: "Photo: Dana Ruiz" },
      { imageUrl: "https://picsum.photos/seed/bandshell/1600/1200", imageAlt: "A brass band performing under a lit bandshell to a crowd on picnic blankets", caption: "Thursday concerts at the Central Park bandshell", credit: "Photo: Parks Department" },
      { imageUrl: "https://picsum.photos/seed/planting/1600/1200", imageAlt: "Volunteers kneeling in a garden bed planting purple coneflowers", caption: "Pollinator garden planting with the Garden Club", credit: "Photo: Marcus Lee" },
      { imageUrl: "https://picsum.photos/seed/canoe/1600/1200", imageAlt: "Two teenagers paddling a red canoe across a calm lake", caption: "Teen paddling camp on Lake Hollis", credit: "Photo: Parks Department" },
      { imageUrl: "https://picsum.photos/seed/lanterns/1600/1200", imageAlt: "Paper lanterns strung between trees above a crowded evening market", caption: "Night market on the riverfront", credit: "Photo: Aisha Grant" },
      { imageUrl: "https://picsum.photos/seed/trailrun/1600/1200", imageAlt: "Runners in race bibs on a gravel trail through tall grass", caption: "The Greenway 5K, 1,200 runners strong", credit: "Photo: Dana Ruiz" },
    ],
  },
  render: ({ id, heading, headingLevel, intro, columns, shape, images }) => {
    const H = headingLevel || "h2";
    const uid = `p1-gallery-${id}`;
    const list = (images ?? []).filter((img) => img?.imageUrl);
    const cols = gridCols[columns] ?? gridCols["3"];
    const ratio = shapeClass[shape] ?? shapeClass.landscape;
    const total = list.length;

    return (
      <section id={uid} className="bg-white px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-7xl">
          {heading || intro ? (
            <div className="max-w-2xl">
              {heading ? <H className="text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl">{heading}</H> : null}
              {intro ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
            </div>
          ) : null}

          {total > 0 ? (
            <ul role="list" className={`${heading || intro ? "mt-10 sm:mt-12" : ""} grid grid-cols-1 gap-x-4 gap-y-8 sm:gap-x-6 ${cols}`}>
              {list.map((img, i) => (
                <li key={`${img.imageUrl}-${i}`}>
                  <figure>
                    <a
                      id={`${uid}-thumb-${i + 1}`}
                      href={`#${uid}-view-${i + 1}`}
                      className="group block scroll-mt-24 overflow-hidden rounded-xl bg-neutral-100 ring-1 ring-neutral-950/5 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-indigo-600"
                    >
                      <img
                        src={img.imageUrl}
                        alt={img.imageAlt || img.caption || `Photo ${i + 1} of ${total}`}
                        loading="lazy"
                        className={`w-full object-cover transition duration-300 group-hover:scale-103 motion-reduce:transition-none motion-reduce:group-hover:scale-100 ${ratio}`}
                      />
                      <span className="sr-only">, open full size</span>
                    </a>
                    {img.caption ? <figcaption className="mt-3 text-sm leading-6 text-pretty text-neutral-600">{img.caption}</figcaption> : null}
                  </figure>
                </li>
              ))}
            </ul>
          ) : null}
        </div>

        {list.map((img, i) => {
          const n = i + 1;
          const prev = n === 1 ? total : n - 1;
          const next = n === total ? 1 : n + 1;
          return (
            <div
              key={`${img.imageUrl}-view-${i}`}
              id={`${uid}-view-${n}`}
              aria-label={`Photo ${n} of ${total}`}
              role="group"
              className="fixed inset-0 z-50 hidden flex-col bg-neutral-950/95 p-4 text-white target:flex sm:p-6"
            >
              <div className="flex items-center justify-between gap-4">
                <p className="text-sm text-neutral-300 tabular-nums">
                  {n} / {total}
                </p>
                <a
                  href={`#${uid}-thumb-${n}`}
                  className={`inline-flex min-h-11 items-center gap-2 rounded-lg px-3 text-sm font-semibold text-white hover:bg-white/10 ${linkRing}`}
                >
                  Close
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
                    <path d="M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z" />
                  </svg>
                </a>
              </div>

              <figure className="flex min-h-0 flex-1 flex-col items-center justify-center gap-4 py-4">
                <img src={img.imageUrl} alt={img.imageAlt || img.caption || `Photo ${n} of ${total}`} loading="lazy" className="min-h-0 max-w-full flex-1 rounded-lg object-contain" />
                {img.caption || img.credit ? (
                  <figcaption className="max-w-2xl text-center text-sm leading-6 text-pretty text-neutral-200">
                    {img.caption}
                    {img.caption && img.credit ? <span aria-hidden="true"> · </span> : null}
                    {img.credit ? <span className="text-neutral-400">{img.credit}</span> : null}
                  </figcaption>
                ) : null}
              </figure>

              {total > 1 ? (
                <nav aria-label="Gallery" className="flex items-center justify-between gap-4">
                  <a
                    href={`#${uid}-view-${prev}`}
                    className={`inline-flex min-h-11 items-center gap-2 rounded-lg px-3 text-sm font-semibold text-white ring-1 ring-white/20 hover:bg-white/10 ${linkRing}`}
                  >
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
                      <path fillRule="evenodd" d="M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z" clipRule="evenodd" />
                    </svg>
                    Previous<span className="sr-only"> photo</span>
                  </a>
                  <a
                    href={`#${uid}-view-${next}`}
                    className={`inline-flex min-h-11 items-center gap-2 rounded-lg px-3 text-sm font-semibold text-white ring-1 ring-white/20 hover:bg-white/10 ${linkRing}`}
                  >
                    Next<span className="sr-only"> photo</span>
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
                      <path fillRule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
                    </svg>
                  </a>
                </nav>
              ) : null}
            </div>
          );
        })}
      </section>
    );
  },
};
```
