# Add the "Horizontal Scroll Story" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/scroll-horizontal) to this Pantheon Content Publisher (P1) Next.js project. Big-number story chapters that pin and slide sideways as the page scrolls, with a progress line. Stacks on phones.

## Steps

1. Install the dependency: `pnpm add gsap` (use the project's package manager if it isn't pnpm).
2. Create these files with the exact contents below, in the same folder: `components/puck/scroll-horizontal-block.tsx`, `components/puck/scroll-horizontal.client.tsx`. If `components/puck/` doesn't exist, use the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`).
3. In `puck.config.tsx`, import it: `import { scrollHorizontalBlock } from "./components/puck/scroll-horizontal-block";`
4. Register it under `components` as `ScrollHorizontalBlock: scrollHorizontalBlock`.
5. Add `"ScrollHorizontalBlock"` to the best-fitting entry in `categories` (this block's library category is "Carousels"). Create a category only if none fits.
6. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
7. 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

- The block is two files: a server-safe Puck config and a `"use client"` island it imports by relative path. Keep both files in the same folder and keep the island's file name unchanged.
- WebGPU effects are progressive enhancement: content is server-rendered and a CSS fallback shows wherever WebGPU is unavailable. Don't move content into the client file.
- 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/scroll-horizontal-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { ScrollHorizontalStage } from "./scroll-horizontal.client";

/**
 * Horizontal Scroll Story — a row of big-number chapters that slides sideways while the page
 * scrolls down (pinned with GSAP ScrollTrigger), with a progress line. Phones, reduced motion
 * and no-JS get a plain stack or swipe row. Needs `pnpm add gsap` and scroll-horizontal.client.tsx.
 * Register: `ScrollHorizontalBlock: scrollHorizontalBlock` in puck.config.tsx.
 */

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

type Panel = {
  kicker: string;
  figure: string;
  unit: string;
  title: string;
  body: string;
  imageUrl: string;
  imageAlt: string;
};

export type ScrollHorizontalProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  panels: Panel[];
  footnote: string;
};

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

