# Add the "Pricing Toggle" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/pricing-toggle) to this Pantheon Content Publisher (P1) Next.js project. Plan or membership tiers with a monthly/annual switch built from radios and CSS :has(), plus a visible savings note.

## Steps

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

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

/**
 * Pricing Toggle — membership or plan tiers with a monthly/annual switch. The switch is two
 * radio buttons and CSS :has(), so prices change with no JavaScript.
 * Register: `PricingToggleBlock: pricingToggleBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";
type Billing = "monthly" | "annual";

type Tier = {
  name: string;
  description: string;
  monthlyPrice: string;
  annualPrice: string;
  annualNote: string;
  features: string;
  ctaLabel: string;
  ctaHref: string;
  featured: boolean;
  badge: string;
};

export type PricingToggleProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  monthlyLabel: string;
  annualLabel: string;
  savingsNote: string;
  defaultBilling: Billing;
  periodMonthly: string;
  tiers: Tier[];
  note: string;
};

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

// Annual is the second radio; these swap visibility when it's checked.
const showMonthly = "group-has-[[data-billing=annual]:checked]/billing:hidden";
const showAnnual = "hidden group-has-[[data-billing=annual]:checked]/billing:block";
const showAnnualFlex = "hidden group-has-[[data-billing=annual]:checked]/billing:flex";
const showMonthlyFlex = "flex group-has-[[data-billing=annual]:checked]/billing:hidden";

export const pricingToggleBlock: ComponentConfig<PricingToggleProps> = {
  label: "Pricing Toggle",
  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" },
    monthlyLabel: { type: "text", label: "Monthly option label" },
    annualLabel: { type: "text", label: "Annual option label" },
    savingsNote: { type: "text", label: "Savings note", metadata: { help: "Shown on the annual option and above the tiers when annual is picked, such as \"Save 16%\". Leave blank to hide it." } },
    defaultBilling: {
      type: "radio",
      label: "Selected at first",
      options: [
        { label: "Monthly", value: "monthly" },
        { label: "Annual", value: "annual" },
      ],
      metadata: { help: "Which prices visitors see before they touch the switch." },
    },
    periodMonthly: { type: "text", label: "Price suffix", metadata: { help: "Shown after every price, such as /month. Annual prices are shown per month too, so they compare fairly." } },
    tiers: {
      type: "array",
      label: "Tiers",
      min: 1,
      max: 4,
      getItemSummary: (item) => `${item?.name || "Tier"}${item?.featured ? " (featured)" : ""}`,
      defaultItemProps: {
        name: "New tier",
        description: "",
        monthlyPrice: "$30",
        annualPrice: "$25",
        annualNote: "$300 billed once a year",
        features: "First benefit\nSecond benefit",
        ctaLabel: "Choose plan",
        ctaHref: "/join",
        featured: false,
        badge: "",
      },
      arrayFields: {
        name: { type: "text", label: "Name" },
        description: { type: "textarea", label: "Description" },
        monthlyPrice: { type: "text", label: "Monthly price", metadata: { help: "Type it as it should appear, such as $30 or Free." } },
        annualPrice: { type: "text", label: "Annual price, per month", metadata: { help: "The monthly equivalent when paid yearly, such as $25." } },
        annualNote: { type: "text", label: "Annual billing note", metadata: { help: "Shown under the annual price, such as \"$300 billed once a year\"." } },
        features: { type: "textarea", label: "Benefits", metadata: { help: "One benefit per line." } },
        ctaLabel: { type: "text", label: "Button text" },
        ctaHref: { type: "text", label: "Button link", metadata: { help: "A path (/join), full URL or #anchor. Monthly and annual share the same link; add ?plan= on your checkout page if it needs to tell them apart." } },
        featured: {
          type: "radio",
          label: "Featured",
          options: [
            { label: "Yes", value: true },
            { label: "No", value: false },
          ],
          metadata: { help: "Highlights this tier. Feature one tier at most." },
        },
        badge: { type: "text", label: "Badge", metadata: { help: "Short label such as \"Most popular\". Leave blank to hide it." } },
      },
    },
    note: { type: "textarea", label: "Footnote", metadata: { help: "Small print under the tiers. Leave blank to hide it." } },
  },
  defaultProps: {
    heading: "Join the workshop",
    headingLevel: "h2",
    intro: "Membership opens the wood shop, print studio and textile room to anyone in the county. Sliding-scale rates are always available. Just ask at the front desk.",
    monthlyLabel: "Monthly",
    annualLabel: "Yearly",
    savingsNote: "Save 16%",
    defaultBilling: "monthly",
    periodMonthly: "/month",
    tiers: [
      {
        name: "Tinkerer",
        description: "Weekend access for people starting their first project.",
        monthlyPrice: "$25",
        annualPrice: "$21",
        annualNote: "$252 billed once a year",
        features: "Saturday and Sunday open shop\nHand tools and sewing machines\nOne intro class each quarter",
        ctaLabel: "Start tinkering",
        ctaHref: "/join?plan=tinkerer",
        featured: false,
        badge: "",
      },
      {
        name: "Maker",
        description: "Full-week access and the big machines, once you've passed a safety check.",
        monthlyPrice: "$45",
        annualPrice: "$38",
        annualNote: "$456 billed once a year",
        features: "Open shop seven days a week\nTable saw, laser cutter and kiln\nTwo guest passes a month\n15% off every class",
        ctaLabel: "Become a maker",
        ctaHref: "/join?plan=maker",
        featured: true,
        badge: "Most chosen",
      },
      {
        name: "Studio",
        description: "A dedicated bench for artists and small businesses building something bigger.",
        monthlyPrice: "$90",
        annualPrice: "$75",
        annualNote: "$900 billed once a year",
        features: "Everything in Maker\nReserved bench and locking storage\n24-hour keycard access\nListing in our artisan directory",
        ctaLabel: "Reserve a studio",
        ctaHref: "/join?plan=studio",
        featured: false,
        badge: "",
      },
    ],
    note: "Prices are sample rates. Members under 18 must bring a guardian. Need-based scholarships cover up to 100% of any tier.",
  },
  render: ({ id, heading, headingLevel, intro, monthlyLabel, annualLabel, savingsNote, defaultBilling, periodMonthly, tiers, note }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] || "h3";
    const uid = `pt-${id || "pricing"}`;
    const list = (tiers ?? []).filter((t) => t?.name);
    const annualFirst = defaultBilling === "annual";
    const cols = list.length >= 4 ? "lg:grid-cols-4" : list.length === 3 ? "lg:grid-cols-3" : list.length === 2 ? "md:grid-cols-2" : "";

    const option = (value: Billing, label: string) => (
      <label className="relative flex min-h-11 cursor-pointer items-center justify-center gap-2 rounded-full px-5 text-sm font-semibold text-neutral-700 transition select-none hover:text-neutral-950 has-checked:bg-neutral-950 has-checked:text-white has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-indigo-600">
        <input type="radio" name={`${uid}-billing`} value={value} data-billing={value} defaultChecked={annualFirst ? value === "annual" : value === "monthly"} className="sr-only" />
        {label}
        {value === "annual" && savingsNote ? (
          <span className="rounded-full bg-indigo-100 px-2 py-0.5 text-xs font-semibold text-indigo-800">{savingsNote}</span>
        ) : null}
      </label>
    );

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

          <fieldset className={`flex justify-center ${heading || intro ? "mt-10" : ""}`}>
            <legend className="sr-only">Billing period</legend>
            <div className="inline-flex flex-wrap justify-center gap-1 rounded-full bg-neutral-100 p-1 ring-1 ring-neutral-200">
              {option("monthly", monthlyLabel || "Monthly")}
              {option("annual", annualLabel || "Yearly")}
            </div>
          </fieldset>

          {list.length ? (
            <ul role="list" className={`mx-auto mt-12 grid max-w-md grid-cols-1 gap-6 sm:mt-14 md:max-w-none lg:items-start lg:gap-8 ${cols} ${list.length === 2 ? "md:max-w-4xl" : ""}`}>
              {list.map((tier, i) => {
                const featured = Boolean(tier.featured);
                const features = (tier.features || "")
                  .split("\n")
                  .map((f) => f.trim())
                  .filter(Boolean);
                const monthly = tier.monthlyPrice || "";
                const annual = tier.annualPrice || monthly;
                return (
                  <li
                    key={`${tier.name}-${i}`}
                    className={`relative flex h-full flex-col rounded-2xl p-7 sm:p-8 ${featured ? "bg-indigo-700 text-white shadow-xl shadow-indigo-900/20" : "bg-white ring-1 ring-neutral-200"}`}
                  >
                    <div className="flex flex-wrap items-center justify-between gap-3">
                      <Sub className={`text-lg leading-7 font-semibold ${featured ? "text-white" : "text-neutral-950"}`}>{tier.name}</Sub>
                      {tier.badge ? (
                        <p className={`rounded-full px-3 py-1 text-xs leading-5 font-semibold ${featured ? "bg-white/15 text-white ring-1 ring-white/25 ring-inset" : "bg-indigo-50 text-indigo-700 ring-1 ring-indigo-600/15 ring-inset"}`}>
                          {tier.badge}
                        </p>
                      ) : null}
                    </div>
                    {tier.description ? <p className={`mt-3 text-sm leading-6 text-pretty ${featured ? "text-indigo-100" : "text-neutral-600"}`}>{tier.description}</p> : null}

                    {monthly ? (
                      <div className="mt-7">
                        <p className={`items-baseline gap-x-1 ${showMonthlyFlex}`}>
                          <span className={`text-5xl font-semibold tracking-tight tabular-nums ${featured ? "text-white" : "text-neutral-950"}`}>{monthly}</span>
                          {periodMonthly ? <span className={`text-sm font-medium ${featured ? "text-indigo-100" : "text-neutral-600"}`}>{periodMonthly}</span> : null}
                        </p>
                        <p className={`items-baseline gap-x-1 ${showAnnualFlex}`}>
                          <span className={`text-5xl font-semibold tracking-tight tabular-nums ${featured ? "text-white" : "text-neutral-950"}`}>{annual}</span>
                          {periodMonthly ? <span className={`text-sm font-medium ${featured ? "text-indigo-100" : "text-neutral-600"}`}>{periodMonthly}</span> : null}
                          {annual !== monthly ? (
                            <span className={`ml-2 text-sm tabular-nums line-through ${featured ? "text-indigo-200" : "text-neutral-500"}`}>
                              <span className="sr-only">was </span>
                              {monthly}
                            </span>
                          ) : null}
                        </p>
                        <p className={`mt-1.5 min-h-6 text-sm leading-6 ${featured ? "text-indigo-100" : "text-neutral-600"}`}>
                          <span className={showMonthly}>Billed monthly, cancel any time</span>
                          <span className={showAnnual}>{tier.annualNote || "Billed once a year"}</span>
                        </p>
                      </div>
                    ) : null}

                    {tier.ctaLabel ? (
                      <a
                        href={tier.ctaHref || "#"}
                        className={`mt-7 flex min-h-11 items-center justify-center rounded-lg px-5 py-3 text-center text-base font-semibold transition focus-visible:outline-2 focus-visible:outline-offset-2 ${
                          featured
                            ? "bg-white text-indigo-700 shadow-xs hover:bg-indigo-50 focus-visible:outline-white"
                            : "bg-indigo-600 text-white shadow-xs hover:bg-indigo-700 focus-visible:outline-indigo-600"
                        }`}
                      >
                        {tier.ctaLabel}
                      </a>
                    ) : null}

                    {features.length ? (
                      <ul role="list" className={`mt-8 space-y-3 text-sm leading-6 ${featured ? "text-indigo-50" : "text-neutral-700"}`}>
                        {features.map((feature, j) => (
                          <li key={j} className="flex gap-x-3">
                            <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className={`h-6 w-5 flex-none ${featured ? "text-white" : "text-indigo-600"}`}>
                              <path fillRule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clipRule="evenodd" />
                            </svg>
                            {feature}
                          </li>
                        ))}
                      </ul>
                    ) : null}
                  </li>
                );
              })}
            </ul>
          ) : null}

          {note ? <p className="mx-auto mt-12 max-w-2xl text-center text-sm leading-6 text-pretty text-neutral-600">{note}</p> : null}
        </div>
      </section>
    );
  },
};
```
