# Add the "Product Grid" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/product-grid) to this Pantheon Content Publisher (P1) Next.js project. Shop items as photo cards with price, sale price and badge, plus an optional one-tap add-to-cart form that posts the SKU.

## Steps

1. Create `components/puck/product-grid-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 { productGridBlock } from "./components/puck/product-grid-block";`
3. Register it under `components` as `ProductGridBlock: productGridBlock`.
4. Add `"ProductGridBlock"` to the best-fitting entry in `categories` (this block's library category is "Ecommerce"). 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/product-grid-block.tsx`

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

/**
 * Product Grid — shop items as photo cards with price, sale price, badge and an optional
 * one-tap add-to-cart form that posts sku and quantity to your cart. No JavaScript.
 * Register: `ProductGridBlock: productGridBlock` in puck.config.tsx.
 */

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

type Product = {
  name: string;
  price: string;
  compareAt: string;
  badge: string;
  note: string;
  href: string;
  sku: string;
  imageUrl: string;
  imageAlt: string;
};

export type ProductGridProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  columns: "3" | "4";
  quickAdd: boolean;
  cartAction: string;
  addLabel: string;
  products: Product[];
  viewAllLabel: string;
  viewAllHref: string;
  footnote: string;
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };

const colClass: Record<string, string> = {
  "3": "sm:grid-cols-2 lg:grid-cols-3",
  "4": "sm:grid-cols-2 lg:grid-cols-4",
};