export const scrollHorizontalBlock: ComponentConfig<ScrollHorizontalProps> = {
  label: "Horizontal Scroll Story",
  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" },
    panels: {
      type: "array",
      label: "Chapters",
      min: 1,
      max: 8,
      getItemSummary: (item) => item?.title || item?.figure || "Chapter",
      defaultItemProps: {
        kicker: "Chapter",
        figure: "100",
        unit: "people reached",
        title: "What happened",
        body: "Two or three sentences on what this number means and who it reached.",
        imageUrl: "",
        imageAlt: "",
      },
      arrayFields: {
        kicker: { type: "text", label: "Kicker", metadata: { help: "Short label above the number, e.g. \"Chapter 1 · Winter\"." } },
        figure: { type: "text", label: "Big number", metadata: { help: "Keep it short: \"4,200\", \"92%\", \"1st\". Leave blank for a text-only chapter." } },
        unit: { type: "text", label: "Number label", metadata: { help: "What the number counts, e.g. \"meals delivered\"." } },
        title: { type: "text", label: "Title" },
        body: { type: "textarea", label: "Body" },
        imageUrl: { type: "text", label: "Image URL", metadata: { help: "Optional portrait photo (4:5). Leave blank for a text-only chapter." } },
        imageAlt: { type: "text", label: "Image description", metadata: { help: "Describe the photo for people who can't see it." } },
      },
    },
    footnote: { type: "text", label: "Source line", metadata: { help: "Where the numbers come from, e.g. \"Source: 2025 annual report\". Leave blank to hide it." } },
  },
  defaultProps: {
    eyebrow: "Westside Community Pantry · 2025",
    heading: "One year, in four chapters",
    headingLevel: "h2",
    intro: "From a church basement with two folding tables to a market-style pantry open six days a week. Keep scrolling.",
    panels: [
      {
        kicker: "Chapter 1 · Winter",
        figure: "38",
        unit: "volunteers on day one",
        title: "We opened the doors",
        body: "A cold January Saturday, a borrowed van and a line around the block. Neighbors showed up to help before we'd finished asking.",
        imageUrl: "https://picsum.photos/seed/pantrydoors/800/1000",
        imageAlt: "Volunteers in winter coats unloading boxes of produce from a van",
      },
      {
        kicker: "Chapter 2 · Spring",
        figure: "1,240",
        unit: "households registered",
        title: "Choice, not a box",
        body: "We switched to a market model, so families pick their own groceries. Waste fell, and so did the stigma of asking for help.",
        imageUrl: "https://picsum.photos/seed/pantryshelves/800/1000",
        imageAlt: "A shopper choosing vegetables from well-stocked pantry shelves",
      },
      {
        kicker: "Chapter 3 · Summer",
        figure: "9 tons",
        unit: "of fresh produce",
        title: "Growers came to us",
        body: "Twelve local farms began donating their seconds, and our cold room went from an afterthought to the heart of the building.",
        imageUrl: "https://picsum.photos/seed/farmcrates/800/1000",
        imageAlt: "Wooden crates of tomatoes, peppers and greens stacked on a loading dock",
      },
      {
        kicker: "Chapter 4 · Fall",
        figure: "6",
        unit: "days a week",
        title: "Open when people need us",
        body: "Evening and Saturday hours mean working parents no longer choose between a shift and a full fridge. Next up: a second site.",
        imageUrl: "https://picsum.photos/seed/pantrynight/800/1000",
        imageAlt: "The pantry's lit storefront on a dark evening with people inside",
      },
    ],
    footnote: "Sample figures for illustration. Source: Westside Community Pantry 2025 annual report.",
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, panels, footnote }) => {
    const H = headingLevel || "h2";
    const Sub = SUB[H] ?? "h3";
    const items = (panels ?? []).filter((p) => p && (p.figure || p.title || p.body));
    const headingId = `${id}-heading`;
    return (
      <section aria-labelledby={heading ? headingId : undefined} className="overflow-x-clip bg-neutral-50 py-16 sm:py-20 lg:py-24">
        <ScrollHorizontalStage count={items.length}>
          {eyebrow || heading || intro ? (
            <div className="mx-auto w-full max-w-7xl px-4 sm:px-6 lg:px-8">
              <div className="grid grid-cols-1 gap-4 lg:grid-cols-12 lg:items-end lg:gap-12">
                <div className="lg:col-span-7">
                  {eyebrow ? <p className="text-xs font-semibold tracking-widest text-indigo-700 uppercase sm:text-sm">{eyebrow}</p> : null}
                  {heading ? (
                    <H id={headingId} className="mt-3 text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-5xl">
                      {heading}
                    </H>
                  ) : null}
                </div>
                {intro ? <p className="text-base leading-7 text-pretty text-neutral-600 lg:col-span-5 lg:text-lg lg:leading-8">{intro}</p> : null}
              </div>
            </div>
          ) : null}
          {items.length ? (
            <div className="mx-auto mt-10 w-full max-w-7xl px-4 sm:mt-14 sm:px-6 lg:px-8">
              <ol
                data-track=""
                className="flex flex-col gap-12 md:snap-x md:snap-mandatory md:flex-row md:gap-0 relative md:overflow-x-auto md:overscroll-x-contain md:pb-4"
              >
                {items.map((panel, i) => (
                  <li
                    key={i}
                    data-panel=""
                    className="grid shrink-0 grid-cols-1 gap-6 border-t border-neutral-300 pt-6 md:w-4/5 md:snap-start md:grid-cols-5 md:gap-8 md:border-t-0 md:border-l md:pt-0 md:pr-10 md:pl-8 lg:w-3/5 xl:w-1/2"
                  >
                    <div className="flex flex-col md:col-span-3">
                      {panel.kicker ? <p className="text-xs font-semibold tracking-widest text-indigo-700 uppercase">{panel.kicker}</p> : null}
                      {panel.figure ? (
                        <p data-figure="" className="mt-4 text-6xl leading-none font-semibold tracking-tighter text-neutral-950 tabular-nums sm:text-7xl lg:text-8xl">
                          {panel.figure}
                        </p>
                      ) : null}
                      {panel.unit ? <p className="mt-3 text-base font-medium text-neutral-600">{panel.unit}</p> : null}
                      {panel.title ? <Sub className="mt-8 text-xl font-semibold tracking-tight text-neutral-950 sm:text-2xl">{panel.title}</Sub> : null}
                      {panel.body ? <p className="mt-3 max-w-md text-base leading-7 text-pretty text-neutral-600">{panel.body}</p> : null}
                    </div>
                    {panel.imageUrl ? (
                      <div className="aspect-4/5 max-w-xs overflow-hidden rounded-2xl bg-neutral-200 md:col-span-2 md:max-w-none md:self-end">
                        <img data-media="" src={panel.imageUrl} alt={panel.imageAlt || ""} loading="lazy" className="size-full object-cover" />
                      </div>
                    ) : null}
                  </li>
                ))}
              </ol>
            </div>
          ) : null}
          {footnote ? (
            <div className="mx-auto mt-10 w-full max-w-7xl px-4 sm:px-6 lg:px-8">
              <p className="text-xs text-neutral-600">{footnote}</p>
            </div>
          ) : null}
        </ScrollHorizontalStage>
      </section>
    );
  },
};
```

## File: `components/puck/scroll-horizontal.client.tsx`

```tsx
"use client";

