# Add the "Checkout Form" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/checkout-form) to this Pantheon Content Publisher (P1) Next.js project. Contact, shipping, delivery method and billing beside an order summary. Card entry is left to your payment processor.

## Steps

1. Create `components/puck/checkout-form-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 { checkoutFormBlock } from "./components/puck/checkout-form-block";`
3. Register it under `components` as `CheckoutFormBlock: checkoutFormBlock`.
4. Add `"CheckoutFormBlock"` 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/checkout-form-block.tsx`

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

/**
 * Checkout Form — contact, shipping address, delivery method, billing and order notes beside an
 * order summary, posting to your order endpoint. It never collects card data: payment must go
 * through the site's payment processor (hosted fields or a redirect after this step).
 * Register: `CheckoutFormBlock: checkoutFormBlock` in puck.config.tsx.
 */

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

type Delivery = { name: string; detail: string; price: string };
type OrderItem = { name: string; detail: string; price: string; imageUrl: string; imageAlt: string };
type SummaryRow = { label: string; value: string };

export type CheckoutFormProps = {
  heading: string;
  headingLevel: Heading;
  formAction: string;
  countries: string;
  deliveryOptions: Delivery[];
  paymentHeading: string;
  paymentNote: string;
  submitLabel: string;
  termsNote: string;
  summaryHeading: string;
  items: OrderItem[];
  rows: SummaryRow[];
  totalLabel: string;
  total: string;
};

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

const inputClass =
  "block min-h-11 w-full rounded-lg border-0 bg-white px-3.5 py-2.5 text-base text-neutral-950 shadow-xs ring-1 ring-neutral-300 ring-inset placeholder:text-neutral-500 focus:ring-2 focus:ring-indigo-600 focus:outline-none";
const labelClass = "block text-sm leading-6 font-medium text-neutral-900";
const legendClass = "text-lg leading-7 font-semibold text-neutral-950";
const optional = <span className="font-normal text-neutral-600">(optional)</span>;

const Chevron = () => (
  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="pointer-events-none absolute top-1/2 right-3 size-5 -translate-y-1/2 text-neutral-500">
    <path fillRule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
  </svg>
);

export const checkoutFormBlock: ComponentConfig<CheckoutFormProps> = {
  label: "Checkout Form",
  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." },
    },
    formAction: {
      type: "text",
      label: "Order URL",
      metadata: {
        help: "Where the order details post before payment. Your handler should then hand off to your payment processor's hosted page or fields. This form never collects card numbers.",
      },
    },
    countries: { type: "textarea", label: "Countries", metadata: { help: "One per line, in the order shown. The first is selected at first." } },
    deliveryOptions: {
      type: "array",
      label: "Delivery methods",
      min: 1,
      max: 5,
      getItemSummary: (item) => `${item?.name || "Method"}${item?.price ? ` · ${item.price}` : ""}`,
      defaultItemProps: { name: "Express", detail: "1–2 business days", price: "$18.00" },
      arrayFields: {
        name: { type: "text", label: "Name" },
        detail: { type: "text", label: "Detail", metadata: { help: "Such as the delivery window." } },
        price: { type: "text", label: "Price", metadata: { help: "Shown as typed, such as $6.95 or Free. Can be bound to a data source." } },
      },
      metadata: { help: "The first method is selected at first. Sent as delivery_method." },
    },
    paymentHeading: { type: "text", label: "Payment heading" },
    paymentNote: {
      type: "textarea",
      label: "Payment note",
      metadata: { help: "Explains where card details are entered. Payment must happen on your processor's secure page or fields, never in this form." },
    },
    submitLabel: { type: "text", label: "Button text" },
    termsNote: { type: "textarea", label: "Terms note", metadata: { help: "Small print under the button. Leave blank to hide it." } },
    summaryHeading: { type: "text", label: "Summary heading" },
    items: {
      type: "array",
      label: "Order items",
      min: 0,
      max: 20,
      getItemSummary: (item) => item?.name || "Item",
      defaultItemProps: { name: "New item", detail: "Qty 1", price: "$10.00", imageUrl: "https://picsum.photos/seed/orderitem/200/200", imageAlt: "" },
      arrayFields: {
        name: { type: "text", label: "Name" },
        detail: { type: "text", label: "Detail", metadata: { help: "Options and quantity, such as \"Forest green · Qty 2\"." } },
        price: { type: "text", label: "Line total" },
        imageUrl: { type: "text", label: "Image URL" },
        imageAlt: { type: "text", label: "Image alt text", metadata: { help: "Leave blank if the photo only repeats the item name." } },
      },
      metadata: { help: "Usually bound to your cart data source." },
    },
    rows: {
      type: "array",
      label: "Summary rows",
      min: 0,
      max: 8,
      getItemSummary: (item) => `${item?.label || "Row"}: ${item?.value || "—"}`,
      defaultItemProps: { label: "Shipping", value: "$0.00" },
      arrayFields: {
        label: { type: "text", label: "Label" },
        value: { type: "text", label: "Amount" },
      },
    },
    totalLabel: { type: "text", label: "Total label" },
    total: { type: "text", label: "Total", metadata: { help: "Shown as typed. Can be bound to a data source." } },
  },
  defaultProps: {
    heading: "Checkout",
    headingLevel: "h2",
    formAction: "/shop/checkout/order",
    countries: "United States\nCanada",
    deliveryOptions: [
      { name: "Standard", detail: "4–6 business days", price: "Free" },
      { name: "Express", detail: "1–2 business days", price: "$18.00" },
      { name: "Pick up at the Museum Store", detail: "Ready in 2 hours during open hours", price: "Free" },
    ],
    paymentHeading: "Payment",
    paymentNote: "After you review your order, you'll enter your card or digital wallet on our payment provider's secure page. We never see or store your full card number.",
    submitLabel: "Review and pay",
    termsNote: "By placing your order you agree to our shop terms and 30-day return policy. Purchases support specimen care and free school field trips.",
    summaryHeading: "Order summary",
    items: [
      { name: "Herbarium Canvas Tote", detail: "Forest green · Qty 1", price: "$32.00", imageUrl: "https://picsum.photos/seed/canvastote/200/200", imageAlt: "" },
      { name: "Mineral Discovery Kit", detail: "Qty 2", price: "$68.00", imageUrl: "https://picsum.photos/seed/minerals/200/200", imageAlt: "" },
      { name: "Ohio Valley Birds Field Guide", detail: "Paperback · Qty 1", price: "$18.00", imageUrl: "https://picsum.photos/seed/fieldguide/200/200", imageAlt: "" },
    ],
    rows: [
      { label: "Subtotal", value: "$118.00" },
      { label: "Member discount", value: "−$11.80" },
      { label: "Shipping", value: "Free" },
      { label: "Estimated tax", value: "$6.37" },
    ],
    totalLabel: "Total (sample)",
    total: "$112.57",
  },
  render: ({ id, heading, headingLevel, formAction, countries, deliveryOptions, paymentHeading, paymentNote, submitLabel, termsNote, summaryHeading, items, rows, totalLabel, total }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] || "h3";
    const uid = `co-${id || "checkout"}`;
    const countryList = (countries || "").split("\n").map((c) => c.trim()).filter(Boolean);
    const methods = (deliveryOptions ?? []).filter((d) => d?.name);
    const lines = (items ?? []).filter((it) => it?.name);
    const summary = (rows ?? []).filter((r) => r?.label);
    const hasSummary = Boolean(summaryHeading || lines.length || summary.length || total);

    return (
      <section className="bg-neutral-50 px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-6xl">
          {heading ? <H className="text-3xl font-semibold tracking-tight text-neutral-950 sm:text-4xl">{heading}</H> : null}

          <div className={`grid grid-cols-1 items-start gap-10 lg:grid-cols-12 lg:gap-12 ${heading ? "mt-10" : ""}`}>
            {hasSummary ? (
              <aside
                aria-labelledby={summaryHeading ? `${uid}-summary` : undefined}
                aria-label={summaryHeading ? undefined : "Order summary"}
                className="rounded-2xl bg-white p-6 ring-1 ring-neutral-200 sm:p-8 lg:sticky lg:top-8 lg:col-span-5 lg:col-start-8 lg:row-start-1"
              >
                {summaryHeading ? (
                  <Sub id={`${uid}-summary`} className="text-lg leading-7 font-semibold text-neutral-950">
                    {summaryHeading}
                  </Sub>
                ) : null}
                {lines.length ? (
                  <ul role="list" className={`divide-y divide-neutral-200 ${summaryHeading ? "mt-4" : ""}`}>
                    {lines.map((it, i) => (
                      <li key={`${it.name}-${i}`} className="flex items-center gap-4 py-4">
                        {it.imageUrl ? <img src={it.imageUrl} alt={it.imageAlt || ""} className="size-16 shrink-0 rounded-lg bg-neutral-100 object-cover ring-1 ring-neutral-950/5" /> : null}
                        <div className="min-w-0 flex-1">
                          <p className="text-sm leading-6 font-semibold text-neutral-950">{it.name}</p>
                          {it.detail ? <p className="text-sm leading-5 text-neutral-600">{it.detail}</p> : null}
                        </div>
                        {it.price ? <p className="shrink-0 text-sm font-medium text-neutral-950 tabular-nums">{it.price}</p> : null}
                      </li>
                    ))}
                  </ul>
                ) : null}
                {summary.length || total ? (
                  <dl className="mt-2 space-y-3 border-t border-neutral-200 pt-6 text-sm">
                    {summary.map((r, i) => (
                      <div key={`${r.label}-${i}`} className="flex items-baseline justify-between gap-4">
                        <dt className="text-neutral-600">{r.label}</dt>
                        <dd className="font-medium text-neutral-950 tabular-nums">{r.value || "—"}</dd>
                      </div>
                    ))}
                    {total ? (
                      <div className="flex items-baseline justify-between gap-4 border-t border-neutral-200 pt-4">
                        <dt className="text-base font-semibold text-neutral-950">{totalLabel || "Total"}</dt>
                        <dd className="text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums">{total}</dd>
                      </div>
                    ) : null}
                  </dl>
                ) : null}
              </aside>
            ) : null}

            <form action={formAction || undefined} method="post" className={`space-y-10 ${hasSummary ? "lg:col-span-7 lg:row-start-1" : "lg:col-span-8 lg:col-start-3"}`}>
              <p className="text-sm leading-6 text-neutral-600">All fields are required unless marked optional.</p>

              <fieldset>
                <legend className={legendClass}>Contact</legend>
                <div className="mt-4 grid grid-cols-1 gap-6 sm:grid-cols-2">
                  <div>
                    <label htmlFor={`${uid}-email`} className={labelClass}>Email</label>
                    <input id={`${uid}-email`} name="email" type="email" required autoComplete="email" inputMode="email" aria-describedby={`${uid}-email-hint`} className={`mt-2 ${inputClass}`} />
                    <p id={`${uid}-email-hint`} className="mt-2 text-sm leading-6 text-neutral-600">
                      For your receipt and shipping updates.
                    </p>
                  </div>
                  <div>
                    <label htmlFor={`${uid}-phone`} className={labelClass}>
                      Phone {optional}
                    </label>
                    <input id={`${uid}-phone`} name="phone" type="tel" autoComplete="tel" inputMode="tel" className={`mt-2 ${inputClass}`} />
                  </div>
                </div>
              </fieldset>

              <fieldset>
                <legend className={legendClass}>Shipping address</legend>
                <div className="mt-4 grid grid-cols-1 gap-6 sm:grid-cols-6">
                  <div className="sm:col-span-3">
                    <label htmlFor={`${uid}-first`} className={labelClass}>First name</label>
                    <input id={`${uid}-first`} name="shipping_first_name" type="text" required autoComplete="shipping given-name" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-3">
                    <label htmlFor={`${uid}-last`} className={labelClass}>Last name</label>
                    <input id={`${uid}-last`} name="shipping_last_name" type="text" required autoComplete="shipping family-name" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-6">
                    <label htmlFor={`${uid}-line1`} className={labelClass}>Street address</label>
                    <input id={`${uid}-line1`} name="shipping_address1" type="text" required autoComplete="shipping address-line1" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-6">
                    <label htmlFor={`${uid}-line2`} className={labelClass}>
                      Apartment, suite or unit {optional}
                    </label>
                    <input id={`${uid}-line2`} name="shipping_address2" type="text" autoComplete="shipping address-line2" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-2">
                    <label htmlFor={`${uid}-city`} className={labelClass}>City</label>
                    <input id={`${uid}-city`} name="shipping_city" type="text" required autoComplete="shipping address-level2" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-2">
                    <label htmlFor={`${uid}-state`} className={labelClass}>State or province</label>
                    <input id={`${uid}-state`} name="shipping_state" type="text" required autoComplete="shipping address-level1" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-2">
                    <label htmlFor={`${uid}-zip`} className={labelClass}>ZIP or postal code</label>
                    <input id={`${uid}-zip`} name="shipping_postal_code" type="text" required autoComplete="shipping postal-code" className={`mt-2 ${inputClass}`} />
                  </div>
                  {countryList.length ? (
                    <div className="sm:col-span-6">
                      <label htmlFor={`${uid}-country`} className={labelClass}>Country</label>
                      <div className="relative mt-2">
                        <select id={`${uid}-country`} name="shipping_country" required autoComplete="shipping country-name" defaultValue={countryList[0]} className={`appearance-none pr-10 ${inputClass}`}>
                          {countryList.map((c, i) => (
                            <option key={`${c}-${i}`} value={c}>
                              {c}
                            </option>
                          ))}
                        </select>
                        <Chevron />
                      </div>
                    </div>
                  ) : null}
                </div>
              </fieldset>

              {methods.length ? (
                <fieldset>
                  <legend className={legendClass}>Delivery method</legend>
                  <div className="mt-4 grid grid-cols-1 gap-3 sm:grid-cols-2">
                    {methods.map((m, i) => (
                      <label
                        key={`${m.name}-${i}`}
                        className="relative flex min-h-16 cursor-pointer items-start justify-between gap-4 rounded-xl bg-white px-4 py-3 ring-1 ring-neutral-300 transition select-none ring-inset hover:ring-indigo-400 has-checked:bg-indigo-50 has-checked:ring-2 has-checked:ring-indigo-600 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-indigo-600"
                      >
                        <input type="radio" name="delivery_method" value={m.name} required defaultChecked={i === 0} className="sr-only" />
                        <span className="min-w-0">
                          <span className="block text-sm leading-6 font-semibold text-neutral-950">{m.name}</span>
                          {m.detail ? <span className="block text-sm leading-5 text-neutral-600">{m.detail}</span> : null}
                        </span>
                        {m.price ? <span className="shrink-0 text-sm leading-6 font-semibold text-neutral-950 tabular-nums">{m.price}</span> : null}
                      </label>
                    ))}
                  </div>
                </fieldset>
              ) : null}

              <fieldset className="group/billing">
                <legend className={legendClass}>Billing address</legend>
                <div className="mt-3 flex gap-3">
                  <div className="flex h-11 shrink-0 items-center">
                    <input
                      id={`${uid}-same`}
                      name="billing_same_as_shipping"
                      type="checkbox"
                      value="yes"
                      defaultChecked
                      aria-controls={`${uid}-billing`}
                      className="size-5 rounded border-neutral-400 accent-indigo-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                    />
                  </div>
                  <label htmlFor={`${uid}-same`} className="flex min-h-11 cursor-pointer items-center text-sm leading-6 font-medium text-neutral-900">
                    Same as shipping address
                  </label>
                </div>
                <div id={`${uid}-billing`} className="mt-4 grid grid-cols-1 gap-6 rounded-xl bg-white p-4 ring-1 ring-neutral-200 group-has-checked/billing:hidden sm:grid-cols-6 sm:p-6">
                  <p className="text-sm leading-6 text-neutral-600 sm:col-span-6">Fill these in only if your card's billing address is different.</p>
                  <div className="sm:col-span-6">
                    <label htmlFor={`${uid}-bname`} className={labelClass}>Name on card</label>
                    <input id={`${uid}-bname`} name="billing_name" type="text" autoComplete="billing name" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-6">
                    <label htmlFor={`${uid}-bline1`} className={labelClass}>Street address</label>
                    <input id={`${uid}-bline1`} name="billing_address1" type="text" autoComplete="billing address-line1" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-2">
                    <label htmlFor={`${uid}-bcity`} className={labelClass}>City</label>
                    <input id={`${uid}-bcity`} name="billing_city" type="text" autoComplete="billing address-level2" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-2">
                    <label htmlFor={`${uid}-bstate`} className={labelClass}>State or province</label>
                    <input id={`${uid}-bstate`} name="billing_state" type="text" autoComplete="billing address-level1" className={`mt-2 ${inputClass}`} />
                  </div>
                  <div className="sm:col-span-2">
                    <label htmlFor={`${uid}-bzip`} className={labelClass}>ZIP or postal code</label>
                    <input id={`${uid}-bzip`} name="billing_postal_code" type="text" autoComplete="billing postal-code" className={`mt-2 ${inputClass}`} />
                  </div>
                </div>
              </fieldset>

              <section aria-labelledby={`${uid}-pay`} className="rounded-xl border-2 border-dashed border-neutral-300 bg-white p-5 sm:p-6">
                <div className="flex items-start gap-4">
                  <span className="flex size-11 shrink-0 items-center justify-center rounded-full bg-indigo-50 ring-1 ring-indigo-600/10">
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 text-indigo-600">
                      <path fillRule="evenodd" d="M10 1a4.5 4.5 0 0 0-4.5 4.5V9H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2h-.5V5.5A4.5 4.5 0 0 0 10 1Zm3 8V5.5a3 3 0 1 0-6 0V9h6Z" clipRule="evenodd" />
                    </svg>
                  </span>
                  <div className="min-w-0">
                    <Sub id={`${uid}-pay`} className={legendClass}>
                      {paymentHeading || "Payment"}
                    </Sub>
                    <p className="mt-1 text-sm leading-6 text-pretty text-neutral-600">
                      {paymentNote || "You'll enter payment details on our payment provider's secure page after this step."}
                    </p>
                  </div>
                </div>
              </section>

              <div>
                <label htmlFor={`${uid}-notes`} className={labelClass}>
                  Order notes or gift message {optional}
                </label>
                <textarea id={`${uid}-notes`} name="order_notes" rows={3} maxLength={500} aria-describedby={`${uid}-notes-hint`} className={`mt-2 ${inputClass}`} />
                <p id={`${uid}-notes-hint`} className="mt-2 text-sm leading-6 text-neutral-600">
                  Up to 500 characters. Gift messages are printed on a card; prices are left off the packing slip.
                </p>
              </div>

              <div className="border-t border-neutral-200 pt-8">
                <button
                  type="submit"
                  className="inline-flex min-h-12 w-full items-center justify-center gap-2 rounded-lg bg-indigo-600 px-6 py-3 text-base font-semibold text-white shadow-xs transition hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                >
                  {submitLabel || "Review and pay"}
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-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>
                </button>
                {termsNote ? <p className="mt-4 text-xs leading-5 text-pretty text-neutral-600">{termsNote}</p> : null}
              </div>
            </form>
          </div>
        </div>
      </section>
    );
  },
};
```