export const productGridBlock: ComponentConfig<ProductGridProps> = {
  label: "Product Grid",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. Leave blank to hide it." } },
    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 on wide screens",
      options: [
        { label: "Three", value: "3" },
        { label: "Four", value: "4" },
      ],
      metadata: { help: "Phones show one column and tablets two, whatever you pick." },
    },
    quickAdd: {
      type: "radio",
      label: "Quick add-to-cart",
      options: [
        { label: "Show", value: true },
        { label: "Hide", value: false },
      ],
      metadata: { help: "Adds a button to each card that puts one of the item in the cart. Items need a SKU." },
    },
    cartAction: {
      type: "text",
      label: "Cart URL",
      metadata: { help: "Where the add-to-cart button posts. Sent with POST using the field names sku and quantity." },
    },
    addLabel: { type: "text", label: "Add button text" },
    products: {
      type: "array",
      label: "Products",
      min: 1,
      max: 12,
      getItemSummary: (item) => item?.name || "Product",
      defaultItemProps: { name: "New product", price: "$20.00", compareAt: "", badge: "", note: "", href: "#", sku: "", imageUrl: "https://picsum.photos/seed/shopitem/800/1000", imageAlt: "" },
      arrayFields: {
        name: { type: "text", label: "Name" },
        price: { type: "text", label: "Price", metadata: { help: "Shown as typed, such as $24.00. Can be bound to a data source." } },
        compareAt: { type: "text", label: "Original price", metadata: { help: "Shown struck through beside the price when the item is on sale. Leave blank otherwise." } },
        badge: { type: "text", label: "Badge", metadata: { help: "A short tag such as \"Member favorite\" or \"Made locally\". Leave blank to hide it." } },
        note: { type: "text", label: "Short note", metadata: { help: "One line under the name, such as the color or maker." } },
        href: { type: "text", label: "Product link" },
        sku: { type: "text", label: "SKU", metadata: { help: "Sent to the cart by the quick add button. Leave blank to hide the button on this card." } },
        imageUrl: { type: "text", label: "Image URL" },
        imageAlt: { type: "text", label: "Image alt text", metadata: { help: "Describe the item. The product name is already read out, so add what the photo shows." } },
      },
    },
    viewAllLabel: { type: "text", label: "View all link text", metadata: { help: "Leave blank to hide the link." } },
    viewAllHref: { type: "text", label: "View all link URL" },
    footnote: { type: "text", label: "Footnote", metadata: { help: "Small print under the grid, such as a member discount note. Leave blank to hide it." } },
  },
  defaultProps: {
    eyebrow: "The Museum Store",
    heading: "Field-guide finds for curious minds",
    headingLevel: "h2",
    intro: "Every purchase funds specimen care and free school field trips. Members save 10% on everything in the shop.",
    columns: "4",
    quickAdd: true,
    cartAction: "/shop/cart",
    addLabel: "Add to cart",
    products: [
      {
        name: "Trilobite Fossil Cast",
        price: "$28.00",
        compareAt: "",
        badge: "Member favorite",
        note: "Resin replica, cast from our collection",
        href: "/shop/trilobite-cast",
        sku: "NHM-1042",
        imageUrl: "https://picsum.photos/seed/trilobite/800/1000",
        imageAlt: "Gray ribbed fossil replica resting on a linen cloth",
      },
      {
        name: "Ohio Valley Birds Field Guide",
        price: "$18.00",
        compareAt: "$24.00",
        badge: "",
        note: "Paperback, 212 pages",
        href: "/shop/ohio-valley-birds",
        sku: "NHM-2210",
        imageUrl: "https://picsum.photos/seed/fieldguide/800/1000",
        imageAlt: "Pocket-sized bird guide open to a page of warbler illustrations",
      },
      {
        name: "Mineral Discovery Kit",
        price: "$34.00",
        compareAt: "",
        badge: "Ages 8+",
        note: "Twelve specimens with an ID chart",
        href: "/shop/mineral-kit",
        sku: "NHM-3307",
        imageUrl: "https://picsum.photos/seed/minerals/800/1000",
        imageAlt: "Wooden tray of labeled quartz, pyrite and amethyst samples",
      },
      {
        name: "Mammoth Tusk Enamel Mug",
        price: "$16.00",
        compareAt: "",
        badge: "Made locally",
        note: "Speckled cream, 12 oz",
        href: "/shop/mammoth-mug",
        sku: "NHM-4115",
        imageUrl: "https://picsum.photos/seed/enamelmug/800/1000",
        imageAlt: "Cream enamel camp mug printed with a line drawing of a mammoth",
      },
    ],
    viewAllLabel: "Shop all 140 items",
    viewAllHref: "/shop",
    footnote: "Prices shown are sample data. Member discount is applied at checkout.",
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, columns, quickAdd, cartAction, addLabel, products, viewAllLabel, viewAllHref, footnote }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] || "h3";
    const uid = `pg-${id || "grid"}`;
    const list = (products ?? []).filter((p) => p?.name);
    const showAdd = quickAdd !== false;
    const hasHeader = Boolean(eyebrow || heading || intro || viewAllLabel);

    return (
      <section 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">
          {hasHeader ? (
            <div className="flex flex-col gap-6 sm:flex-row sm:items-end sm:justify-between">
              <div className="max-w-2xl">
                {eyebrow ? <p className="text-sm font-semibold tracking-wide text-indigo-700 uppercase">{eyebrow}</p> : null}
                {heading ? (
                  <H id={`${uid}-h`} className={`text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl ${eyebrow ? "mt-3" : ""}`}>
                    {heading}
                  </H>
                ) : null}
                {intro ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
              </div>
              {viewAllLabel ? (
                <a
                  href={viewAllHref || "#"}
                  className="group inline-flex min-h-11 shrink-0 items-center gap-1.5 self-start rounded px-1 text-base font-semibold text-indigo-700 hover:text-indigo-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:self-auto"
                >
                  {viewAllLabel}
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 transition group-hover:translate-x-0.5">
                    <path fillRule="evenodd" d="M3 10a.75.75 0 0 1 .75-.75h10.64l-3.22-3.22a.75.75 0 1 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06l3.22-3.22H3.75A.75.75 0 0 1 3 10Z" clipRule="evenodd" />
                  </svg>
                </a>
              ) : null}
            </div>
          ) : null}

          {list.length ? (
            <ul role="list" aria-labelledby={heading ? `${uid}-h` : undefined} className={`grid grid-cols-1 gap-x-6 gap-y-12 ${colClass[columns] || colClass["4"]} ${hasHeader ? "mt-12" : ""}`}>
              {list.map((p, i) => {
                const onSale = Boolean(p.compareAt);
                return (
                  <li key={`${p.name}-${i}`} className="group relative flex flex-col">
                    <div className="relative overflow-hidden rounded-2xl bg-neutral-100 ring-1 ring-neutral-950/5">
                      {p.imageUrl ? (
                        <img src={p.imageUrl} alt={p.imageAlt || ""} className="aspect-4/5 w-full object-cover transition duration-500 group-hover:scale-105" />
                      ) : (
                        <div aria-hidden="true" className="aspect-4/5 w-full bg-neutral-100" />
                      )}
                      {p.badge ? (
                        <p className="absolute top-3 left-3 rounded-full bg-white/95 px-3 py-1 text-xs leading-5 font-semibold text-neutral-950 shadow-xs ring-1 ring-neutral-950/5">
                          {p.badge}
                        </p>
                      ) : null}
                    </div>
                    <div className="mt-4 flex flex-1 flex-col">
                      <div className="flex items-start justify-between gap-4">
                        <Sub className="text-base leading-6 font-semibold text-neutral-950">
                          <a href={p.href || "#"} className="rounded-sm focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-indigo-600">
                            {/* Stretched link: the whole card opens the product, while the quick-add form sits above it. */}
                            <span aria-hidden="true" className="absolute inset-0" />
                            {p.name}
                          </a>
                        </Sub>
                        {p.price ? (
                          <p className="shrink-0 text-right text-base leading-6 tabular-nums">
                            {onSale ? (
                              <>
                                <span className="sr-only">Sale price </span>
                                <span className="font-semibold text-indigo-700">{p.price}</span>
                                <span className="sr-only">, was </span>
                                <s className="block text-sm text-neutral-600">{p.compareAt}</s>
                              </>
                            ) : (
                              <span className="font-semibold text-neutral-950">{p.price}</span>
                            )}
                          </p>
                        ) : null}
                      </div>
                      {p.note ? <p className="mt-1 text-sm leading-6 text-neutral-600">{p.note}</p> : null}
                      {showAdd && p.sku ? (
                        <form action={cartAction || undefined} method="post" className="relative z-10 mt-auto pt-4">
                          <input type="hidden" name="sku" value={p.sku} />
                          <input type="hidden" name="quantity" value="1" />
                          <button
                            type="submit"
                            className="inline-flex min-h-11 w-full items-center justify-center gap-2 rounded-lg bg-white px-4 py-2.5 text-sm font-semibold text-neutral-950 ring-1 ring-neutral-300 transition ring-inset hover:bg-neutral-950 hover:text-white hover:ring-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                          >
                            <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4">
                              <path d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z" />
                            </svg>
                            {addLabel || "Add to cart"}
                            <span className="sr-only">: {p.name}</span>
                          </button>
                        </form>
                      ) : null}
                    </div>
                  </li>
                );
              })}
            </ul>
          ) : null}

          {footnote ? <p className="mt-12 border-t border-neutral-200 pt-6 text-sm leading-6 text-neutral-600">{footnote}</p> : null}
        </div>
      </section>
    );
  },
};
```