import { useEffect, useLayoutEffect, useRef, useState } from "react";
import type { ReactNode } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";

/**
 * Motion half of the Horizontal Scroll Story. The chapters arrive server-rendered as a stack
 * (phones) or a swipeable row (tablet up). On wide screens without reduced motion this pins
 * the section and scrubs the row sideways with the page scroll, drifting each big number and
 * photo a little against it. Everything is undone when the media query stops matching.
 */

if (typeof window !== "undefined") gsap.registerPlugin(ScrollTrigger);

const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

type ScrollHorizontalStageProps = {
  count: number;
  children: ReactNode;
};

const pad = (n: number) => String(n).padStart(2, "0");

export function ScrollHorizontalStage({ count, children }: ScrollHorizontalStageProps) {
  const rootRef = useRef<HTMLDivElement>(null);
  const pinRef = useRef<HTMLDivElement>(null);
  const fillRef = useRef<HTMLDivElement>(null);
  const [pinned, setPinned] = useState(false);
  const [active, setActive] = useState(0);

  useIsoLayoutEffect(() => {
    const root = rootRef.current;
    const pin = pinRef.current;
    const track = pin?.querySelector<HTMLElement>("[data-track]");
    // Inside an editor iframe the page scroll belongs to another window; keep the static layout.
    if (!root || !pin || !track || count < 2 || root.ownerDocument !== document) return;

    const ctx = gsap.context(() => {
      const mm = gsap.matchMedia();
      mm.add("(min-width: 768px) and (prefers-reduced-motion: no-preference)", () => {
        const panels = Array.from(track.querySelectorAll<HTMLElement>("[data-panel]"));
        const n = panels.length;
        if (n < 2) return;
        const fill = fillRef.current;
        let last = -1;

        gsap.set(track, { overflow: "visible", scrollSnapType: "none", paddingBottom: 0 });
        gsap.set(pin, { minHeight: "100svh", display: "flex", flexDirection: "column", justifyContent: "center", overflow: "hidden", paddingTop: "3rem", paddingBottom: "6rem" });
        if (fill) gsap.set(fill, { scaleX: 0, transformOrigin: "0% 50%" });

        const distance = () => Math.max(0, track.scrollWidth - track.clientWidth);
        const row = gsap.to(track, {
          x: () => -distance(),
          ease: "none",
          scrollTrigger: {
            trigger: pin,
            pin: true,
            start: "top top",
            end: () => `+=${distance()}`,
            scrub: 0.8,
            anticipatePin: 1,
            invalidateOnRefresh: true,
            onUpdate: (self) => {
              if (fill) gsap.set(fill, { scaleX: self.progress });
              const i = Math.round(self.progress * (n - 1));
              if (i !== last) {
                last = i;
                setActive(i);
              }
            },
          },
        });

        panels.forEach((panel) => {
          const along = { trigger: panel, containerAnimation: row, start: "left right", end: "right left", scrub: true };
          const figure = panel.querySelector("[data-figure]");
          const media = panel.querySelector("[data-media]");
          if (figure) gsap.fromTo(figure, { xPercent: 10 }, { xPercent: -8, ease: "none", scrollTrigger: along });
          if (media) gsap.fromTo(media, { scale: 1.16, xPercent: -5 }, { scale: 1.02, xPercent: 5, ease: "none", scrollTrigger: { ...along } });
        });

        setPinned(true);
        return () => {
          setPinned(false);
          setActive(0);
        };
      });
    }, root);

    return () => ctx.revert();
  }, [count]);

  return (
    <div ref={rootRef}>
      <div ref={pinRef} className="relative">
        {children}
        {count > 1 ? (
          <div hidden={!pinned} aria-hidden="true" className="pointer-events-none absolute inset-x-0 bottom-6 lg:bottom-10">
            <div className="mx-auto flex max-w-7xl items-center gap-5 px-4 sm:px-6 lg:px-8">
              <p className="shrink-0 text-sm font-semibold text-neutral-950 tabular-nums">
                {pad(active + 1)} <span className="font-normal text-neutral-500">/ {pad(count)}</span>
              </p>
              <div className="relative h-px flex-1 bg-neutral-300">
                <div ref={fillRef} className="absolute inset-0 bg-indigo-600" />
                {Array.from({ length: count }, (_, k) => (
                  <span
                    key={k}
                    style={{ left: `${(k / (count - 1)) * 100}%` }}
                    className={`absolute top-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full ring-4 ring-neutral-50 transition-colors duration-500 ${k <= active ? "bg-indigo-600" : "bg-neutral-300"}`}
                  />
                ))}
              </div>
            </div>
          </div>
        ) : null}
      </div>
    </div>
  );
}
```
