{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sticky-feature",
  "type": "registry:block",
  "title": "Sticky Feature",
  "description": "A pinned left panel with a progress rail while numbered steps scroll past on the right.",
  "dependencies": [
    "svg-scroll-draw"
  ],
  "files": [
    {
      "path": "registry/blocks/sticky-feature.tsx",
      "content": "'use client';\n\n/**\n * sticky-feature — a left panel that stays in place while the steps on the\n * right scroll past it. The panel tracks the step in view and fills a progress\n * rail as the reader moves through the list.\n *\n * Built on svg-scroll-draw (MIT): https://svg-scroll-draw.vercel.app/blocks\n * Needs: react, svg-scroll-draw. Styling: Tailwind CSS.\n *\n * The pin is plain CSS `position: sticky` rather than `scrollPin`, because\n * scrollPin moves the element into a wrapper div and React expects to own that\n * node. Sticky does not work inside an ancestor with `overflow: hidden`, so keep\n * this block out of one. Below the `md` breakpoint it becomes a single column.\n *\n * Reduced motion is handled by the library: steps are shown at full opacity and\n * the rail is full. The active-step highlight is state, not motion, so it keeps\n * working either way.\n */\n\nimport { useEffect, useRef, useState } from 'react';\nimport { scrollAnimate } from 'svg-scroll-draw';\nimport { ScrollAnimate } from 'svg-scroll-draw/react';\n\nexport interface FeatureStep {\n  title: string;\n  body: string;\n}\n\nexport interface StickyFeatureProps {\n  eyebrow?: string;\n  heading?: string;\n  intro?: string;\n  steps?: FeatureStep[];\n  className?: string;\n}\n\nconst DEFAULT_STEPS: FeatureStep[] = [\n  { title: 'Install', body: 'Add one package. It has no dependencies of its own, so nothing else comes with it.' },\n  { title: 'Wrap', body: 'Put the component around the SVG or element you want to move.' },\n  { title: 'Tune', body: 'Pick an easing and a trigger window. The defaults are a good start.' },\n  { title: 'Ship', body: 'Server-rendered markup stays readable. The motion is added in the browser.' },\n];\n\nexport function StickyFeature({\n  eyebrow = 'How it works',\n  heading = 'Four steps from idea to motion',\n  intro = 'The panel stays put while the steps scroll by.',\n  steps = DEFAULT_STEPS,\n  className = '',\n}: StickyFeatureProps) {\n  const [active, setActive] = useState(0);\n  const listRef = useRef<HTMLOListElement>(null);\n  const railRef = useRef<HTMLSpanElement>(null);\n\n  // Progress rail: scales from 0 to 1 between the first step reaching the middle\n  // of the viewport and the last step being fully on screen. The rail sits inside\n  // the sticky panel, so its own position never changes; `triggerElement`\n  // measures the scrolling list instead.\n  useEffect(() => {\n    const list = listRef.current;\n    const rail = railRef.current;\n    if (!list || !rail) return;\n\n    const anim = scrollAnimate(rail, {\n      props: { transform: ['scaleY(0)', 'scaleY(1)'] },\n      triggerElement: list,\n      trigger: { start: 'top 60%', end: 'bottom 85%' },\n      easing: 'linear',\n    });\n    return () => anim.destroy();\n  }, []);\n\n  // Keyed on the titles, not the count: the list items are keyed by title, so\n  // the same number of renamed steps (a locale switch) replaces every <li>, and\n  // an observer kept on the old ones froze the highlight.\n  const titles = steps.map((s) => s.title).join('\\u0000');\n\n  // Active step: the last step with any part in the top half of the viewport.\n  // A set of visible steps, rather than a thin band, so a fast scroll that jumps\n  // a step straight past the middle still lands on the right one.\n  useEffect(() => {\n    const list = listRef.current;\n    if (!list || typeof IntersectionObserver === 'undefined') return;\n\n    const items = Array.from(list.querySelectorAll<HTMLElement>('[data-step]'));\n    const inView = new Set<number>();\n    const observer = new IntersectionObserver(\n      (entries) => {\n        for (const entry of entries) {\n          const index = Number((entry.target as HTMLElement).dataset.step);\n          if (entry.isIntersecting) inView.add(index);\n          else inView.delete(index);\n        }\n        if (inView.size) setActive(Math.max(...inView));\n      },\n      { rootMargin: '0px 0px -50% 0px' },\n    );\n    items.forEach((item) => observer.observe(item));\n    return () => observer.disconnect();\n  }, [titles]);\n\n  return (\n    <section className={`mx-auto grid w-full max-w-5xl gap-10 md:grid-cols-2 md:gap-16 ${className}`}>\n      {/* Pinned panel */}\n      <div className=\"md:sticky md:top-24 md:self-start\">\n        <p className=\"font-mono text-xs text-neutral-600 dark:text-neutral-400\">\n          {eyebrow}\n        </p>\n        <h2 className=\"mt-3 text-3xl font-medium tracking-tight text-neutral-950 sm:text-4xl dark:text-neutral-50\">\n          {heading}\n        </h2>\n        <p className=\"mt-3 text-neutral-600 dark:text-neutral-400\">{intro}</p>\n\n        <div className=\"mt-8 hidden gap-5 md:flex\">\n          <span className=\"relative w-1 shrink-0 overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-800\">\n            <span ref={railRef} className=\"absolute inset-0 origin-top bg-[#ff90e8]\" style={{ transform: 'scaleY(0)' }} />\n          </span>\n          <ol className=\"space-y-3\">\n            {steps.map((step, i) => (\n              <li\n                key={step.title}\n                aria-current={i === active ? 'step' : undefined}\n                className={`flex items-baseline gap-3 text-sm transition-colors duration-300 ${\n                  i === active\n                    ? 'font-semibold text-neutral-950 dark:text-neutral-50'\n                    : 'text-neutral-600 dark:text-neutral-400'\n                }`}\n              >\n                <span className=\"font-mono text-xs\">{String(i + 1).padStart(2, '0')}</span>\n                {step.title}\n              </li>\n            ))}\n          </ol>\n        </div>\n      </div>\n\n      {/* Scrolling steps */}\n      <ol ref={listRef} className=\"space-y-6 md:space-y-[30vh] md:py-[10vh]\">\n        {steps.map((step, i) => (\n          <li key={step.title} data-step={i}>\n            <ScrollAnimate\n              props={{ opacity: [0.3, 1], transform: ['translateY(24px)', 'translateY(0px)'] }}\n              trigger={{ start: 'top 85%', end: 'top 55%' }}\n              easing=\"ease-out\"\n              className=\"rounded-2xl border border-neutral-200 bg-white p-6 sm:p-8 dark:border-neutral-800 dark:bg-neutral-950\"\n            >\n              <span className=\"font-mono text-xs text-neutral-600 dark:text-neutral-400\">\n                Step {String(i + 1).padStart(2, '0')}\n              </span>\n              <h3 className=\"mt-2 text-xl font-semibold text-neutral-950 dark:text-neutral-50\">{step.title}</h3>\n              <p className=\"mt-2 leading-relaxed text-neutral-600 dark:text-neutral-400\">{step.body}</p>\n            </ScrollAnimate>\n          </li>\n        ))}\n      </ol>\n    </section>\n  );\n}\n\nexport default StickyFeature;\n",
      "type": "registry:component",
      "target": "components/scroll/sticky-feature.tsx"
    }
  ],
  "categories": [
    "scroll",
    "features"
  ]
}
